Skip to content

Commit

Permalink
wfnews-2179
Browse files Browse the repository at this point in the history
  • Loading branch information
yzlucas committed May 15, 2024
1 parent f9c2f31 commit b44c172
Showing 1 changed file with 31 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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];
}
}
}

Expand Down Expand Up @@ -501,6 +503,7 @@ export class AdminIncidentForm implements OnInit, OnChanges {
this.incident.contact.emailAddress =
response.contactEmailAddress;
this.incident.incidentOverview = response.incidentOverview;
this.cdr.detectChanges();
}
}

Expand Down Expand Up @@ -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) {
Expand All @@ -605,7 +610,6 @@ export class AdminIncidentForm implements OnInit, OnChanges {
}
}
publishIncident(incident): Promise<any> {

if (incident.publishedIncidentDetailGuid == null) {
// If publishedIncidentGuid is null, just save the incident
// let publishedGuid;
Expand All @@ -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);
Expand Down

0 comments on commit b44c172

Please sign in to comment.