72 lines
2.5 KiB
TypeScript
72 lines
2.5 KiB
TypeScript
import { Component, OnInit, ViewChild } from '@angular/core';
|
|
import { MatButton } from '@angular/material/button';
|
|
import { ActivatedRoute, Router } from '@angular/router';
|
|
import { OverheadAdvanceService } from '../data-object-service';
|
|
import { NULL_OverheadAdvance, OverheadAdvance } from '../data-objects';
|
|
import { MessageService } from '../message.service';
|
|
|
|
@Component({
|
|
selector: 'app-overhead-advance-details',
|
|
templateUrl: './overhead-advance-details.component.html',
|
|
styleUrls: ['./overhead-advance-details.component.css']
|
|
})
|
|
export class OverheadAdvanceDetailsComponent implements OnInit {
|
|
|
|
@ViewChild('submitButton') submitButton: MatButton
|
|
|
|
overheadAdvance: OverheadAdvance = NULL_OverheadAdvance
|
|
readonly: boolean
|
|
|
|
constructor(
|
|
private overheadAdvanceService: OverheadAdvanceService,
|
|
private messageService: MessageService,
|
|
private route: ActivatedRoute,
|
|
private router: Router
|
|
) { }
|
|
|
|
async getOverheadAdvance(): Promise<void> {
|
|
try {
|
|
const id = +this.route.snapshot.paramMap.get('id')
|
|
this.readonly = false
|
|
if (id != 0) {
|
|
this.overheadAdvance = await this.overheadAdvanceService.getOverheadAdvance(id)
|
|
this.readonly = true
|
|
}
|
|
} catch (err) {
|
|
this.messageService.add(JSON.stringify(err, undefined, 4))
|
|
}
|
|
}
|
|
|
|
async saveOverheadAdvance() {
|
|
try {
|
|
this.submitButton.disabled = true
|
|
this.messageService.add("saveOverheadAdvance")
|
|
this.messageService.add(JSON.stringify(this.overheadAdvance, undefined, 4))
|
|
if (this.overheadAdvance.enddate == null) {
|
|
this.overheadAdvance.enddate = ''
|
|
}
|
|
if (this.overheadAdvance.startdate == null) {
|
|
this.overheadAdvance.startdate = ''
|
|
}
|
|
if (this.overheadAdvance.id == 0) {
|
|
this.messageService.add("about to insert new overheadAdvance")
|
|
this.overheadAdvance = await this.overheadAdvanceService.postOverheadAdvance(this.overheadAdvance)
|
|
this.messageService.add(`Successfully added overheadAdvance with id ${this.overheadAdvance.id}`)
|
|
} else {
|
|
this.messageService.add("about to update existing overheadAdvance")
|
|
this.overheadAdvance = await this.overheadAdvanceService.putOverheadAdvance(this.overheadAdvance)
|
|
this.messageService.add(`Successfully changed overheadAdvance with id ${this.overheadAdvance.id}`)
|
|
}
|
|
this.router.navigate(['/overheadadvances'])
|
|
} finally {
|
|
this.submitButton.disabled = false
|
|
}
|
|
}
|
|
|
|
|
|
ngOnInit(): void {
|
|
this.getOverheadAdvance()
|
|
}
|
|
|
|
}
|