re-enable submit button in finally block

This commit is contained in:
Wolfgang Hottgenroth 2021-09-07 16:02:09 +02:00
parent d21a5986a8
commit 356c8c0bbd
Signed by: wn
GPG Key ID: 6C1E5E531E0D5D7F
6 changed files with 98 additions and 64 deletions

View File

@ -52,16 +52,22 @@ export class CommercialUnitDetailsComponent implements OnInit {
}
async saveCommercialPremise() {
this.submitButton.disabled = true
this.messageService.add(`saveCommercialPremise: ${ JSON.stringify(this.commercialPremise, undefined, 4) }`)
if (this.commercialPremise.id == 0) {
this.messageService.add("about to insert new commercialPremise")
this.commercialPremise = await this.commercialPremiseService.postCommercialPremise(this.commercialPremise)
this.messageService.add(`Successfully added flat with id ${this.commercialPremise.id}`)
} else {
this.messageService.add("about to update existing commercialPremise")
try {
this.submitButton.disabled = true
this.messageService.add(`saveCommercialPremise: ${ JSON.stringify(this.commercialPremise, undefined, 4) }`)
if (this.commercialPremise.id == 0) {
this.messageService.add("about to insert new commercialPremise")
this.commercialPremise = await this.commercialPremiseService.postCommercialPremise(this.commercialPremise)
this.messageService.add(`Successfully added commercialPremise with id ${this.commercialPremise.id}`)
} else {
this.messageService.add("about to update existing commercialPremise")
this.commercialPremise = await this.commercialPremiseService.putCommercialPremise(this.commercialPremise)
this.messageService.add(`Successfully changed commercialPremise with id ${this.commercialPremise.id}`)
}
this.router.navigate(['/commercialunits'])
} finally {
this.submitButton.disabled = false
}
this.router.navigate(['/commercialunits'])
}

View File

@ -63,16 +63,22 @@ export class FlatDetailsComponent implements OnInit {
}
async saveFlat() {
this.submitButton.disabled = true
this.messageService.add(`saveFlat: ${ JSON.stringify(this.flat, undefined, 4) }`)
if (this.flat.id == 0) {
this.messageService.add("about to insert new flat")
this.flat = await this.flatService.postFlat(this.flat)
this.messageService.add(`Successfully added flat with id ${this.flat.id}`)
} else {
this.messageService.add("about to update existing flat")
try {
this.submitButton.disabled = true
this.messageService.add(`saveFlat: ${ JSON.stringify(this.flat, undefined, 4) }`)
if (this.flat.id == 0) {
this.messageService.add("about to insert new flat")
this.flat = await this.flatService.postFlat(this.flat)
this.messageService.add(`Successfully added flat with id ${this.flat.id}`)
} else {
this.messageService.add("about to update existing flat")
this.flat = await this.flatService.putFlat(this.flat)
this.messageService.add(`Successfully changed flat with id ${this.flat.id}`)
}
this.router.navigate(['/flats'])
} finally {
this.submitButton.disabled = false
}
this.router.navigate(['/flats'])
}
ngOnInit(): void {

View File

@ -35,18 +35,23 @@ export class OverheadAdvanceDetailsComponent implements OnInit {
}
async saveOverheadAdvance() {
this.submitButton.disabled = true
this.messageService.add("saveOverheadAdvance")
this.messageService.add(JSON.stringify(this.overheadAdvance, undefined, 4))
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")
try {
this.submitButton.disabled = true
this.messageService.add("saveOverheadAdvance")
this.messageService.add(JSON.stringify(this.overheadAdvance, undefined, 4))
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
}
this.router.navigate(['/overheadadvances'])
// this.submitButton.disabled = false
}

View File

@ -52,16 +52,22 @@ export class ParkingDetailsComponent implements OnInit {
}
async saveParking() {
this.submitButton.disabled = true
this.messageService.add(`saveParking: ${ JSON.stringify(this.parking, undefined, 4) }`)
if (this.parking.id == 0) {
this.messageService.add("about to insert new parking")
this.parking = await this.parkingService.postParking(this.parking)
this.messageService.add(`Successfully added flat with id ${this.parking.id}`)
} else {
this.messageService.add("about to update existing parking")
try {
this.submitButton.disabled = true
this.messageService.add(`saveParking: ${ JSON.stringify(this.parking, undefined, 4) }`)
if (this.parking.id == 0) {
this.messageService.add("about to insert new parking")
this.parking = await this.parkingService.postParking(this.parking)
this.messageService.add(`Successfully added parking with id ${this.parking.id}`)
} else {
this.messageService.add("about to update existing parking")
this.parking = await this.parkingService.putParking(this.parking)
this.messageService.add(`Successfully changed parking with id ${this.parking.id}`)
}
this.router.navigate(['/parkings'])
} finally {
this.submitButton.disabled = false
}
this.router.navigate(['/parkings'])
}

View File

@ -41,18 +41,23 @@ export class PremiseDetailsComponent implements OnInit {
}
async savePremise() {
this.submitButton.disabled = true
this.messageService.add("savePremise")
this.messageService.add(JSON.stringify(this.premise, undefined, 4))
if (this.premise.id == 0) {
this.messageService.add("about to insert new premise")
this.premise = await this.premiseService.postPremise(this.premise)
this.messageService.add(`Successfully added premises with id ${this.premise.id}`)
} else {
this.messageService.add("about to update existing premise")
try {
this.submitButton.disabled = true
this.messageService.add("savePremise")
this.messageService.add(JSON.stringify(this.premise, undefined, 4))
if (this.premise.id == 0) {
this.messageService.add("about to insert new premise")
this.premise = await this.premiseService.postPremise(this.premise)
this.messageService.add(`Successfully added premises with id ${this.premise.id}`)
} else {
this.messageService.add("about to update existing premise")
this.premise = await this.premiseService.putPremise(this.premise)
this.messageService.add(`Successfully changed premises with id ${this.premise.id}`)
}
this.router.navigate(['/premises'])
} finally {
this.submitButton.disabled = false
}
this.router.navigate(['/premises'])
// this.submitButton.disabled = false
}
ngOnInit(): void {

View File

@ -56,23 +56,29 @@ export class TenantDetailsComponent implements OnInit {
}
async saveTenant() {
this.submitButton.disabled = true
this.messageService.add("saveTenant")
this.messageService.add(JSON.stringify(this.tenant, undefined, 4))
if (this.tenant.id == 0) {
this.messageService.add("about to insert new tenant")
this.account = {
"id": 0,
"description": `account_${this.tenant.firstname}_${this.tenant.lastname}`
try {
this.submitButton.disabled = true
this.messageService.add("saveTenant")
this.messageService.add(JSON.stringify(this.tenant, undefined, 4))
if (this.tenant.id == 0) {
this.messageService.add("about to insert new tenant")
this.account = {
"id": 0,
"description": `account_${this.tenant.firstname}_${this.tenant.lastname}`
}
this.account = await this.accountService.postAccount(this.account)
this.tenant.account = this.account.id
this.tenant = await this.tenantService.postTenant(this.tenant)
this.messageService.add(`Successfully added account with id ${this.account.id} and tenant with id ${this.tenant.id}`)
} else {
this.messageService.add("about to update existing tenant")
this.tenant = await this.tenantService.putTenant(this.tenant)
this.messageService.add(`Successfully changed tenant with id ${this.tenant.id}`)
}
this.account = await this.accountService.postAccount(this.account)
this.tenant.account = this.account.id
this.tenant = await this.tenantService.postTenant(this.tenant)
this.messageService.add(`Successfully added account with id ${this.account.id} and tenant with id ${this.tenant.id}`)
} else {
this.messageService.add("about to update existing tenant")
this.router.navigate(['/tenants'])
} finally {
this.submitButton.disabled = false
}
this.router.navigate(['/tenants'])
}
ngOnInit(): void {