-
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.
Make sure template can be downloaded bump 0.5.1
- Loading branch information
Showing
10 changed files
with
69 additions
and
6 deletions.
There are no files selected for viewing
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
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
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
25 changes: 25 additions & 0 deletions
25
PWA/public/Services/FetchEventHandlers/DownloadSpreadsheetTemplateHandler.js
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,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)); | ||
} | ||
} | ||
} |
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
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
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
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
30 changes: 30 additions & 0 deletions
30
PWA/src/Services/FetchEventHandlers/DownloadSpreadsheetTemplateHandler.ts
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,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)); | ||
} | ||
} | ||
} |
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