From b44c172f6e92d81b0d6a424ab56be262b4d1100f Mon Sep 17 00:00:00 2001 From: Lucas Li Date: Wed, 15 May 2024 11:32:52 -0700 Subject: [PATCH] wfnews-2179 --- .../admin-incident-form.component.ts | 55 +++++++++++-------- 1 file changed, 31 insertions(+), 24 deletions(-) diff --git a/client/wfnews-war/src/main/angular/src/app/components/admin-incident-form/admin-incident-form.component.ts b/client/wfnews-war/src/main/angular/src/app/components/admin-incident-form/admin-incident-form.component.ts index 06b11cc06f..81a915d508 100644 --- a/client/wfnews-war/src/main/angular/src/app/components/admin-incident-form/admin-incident-form.component.ts +++ b/client/wfnews-war/src/main/angular/src/app/components/admin-incident-form/admin-incident-form.component.ts @@ -116,7 +116,7 @@ export class AdminIncidentForm implements OnInit, OnChanges { currentAdminIncidentCause: IncidentCauseResource; publishedIncidentType: string; publishedIncidentDetailGuid: string; - currentEtag: string; + currentIncidentName: string; constructor( private readonly formBuilder: UntypedFormBuilder, @@ -220,6 +220,7 @@ export class AdminIncidentForm implements OnInit, OnChanges { .subscribe( (incidentResponse) => { self.currentAdminIncident = incidentResponse.response; + this.currentIncidentName = self.currentAdminIncident.incidentName; this.publishedIncidentType = self.currentAdminIncident.type; (self.incident as any).discoveryDate = new Date( self.currentAdminIncident.discoveryTimestamp, @@ -386,22 +387,23 @@ export class AdminIncidentForm implements OnInit, OnChanges { } populatePublishedIMFields(result) { - const response = result?.body; - this.currentEtag = result?.headers?.get('ETag') - this.publishedIncidentDetailGuid = - response?.publishedIncidentDetailGuid; - - this.incident.cause = 0; - this.incident.causeComments = response?.incidentCauseDetail; - Object.entries(CauseOptionDisclaimer).forEach( - ([index, disclaimer]) => { - if (disclaimer === response?.incidentCauseDetail) { - this.incident.cause = Number.parseInt(index, 10); - } - }, - ); - if (!response?.incidentCauseDetail) { - this.incident.causeComments = CauseOptionDisclaimer[0]; + if (result?.body) { + const response = result.body; + this.publishedIncidentDetailGuid = + response?.publishedIncidentDetailGuid; + + this.incident.cause = 0; + this.incident.causeComments = response?.incidentCauseDetail; + Object.entries(CauseOptionDisclaimer).forEach( + ([index, disclaimer]) => { + if (disclaimer === response?.incidentCauseDetail) { + this.incident.cause = Number.parseInt(index, 10); + } + }, + ); + if (!response?.incidentCauseDetail) { + this.incident.causeComments = CauseOptionDisclaimer[0]; + } } } @@ -501,6 +503,7 @@ export class AdminIncidentForm implements OnInit, OnChanges { this.incident.contact.emailAddress = response.contactEmailAddress; this.incident.incidentOverview = response.incidentOverview; + this.cdr.detectChanges(); } } @@ -577,9 +580,11 @@ export class AdminIncidentForm implements OnInit, OnChanges { }; try { + console.log(this.publishedIncidentDetailGuid) const doc = await self.publishIncident(publishedIncidentResource); - this.publishedIncidentDetailGuid = doc?.publishedIncidentDetailGuid; - + if (doc) { + this.publishedIncidentDetailGuid = doc.publishedIncidentDetailGuid; + } // Handle evac orders await this.evacOrdersDetailsPanel.persistEvacOrders(); if (doc) { @@ -605,7 +610,6 @@ export class AdminIncidentForm implements OnInit, OnChanges { } } publishIncident(incident): Promise { - if (incident.publishedIncidentDetailGuid == null) { // If publishedIncidentGuid is null, just save the incident // let publishedGuid; @@ -630,16 +634,19 @@ export class AdminIncidentForm implements OnInit, OnChanges { } } else { // If publishedIncidentGuid is not null, check for updates and then save the incident - return this.publishedIncidentService.getIMPublishedIncident(incident) + return this.publishedIncidentService.fetchIMIncident(this.wildFireYear, this.incidentNumberSequnce) .toPromise() .then(data => { - let etag = data.headers.get('ETag') - if (etag != this.currentEtag) { + let name = data.response.incidentName; + if (name != this.currentIncidentName) { this.snackbarService.open( - 'There have been updates on this incident. To retrieve the latest information, please refresh the page. Note that after refreshing, any ongoing edits will be lost', + 'Fire Name has changed externally and has been updated on this page. Confirm change and re-publish', 'Ok', { duration: 10000, panelClass: 'snackbar-error' }, ); + this.currentIncidentName = name; + this.incidentForm.get('fireName').setValue(name); + this.incident.fireName = name; return; } else { const saveResult = this.publishedIncidentService.saveIMPublishedIncident(incident);