2022-09-01 22:32:03 +00:00
|
|
|
<script setup lang="ts">
|
2022-09-25 22:33:13 +00:00
|
|
|
import { useAuthStore } from "~~/stores/auth";
|
2022-09-13 03:36:22 +00:00
|
|
|
import { useItemStore } from "~~/stores/items";
|
|
|
|
import { useLabelStore } from "~~/stores/labels";
|
|
|
|
import { useLocationStore } from "~~/stores/locations";
|
|
|
|
|
2022-09-01 22:32:03 +00:00
|
|
|
definePageMeta({
|
2022-09-09 22:46:53 +00:00
|
|
|
layout: "home",
|
2022-09-01 22:32:03 +00:00
|
|
|
});
|
|
|
|
useHead({
|
2022-09-09 22:46:53 +00:00
|
|
|
title: "Homebox | Home",
|
2022-09-01 22:32:03 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
const api = useUserApi();
|
2022-09-02 01:52:40 +00:00
|
|
|
|
2022-09-25 22:33:13 +00:00
|
|
|
const auth = useAuthStore();
|
|
|
|
|
|
|
|
if (auth.self === null) {
|
|
|
|
const { data, error } = await api.self();
|
|
|
|
if (error) {
|
2022-09-29 05:42:33 +00:00
|
|
|
navigateTo("/");
|
2022-09-25 22:33:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
auth.$patch({ self: data.item });
|
|
|
|
|
|
|
|
console.log(auth.self);
|
|
|
|
}
|
|
|
|
|
2022-09-13 03:36:22 +00:00
|
|
|
const itemsStore = useItemStore();
|
|
|
|
const items = computed(() => itemsStore.items);
|
2022-09-02 01:52:40 +00:00
|
|
|
|
2022-09-13 03:36:22 +00:00
|
|
|
const locationStore = useLocationStore();
|
|
|
|
const locations = computed(() => locationStore.locations);
|
2022-09-03 09:17:57 +00:00
|
|
|
|
2022-09-13 03:36:22 +00:00
|
|
|
const labelsStore = useLabelStore();
|
|
|
|
const labels = computed(() => labelsStore.labels);
|
2022-09-03 09:17:57 +00:00
|
|
|
|
|
|
|
const totalItems = computed(() => items.value?.length || 0);
|
|
|
|
const totalLocations = computed(() => locations.value?.length || 0);
|
|
|
|
const totalLabels = computed(() => labels.value?.length || 0);
|
|
|
|
|
|
|
|
const stats = [
|
|
|
|
{
|
2022-09-09 22:46:53 +00:00
|
|
|
label: "Locations",
|
2022-09-03 09:17:57 +00:00
|
|
|
value: totalLocations,
|
|
|
|
},
|
|
|
|
{
|
2022-09-09 22:46:53 +00:00
|
|
|
label: "Items",
|
2022-09-03 09:17:57 +00:00
|
|
|
value: totalItems,
|
|
|
|
},
|
|
|
|
{
|
2022-09-09 22:46:53 +00:00
|
|
|
label: "Labels",
|
2022-09-03 09:17:57 +00:00
|
|
|
value: totalLabels,
|
|
|
|
},
|
|
|
|
];
|
2022-09-06 18:32:13 +00:00
|
|
|
|
|
|
|
const importDialog = ref(false);
|
|
|
|
const importCsv = ref(null);
|
2022-09-09 06:05:23 +00:00
|
|
|
const importLoading = ref(false);
|
2022-09-06 18:32:13 +00:00
|
|
|
const importRef = ref<HTMLInputElement>(null);
|
|
|
|
whenever(
|
|
|
|
() => !importDialog.value,
|
|
|
|
() => {
|
|
|
|
importCsv.value = null;
|
|
|
|
}
|
|
|
|
);
|
|
|
|
|
|
|
|
function setFile(e: Event & { target: HTMLInputElement }) {
|
|
|
|
importCsv.value = e.target.files[0];
|
|
|
|
}
|
|
|
|
|
2022-09-09 06:05:23 +00:00
|
|
|
const toast = useNotifier();
|
|
|
|
|
2022-09-06 18:32:13 +00:00
|
|
|
function openDialog() {
|
|
|
|
importDialog.value = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
function uploadCsv() {
|
|
|
|
importRef.value.click();
|
|
|
|
}
|
2022-09-09 06:05:23 +00:00
|
|
|
|
2022-09-13 03:36:22 +00:00
|
|
|
const eventBus = useEventBus();
|
|
|
|
|
2022-09-09 06:05:23 +00:00
|
|
|
async function submitCsvFile() {
|
|
|
|
importLoading.value = true;
|
|
|
|
|
|
|
|
const { error } = await api.items.import(importCsv.value);
|
|
|
|
|
|
|
|
if (error) {
|
2022-09-09 22:46:53 +00:00
|
|
|
toast.error("Import failed. Please try again later.");
|
2022-09-09 06:05:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Reset
|
|
|
|
importDialog.value = false;
|
|
|
|
importLoading.value = false;
|
|
|
|
importCsv.value = null;
|
|
|
|
importRef.value.value = null;
|
2022-09-13 03:36:22 +00:00
|
|
|
|
|
|
|
eventBus.emit(EventTypes.ClearStores);
|
2022-09-09 06:05:23 +00:00
|
|
|
}
|
2022-09-01 22:32:03 +00:00
|
|
|
</script>
|
|
|
|
|
|
|
|
<template>
|
2022-09-25 22:33:13 +00:00
|
|
|
<div>
|
2022-09-06 18:32:13 +00:00
|
|
|
<BaseModal v-model="importDialog">
|
|
|
|
<template #title> Import CSV File </template>
|
|
|
|
<p>
|
|
|
|
Import a CSV file containing your items, labels, and locations. See documentation for more information on the
|
|
|
|
required format.
|
|
|
|
</p>
|
|
|
|
|
2022-09-09 06:05:23 +00:00
|
|
|
<form @submit.prevent="submitCsvFile">
|
|
|
|
<div class="flex flex-col gap-2 py-6">
|
|
|
|
<input ref="importRef" type="file" class="hidden" accept=".csv" @change="setFile" />
|
2022-09-25 22:33:13 +00:00
|
|
|
|
2022-09-09 06:05:23 +00:00
|
|
|
<BaseButton type="button" @click="uploadCsv">
|
|
|
|
<Icon class="h-5 w-5 mr-2" name="mdi-upload" />
|
|
|
|
Upload
|
|
|
|
</BaseButton>
|
|
|
|
<p class="text-center pt-4 -mb-5">
|
|
|
|
{{ importCsv?.name }}
|
|
|
|
</p>
|
|
|
|
</div>
|
|
|
|
|
|
|
|
<div class="modal-action">
|
|
|
|
<BaseButton type="submit" :disabled="!importCsv"> Submit </BaseButton>
|
|
|
|
</div>
|
|
|
|
</form>
|
2022-09-06 18:32:13 +00:00
|
|
|
</BaseModal>
|
2022-09-25 22:33:13 +00:00
|
|
|
<BaseContainer class="flex flex-col gap-16 pb-16">
|
|
|
|
<section>
|
|
|
|
<BaseCard>
|
|
|
|
<template #title> Welcome Back, {{ auth.self ? auth.self.name : "Username" }} </template>
|
|
|
|
<template #subtitle> {{ auth.self.isSuperuser ? "Admin" : "User" }} </template>
|
|
|
|
<template #title-actions>
|
|
|
|
<div class="flex justify-end gap-2">
|
|
|
|
<div class="tooltip" data-tip="Import CSV File">
|
|
|
|
<button class="btn btn-primary btn-sm" @click="openDialog">
|
|
|
|
<Icon name="mdi-database" class="mr-2"></Icon>
|
|
|
|
Import
|
|
|
|
</button>
|
2022-09-03 09:17:57 +00:00
|
|
|
</div>
|
2022-10-01 20:13:53 +00:00
|
|
|
<BaseButton type="button" size="sm" to="/profile">
|
2022-09-25 22:33:13 +00:00
|
|
|
<Icon class="h-5 w-5 mr-2" name="mdi-person" />
|
|
|
|
Profile
|
|
|
|
</BaseButton>
|
2022-09-03 09:17:57 +00:00
|
|
|
</div>
|
2022-09-25 22:33:13 +00:00
|
|
|
</template>
|
|
|
|
|
|
|
|
<div
|
2022-10-01 20:13:53 +00:00
|
|
|
class="grid grid-cols-1 divide-y divide-base-300 border-t border-base-300 sm:grid-cols-3 sm:divide-y-0 sm:divide-x"
|
2022-09-25 22:33:13 +00:00
|
|
|
>
|
|
|
|
<div v-for="stat in stats" :key="stat.label" class="px-6 py-5 text-center text-sm font-medium">
|
2022-10-01 20:13:53 +00:00
|
|
|
<span class="text-base-900 font-bold">{{ stat.value.value }}</span>
|
2022-09-25 22:33:13 +00:00
|
|
|
{{ " " }}
|
2022-10-01 20:13:53 +00:00
|
|
|
<span class="text-base-600">{{ stat.label }}</span>
|
2022-09-03 09:17:57 +00:00
|
|
|
</div>
|
|
|
|
</div>
|
2022-09-25 22:33:13 +00:00
|
|
|
</BaseCard>
|
|
|
|
</section>
|
|
|
|
|
|
|
|
<section>
|
|
|
|
<BaseSectionHeader class="mb-5"> Labels </BaseSectionHeader>
|
|
|
|
<div class="flex gap-2 flex-wrap">
|
|
|
|
<LabelChip v-for="label in labels" :key="label.id" size="lg" :label="label" />
|
2022-09-03 09:17:57 +00:00
|
|
|
</div>
|
2022-09-25 22:33:13 +00:00
|
|
|
</section>
|
|
|
|
|
|
|
|
<section>
|
|
|
|
<BaseSectionHeader class="mb-5"> Storage Locations </BaseSectionHeader>
|
|
|
|
<div class="grid grid-cols-1 sm:grid-cols-2 card md:grid-cols-3 gap-4">
|
|
|
|
<LocationCard v-for="location in locations" :key="location.id" :location="location" />
|
2022-09-03 09:17:57 +00:00
|
|
|
</div>
|
2022-09-25 22:33:13 +00:00
|
|
|
</section>
|
|
|
|
|
|
|
|
<section>
|
|
|
|
<BaseSectionHeader class="mb-5"> Items </BaseSectionHeader>
|
|
|
|
<div class="grid grid-cols-1 sm:grid-cols-2 gap-4">
|
|
|
|
<ItemCard v-for="item in items" :key="item.id" :item="item" />
|
|
|
|
</div>
|
|
|
|
</section>
|
|
|
|
</BaseContainer>
|
|
|
|
</div>
|
2022-09-01 22:32:03 +00:00
|
|
|
</template>
|