From 9312251f0d6260cc8f6176f93c865bd7a006d76b Mon Sep 17 00:00:00 2001 From: Menno <129762469+rcmenno@users.noreply.github.com> Date: Sun, 11 Aug 2024 22:52:56 +0200 Subject: [PATCH] Wip --- PWA/public/RouteEvents.js | 1 + PWA/public/Services/CacheFilePathService.js | 4 ++- .../ContinueDistributionHandler.js | 22 ++++++++++++++ .../FetchEventHandlers/FetchEventHandlers.js | 4 ++- ...tBenificiaryCodeInputMethodHandler copy.js | 29 +++++++++++++++++++ PWA/public/entry_not_found.html | 2 +- PWA/src/RouteEvents.ts | 1 + PWA/src/Services/CacheFilePathService.ts | 4 ++- .../ContinueDistributionHandler.ts | 27 +++++++++++++++++ .../FetchEventHandlers/FetchEventHandlers.ts | 4 ++- 10 files changed, 93 insertions(+), 5 deletions(-) create mode 100644 PWA/public/Services/FetchEventHandlers/ContinueDistributionHandler.js create mode 100644 PWA/public/Services/FetchEventHandlers/SelectBenificiaryCodeInputMethodHandler copy.js create mode 100644 PWA/src/Services/FetchEventHandlers/ContinueDistributionHandler.ts diff --git a/PWA/public/RouteEvents.js b/PWA/public/RouteEvents.js index 431d6ef..51f6a0f 100644 --- a/PWA/public/RouteEvents.js +++ b/PWA/public/RouteEvents.js @@ -26,4 +26,5 @@ RouteEvents.selectBenificiaryCodeInputMethod = "/save_input_method"; RouteEvents.checkBenificiaryCodeInputMethod = "/entry"; RouteEvents.checkWhosMissing = "/missing"; RouteEvents.received = "/received"; +RouteEvents.continueDistribution = "/continueDistribution"; export { RouteEvents }; diff --git a/PWA/public/Services/CacheFilePathService.js b/PWA/public/Services/CacheFilePathService.js index 6f9fe02..d4c35c8 100644 --- a/PWA/public/Services/CacheFilePathService.js +++ b/PWA/public/Services/CacheFilePathService.js @@ -27,6 +27,7 @@ import { CheckWhosMissingPageHandler } from "./FetchEventHandlers/CheckWhosMissi import { MarkAsReceivedPostHandler } from "./FetchEventHandlers/MarkAsReceivedPostHandler.js"; import { HomepageHandler } from "./FetchEventHandlers/HomepageHandler.js"; import { DateService } from "./DateService.js"; +import { ContinueDistributionHandler } from "./FetchEventHandlers/ContinueDistributionHandler.js"; // Provides all the files that have to be cached for offline use export class CacheFilePathService { pathsOfFilesToCache() { @@ -126,7 +127,8 @@ export class CacheFilePathService { ViewDistributionDataHandler.name, CheckWhosMissingPageHandler.name, MarkAsReceivedPostHandler.name, - HomepageHandler.name + HomepageHandler.name, + ContinueDistributionHandler.name ]); } interfacesPaths() { diff --git a/PWA/public/Services/FetchEventHandlers/ContinueDistributionHandler.js b/PWA/public/Services/FetchEventHandlers/ContinueDistributionHandler.js new file mode 100644 index 0000000..a1f95b0 --- /dev/null +++ b/PWA/public/Services/FetchEventHandlers/ContinueDistributionHandler.js @@ -0,0 +1,22 @@ +import { RouteEvents } from "../../RouteEvents.js"; +import { ResponseTools } from "../ResponseTools.js"; +export class ContinueDistributionHandler { + canHandleEvent(event) { + return event.request.url.includes(RouteEvents.continueDistribution); + } + async handleEvent(event) { + //TODO this should be context aware + return await ResponseTools.wrapInHtmlTemplate(this.templatepageForInputMethod("text")); + } + templatepageForInputMethod(inputMethod) { + if (inputMethod == "video") { + return RouteEvents.codeInputUsingCamera; + } + else if (inputMethod == "text") { + return RouteEvents.codeinputUsingTextField; + } + else { + throw "Unexpected input method: " + inputMethod; + } + } +} diff --git a/PWA/public/Services/FetchEventHandlers/FetchEventHandlers.js b/PWA/public/Services/FetchEventHandlers/FetchEventHandlers.js index ba1f529..28c62aa 100644 --- a/PWA/public/Services/FetchEventHandlers/FetchEventHandlers.js +++ b/PWA/public/Services/FetchEventHandlers/FetchEventHandlers.js @@ -14,6 +14,7 @@ import { BeneficiaryCodePostHandler } from "./BeneficiaryCodePostHandler.js"; import { CheckWhosMissingPageHandler } from "./CheckWhosMissingPagehandler.js"; import { MarkAsReceivedPostHandler } from "./MarkAsReceivedPostHandler.js"; import { HomepageHandler } from "./HomepageHandler.js"; +import { ContinueDistributionHandler } from "./ContinueDistributionHandler.js"; export class FetchEventHandlers extends ActiveSessionContainer { constructor() { super(...arguments); @@ -32,7 +33,8 @@ export class FetchEventHandlers extends ActiveSessionContainer { new ViewDistributionDataHandler(this.activeSession), new CheckWhosMissingPageHandler(this.activeSession), new MarkAsReceivedPostHandler(this.activeSession), - new HomepageHandler() + new HomepageHandler(), + new ContinueDistributionHandler() ]; } handlersForEvent(event) { diff --git a/PWA/public/Services/FetchEventHandlers/SelectBenificiaryCodeInputMethodHandler copy.js b/PWA/public/Services/FetchEventHandlers/SelectBenificiaryCodeInputMethodHandler copy.js new file mode 100644 index 0000000..8aab629 --- /dev/null +++ b/PWA/public/Services/FetchEventHandlers/SelectBenificiaryCodeInputMethodHandler copy.js @@ -0,0 +1,29 @@ +import { RouteEvents } from "../../RouteEvents.js"; +import { DeserialisationService } from "../DeserialisationService.js"; +import { ResponseTools } from "../ResponseTools.js"; +export class SelectBenificiaryCodeInputMethodHandler { + canHandleEvent(event) { + return event.request.url.endsWith(RouteEvents.selectBenificiaryCodeInputMethod); + } + async handleEvent(event) { + try { + const post = await DeserialisationService.deserializeFormDataFromRequest(event.request); + return ResponseTools.wrapInHtmlTemplate(this.templatepageForInputMethod(post.input_method)); + } + catch (error) { + console.error(error); + return fetch(RouteEvents.home); + } + } + templatepageForInputMethod(inputMethod) { + if (inputMethod == "video") { + return RouteEvents.codeInputUsingCamera; + } + else if (inputMethod == "text") { + return RouteEvents.codeinputUsingTextField; + } + else { + throw "Unexpected input method: " + inputMethod; + } + } +} diff --git a/PWA/public/entry_not_found.html b/PWA/public/entry_not_found.html index 2b08a76..11f5e80 100644 --- a/PWA/public/entry_not_found.html +++ b/PWA/public/entry_not_found.html @@ -2,7 +2,7 @@

-
+

diff --git a/PWA/src/RouteEvents.ts b/PWA/src/RouteEvents.ts index 628c3de..8266aee 100644 --- a/PWA/src/RouteEvents.ts +++ b/PWA/src/RouteEvents.ts @@ -26,4 +26,5 @@ export class RouteEvents { static checkBenificiaryCodeInputMethod = "/entry" static checkWhosMissing = "/missing" static received = "/received" + static continueDistribution = "/continueDistribution" } \ No newline at end of file diff --git a/PWA/src/Services/CacheFilePathService.ts b/PWA/src/Services/CacheFilePathService.ts index 08d799f..a0a4894 100644 --- a/PWA/src/Services/CacheFilePathService.ts +++ b/PWA/src/Services/CacheFilePathService.ts @@ -27,6 +27,7 @@ import { CheckWhosMissingPageHandler } from "./FetchEventHandlers/CheckWhosMissi import { MarkAsReceivedPostHandler } from "./FetchEventHandlers/MarkAsReceivedPostHandler.js"; import { HomepageHandler } from "./FetchEventHandlers/HomepageHandler.js"; import { DateService } from "./DateService.js"; +import { ContinueDistributionHandler } from "./FetchEventHandlers/ContinueDistributionHandler.js"; // Provides all the files that have to be cached for offline use export class CacheFilePathService { @@ -139,7 +140,8 @@ export class CacheFilePathService { ViewDistributionDataHandler.name, CheckWhosMissingPageHandler.name, MarkAsReceivedPostHandler.name, - HomepageHandler.name + HomepageHandler.name, + ContinueDistributionHandler.name ]); } diff --git a/PWA/src/Services/FetchEventHandlers/ContinueDistributionHandler.ts b/PWA/src/Services/FetchEventHandlers/ContinueDistributionHandler.ts new file mode 100644 index 0000000..6657839 --- /dev/null +++ b/PWA/src/Services/FetchEventHandlers/ContinueDistributionHandler.ts @@ -0,0 +1,27 @@ +import { FetchEvent } from "../../Interfaces/FetchEvent.js"; +import { FetchEventHandler } from "../../Interfaces/FetchEventHandler.js"; +import { BeneficiaryCodeInputMethodPost } from "../../Models/BeneficiaryCodeInputMethodPost.js"; +import { RouteEvents } from "../../RouteEvents.js"; +import { DeserialisationService } from "../DeserialisationService.js"; +import { ResponseTools } from "../ResponseTools.js"; + +export class ContinueDistributionHandler implements FetchEventHandler { + canHandleEvent(event: FetchEvent): boolean { + return event.request.url.includes(RouteEvents.continueDistribution) + } + + async handleEvent(event: FetchEvent): Promise { + //TODO this should be context aware + return await ResponseTools.wrapInHtmlTemplate(this.templatepageForInputMethod("text")) + } + + private templatepageForInputMethod(inputMethod: string): string { + if(inputMethod == "video") { + return RouteEvents.codeInputUsingCamera + } else if(inputMethod == "text") { + return RouteEvents.codeinputUsingTextField + } else { + throw "Unexpected input method: " + inputMethod + } + } + } \ No newline at end of file diff --git a/PWA/src/Services/FetchEventHandlers/FetchEventHandlers.ts b/PWA/src/Services/FetchEventHandlers/FetchEventHandlers.ts index 816603e..269837e 100644 --- a/PWA/src/Services/FetchEventHandlers/FetchEventHandlers.ts +++ b/PWA/src/Services/FetchEventHandlers/FetchEventHandlers.ts @@ -16,6 +16,7 @@ import { BeneficiaryCodePostHandler } from "./BeneficiaryCodePostHandler.js"; import { CheckWhosMissingPageHandler } from "./CheckWhosMissingPagehandler.js"; import { MarkAsReceivedPostHandler } from "./MarkAsReceivedPostHandler.js"; import { HomepageHandler } from "./HomepageHandler.js"; +import { ContinueDistributionHandler } from "./ContinueDistributionHandler.js"; export class FetchEventHandlers extends ActiveSessionContainer implements FetchEventHandler { all: FetchEventHandler[] = [ @@ -33,7 +34,8 @@ export class FetchEventHandlers extends ActiveSessionContainer implements FetchE new ViewDistributionDataHandler(this.activeSession), new CheckWhosMissingPageHandler(this.activeSession), new MarkAsReceivedPostHandler(this.activeSession), - new HomepageHandler() + new HomepageHandler(), + new ContinueDistributionHandler() ]; handlersForEvent(event: FetchEvent): FetchEventHandler[] {