From 810629131928209651d321faed48917fe6706865 Mon Sep 17 00:00:00 2001 From: rcmenno <129762469+rcmenno@users.noreply.github.com> Date: Fri, 25 Oct 2024 15:32:08 +0200 Subject: [PATCH] Make sure distributions routes to the distributions page bump --- PWA/package.json | 2 +- PWA/public/RouteEvents.js | 1 + PWA/public/Services/CacheFilePathService.js | 4 +++- .../FetchEventHandlers/DistributionsHandler.js | 10 ++++++++++ .../FetchEventHandlers/FetchEventHandlers.js | 4 +++- PWA/public/index.html | 5 ++++- PWA/public/template.html | 4 +++- PWA/src/RouteEvents.ts | 1 + PWA/src/Services/CacheFilePathService.ts | 4 +++- .../FetchEventHandlers/DistributionsHandler.ts | 14 ++++++++++++++ .../FetchEventHandlers/FetchEventHandlers.ts | 4 +++- .../Services/FetchEventHandlers/HomepageHandler.ts | 2 +- 12 files changed, 47 insertions(+), 8 deletions(-) create mode 100644 PWA/public/Services/FetchEventHandlers/DistributionsHandler.js create mode 100644 PWA/src/Services/FetchEventHandlers/DistributionsHandler.ts diff --git a/PWA/package.json b/PWA/package.json index a0e7fea..21aabd1 100644 --- a/PWA/package.json +++ b/PWA/package.json @@ -1,6 +1,6 @@ { "name": "ReliefBox", - "version": "0.9.0", + "version": "0.10.0", "description": "A tool for managing the distribution of relief items during humanitarian emergencies.", "main": "index.js", "scripts": { diff --git a/PWA/public/RouteEvents.js b/PWA/public/RouteEvents.js index 4391835..ee66019 100644 --- a/PWA/public/RouteEvents.js +++ b/PWA/public/RouteEvents.js @@ -31,3 +31,4 @@ RouteEvents.received = "/received"; RouteEvents.continueDistribution = "/continueDistribution"; RouteEvents.downloadData = "/download_data"; RouteEvents.downloadSpreadsheetTemplate = "/download_template"; +RouteEvents.distributions = "/distributions"; diff --git a/PWA/public/Services/CacheFilePathService.js b/PWA/public/Services/CacheFilePathService.js index 8e1ae12..84e0ae7 100644 --- a/PWA/public/Services/CacheFilePathService.js +++ b/PWA/public/Services/CacheFilePathService.js @@ -33,6 +33,7 @@ import { BeneficiaryStatusService } from "./BeneficiaryStatusService.js"; import { DownloadSpreadsheetTemplateHandler } from "./FetchEventHandlers/DownloadSpreadsheetTemplateHandler.js"; import { DeleteDistributionsConfirmHandler } from "./FetchEventHandlers/DeleteDistributionsConfirmHandler.js"; import { DistributionResponseProvider } from "./DistributionResponseProvider.js"; +import { DistributionsHandler } from "./FetchEventHandlers/DistributionsHandler.js"; // Provides all the files that have to be cached for offline use export class CacheFilePathService { pathsOfFilesToCache() { @@ -139,7 +140,8 @@ export class CacheFilePathService { ContinueDistributionHandler.name, DownloadDataHandler.name, DownloadSpreadsheetTemplateHandler.name, - DeleteDistributionsConfirmHandler.name + DeleteDistributionsConfirmHandler.name, + DistributionsHandler.name ]); } interfacesPaths() { diff --git a/PWA/public/Services/FetchEventHandlers/DistributionsHandler.js b/PWA/public/Services/FetchEventHandlers/DistributionsHandler.js new file mode 100644 index 0000000..7e51350 --- /dev/null +++ b/PWA/public/Services/FetchEventHandlers/DistributionsHandler.js @@ -0,0 +1,10 @@ +import { RouteEvents } from "../../RouteEvents.js"; +import { ResponseTools } from "../ResponseTools.js"; +export class DistributionsHandler { + canHandleEvent(event) { + return event.request.url.endsWith(RouteEvents.distributions); + } + async handleEvent(event) { + return await ResponseTools.fetchFromCacheWithRemoteAsFallBack(RouteEvents.home); + } +} diff --git a/PWA/public/Services/FetchEventHandlers/FetchEventHandlers.js b/PWA/public/Services/FetchEventHandlers/FetchEventHandlers.js index b78259a..cccba66 100644 --- a/PWA/public/Services/FetchEventHandlers/FetchEventHandlers.js +++ b/PWA/public/Services/FetchEventHandlers/FetchEventHandlers.js @@ -18,6 +18,7 @@ import { ContinueDistributionHandler } from "./ContinueDistributionHandler.js"; import { DownloadDataHandler } from "./DownloadDataHandler.js"; import { DownloadSpreadsheetTemplateHandler } from "./DownloadSpreadsheetTemplateHandler.js"; import { DeleteDistributionsConfirmHandler } from "./DeleteDistributionsConfirmHandler.js"; +import { DistributionsHandler } from "./DistributionsHandler.js"; export class FetchEventHandlers extends ActiveSessionContainer { constructor() { super(...arguments); @@ -40,7 +41,8 @@ export class FetchEventHandlers extends ActiveSessionContainer { new ContinueDistributionHandler(this.activeSession), new DownloadDataHandler(this.activeSession), new DownloadSpreadsheetTemplateHandler(), - new DeleteDistributionsConfirmHandler() + new DeleteDistributionsConfirmHandler(), + new DistributionsHandler() ]; } handlersForEvent(event) { diff --git a/PWA/public/index.html b/PWA/public/index.html index 1cc268f..fdd8ac0 100644 --- a/PWA/public/index.html +++ b/PWA/public/index.html @@ -39,7 +39,7 @@ - + Home + + Distributions + Documentation diff --git a/PWA/public/template.html b/PWA/public/template.html index b7540c8..7a0f4a8 100644 --- a/PWA/public/template.html +++ b/PWA/public/template.html @@ -52,7 +52,9 @@ Home - + + Distributions + Documentation diff --git a/PWA/src/RouteEvents.ts b/PWA/src/RouteEvents.ts index ef37504..2c98863 100644 --- a/PWA/src/RouteEvents.ts +++ b/PWA/src/RouteEvents.ts @@ -31,4 +31,5 @@ export class RouteEvents { static continueDistribution = "/continueDistribution" static downloadData = "/download_data" static downloadSpreadsheetTemplate = "/download_template" + static distributions = "/distributions" } \ No newline at end of file diff --git a/PWA/src/Services/CacheFilePathService.ts b/PWA/src/Services/CacheFilePathService.ts index 77dbf9a..f7de52f 100644 --- a/PWA/src/Services/CacheFilePathService.ts +++ b/PWA/src/Services/CacheFilePathService.ts @@ -33,6 +33,7 @@ import { BeneficiaryStatusService } from "./BeneficiaryStatusService.js"; import { DownloadSpreadsheetTemplateHandler } from "./FetchEventHandlers/DownloadSpreadsheetTemplateHandler.js"; import { DeleteDistributionsConfirmHandler } from "./FetchEventHandlers/DeleteDistributionsConfirmHandler.js"; import { DistributionResponseProvider } from "./DistributionResponseProvider.js"; +import { DistributionsHandler } from "./FetchEventHandlers/DistributionsHandler.js"; // Provides all the files that have to be cached for offline use export class CacheFilePathService { @@ -152,7 +153,8 @@ export class CacheFilePathService { ContinueDistributionHandler.name, DownloadDataHandler.name, DownloadSpreadsheetTemplateHandler.name, - DeleteDistributionsConfirmHandler.name + DeleteDistributionsConfirmHandler.name, + DistributionsHandler.name ]); } diff --git a/PWA/src/Services/FetchEventHandlers/DistributionsHandler.ts b/PWA/src/Services/FetchEventHandlers/DistributionsHandler.ts new file mode 100644 index 0000000..485f753 --- /dev/null +++ b/PWA/src/Services/FetchEventHandlers/DistributionsHandler.ts @@ -0,0 +1,14 @@ +import { FetchEvent } from "../../Interfaces/FetchEvent.js"; +import { FetchEventHandler } from "../../Interfaces/FetchEventHandler.js"; +import { RouteEvents } from "../../RouteEvents.js"; +import { ResponseTools } from "../ResponseTools.js"; + +export class DistributionsHandler implements FetchEventHandler { + canHandleEvent(event: FetchEvent): boolean { + return event.request.url.endsWith(RouteEvents.distributions); + } + + async handleEvent(event: FetchEvent): Promise { + return await ResponseTools.fetchFromCacheWithRemoteAsFallBack(RouteEvents.home); + } +} diff --git a/PWA/src/Services/FetchEventHandlers/FetchEventHandlers.ts b/PWA/src/Services/FetchEventHandlers/FetchEventHandlers.ts index 9fd8412..41c46e6 100644 --- a/PWA/src/Services/FetchEventHandlers/FetchEventHandlers.ts +++ b/PWA/src/Services/FetchEventHandlers/FetchEventHandlers.ts @@ -20,6 +20,7 @@ import { ContinueDistributionHandler } from "./ContinueDistributionHandler.js"; import { DownloadDataHandler } from "./DownloadDataHandler.js"; import { DownloadSpreadsheetTemplateHandler } from "./DownloadSpreadsheetTemplateHandler.js"; import { DeleteDistributionsConfirmHandler } from "./DeleteDistributionsConfirmHandler.js"; +import { DistributionsHandler } from "./DistributionsHandler.js"; export class FetchEventHandlers extends ActiveSessionContainer implements FetchEventHandler { all: FetchEventHandler[] = [ @@ -41,7 +42,8 @@ export class FetchEventHandlers extends ActiveSessionContainer implements FetchE new ContinueDistributionHandler(this.activeSession), new DownloadDataHandler(this.activeSession), new DownloadSpreadsheetTemplateHandler(), - new DeleteDistributionsConfirmHandler() + new DeleteDistributionsConfirmHandler(), + new DistributionsHandler() ]; handlersForEvent(event: FetchEvent): FetchEventHandler[] { diff --git a/PWA/src/Services/FetchEventHandlers/HomepageHandler.ts b/PWA/src/Services/FetchEventHandlers/HomepageHandler.ts index 1427aea..ede1016 100644 --- a/PWA/src/Services/FetchEventHandlers/HomepageHandler.ts +++ b/PWA/src/Services/FetchEventHandlers/HomepageHandler.ts @@ -17,4 +17,4 @@ export class HomepageHandler extends ActiveSessionContainer implements FetchEven return await ResponseTools.fetchFromCacheWithRemoteAsFallBack(RouteEvents.home) } } -} +} \ No newline at end of file