From a5c6c3d9b3ecedff886502ca8909775f77100646 Mon Sep 17 00:00:00 2001 From: Hayden <64056131+hay-kot@users.noreply.github.com> Date: Mon, 13 Feb 2023 09:39:00 -0900 Subject: [PATCH] get tsv export from tools page --- frontend/lib/api/classes/reports.ts | 27 +++++++ frontend/lib/api/user.ts | 3 + frontend/pages/tools.vue | 106 +++++++++++++++------------- 3 files changed, 88 insertions(+), 48 deletions(-) create mode 100644 frontend/lib/api/classes/reports.ts diff --git a/frontend/lib/api/classes/reports.ts b/frontend/lib/api/classes/reports.ts new file mode 100644 index 0000000..03890cb --- /dev/null +++ b/frontend/lib/api/classes/reports.ts @@ -0,0 +1,27 @@ +import { BaseAPI, route } from "../base"; + +export class ReportsAPI extends BaseAPI { + async billOfMaterials(): Promise { + const { data: stream, error } = await this.http.get({ url: route("/reporting/bill-of-materials") }); + + if (error) { + return; + } + + const reader = stream.getReader(); + let data = ""; + while (true) { + const { done, value } = await reader.read(); + if (done) { + break; + } + data += new TextDecoder("utf-8").decode(value); + } + + const blob = new Blob([data], { type: "text/tsv" }); + const link = document.createElement("a"); + link.href = window.URL.createObjectURL(blob); + link.download = "bill-of-materials.tsv"; + link.click(); + } +} diff --git a/frontend/lib/api/user.ts b/frontend/lib/api/user.ts index a0fd413..fa08258 100644 --- a/frontend/lib/api/user.ts +++ b/frontend/lib/api/user.ts @@ -7,6 +7,7 @@ import { UserApi } from "./classes/users"; import { ActionsAPI } from "./classes/actions"; import { StatsAPI } from "./classes/stats"; import { AssetsApi } from "./classes/assets"; +import { ReportsAPI } from "./classes/reports"; import { Requests } from "~~/lib/requests"; export class UserClient extends BaseAPI { @@ -18,6 +19,7 @@ export class UserClient extends BaseAPI { actions: ActionsAPI; stats: StatsAPI; assets: AssetsApi; + reports: ReportsAPI; constructor(requests: Requests, attachmentToken: string) { super(requests, attachmentToken); @@ -30,6 +32,7 @@ export class UserClient extends BaseAPI { this.actions = new ActionsAPI(requests); this.stats = new StatsAPI(requests); this.assets = new AssetsApi(requests); + this.reports = new ReportsAPI(requests); Object.freeze(this); } diff --git a/frontend/pages/tools.vue b/frontend/pages/tools.vue index e1ba350..181c308 100644 --- a/frontend/pages/tools.vue +++ b/frontend/pages/tools.vue @@ -2,6 +2,32 @@
+ + +
+ + + Generates a printable PDF of labels for a range of Asset ID. These are not specific to your inventory so + your are able to print labels ahead of time and apply them to your inventory when you receive them. + + + + + Generates a TSV (Tab Separated Values) file that can be imported into a spreadsheet program. This is a + summary of your inventory with basic item and pricing information + + +
+
-
- - - Imports the standard CSV format for Homebox. This will not overwrite any existing items in your - inventory. It will only add new items. - - -
- -
- - +
+ + + Imports the standard CSV format for Homebox. This will not overwrite any existing items in your + inventory. It will only add new items. + + +
-
- - - Ensures that all items in your inventory have a valid asset_id field. This is done by finding the highest - current asset_id field in the database and applying the next value to each item that has an unset asset_id - field. This is done in order of the created_at field. - - - - Resets the time value for all date time fields in your inventory to the beginning of the date. This is to - fix a bug that was introduced early on in the development of the site that caused the time value to be - stored with the time which caused issues with date fields displaying accurate values. - - See Github Issue #236 for more details - - -
+
+ + + Ensures that all items in your inventory have a valid asset_id field. This is done by finding the highest + current asset_id field in the database and applying the next value to each item that has an unset asset_id + field. This is done in order of the created_at field. + + + + Resets the time value for all date time fields in your inventory to the beginning of the date. This is to + fix a bug that was introduced early on in the development of the site that caused the time value to be + stored with the time which caused issues with date fields displaying accurate values. + + See Github Issue #236 for more details + + +
@@ -96,6 +102,10 @@ const confirm = useConfirm(); const notify = useNotifier(); + async function getBillOfMaterials() { + await api.reports.billOfMaterials(); + } + async function ensureAssetIDs() { const { isCanceled } = await confirm.open( "Are you sure you want to ensure all assets have an ID? This can take a while and cannot be undone."