From 40fef3bbc619c29967683935fad2b06dd88c9a64 Mon Sep 17 00:00:00 2001 From: Sean Sylver Date: Fri, 19 Apr 2024 13:20:10 -0700 Subject: [PATCH 1/4] WFNEWS-1631 Unsubscribe from rxjs interval --- .../title-page/rof-title-page.component.ts | 20 ++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/client/wfnews-war/src/main/angular/src/app/components/report-of-fire/title-page/rof-title-page.component.ts b/client/wfnews-war/src/main/angular/src/app/components/report-of-fire/title-page/rof-title-page.component.ts index 5e9c2d4481..272f9e306d 100644 --- a/client/wfnews-war/src/main/angular/src/app/components/report-of-fire/title-page/rof-title-page.component.ts +++ b/client/wfnews-war/src/main/angular/src/app/components/report-of-fire/title-page/rof-title-page.component.ts @@ -12,7 +12,7 @@ import { CommonUtilityService } from '@app/services/common-utility.service'; import { ReportOfFirePage } from '@app/components/report-of-fire/report-of-fire.component'; import { App } from '@capacitor/app'; import { BackgroundTask } from '@capawesome/capacitor-background-task'; -import { interval } from 'rxjs'; +import { Subscription, interval } from 'rxjs'; import { ReportOfFireService } from '@app/services/report-of-fire-service'; @Component({ @@ -27,7 +27,7 @@ export class RoFTitlePage extends RoFPage implements OnInit { public messages: any; public offLineMessages: any; offLine = false; - private intervalRef; + private intervalRef: Subscription; public constructor( protected dialog: MatDialog, @@ -66,11 +66,11 @@ export class RoFTitlePage extends RoFPage implements OnInit { // The app state has been changed to inactive. // Start the background task by calling `beforeExit`. const taskId = await BackgroundTask.beforeExit(async () => { - const self = this; if(!this.intervalRef) { this.intervalRef = interval(30000).subscribe(() => { - self.checkStoredRoF(); + if(this.checkStoredRoF()) + this.unsubscribeInterval(); }); } @@ -79,12 +79,18 @@ export class RoFTitlePage extends RoFPage implements OnInit { }); } + unsubscribeInterval() { + console.log('rof: unsubscribing') + this.intervalRef?.unsubscribe(); + } + openCallPage() { this.reportOfFirePage.selectPage('call-page', null, false); } async checkStoredRoF() { - const self = this; + let rofSubmitted = false; + // first check do 24 hour check in storage and remove offline RoF if timeframe has elapsed await this.commonUtilityService.removeInvalidOfflineRoF(); @@ -93,12 +99,12 @@ export class RoFTitlePage extends RoFPage implements OnInit { if (result) { await this.reportOfFireService.syncDataWithServer().then(response => { if(response) { - //self?.intervalRef?.unsubscribe(); - //self.intervalRef = null; + rofSubmitted = true; } }); }; }); + return rofSubmitted; } triggerLocationServiceCheck() { From a91d0a2845c7fd3d7d3fb9d9bf16753bbf9cbe99 Mon Sep 17 00:00:00 2001 From: Sean Sylver Date: Fri, 19 Apr 2024 13:21:21 -0700 Subject: [PATCH 2/4] WFNEWS-1631 Unsubscribe from rxjs interval --- .../report-of-fire/title-page/rof-title-page.component.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/client/wfnews-war/src/main/angular/src/app/components/report-of-fire/title-page/rof-title-page.component.ts b/client/wfnews-war/src/main/angular/src/app/components/report-of-fire/title-page/rof-title-page.component.ts index 272f9e306d..4b3d077f56 100644 --- a/client/wfnews-war/src/main/angular/src/app/components/report-of-fire/title-page/rof-title-page.component.ts +++ b/client/wfnews-war/src/main/angular/src/app/components/report-of-fire/title-page/rof-title-page.component.ts @@ -80,7 +80,6 @@ export class RoFTitlePage extends RoFPage implements OnInit { } unsubscribeInterval() { - console.log('rof: unsubscribing') this.intervalRef?.unsubscribe(); } From ee67fa7b3313ef34f0c4a2b0b9ca1b688e95603c Mon Sep 17 00:00:00 2001 From: Sean Sylver Date: Fri, 19 Apr 2024 15:45:59 -0700 Subject: [PATCH 3/4] WFNEWS-1631 Use js setInterval --- .../title-page/rof-title-page.component.ts | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/client/wfnews-war/src/main/angular/src/app/components/report-of-fire/title-page/rof-title-page.component.ts b/client/wfnews-war/src/main/angular/src/app/components/report-of-fire/title-page/rof-title-page.component.ts index 4b3d077f56..1bbc47bcc6 100644 --- a/client/wfnews-war/src/main/angular/src/app/components/report-of-fire/title-page/rof-title-page.component.ts +++ b/client/wfnews-war/src/main/angular/src/app/components/report-of-fire/title-page/rof-title-page.component.ts @@ -12,7 +12,6 @@ import { CommonUtilityService } from '@app/services/common-utility.service'; import { ReportOfFirePage } from '@app/components/report-of-fire/report-of-fire.component'; import { App } from '@capacitor/app'; import { BackgroundTask } from '@capawesome/capacitor-background-task'; -import { Subscription, interval } from 'rxjs'; import { ReportOfFireService } from '@app/services/report-of-fire-service'; @Component({ @@ -27,7 +26,7 @@ export class RoFTitlePage extends RoFPage implements OnInit { public messages: any; public offLineMessages: any; offLine = false; - private intervalRef: Subscription; + private intervalRef; public constructor( protected dialog: MatDialog, @@ -68,10 +67,10 @@ export class RoFTitlePage extends RoFPage implements OnInit { const taskId = await BackgroundTask.beforeExit(async () => { if(!this.intervalRef) { - this.intervalRef = interval(30000).subscribe(() => { - if(this.checkStoredRoF()) - this.unsubscribeInterval(); - }); + this.intervalRef = setInterval(async () => { + if(await this.checkStoredRoF()) + this.clearBackgroundInterval() + }, 30000); } BackgroundTask.finish({ taskId }); @@ -79,8 +78,9 @@ export class RoFTitlePage extends RoFPage implements OnInit { }); } - unsubscribeInterval() { - this.intervalRef?.unsubscribe(); + clearBackgroundInterval() { + clearInterval(this.intervalRef) + this.intervalRef = null; } openCallPage() { From 7646bca33b701d10b7dcdd520d7e46b3de47941f Mon Sep 17 00:00:00 2001 From: Sean Sylver Date: Mon, 22 Apr 2024 20:08:40 -0700 Subject: [PATCH 4/4] WFNEWS-1631 Add debug attributes to payload --- .../title-page/rof-title-page.component.ts | 6 +++--- .../app/services/report-of-fire-service.ts | 21 +++++++++++-------- 2 files changed, 15 insertions(+), 12 deletions(-) diff --git a/client/wfnews-war/src/main/angular/src/app/components/report-of-fire/title-page/rof-title-page.component.ts b/client/wfnews-war/src/main/angular/src/app/components/report-of-fire/title-page/rof-title-page.component.ts index 1bbc47bcc6..2fb59e8b3b 100644 --- a/client/wfnews-war/src/main/angular/src/app/components/report-of-fire/title-page/rof-title-page.component.ts +++ b/client/wfnews-war/src/main/angular/src/app/components/report-of-fire/title-page/rof-title-page.component.ts @@ -68,7 +68,7 @@ export class RoFTitlePage extends RoFPage implements OnInit { if(!this.intervalRef) { this.intervalRef = setInterval(async () => { - if(await this.checkStoredRoF()) + if(await this.checkStoredRoF(this.intervalRef)) this.clearBackgroundInterval() }, 30000); } @@ -87,7 +87,7 @@ export class RoFTitlePage extends RoFPage implements OnInit { this.reportOfFirePage.selectPage('call-page', null, false); } - async checkStoredRoF() { + async checkStoredRoF(intervalRef) { let rofSubmitted = false; // first check do 24 hour check in storage and remove offline RoF if timeframe has elapsed @@ -96,7 +96,7 @@ export class RoFTitlePage extends RoFPage implements OnInit { // check if the app is in the background and online and if so, check for saved offline RoF to be submitted await this.commonUtilityService.checkOnlineStatus().then(async (result) => { if (result) { - await this.reportOfFireService.syncDataWithServer().then(response => { + await this.reportOfFireService.syncDataWithServer(intervalRef).then(response => { if(response) { rofSubmitted = true; } diff --git a/client/wfnews-war/src/main/angular/src/app/services/report-of-fire-service.ts b/client/wfnews-war/src/main/angular/src/app/services/report-of-fire-service.ts index 59ab7aedad..e37adcc962 100644 --- a/client/wfnews-war/src/main/angular/src/app/services/report-of-fire-service.ts +++ b/client/wfnews-war/src/main/angular/src/app/services/report-of-fire-service.ts @@ -232,15 +232,14 @@ export class ReportOfFireService { return base64; } - async submitOfflineReportToServer(offlineReport?): Promise { + async submitOfflineReportToServer(rofJson?): Promise { // retrieve the offline RoF from the device's storage and convert to FormData for submission // images will already to converted to base64 string from initial submission const rofUrl = this.appConfigService.getConfig().rest['fire-report-api']; - const rofJson = JSON.parse(offlineReport); - const resource = rofJson.resource; - const image1 = rofJson.image1; - const image2 = rofJson.image2; - const image3 = rofJson.image3; + const resource = JSON.stringify(rofJson?.resource); + const image1 = rofJson?.image1; + const image2 = rofJson?.image2; + const image3 = rofJson?.image3; const formData = new FormData(); if (resource) { @@ -319,7 +318,7 @@ export class ReportOfFireService { } } - async syncDataWithServer() { + async syncDataWithServer(intervalRef) { let dataSynced = false; let submissionID = null; let duplicateStored = false; @@ -339,7 +338,12 @@ export class ReportOfFireService { submissionID = resourceJson?.submissionID if (submissionID && submissionIdList?.includes(submissionID)) { duplicateStored = true; - } + } + resourceJson['duplicateStored'] = duplicateStored; + resourceJson['intervalRef'] = intervalRef; + let offlineReportJson = JSON.parse(offlineReport) + offlineReportJson['resource'] = resourceJson; + offlineReport = offlineReportJson } // Reject duplicate if submissionID has already been stored @@ -353,7 +357,6 @@ export class ReportOfFireService { // Remove the locally stored data if sync is successful this.storageService.removeData('offlineReportData'); const rof = this.storageService.getData('offlineReportData') - console.log('rof: ' + rof) // store submissionID for duplicate check if (submissionID) { submissionIdList = submissionIdList ? submissionIdList + ", " + submissionID : submissionID;