From b875c2465d3540bb391038193f2b5eee54a61e83 Mon Sep 17 00:00:00 2001 From: Evert Prants Date: Sat, 28 Jan 2023 09:30:11 +0200 Subject: [PATCH] additions --- src/components/ImageBox.vue | 38 ++++++++ src/components/PageHead.vue | 2 +- src/components/form/base/Autocomplete.vue | 3 +- src/components/form/base/Select.vue | 3 +- src/components/item/NewItemModal.vue | 74 +++++++-------- src/components/item/StoredItemCard.vue | 4 +- src/router/index.ts | 6 ++ src/store/building.store.ts | 34 ++++--- src/store/storage.store.ts | 32 +++++++ src/views/Dashboard.vue | 100 ++++++++------------ src/views/Demo.vue | 65 +++++++++++++ src/views/building/BuildingListItem.vue | 16 ++++ src/views/building/BuildingView.vue | 5 +- src/views/building/floors/FloorListItem.vue | 41 ++------ 14 files changed, 276 insertions(+), 147 deletions(-) create mode 100644 src/components/ImageBox.vue create mode 100644 src/store/storage.store.ts create mode 100644 src/views/Demo.vue create mode 100644 src/views/building/BuildingListItem.vue diff --git a/src/components/ImageBox.vue b/src/components/ImageBox.vue new file mode 100644 index 0000000..0a7c730 --- /dev/null +++ b/src/components/ImageBox.vue @@ -0,0 +1,38 @@ + + + + + diff --git a/src/components/PageHead.vue b/src/components/PageHead.vue index 0382195..3de9262 100644 --- a/src/components/PageHead.vue +++ b/src/components/PageHead.vue @@ -1,6 +1,6 @@ - -
+
-
+
{ ); }); -const itemTransactionTypesOptions = computed(() => { - return Object.keys(TransactionTypeName).reduce( - (list, key) => [ - ...list, - { - value: key.toString(), - name: TransactionTypeName[key as TransactionType], - description: TransactionTypeDescription[key as TransactionType], - }, - ], - [] - ); -}); - const validators = ref([ { field: 'displayName', @@ -204,10 +186,6 @@ const validators = ref([ field: 'type', validators: [IsRequired()], }, - { - field: 'transactionInfo.type', - validators: [IsRequired()], - }, { field: 'transactionInfo.actionAt', validators: [IsRequired()], @@ -227,8 +205,16 @@ const currencies = [ const searchForItems = async (search: string) => { if (!search || search.length < 3) return []; + + const query = new URLSearchParams(); + if (search.startsWith('b:') && search.length > 3) { + query.append('barcode', search.substring(2)); + } else { + query.append('searchTerm', search); + } + const { data: list } = await jfetch( - `${BACKEND_URL}/storage/item?searchTerm=${search}`, + `${BACKEND_URL}/storage/item?${query.toString()}`, { headers: authHeader.value, } @@ -261,7 +247,11 @@ watch( const startAddingNewItem = (insert: string) => { item.value = insert; - data.value['displayName'] = insert; + if (insert.startsWith('b:')) { + data.value['barcode'] = insert.substring(2); + } else { + data.value['displayName'] = insert; + } }; const onSubmit = async (form: FormSubmit) => { diff --git a/src/components/item/StoredItemCard.vue b/src/components/item/StoredItemCard.vue index efd12fe..2da7313 100644 --- a/src/components/item/StoredItemCard.vue +++ b/src/components/item/StoredItemCard.vue @@ -20,7 +20,9 @@ {{ storedItem.item.displayName }} - ยท Added {{ dateToLocaleString(storedItem.acquiredAt || storedItem.createdAt) diff --git a/src/router/index.ts b/src/router/index.ts index 059531d..5904af1 100644 --- a/src/router/index.ts +++ b/src/router/index.ts @@ -7,6 +7,7 @@ import BuildingView from '../views/building/BuildingView.vue'; import FloorView from '../views/building/floors/FloorView.vue'; import { createRouter, createWebHashHistory } from 'vue-router'; import { useUserStore } from '../store/user.store'; +import Demo from '../views/Demo.vue'; const routes: RouteRecordRaw[] = [ { @@ -24,6 +25,11 @@ const routes: RouteRecordRaw[] = [ path: '/planner', component: HousePlanner, }, + { + name: 'demo', + path: '/demo', + component: Demo, + }, { name: 'buildings', path: '/building/:id', diff --git a/src/store/building.store.ts b/src/store/building.store.ts index 5b91c00..c378bfb 100644 --- a/src/store/building.store.ts +++ b/src/store/building.store.ts @@ -14,7 +14,9 @@ const { authHeader } = useAccessToken(); export const useBuildingStore = defineStore('building', { state: () => { return { + loadingBuildings: false, buildings: [] as BuildingListItem[], + loadingFloors: false, floors: [] as FloorListItem[], building: null as null | BuildingResponse, }; @@ -30,19 +32,29 @@ export const useBuildingStore = defineStore('building', { this.building = building; }, async getBuildings() { - const { data: buildings } = await jfetch(`${BACKEND_URL}/buildings`, { - headers: authHeader.value, - }); - this.buildings = buildings; + this.loadingBuildings = true; + try { + const { data: buildings } = await jfetch(`${BACKEND_URL}/buildings`, { + headers: authHeader.value, + }); + this.buildings = buildings; + } finally { + this.loadingBuildings = false; + } }, async getFloors(building: number) { - const { data: floors } = await jfetch( - `${BACKEND_URL}/buildings/${building}/floors`, - { - headers: authHeader.value, - } - ); - this.floors = floors; + this.loadingFloors = true; + try { + const { data: floors } = await jfetch( + `${BACKEND_URL}/buildings/${building}/floors`, + { + headers: authHeader.value, + } + ); + this.floors = floors; + } finally { + this.loadingFloors = false; + } }, async saveFloor( building: number, diff --git a/src/store/storage.store.ts b/src/store/storage.store.ts new file mode 100644 index 0000000..ce1282a --- /dev/null +++ b/src/store/storage.store.ts @@ -0,0 +1,32 @@ +import { defineStore } from 'pinia'; +import { useAccessToken } from '../composables/useAccessToken'; +import { BACKEND_URL } from '../constants'; +import { StoredItem } from '../interfaces/storage.interfaces'; +import jfetch from '../utils/jfetch'; + +const { authHeader } = useAccessToken(); +export const useStorageStore = defineStore('storage', { + state: () => { + return { + loadingExpiringItems: false, + expiringItems: [] as StoredItem[], + }; + }, + actions: { + async getExpiringItems() { + this.loadingExpiringItems = true; + this.expiringItems = []; + try { + const { data: items } = await jfetch( + `${BACKEND_URL}/storage/expiring`, + { + headers: authHeader.value, + } + ); + this.expiringItems = items; + } finally { + this.loadingExpiringItems = false; + } + }, + }, +}); diff --git a/src/views/Dashboard.vue b/src/views/Dashboard.vue index 4827b04..45d57e8 100644 --- a/src/views/Dashboard.vue +++ b/src/views/Dashboard.vue @@ -1,73 +1,57 @@ diff --git a/src/views/Demo.vue b/src/views/Demo.vue new file mode 100644 index 0000000..ab6ac1d --- /dev/null +++ b/src/views/Demo.vue @@ -0,0 +1,65 @@ + + + diff --git a/src/views/building/BuildingListItem.vue b/src/views/building/BuildingListItem.vue new file mode 100644 index 0000000..d5527d6 --- /dev/null +++ b/src/views/building/BuildingListItem.vue @@ -0,0 +1,16 @@ + + + diff --git a/src/views/building/BuildingView.vue b/src/views/building/BuildingView.vue index 1f163dd..298ee7e 100644 --- a/src/views/building/BuildingView.vue +++ b/src/views/building/BuildingView.vue @@ -23,7 +23,10 @@

Floors

-
+
- -
- -
- {{ floor.displayName }} - Floor {{ floor.number }} -
-
-
+ - -