Skip to content

Commit

Permalink
Wip
Browse files Browse the repository at this point in the history
  • Loading branch information
rcmenno committed Aug 11, 2024
1 parent 8a98fb2 commit 9312251
Show file tree
Hide file tree
Showing 10 changed files with 93 additions and 5 deletions.
1 change: 1 addition & 0 deletions PWA/public/RouteEvents.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,5 @@ RouteEvents.selectBenificiaryCodeInputMethod = "/save_input_method";
RouteEvents.checkBenificiaryCodeInputMethod = "/entry";
RouteEvents.checkWhosMissing = "/missing";
RouteEvents.received = "/received";
RouteEvents.continueDistribution = "/continueDistribution";
export { RouteEvents };
4 changes: 3 additions & 1 deletion PWA/public/Services/CacheFilePathService.js
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down Expand Up @@ -126,7 +127,8 @@ export class CacheFilePathService {
ViewDistributionDataHandler.name,
CheckWhosMissingPageHandler.name,
MarkAsReceivedPostHandler.name,
HomepageHandler.name
HomepageHandler.name,
ContinueDistributionHandler.name
]);
}
interfacesPaths() {
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
}
}
}
4 changes: 3 additions & 1 deletion PWA/public/Services/FetchEventHandlers/FetchEventHandlers.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
}
}
}
2 changes: 1 addition & 1 deletion PWA/public/entry_not_found.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<div class="box">
<label class="label is-medium">Beneficiary not found!</label>
<br>
<form action="/input" method="GET">
<form action="/continueDistribution" method="GET">
<button class="button is-block is-info is-medium is-fullwidth">Continue distribution</button>
</form>
<br>
Expand Down
1 change: 1 addition & 0 deletions PWA/src/RouteEvents.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,5 @@ export class RouteEvents {
static checkBenificiaryCodeInputMethod = "/entry"
static checkWhosMissing = "/missing"
static received = "/received"
static continueDistribution = "/continueDistribution"
}
4 changes: 3 additions & 1 deletion PWA/src/Services/CacheFilePathService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -139,7 +140,8 @@ export class CacheFilePathService {
ViewDistributionDataHandler.name,
CheckWhosMissingPageHandler.name,
MarkAsReceivedPostHandler.name,
HomepageHandler.name
HomepageHandler.name,
ContinueDistributionHandler.name
]);
}

Expand Down
27 changes: 27 additions & 0 deletions PWA/src/Services/FetchEventHandlers/ContinueDistributionHandler.ts
Original file line number Diff line number Diff line change
@@ -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<Response> {
//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
}
}
}
4 changes: 3 additions & 1 deletion PWA/src/Services/FetchEventHandlers/FetchEventHandlers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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[] = [
Expand All @@ -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[] {
Expand Down

0 comments on commit 9312251

Please sign in to comment.