Skip to content

Commit

Permalink
wfnews-2154, avoid wfnews-admin publish conflict
Browse files Browse the repository at this point in the history
  • Loading branch information
yzlucas committed Apr 30, 2024
1 parent 7e186e3 commit 9470fb5
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<a class="link" routerLink="../admin" ><mat-icon svgIcon="back-icon" style="height:13px; width: 15px;"></mat-icon> Back to Admin Front Page</a>
<div class="title">
<div>
<h1>Fire Number: <span *ngIf="currentAdminIncident">{{currentAdminIncident.incidentLabel}}</span><span [ngClass]="{'pub-chip': incident.publishedStatus.toLowerCase() === 'published', 'unpub-chip': incident.publishedStatus.toLowerCase() !== 'published'}">{{incident.publishedStatus}}</span></h1>
<h1>Fire Number: <span *ngIf="currentAdminIncident">{{currentAdminIncident.incidentLabel}}</span><span [ngClass]="{'pub-chip': incident.publishedStatus?.toLowerCase() === 'published', 'unpub-chip': incident.publishedStatus?.toLowerCase() !== 'published'}">{{incident.publishedStatus}}</span></h1>
<h2 class="wildfire-count">
<div *ngIf="incident.lastPublished">
Last Published: {{getPublishedDate().toDateString()}} - {{getPublishedDate().toLocaleTimeString()}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ export class AdminIncidentForm implements OnInit, OnChanges {
currentAdminIncidentCause: IncidentCauseResource;
publishedIncidentType: string;
publishedIncidentDetailGuid: string;
currentEtag: string;

constructor(
private readonly formBuilder: UntypedFormBuilder,
Expand Down Expand Up @@ -293,7 +294,9 @@ export class AdminIncidentForm implements OnInit, OnChanges {
});

incidentResponse.getPublishedIncident.subscribe(
(response) => {
(result) => {
const response = result.body;
this.currentEtag = result.headers.get('ETag')
self.publishedIncidentDetailGuid =
response.publishedIncidentDetailGuid;
self.incident.traditionalTerritory =
Expand Down Expand Up @@ -481,21 +484,21 @@ export class AdminIncidentForm implements OnInit, OnChanges {

try {
const doc = await self.publishIncident(publishedIncidentResource);
this.publishedIncidentDetailGuid = doc.publishedIncidentDetailGuid;
this.publishedIncidentDetailGuid = doc?.publishedIncidentDetailGuid;

// Handle evac orders
await this.evacOrdersDetailsPanel.persistEvacOrders();

this.snackbarService.open('Incident Published Successfully', 'OK', {
duration: 100000,
panelClass: 'snackbar-success-v2',
});

// Update the Draft/Publish status on incident name
this.incident.lastPublished = doc.publishedTimestamp;
this.incident.publishedStatus = doc.newsPublicationStatusCode;
this.incidentForm.markAsPristine();
this.setIsFormDirty(false);
if (doc) {
this.snackbarService.open('Incident Published Successfully', 'OK', {
duration: 100000,
panelClass: 'snackbar-success-v2',
});
// Update the Draft/Publish status on incident name
this.incident.lastPublished = doc?.publishedTimestamp;
this.incident.publishedStatus = doc?.newsPublicationStatusCode;
this.incidentForm.markAsPristine();
this.setIsFormDirty(false);
}
} catch (err) {
this.snackbarService.open(
'Failed to Publish Incident: ' + JSON.stringify(err.message),
Expand All @@ -509,9 +512,27 @@ export class AdminIncidentForm implements OnInit, OnChanges {
}

publishIncident(incident): Promise<any> {
return this.publishedIncidentService
.saveIMPublishedIncident(incident)
.toPromise();
return this.publishedIncidentService.getIMPublishedIncident(incident)
.toPromise()
.then(data => {
let etag = data.headers.get('ETag')
if(etag != this.currentEtag) {
this.snackbarService.open(
'There have been updates on this incident. To retrieve the latest information, please refresh the page.',
'Ok',
{ duration: 10000, panelClass: 'snackbar-error' },
);
return;
} else {
return this.publishedIncidentService
.saveIMPublishedIncident(incident)
.toPromise();
}
})
.catch(error => {
console.error('Error publishing incident:', error);
throw error; // Rethrow or handle the error as required
});
}

onShowPreview() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { HttpClient } from '@angular/common/http';
import { HttpClient, HttpHeaders } from '@angular/common/http';
import { Injectable } from '@angular/core';
import { SituationReport } from '@app/components/wf-admin-panel/dashboard-panel/edit-dashboard.component';
import { LocationData } from '@app/components/wildfires-list-header/filter-by-location/filter-by-location-dialog.component';
Expand Down Expand Up @@ -182,6 +182,7 @@ export class PublishedIncidentService {
'Content-Type': 'application/json',
Authorization: `bearer ${this.tokenService.getOauthToken()}`,
},
observe: 'response'
}),
});
}),
Expand Down Expand Up @@ -209,6 +210,25 @@ export class PublishedIncidentService {
}
}

public getIMPublishedIncident(publishedIncident: any): Observable<any> {
const publishedUrl = `${this.appConfigService.getConfig().rest['incidents']}/publishedIncidents`;
const headers = new HttpHeaders({
Authorization: `Bearer ${this.tokenService.getOauthToken()}`
});

if (publishedIncident.publishedIncidentDetailGuid) {
return this.httpClient.get(publishedUrl + `/${publishedIncident.publishedIncidentDetailGuid}`, {
headers: headers,
observe: 'response'
}).pipe(
map(response => {
console.log('ETag:', response.headers.get('ETag'));
return response;
})
);
}
}

public fetchPublishedIncidentAttachments(incidentName): Observable<any> {
const url = `${
this.appConfigService.getConfig().rest['wfnews']
Expand Down

0 comments on commit 9470fb5

Please sign in to comment.