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 @@