homebox/frontend/pages/home.vue

180 lines
5.4 KiB
Vue
Raw Normal View History

2022-09-01 22:32:03 +00:00
<script setup lang="ts">
definePageMeta({
layout: "home",
2022-09-01 22:32:03 +00:00
});
useHead({
title: "Homebox | Home",
2022-09-01 22:32:03 +00:00
});
const api = useUserApi();
2022-09-02 01:52:40 +00:00
const { data: locations } = useAsyncData("locations", async () => {
2022-09-01 22:32:03 +00:00
const { data } = await api.locations.getAll();
2022-09-02 01:52:40 +00:00
return data.items;
});
const { data: labels } = useAsyncData("labels", async () => {
2022-09-02 01:52:40 +00:00
const { data } = await api.labels.getAll();
return data.items;
2022-09-01 22:32:03 +00:00
});
2022-09-03 09:17:57 +00:00
const { data: items } = useAsyncData("items", async () => {
2022-09-03 09:17:57 +00:00
const { data } = await api.items.getAll();
return data.items;
});
const totalItems = computed(() => items.value?.length || 0);
const totalLocations = computed(() => locations.value?.length || 0);
const totalLabels = computed(() => labels.value?.length || 0);
const stats = [
{
label: "Locations",
2022-09-03 09:17:57 +00:00
value: totalLocations,
},
{
label: "Items",
2022-09-03 09:17:57 +00:00
value: totalItems,
},
{
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];
console.log("importCsv.value", importCsv.value);
2022-09-06 18:32:13 +00:00
}
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
async function submitCsvFile() {
importLoading.value = true;
const { error } = await api.items.import(importCsv.value);
if (error) {
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-01 22:32:03 +00:00
</script>
<template>
2022-09-04 06:19:13 +00:00
<BaseContainer class="space-y-16 pb-16">
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" />
<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-03 09:17:57 +00:00
<section aria-labelledby="profile-overview-title" class="mt-8">
<div class="overflow-hidden rounded-lg bg-white shadow">
<h2 id="profile-overview-title" class="sr-only">Profile Overview</h2>
2022-09-03 09:17:57 +00:00
<div class="bg-white p-6">
<div class="sm:flex sm:items-center sm:justify-between">
<div class="sm:flex sm:space-x-5">
<div class="mt-4 text-center sm:mt-0 sm:pt-1 sm:text-left">
<p class="text-sm font-medium text-gray-600">Welcome back,</p>
<p class="text-xl font-bold text-gray-900 sm:text-2xl">Hayden Kotelman</p>
<p class="text-sm font-medium text-gray-600">User</p>
</div>
</div>
<div class="mt-5 flex justify-center sm:mt-0">
<a
href="#"
class="flex items-center justify-center rounded-md border border-gray-300 bg-white px-4 py-2 text-sm font-medium text-gray-700 shadow-sm hover:bg-gray-50"
>View profile</a
>
</div>
</div>
</div>
<div
class="grid grid-cols-1 divide-y divide-gray-200 border-t border-gray-200 bg-gray-50 sm:grid-cols-3 sm:divide-y-0 sm:divide-x"
2022-09-02 01:52:40 +00:00
>
2022-09-03 09:17:57 +00:00
<div v-for="stat in stats" :key="stat.label" class="px-6 py-5 text-center text-sm font-medium">
<span class="text-gray-900">{{ stat.value.value }}</span>
{{ " " }}
2022-09-03 09:17:57 +00:00
<span class="text-gray-600">{{ stat.label }}</span>
2022-09-02 01:52:40 +00:00
</div>
2022-09-03 09:17:57 +00:00
</div>
</div>
</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>
</section>
<section>
2022-09-06 18:32:13 +00:00
<BaseSectionHeader class="mb-5">
Items
<template #description>
<div class="tooltip" data-tip="Import CSV File">
<button class="btn btn-primary btn-sm" @click="openDialog">
2022-09-06 18:32:13 +00:00
<Icon name="mdi-database" class="mr-2"></Icon>
Import
</button>
</div>
</template>
</BaseSectionHeader>
2022-09-03 09:17:57 +00:00
<div class="grid sm:grid-cols-2 gap-4">
<ItemCard v-for="item in items" :key="item.id" :item="item" />
2022-09-02 01:52:40 +00:00
</div>
</section>
<section>
<BaseSectionHeader class="mb-5"> Labels </BaseSectionHeader>
2022-09-03 10:02:21 +00:00
<div class="flex gap-2 flex-wrap">
<LabelChip v-for="label in labels" :key="label.id" size="lg" :label="label" />
2022-09-02 01:52:40 +00:00
</div>
</section>
2022-09-01 22:32:03 +00:00
</BaseContainer>
</template>