-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
153 additions
and
109 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)); | ||
} | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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) { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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()) | ||
); | ||
}) | ||
}) | ||
); | ||
}); | ||
|
||
|