2022-09-01 22:32:03 +00:00
|
|
|
<template>
|
|
|
|
<div>
|
2022-12-30 01:19:15 +00:00
|
|
|
<!--
|
|
|
|
Confirmation Modal is a singleton used by all components so we render
|
|
|
|
it here to ensure it's always available. Possibly could move this further
|
|
|
|
up the tree
|
|
|
|
-->
|
|
|
|
<ModalConfirm />
|
|
|
|
<ItemCreateModal v-model="modals.item" />
|
|
|
|
<LabelCreateModal v-model="modals.label" />
|
|
|
|
<LocationCreateModal v-model="modals.location" />
|
2022-09-01 22:32:03 +00:00
|
|
|
<AppToast />
|
2022-12-30 01:19:15 +00:00
|
|
|
<div class="drawer drawer-mobile">
|
|
|
|
<input id="my-drawer-2" v-model="drawerToggle" type="checkbox" class="drawer-toggle" />
|
2022-12-30 05:18:49 +00:00
|
|
|
<div class="drawer-content justify-center bg-base-300 pt-20 lg:pt-0">
|
|
|
|
<AppHeaderDecor class="-mt-10 hidden lg:block" />
|
2022-12-30 01:19:15 +00:00
|
|
|
<!-- Button -->
|
2022-12-30 05:18:49 +00:00
|
|
|
<div class="navbar z-[99] lg:hidden top-0 fixed bg-primary shadow-md drawer-button">
|
|
|
|
<NuxtLink to="/home">
|
|
|
|
<h2 class="mt-1 ml-1 text-3xl font-bold tracking-tight text-base-100 flex">
|
|
|
|
HomeB
|
|
|
|
<AppLogo class="w-8 -mb-3" />
|
|
|
|
x
|
|
|
|
</h2>
|
|
|
|
</NuxtLink>
|
|
|
|
<label for="my-drawer-2" class="btn btn-square btn-ghost ml-auto text-base-100 drawer-button lg:hidden">
|
|
|
|
<Icon name="mdi-menu" class="h-6 w-6" />
|
|
|
|
</label>
|
|
|
|
</div>
|
|
|
|
|
|
|
|
<slot></slot>
|
2022-12-30 01:19:15 +00:00
|
|
|
</div>
|
|
|
|
|
|
|
|
<!-- Sidebar -->
|
|
|
|
<div class="drawer-side shadow-lg">
|
|
|
|
<label for="my-drawer-2" class="drawer-overlay"></label>
|
|
|
|
|
|
|
|
<!-- Top Section -->
|
|
|
|
<div class="w-60 py-5 md:py-10 bg-base-200 flex flex-grow-1 flex-col">
|
|
|
|
<div class="space-y-8">
|
|
|
|
<div class="flex flex-col items-center gap-4">
|
|
|
|
<p>Welcome, {{ username }}</p>
|
|
|
|
<NuxtLink class="avatar placeholder" to="/home">
|
|
|
|
<div class="bg-base-300 text-neutral-content rounded-full w-24 p-4">
|
|
|
|
<AppLogo />
|
|
|
|
</div>
|
|
|
|
</NuxtLink>
|
|
|
|
</div>
|
|
|
|
<div class="flex flex-col bg-base-200">
|
|
|
|
<div class="mx-auto w-40 mb-6">
|
|
|
|
<div class="dropdown overflow visible w-40">
|
|
|
|
<label tabindex="0" class="btn btn-primary btn-block text-lg text-no-transform">
|
|
|
|
<span>
|
|
|
|
<Icon name="mdi-plus" class="mr-1 -ml-1" />
|
|
|
|
</span>
|
|
|
|
Create
|
|
|
|
</label>
|
|
|
|
<ul tabindex="0" class="dropdown-content menu p-2 shadow bg-base-100 rounded-box w-40">
|
|
|
|
<li v-for="btn in dropdown" :key="btn.name">
|
|
|
|
<button @click="btn.action">
|
|
|
|
{{ btn.name }}
|
|
|
|
</button>
|
|
|
|
</li>
|
|
|
|
</ul>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<ul class="flex flex-col mx-auto gap-2 w-40 menu">
|
|
|
|
<li v-for="n in nav" :key="n.id" class="text-xl" @click="unfocus">
|
|
|
|
<NuxtLink
|
|
|
|
v-if="n.to"
|
|
|
|
class="rounded-btn"
|
|
|
|
:to="n.to"
|
|
|
|
:class="{
|
|
|
|
'bg-secondary text-secondary-content': n.active?.value,
|
|
|
|
}"
|
|
|
|
>
|
|
|
|
<Icon :name="n.icon" class="h-6 w-6 mr-4" />
|
|
|
|
{{ n.name }}
|
|
|
|
</NuxtLink>
|
|
|
|
</li>
|
|
|
|
</ul>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
|
|
|
|
<!-- Bottom -->
|
|
|
|
<button class="mt-auto mx-2 hover:bg-base-300 p-3 rounded-btn" @click="logout">Sign Out</button>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
2022-09-01 22:32:03 +00:00
|
|
|
</div>
|
|
|
|
</template>
|
2022-10-15 20:15:55 +00:00
|
|
|
|
|
|
|
<script lang="ts" setup>
|
|
|
|
import { useLabelStore } from "~~/stores/labels";
|
|
|
|
import { useLocationStore } from "~~/stores/locations";
|
|
|
|
|
2023-03-23 05:52:25 +00:00
|
|
|
const username = computed(() => authCtx.user?.name || "User");
|
2022-12-30 01:19:15 +00:00
|
|
|
|
2023-01-01 21:50:48 +00:00
|
|
|
// Preload currency format
|
|
|
|
useFormatCurrency();
|
|
|
|
|
2022-12-30 01:19:15 +00:00
|
|
|
const modals = reactive({
|
|
|
|
item: false,
|
|
|
|
location: false,
|
|
|
|
label: false,
|
|
|
|
import: false,
|
|
|
|
});
|
|
|
|
|
|
|
|
const dropdown = [
|
|
|
|
{
|
|
|
|
name: "Item / Asset",
|
|
|
|
action: () => {
|
|
|
|
modals.item = true;
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "Location",
|
|
|
|
action: () => {
|
|
|
|
modals.location = true;
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "Label",
|
|
|
|
action: () => {
|
|
|
|
modals.label = true;
|
|
|
|
},
|
|
|
|
},
|
|
|
|
];
|
|
|
|
|
|
|
|
const route = useRoute();
|
|
|
|
|
|
|
|
const drawerToggle = ref();
|
|
|
|
|
|
|
|
function unfocus() {
|
|
|
|
// unfocus current element
|
|
|
|
drawerToggle.value = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
const nav = [
|
|
|
|
{
|
|
|
|
icon: "mdi-home",
|
|
|
|
active: computed(() => route.path === "/home"),
|
|
|
|
id: 0,
|
|
|
|
name: "Home",
|
|
|
|
to: "/home",
|
|
|
|
},
|
|
|
|
{
|
2023-02-18 19:56:28 +00:00
|
|
|
icon: "mdi-file-tree",
|
|
|
|
id: 4,
|
|
|
|
active: computed(() => route.path === "/locations"),
|
|
|
|
name: "Locations",
|
|
|
|
to: "/locations",
|
2022-12-30 01:19:15 +00:00
|
|
|
},
|
|
|
|
{
|
2023-01-28 20:53:00 +00:00
|
|
|
icon: "mdi-magnify",
|
2022-12-30 01:19:15 +00:00
|
|
|
id: 3,
|
|
|
|
active: computed(() => route.path === "/items"),
|
2023-01-28 20:53:00 +00:00
|
|
|
name: "Search",
|
2022-12-30 01:19:15 +00:00
|
|
|
to: "/items",
|
|
|
|
},
|
2023-01-28 20:53:00 +00:00
|
|
|
{
|
2023-02-18 19:56:28 +00:00
|
|
|
icon: "mdi-account",
|
|
|
|
id: 1,
|
|
|
|
active: computed(() => route.path === "/profile"),
|
|
|
|
name: "Profile",
|
|
|
|
to: "/profile",
|
2023-01-28 20:53:00 +00:00
|
|
|
},
|
2022-12-30 01:19:15 +00:00
|
|
|
{
|
2023-02-11 04:38:50 +00:00
|
|
|
icon: "mdi-cog",
|
|
|
|
id: 6,
|
|
|
|
active: computed(() => route.path === "/tools"),
|
|
|
|
name: "Tools",
|
|
|
|
to: "/tools",
|
2022-12-30 01:19:15 +00:00
|
|
|
},
|
|
|
|
];
|
2022-10-15 20:15:55 +00:00
|
|
|
|
2023-02-05 21:12:54 +00:00
|
|
|
function isMutation(method: string | undefined) {
|
|
|
|
return method === "POST" || method === "PUT" || method === "DELETE";
|
|
|
|
}
|
|
|
|
function isSuccess(status: number) {
|
|
|
|
return status >= 200 && status < 300;
|
|
|
|
}
|
|
|
|
|
2022-10-15 20:15:55 +00:00
|
|
|
const labelStore = useLabelStore();
|
|
|
|
const reLabel = /\/api\/v1\/labels\/.*/gm;
|
|
|
|
const rmLabelStoreObserver = defineObserver("labelStore", {
|
2023-02-05 21:12:54 +00:00
|
|
|
handler: (resp, req) => {
|
|
|
|
if (isMutation(req?.method) && isSuccess(resp.status) && resp.url.match(reLabel)) {
|
2022-10-15 20:15:55 +00:00
|
|
|
labelStore.refresh();
|
|
|
|
}
|
|
|
|
console.debug("labelStore handler called by observer");
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
|
|
|
const locationStore = useLocationStore();
|
|
|
|
const reLocation = /\/api\/v1\/locations\/.*/gm;
|
|
|
|
const rmLocationStoreObserver = defineObserver("locationStore", {
|
2023-02-05 21:12:54 +00:00
|
|
|
handler: (resp, req) => {
|
|
|
|
if (isMutation(req?.method) && isSuccess(resp.status) && resp.url.match(reLocation)) {
|
2022-11-02 19:54:43 +00:00
|
|
|
locationStore.refreshChildren();
|
|
|
|
locationStore.refreshParents();
|
2022-10-15 20:15:55 +00:00
|
|
|
}
|
2023-02-05 21:12:54 +00:00
|
|
|
|
2022-10-15 20:15:55 +00:00
|
|
|
console.debug("locationStore handler called by observer");
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
|
|
|
const eventBus = useEventBus();
|
|
|
|
eventBus.on(
|
2023-02-05 21:12:54 +00:00
|
|
|
EventTypes.InvalidStores,
|
2022-10-15 20:15:55 +00:00
|
|
|
() => {
|
|
|
|
labelStore.refresh();
|
2022-11-02 19:54:43 +00:00
|
|
|
locationStore.refreshChildren();
|
|
|
|
locationStore.refreshParents();
|
2022-10-15 20:15:55 +00:00
|
|
|
},
|
|
|
|
"stores"
|
|
|
|
);
|
|
|
|
|
|
|
|
onUnmounted(() => {
|
|
|
|
rmLabelStoreObserver();
|
|
|
|
rmLocationStoreObserver();
|
2023-02-05 21:12:54 +00:00
|
|
|
eventBus.off(EventTypes.InvalidStores, "stores");
|
2022-10-15 20:15:55 +00:00
|
|
|
});
|
2022-12-30 01:19:15 +00:00
|
|
|
|
2023-02-18 06:57:21 +00:00
|
|
|
const authCtx = useAuthContext();
|
2022-12-30 01:19:15 +00:00
|
|
|
const api = useUserApi();
|
|
|
|
|
|
|
|
async function logout() {
|
2023-03-23 05:52:25 +00:00
|
|
|
await authCtx.logout(api);
|
2022-12-30 01:19:15 +00:00
|
|
|
}
|
2022-10-15 20:15:55 +00:00
|
|
|
</script>
|