Skip to content

Commit

Permalink
Wip temp
Browse files Browse the repository at this point in the history
  • Loading branch information
rcmenno committed Feb 11, 2024
1 parent 2c8c9d5 commit 6e7caf2
Show file tree
Hide file tree
Showing 13 changed files with 153 additions and 109 deletions.
25 changes: 0 additions & 25 deletions POC/static/navbar-burger.js

This file was deleted.

File renamed without changes
File renamed without changes
File renamed without changes
Binary file added PWA/public/images/icons/app-icon-192x192.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added PWA/public/images/icons/app-icon-512x512.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added PWA/public/images/icons/favicon-16x16.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added PWA/public/images/icons/favicon-32x32.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
47 changes: 47 additions & 0 deletions PWA/public/src/sw.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import { FetchEventHandlers } from "./Services/FetchEventHandlers/FetchEventHandlers.js";
import { CacheFilePathService } from "./Services/CacheFilePathService.js";
import { ActiveSession } from "./SessionState/ActiveSession.js";
import { Database } from "./Services/Database.js";
var CACHE_STATIC_NAME = "static-v10";
var CACHE_DYNAMIC_NAME = "dynamic-v2";
self.addEventListener("install", function (event) {
console.log("[Service Worker] Installing Service Worker ...", event);
console.log(new CacheFilePathService().pathsOfFilesToCache());
event.waitUntil(caches.open(CACHE_STATIC_NAME)
.then(function (cache) {
console.log("[Service Worker] Precaching App Shell");
cache.addAll([
"/",
"/favicon.ico",
"/manifest.json",
"/apple-touch-icon.png",
"/apple-touch-icon-precomposed.png"
]
.concat(new CacheFilePathService().pathsOfFilesToCache()));
}));
});
self.addEventListener("activate", function (event) {
console.log("[Service Worker] Activating Service Worker ....", event);
event.waitUntil(caches.keys().then(function (keyList) {
return Promise.all(keyList.map(function (key) {
if (key !== CACHE_STATIC_NAME && key !== CACHE_DYNAMIC_NAME) {
console.log("[Service Worker] Removing old cache.", key);
return caches.delete(key);
}
}));
}));
return self.clients.claim();
});
// Cache-only
self.addEventListener("fetch", function (event) {
let customHandlers = new FetchEventHandlers(new ActiveSession(new Database(indexedDB)));
console.log("Handling fetch request " + event.request.url);
if (customHandlers.canHandleEvent(event)) {
console.log("using custom event handler");
event.respondWith(customHandlers.handleEvent(event));
}
else {
console.log("using custom cache");
event.respondWith(caches.match(event.request));
}
});
33 changes: 19 additions & 14 deletions PWA/public/sw.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,25 @@ self.addEventListener("install", function (event) {
event.waitUntil(caches.open(CACHE_STATIC_NAME)
.then(function (cache) {
console.log("[Service Worker] Precaching App Shell");
cache.addAll([
"/",
"https://cdn.jsdelivr.net/npm/[email protected]/css/bulma.min.css",
"https://unpkg.com/@zxing/library@latest/umd/index.min.js",
"/favicon.ico",
"/manifest.json",
"/images/ReliefBox-horizontal-nobackground.png",
"/images/510logo.jpg",
"/images/ReliefBox-horizontal.png",
"/images/ReliefBox.PNG",
"/apple-touch-icon.png",
"/apple-touch-icon-precomposed.png"
]
.concat(new CacheFilePathService().pathsOfFilesToCache()));
try {
cache.addAll([
"/",
"https://cdn.jsdelivr.net/npm/[email protected]/css/bulma.min.css",
"https://unpkg.com/@zxing/library@latest/umd/index.min.js",
"/favicon.ico",
"/manifest.json",
"/images/ReliefBox-horizontal-nobackground.png",
"/images/510logo.jpg",
"/images/ReliefBox-horizontal.png",
"/images/ReliefBox.PNG",
"/apple-touch-icon.png",
"/apple-touch-icon-precomposed.png"
]
.concat(new CacheFilePathService().pathsOfFilesToCache()));
}
catch (error) {
console.error("Failed to cache one ore more files because of error " + error);
}
}));
});
self.addEventListener("activate", function (event) {
Expand Down
149 changes: 86 additions & 63 deletions PWA/src/Services/CacheFilePathService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,114 +25,137 @@ import { BeneficiaryEligilityService } from "./BeneficiaryEligilityService.js";
// Provides all the files that have to be cached for offline use
export class CacheFilePathService {
pathsOfFilesToCache(): string[] {
return [
this.pagePaths(),
this.modelPaths(),
this.toplevelScriptsPaths(),
this.fetchEventHanderPaths(),
this.interfacesPaths(),
this.externalLibrariesPaths(),
this.servicePaths(),
this.sessionStatePaths()
return [
this.imagesPaths(),
this.pagePaths(),
this.modelPaths(),
this.toplevelScriptsPaths(),
this.fetchEventHanderPaths(),
this.interfacesPaths(),
this.externalLibrariesPaths(),
this.servicePaths(),
this.sessionStatePaths(),
].reduce((previousArray, currentValue) => {
return previousArray.concat(currentValue)
}, [])
return previousArray.concat(currentValue);
}, []);
}

private pagePaths(): string[] {
return [
RouteEvents.template,
RouteEvents.home,
RouteEvents.distributionsHome,
RouteEvents.nameDistribution,
RouteEvents.listDistributions,
RouteEvents.deleteDistribution,
RouteEvents.uploadData,
RouteEvents.uploadDataError,
RouteEvents.chooseBenificiaryCodeInputMethodPage,
RouteEvents.codeInputUsingCamera,
RouteEvents.codeinputUsingTextField,
RouteEvents.codeInputNotFound,
]
}
RouteEvents.template,
RouteEvents.home,
RouteEvents.distributionsHome,
RouteEvents.nameDistribution,
RouteEvents.listDistributions,
RouteEvents.deleteDistribution,
RouteEvents.uploadData,
RouteEvents.uploadDataError,
RouteEvents.chooseBenificiaryCodeInputMethodPage,
RouteEvents.codeInputUsingCamera,
RouteEvents.codeinputUsingTextField,
RouteEvents.codeInputNotFound,
];
}

private toplevelScriptsPaths(): string[] {
return this.pathsForTypesInFolder("", [
return this.pathsForTypesInFolder("", [
"app",
"sw",
"navbar-burger",
RouteEvents.name
RouteEvents.name,
]);
}

private externalLibrariesPaths(): string[] {
return this.pathsForTypesInFolder("ExternalLibraries", [
"mustache",
"xlsx.full.min"
"xlsx.full.min",
]).concat(
[
"https://cdn.jsdelivr.net/npm/[email protected]/css/bulma.min.css",
"https://unpkg.com/@zxing/library@latest/umd/index.min.js",
]
)
}

private imagesPaths(): string[] {
return this.pathsForTypesInFolder("images", [
"/images/ReliefBox-horizontal-nobackground.png",
"/images/510logo.jpg",
"/images/ReliefBox-horizontal.png",
"/images/ReliefBox.PNG",
]);
}
}

private modelPaths(): string[] {
return this.pathsForTypesInFolder("Models", [
Beneficiary.name,
Distribution.name,
DeleteDistributionPost.name,
SelectDistributionPost.name,
BeneficiaryCodeInputMethodPost.name
BeneficiaryCodeInputMethodPost.name,
]);
}

private servicePaths(): string[] {
return this.pathsForTypesInFolder("Services", [
BenificiaryInfoService.name,
CacheFilePathService.name,
Database.name,
DeserialisationService.name,
FormParser.name,
BeneficiaryEligilityService.name
])
BenificiaryInfoService.name,
CacheFilePathService.name,
Database.name,
DeserialisationService.name,
FormParser.name,
BeneficiaryEligilityService.name,
]);
}

private sessionStatePaths(): string[] {
return this.pathsForTypesInFolder("Services", [
ActiveSession.name
])
return this.pathsForTypesInFolder("Services", [ActiveSession.name]);
}

private fetchEventHanderPaths(): string[] {
return this.pathsForTypesInFolder("Services/FetchEventHandlers", [
BeneficiaryDataUploadHandler.name,
CreateDistributionRequestHandler.name,
DeleteDistributionPostHandler.name,
FetchEventHandlers.name,
ListDistributionRequestHandler.name,
NameDistributionRequestHandler.name,
SelectDistributionRequestHandler.name,
UploadDataHandler.name,
ChooseBenificiaryCodeInputMethodPageHandler.name,
SelectBenificiaryCodeInputMethodHandler.name,
BeneficiaryCodePostHandler.name,
])
BeneficiaryDataUploadHandler.name,
CreateDistributionRequestHandler.name,
DeleteDistributionPostHandler.name,
FetchEventHandlers.name,
ListDistributionRequestHandler.name,
NameDistributionRequestHandler.name,
SelectDistributionRequestHandler.name,
UploadDataHandler.name,
ChooseBenificiaryCodeInputMethodPageHandler.name,
SelectBenificiaryCodeInputMethodHandler.name,
BeneficiaryCodePostHandler.name,
]);
}

private interfacesPaths(): string[] {
return this.pathsForTypesInFolder("Interfaces", [
"FetchEvent",
"FetchEventHandler"
])
"FetchEvent",
"FetchEventHandler",
]);
}

private pathsForTypesInFolder(folder: string, typeNames: String[], extension: string = ".js"): string[] {
return typeNames.map((name) => this.pathForTypeInFolder(name, folder, extension));
private pathsForTypesInFolder(
folder: string,
typeNames: String[],
extension: string = ".js"
): string[] {
return typeNames.map((name) =>
this.pathForTypeInFolder(name, folder, extension)
);
}

private pathForTypeInFolder(typeName: String, folder: string, extension: string = ".js"): string {
let path = "/"
if(folder.length > 0) {
path += folder + "/"
private pathForTypeInFolder(
typeName: String,
folder: string,
extension: string = ".js"
): string {
let path = "/";
if (folder.length > 0) {
path += folder + "/";
}
path += typeName + extension
path += typeName + extension;

return path
return path;
}
}
8 changes: 1 addition & 7 deletions PWA/src/sw.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,20 +15,14 @@ self.addEventListener("install", function (event: any) {
console.log("[Service Worker] Precaching App Shell");
cache.addAll([
"/",
"https://cdn.jsdelivr.net/npm/[email protected]/css/bulma.min.css",
"https://unpkg.com/@zxing/library@latest/umd/index.min.js",
"/favicon.ico",
"/manifest.json",
"/images/ReliefBox-horizontal-nobackground.png",
"/images/510logo.jpg",
"/images/ReliefBox-horizontal.png",
"/images/ReliefBox.PNG",
"/apple-touch-icon.png",
"/apple-touch-icon-precomposed.png"
]
.concat(new CacheFilePathService().pathsOfFilesToCache())
);
})
})
);
});

Expand Down

0 comments on commit 6e7caf2

Please sign in to comment.