Skip to content

Commit

Permalink
Merge branch 'main' into rename-cache-invalidator-lambda-zip
Browse files Browse the repository at this point in the history
  • Loading branch information
sukhpalp authored Apr 23, 2024
2 parents b2d74ea + 52de514 commit 72ff57a
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +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 { Subscription, interval } from 'rxjs';
import { ReportOfFireService } from '@app/services/report-of-fire-service';

@Component({
Expand All @@ -26,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,
Expand Down Expand Up @@ -67,27 +68,26 @@ export class RoFTitlePage extends RoFPage implements OnInit {
const taskId = await BackgroundTask.beforeExit(async () => {

if(!this.intervalRef) {
this.intervalRef = setInterval(async () => {
if(await this.checkStoredRoF(this.intervalRef))
this.clearBackgroundInterval()
}, 30000);
this.intervalRef = interval(30000).subscribe(async () => {
if(await this.checkStoredRoF())
this.unsubscribeInterval();
});
}

BackgroundTask.finish({ taskId });
});
});
}

clearBackgroundInterval() {
clearInterval(this.intervalRef)
this.intervalRef = null;
unsubscribeInterval() {
this.intervalRef?.unsubscribe();
}

openCallPage() {
this.reportOfFirePage.selectPage('call-page', null, false);
}

async checkStoredRoF(intervalRef) {
async checkStoredRoF() {
let rofSubmitted = false;

// first check do 24 hour check in storage and remove offline RoF if timeframe has elapsed
Expand All @@ -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(intervalRef).then(response => {
await this.reportOfFireService.syncDataWithServer().then(response => {
if(response) {
rofSubmitted = true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -232,14 +232,15 @@ export class ReportOfFireService {
return base64;
}

async submitOfflineReportToServer(rofJson?): Promise<any> {
async submitOfflineReportToServer(offlineReport?): Promise<any> {
// 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 resource = JSON.stringify(rofJson?.resource);
const image1 = rofJson?.image1;
const image2 = rofJson?.image2;
const image3 = rofJson?.image3;
const rofJson = JSON.parse(offlineReport);
const resource = rofJson.resource;
const image1 = rofJson.image1;
const image2 = rofJson.image2;
const image3 = rofJson.image3;

const formData = new FormData();
if (resource) {
Expand Down Expand Up @@ -318,7 +319,7 @@ export class ReportOfFireService {
}
}

async syncDataWithServer(intervalRef) {
async syncDataWithServer() {
let dataSynced = false;
let submissionID = null;
let duplicateStored = false;
Expand All @@ -338,12 +339,7 @@ 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
Expand All @@ -356,7 +352,6 @@ export class ReportOfFireService {
dataSynced = true;
// Remove the locally stored data if sync is successful
this.storageService.removeData('offlineReportData');
const rof = this.storageService.getData('offlineReportData')
// store submissionID for duplicate check
if (submissionID) {
submissionIdList = submissionIdList ? submissionIdList + ", " + submissionID : submissionID;
Expand Down

0 comments on commit 72ff57a

Please sign in to comment.