Skip to content

Commit

Permalink
Make sure template can be downloaded bump 0.5.1
Browse files Browse the repository at this point in the history
  • Loading branch information
rcmenno committed Oct 14, 2024
1 parent 4b725ca commit 7e8281b
Show file tree
Hide file tree
Showing 10 changed files with 69 additions and 6 deletions.
2 changes: 1 addition & 1 deletion PWA/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "ReliefBox",
"version": "0.5.0",
"version": "0.5.1",
"description": "A tool for managing the distribution of relief items during humanitarian emergencies.",
"main": "index.js",
"scripts": {
Expand Down
1 change: 1 addition & 0 deletions PWA/public/RouteEvents.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,4 @@ RouteEvents.checkWhosMissing = "/missing";
RouteEvents.received = "/received";
RouteEvents.continueDistribution = "/continueDistribution";
RouteEvents.downloadData = "/download_data";
RouteEvents.downloadSpreadsheetTemplate = "/download_template";
4 changes: 3 additions & 1 deletion PWA/public/Services/CacheFilePathService.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import { DateService } from "./DateService.js";
import { ContinueDistributionHandler } from "./FetchEventHandlers/ContinueDistributionHandler.js";
import { DownloadDataHandler } from "./FetchEventHandlers/DownloadDataHandler.js";
import { BeneficiaryStatusService } from "./BeneficiaryStatusService.js";
import { DownloadSpreadsheetTemplateHandler } from "./FetchEventHandlers/DownloadSpreadsheetTemplateHandler.js";
// Provides all the files that have to be cached for offline use
export class CacheFilePathService {
pathsOfFilesToCache() {
Expand Down Expand Up @@ -132,7 +133,8 @@ export class CacheFilePathService {
MarkAsReceivedPostHandler.name,
HomepageHandler.name,
ContinueDistributionHandler.name,
DownloadDataHandler.name
DownloadDataHandler.name,
DownloadSpreadsheetTemplateHandler.name
]);
}
interfacesPaths() {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { RouteEvents } from "../../RouteEvents.js";
import { ActiveSessionContainer } from "../ActiveSession.js";
export class DownloadSpreadsheetTemplateHandler extends ActiveSessionContainer {
canHandleEvent(event) {
return event.request.url.includes(RouteEvents.downloadSpreadsheetTemplate);
}
async handleEvent(event) {
const fileName = "data_template.xlsx";
const templateResponse = await caches.match(fileName);
if (templateResponse) {
const updatedResponse = new Response(templateResponse.body, {
status: templateResponse.status,
statusText: templateResponse.statusText,
headers: {
'Content-Type': 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
'Content-Disposition': 'attachment; filename="data_processed.xlsx"'
},
});
return updatedResponse;
}
else {
return Promise.reject(Error("Expected cached file named " + fileName));
}
}
}
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.5.0</div>
<div class="navbar-item">Alpha 0.5.1</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
3 changes: 2 additions & 1 deletion PWA/public/sw.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ self.addEventListener("install", function (event) {
"/apple-touch-icon-precomposed.png",
"/images/icons/app-icon-192x192.png",
"/apple-touch-icon-120x120.png",
"/apple-touch-icon-120x120-precomposed.png"
"/apple-touch-icon-120x120-precomposed.png",
"/data_template.xlsx"
]
.concat(new CacheFilePathService().pathsOfFilesToCache()));
})
Expand Down
1 change: 1 addition & 0 deletions PWA/src/RouteEvents.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,5 @@ export class RouteEvents {
static received = "/received"
static continueDistribution = "/continueDistribution"
static downloadData = "/download_data"
static downloadSpreadsheetTemplate = "/download_template"
}
4 changes: 3 additions & 1 deletion PWA/src/Services/CacheFilePathService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import { DateService } from "./DateService.js";
import { ContinueDistributionHandler } from "./FetchEventHandlers/ContinueDistributionHandler.js";
import { DownloadDataHandler } from "./FetchEventHandlers/DownloadDataHandler.js";
import { BeneficiaryStatusService } from "./BeneficiaryStatusService.js";
import { DownloadSpreadsheetTemplateHandler } from "./FetchEventHandlers/DownloadSpreadsheetTemplateHandler.js";

// Provides all the files that have to be cached for offline use
export class CacheFilePathService {
Expand Down Expand Up @@ -145,7 +146,8 @@ export class CacheFilePathService {
MarkAsReceivedPostHandler.name,
HomepageHandler.name,
ContinueDistributionHandler.name,
DownloadDataHandler.name
DownloadDataHandler.name,
DownloadSpreadsheetTemplateHandler.name
]);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import { RouteEvents } from "../../RouteEvents.js";
import { FetchEvent } from "../../Interfaces/FetchEvent.js";
import { FetchEventHandler } from "../../Interfaces/FetchEventHandler.js";
import { ActiveSessionContainer } from "../ActiveSession.js";
import { SpreadSheetService } from "../SpreadSheetService.js";
import { BeneficiaryStatusService } from "../BeneficiaryStatusService.js";

export class DownloadSpreadsheetTemplateHandler extends ActiveSessionContainer implements FetchEventHandler {
canHandleEvent(event: FetchEvent): boolean {
return event.request.url.includes(RouteEvents.downloadSpreadsheetTemplate);
}

async handleEvent(event: FetchEvent): Promise<Response> {
const fileName = "data_template.xlsx"
const templateResponse = await caches.match(fileName)
if (templateResponse) {
const updatedResponse = new Response(templateResponse.body, {
status: templateResponse.status,
statusText: templateResponse.statusText,
headers: {
'Content-Type': 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
'Content-Disposition': 'attachment; filename="data_processed.xlsx"'
},
});
return updatedResponse
} else {
return Promise.reject(Error("Expected cached file named " + fileName));
}
}
}
3 changes: 2 additions & 1 deletion PWA/src/sw.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ self.addEventListener("install", function (event: any) {
"/apple-touch-icon-precomposed.png",
"/images/icons/app-icon-192x192.png",
"/apple-touch-icon-120x120.png",
"/apple-touch-icon-120x120-precomposed.png"
"/apple-touch-icon-120x120-precomposed.png",
"/data_template.xlsx"
]
.concat(new CacheFilePathService().pathsOfFilesToCache())
);
Expand Down

0 comments on commit 7e8281b

Please sign in to comment.