Skip to content

Commit

Permalink
#5 Wip input from camera and manual input
Browse files Browse the repository at this point in the history
  • Loading branch information
rcmenno committed Nov 27, 2023
1 parent d99d9bb commit 1d337ab
Show file tree
Hide file tree
Showing 43 changed files with 442 additions and 124 deletions.
5 changes: 5 additions & 0 deletions PWA/public/Models/BeneficiaryCodeInputMethodPost.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export class BeneficiaryCodeInputMethodPost {
constructor(input_method) {
this.input_method = input_method;
}
}
5 changes: 5 additions & 0 deletions PWA/public/RouteEvents.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,15 @@ RouteEvents.uploadData = "/upload_data.html";
RouteEvents.uploadDataError = "/upload_error.html";
RouteEvents.template = "/template.html";
RouteEvents.chooseBenificiaryCodeInputMethodPage = "/choose_input_method.html";
RouteEvents.codeInputUsingCamera = "/input_video.html";
RouteEvents.codeinputUsingTextField = "/input.html";
RouteEvents.codeInputNotFound = "/entry_not_found.html";
//Non page route events
RouteEvents.postCreateDistribution = "/create_distrib";
RouteEvents.postSelectDistribution = "/select_distrib";
RouteEvents.postDeleteDistribution = "/delete_distrib_confirm";
RouteEvents.listDistributionsFormAction = "/distrib?";
RouteEvents.chooseBenificiaryCodeInputMethod = "/choose_input_method?";
RouteEvents.selectBenificiaryCodeInputMethod = "/save_input_method";
RouteEvents.checkBenificiaryCodeInputMethod = "/entry?";
export { RouteEvents };
33 changes: 21 additions & 12 deletions PWA/public/Services/CacheFilePathService.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import { BeneficiaryDataUploadHandler } from "../FetchEventHandlers/BeneficiaryDataUploadHandler.js";
import { ChooseBenificiaryCodeInputMethodHandler } from "../FetchEventHandlers/ChooseBenificiaryCodeInputMethodHandler.js";
import { CreateDistributionRequestHandler } from "../FetchEventHandlers/CreateDistributionRequestHandler.js";
import { DeleteDistributionPostHandler } from "../FetchEventHandlers/DeleteDistributionPostHandler.js";
import { FetchEventHandlers } from "../FetchEventHandlers/FetchEventHandlers.js";
import { ListDistributionRequestHandler } from "../FetchEventHandlers/ListDistributionRequestHandler.js";
import { NameDistributionRequestHandler } from "../FetchEventHandlers/NameDistributionRequestHandler.js";
import { SelectDistributionRequestHandler } from "../FetchEventHandlers/SelectDistributionRequestHandler.js";
import { UploadDataHandler } from "../FetchEventHandlers/UploadDataHandler.js";
import { BeneficiaryDataUploadHandler } from "./FetchEventHandlers/BeneficiaryDataUploadHandler.js";
import { ChooseBenificiaryCodeInputMethodPageHandler } from "./FetchEventHandlers/ChooseBenificiaryCodeInputMethodPageHandler.js";
import { CreateDistributionRequestHandler } from "./FetchEventHandlers/CreateDistributionRequestHandler.js";
import { DeleteDistributionPostHandler } from "./FetchEventHandlers/DeleteDistributionPostHandler.js";
import { FetchEventHandlers } from "./FetchEventHandlers/FetchEventHandlers.js";
import { ListDistributionRequestHandler } from "./FetchEventHandlers/ListDistributionRequestHandler.js";
import { NameDistributionRequestHandler } from "./FetchEventHandlers/NameDistributionRequestHandler.js";
import { SelectBenificiaryCodeInputMethodHandler } from "./FetchEventHandlers/SelectBenificiaryCodeInputMethodHandler.js";
import { SelectDistributionRequestHandler } from "./FetchEventHandlers/SelectDistributionRequestHandler.js";
import { UploadDataHandler } from "./FetchEventHandlers/UploadDataHandler.js";
import { BenificiarySpreadSheetRow } from "../Models/BenificiarySpreadSheetRow.js";
import { DeleteDistributionPost } from "../Models/DeleteDistributionPost.js";
import { Distribution } from "../Models/Distribution.js";
Expand All @@ -17,6 +18,8 @@ import { BenificiaryJsonValidator } from "./BenificiaryJsonValidator.js";
import { Database } from "./Database.js";
import { DeserialisationService } from "./DeserialisationService.js";
import { FormParser } from "./FormParser.js";
import { BeneficiaryCodePostHandler } from "./FetchEventHandlers/BeneficiaryCodePostHandler.js";
import { BeneficiaryCodeInputMethodPost } from "../Models/BeneficiaryCodeInputMethodPost.js";
export class CacheFilePathService {
pathsOfFilesToCache() {
return [
Expand All @@ -41,7 +44,10 @@ export class CacheFilePathService {
RouteEvents.deleteDistribution,
RouteEvents.uploadData,
RouteEvents.uploadDataError,
RouteEvents.chooseBenificiaryCodeInputMethodPage
RouteEvents.chooseBenificiaryCodeInputMethodPage,
RouteEvents.codeInputUsingCamera,
RouteEvents.codeinputUsingTextField,
RouteEvents.codeInputNotFound,
];
}
toplevelScriptsPaths() {
Expand All @@ -64,6 +70,7 @@ export class CacheFilePathService {
Distribution.name,
DeleteDistributionPost.name,
SelectDistributionPost.name,
BeneficiaryCodeInputMethodPost.name
]);
}
servicePaths() {
Expand All @@ -77,7 +84,7 @@ export class CacheFilePathService {
]);
}
fetchEventHanderPaths() {
return this.pathsForTypesInFolder("FetchEventHandlers", [
return this.pathsForTypesInFolder("Services/FetchEventHandlers", [
BeneficiaryDataUploadHandler.name,
CreateDistributionRequestHandler.name,
DeleteDistributionPostHandler.name,
Expand All @@ -86,7 +93,9 @@ export class CacheFilePathService {
NameDistributionRequestHandler.name,
SelectDistributionRequestHandler.name,
UploadDataHandler.name,
ChooseBenificiaryCodeInputMethodHandler.name
ChooseBenificiaryCodeInputMethodPageHandler.name,
SelectBenificiaryCodeInputMethodHandler.name,
BeneficiaryCodePostHandler.name,
]);
}
interfacesPaths() {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import { RouteEvents } from "../../RouteEvents.js";
import { ResponseTools } from "../ResponseTools.js";
/*
@main.route('/entry', methods=['POST', 'GET'])
@login_required
def beneficiary():
"""Get beneficiary data."""
if 'distrib_id' not in session.keys():
return render_template('index_distrib.html')
if 'code' in request.form.keys():
if request.form['code'].strip() == '':
return render_template('input.html')
else:
code = str(request.form['code'])
elif 'code' in request.args.keys():
if request.args['code'].strip() == '':
return render_template('input.html')
else:
code = str(request.args['code'])
else:
return render_template('input.html')
beneficiary_data = get_beneficiary_entry(beneficiary_id=str(session['distrib_id'])+str(code),
user_email=current_user.email,
distrib_id=session['distrib_id'])
if beneficiary_data == "not_found":
return render_template('entry_not_found.html')
elif beneficiary_data == "no_data":
return render_template('no_data.html')
else:
for internal_field in ['id', 'distrib_id', 'partitionKey']:
if internal_field in beneficiary_data.keys():
beneficiary_data.pop(internal_field)
return render_template('entry.html',
data=beneficiary_data)
*/
export class BeneficiaryCodePostHandler {
canHandleEvent(event) {
return event.request.url.includes(RouteEvents.checkBenificiaryCodeInputMethod);
}
async handleEvent(event) {
//TODO: handle other cases
return ResponseTools.wrapInHtmlTemplate(RouteEvents.codeInputNotFound);
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { RouteEvents } from "../RouteEvents.js";
import { Database } from "../Services/Database.js";
import { BenificiarySpreadSheetRowsDeserializationService } from "../Services/BenificiarySpreadSheetRowsDeserializationService.js";
import { RouteEvents } from "../../RouteEvents.js";
import { Database } from "../Database.js";
import { BenificiarySpreadSheetRowsDeserializationService } from "../BenificiarySpreadSheetRowsDeserializationService.js";
export class BeneficiaryDataUploadHandler {
canHandleEvent(event) {
return event.request.url.endsWith("/uploader");
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { RouteEvents } from "../RouteEvents.js";
import { ResponseTools } from "../Services/ResponseTools.js";
export class ChooseBenificiaryCodeInputMethodHandler {
import { RouteEvents } from "../../RouteEvents.js";
import { ResponseTools } from "../ResponseTools.js";
export class ChooseBenificiaryCodeInputMethodPageHandler {
canHandleEvent(event) {
return event.request.url.endsWith(RouteEvents.chooseBenificiaryCodeInputMethod);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { RouteEvents } from "../RouteEvents.js";
import { ResponseTools } from "../Services/ResponseTools.js";
import { Database } from "../Services/Database.js";
import { DeserialisationService } from "../Services/DeserialisationService.js";
import { BenificiaryInfoService } from "../Services/BenificiaryInfoService.js";
import { RouteEvents } from "../../RouteEvents.js";
import { ResponseTools } from "../ResponseTools.js";
import { Database } from "../Database.js";
import { DeserialisationService } from "../DeserialisationService.js";
import { BenificiaryInfoService } from "../BenificiaryInfoService.js";
export class CreateDistributionRequestHandler {
canHandleEvent(event) {
return event.request.url.endsWith(RouteEvents.postCreateDistribution);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { RouteEvents } from "../RouteEvents.js";
import { Database } from "../Services/Database.js";
import { DeserialisationService } from "../Services/DeserialisationService.js";
import { RouteEvents } from "../../RouteEvents.js";
import { Database } from "../Database.js";
import { DeserialisationService } from "../DeserialisationService.js";
export class DeleteDistributionPostHandler {
canHandleEvent(event) {
return event.request.url.endsWith(RouteEvents.postDeleteDistribution);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { RouteEvents } from "../RouteEvents.js";
import { Distribution } from "../Models/Distribution.js";
import { ResponseTools } from "../Services/ResponseTools.js";
import { Database } from "../Services/Database.js";
import { RouteEvents } from "../../RouteEvents.js";
import { Distribution } from "../../Models/Distribution.js";
import { ResponseTools } from "../ResponseTools.js";
import { Database } from "../Database.js";
export class DeleteDistributionRequestHandler {
canHandleEvent(event) {
return event.request.url.endsWith(RouteEvents.deleteDistribution);
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ import { DeleteDistributionRequestHandler } from "./DeleteDistributionRequestHan
import { UploadDataHandler } from "./UploadDataHandler.js";
import { BeneficiaryDataUploadHandler } from "./BeneficiaryDataUploadHandler.js";
import { DeleteDistributionPostHandler } from "./DeleteDistributionPostHandler.js";
import { ChooseBenificiaryCodeInputMethodHandler } from "./ChooseBenificiaryCodeInputMethodHandler.js";
import { ChooseBenificiaryCodeInputMethodPageHandler } from "./ChooseBenificiaryCodeInputMethodPageHandler.js";
import { SelectBenificiaryCodeInputMethodHandler } from "./SelectBenificiaryCodeInputMethodHandler.js";
import { BeneficiaryCodePostHandler } from "./BeneficiaryCodePostHandler.js";
export class FetchEventHandlers {
constructor() {
this.all = [
Expand All @@ -18,7 +20,9 @@ export class FetchEventHandlers {
new DeleteDistributionPostHandler(),
new UploadDataHandler(),
new BeneficiaryDataUploadHandler(),
new ChooseBenificiaryCodeInputMethodHandler()
new ChooseBenificiaryCodeInputMethodPageHandler(),
new SelectBenificiaryCodeInputMethodHandler(),
new BeneficiaryCodePostHandler()
];
}
handlersForEvent(event) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { RouteEvents } from "../RouteEvents.js";
import { Distribution } from "../Models/Distribution.js";
import { ResponseTools } from "../Services/ResponseTools.js";
import { Database } from "../Services/Database.js";
import { RouteEvents } from "../../RouteEvents.js";
import { Distribution } from "../../Models/Distribution.js";
import { ResponseTools } from "../ResponseTools.js";
import { Database } from "../Database.js";
export class ListDistributionRequestHandler {
canHandleEvent(event) {
const url = event.request.url;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { RouteEvents } from "../RouteEvents.js";
import { ResponseTools } from "../Services/ResponseTools.js";
import { RouteEvents } from "../../RouteEvents.js";
import { ResponseTools } from "../ResponseTools.js";
export class NameDistributionRequestHandler {
canHandleEvent(event) {
return event.request.url.endsWith(RouteEvents.nameDistribution);
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;
}
}
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { RouteEvents } from "../RouteEvents.js";
import { ResponseTools } from "../Services/ResponseTools.js";
import { Database } from "../Services/Database.js";
import { DeserialisationService } from "../Services/DeserialisationService.js";
import { BenificiaryInfoService } from "../Services/BenificiaryInfoService.js";
import { RouteEvents } from "../../RouteEvents.js";
import { ResponseTools } from "../ResponseTools.js";
import { Database } from "../Database.js";
import { DeserialisationService } from "../DeserialisationService.js";
import { BenificiaryInfoService } from "../BenificiaryInfoService.js";
export class SelectDistributionRequestHandler {
canHandleEvent(event) {
return event.request.url.endsWith(RouteEvents.postSelectDistribution);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { RouteEvents } from "../RouteEvents.js";
import { RouteEvents } from "../../RouteEvents.js";
export class UploadDataHandler {
canHandleEvent(event) {
return event.request.url.endsWith("/upload_data?");
Expand Down
13 changes: 13 additions & 0 deletions PWA/public/entry_not_found.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<div class="column is-4 is-offset-4">
<div class="box">
<label class="label is-medium">Beneficiary not found!</label>
<br>
<form action="/input" method="GET">
<button class="button is-block is-info is-medium is-fullwidth">Continue distribution</button>
</form>
<br>
<form action="/" method="GET">
<button class="button is-block is-info is-medium is-fullwidth">Go back to main menu</button>
</form>
</div>
</div>
2 changes: 1 addition & 1 deletion PWA/public/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
<!-- <a class="navbar-item">-->
<img src="images/ReliefBox-horizontal-nobackground.png" width="220" height="30">
<!-- </a>-->

<div class="navbar-item">Alpha 0.1.5</div>
<a role="button" class="navbar-burger" aria-label="menu" aria-expanded="false" data-target="navbarBasicExample">
<span aria-hidden="true"></span>
<span aria-hidden="true"></span>
Expand Down
10 changes: 10 additions & 0 deletions PWA/public/input.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<div class="column is-4 is-offset-4">
<form action="/entry" method="POST">
<div class="field">
<div class="control">
<input class="input is-medium" type="text" name="code" placeholder="Beneficiary code" autofocus="">
</div>
</div>
<button class="button is-block is-info is-medium is-fullwidth">Submit</button>
</form>
</div>
Loading

0 comments on commit 1d337ab

Please sign in to comment.