Files
homebox/frontend/pages/locations.vue
mcarbonne a85c42b539 Implement maintenance view (#235)
* implement backend to query maintenances

* improve backend API for maintenances

* add itemId and itemName (v1/maintenances)

* fix remaining todo in backend (/v1/maintenances)

* refactor: extract MaintenanceEditModal

* first draft (to be cleaned)

* revert dependency updates (not required)

* translation + fix deletion

* fix main menu css issues

* fix main menu "create" button (css)

* enhancement: make item name clickable

* fix: add page title (+ translate existing ones)

* fix: missing toast translation (when updating)

* bug fix: missing group check in backend (for new endpoint)

* backport from following PR (to avoid useless changes)

* maintenances => maintenance
2024-09-23 13:07:27 -04:00

80 lines
1.8 KiB
Vue

<script setup lang="ts">
import { useTreeState } from "~~/components/Location/Tree/tree-state";
import MdiCollapseAllOutline from "~icons/mdi/collapse-all-outline";
definePageMeta({
middleware: ["auth"],
});
useHead({
title: "Homebox | Items",
});
const api = useUserApi();
const { data: tree } = useAsyncData(async () => {
const { data, error } = await api.locations.getTree({
withItems: true,
});
if (error) {
return [];
}
return data;
});
const locationTreeId = "locationTree";
const treeState = useTreeState(locationTreeId);
const route = useRouter();
onMounted(() => {
// set tree state from query params
const query = route.currentRoute.value.query;
if (query && query[locationTreeId]) {
console.debug("setting tree state from query params");
const data = JSON.parse(query[locationTreeId] as string);
for (const key in data) {
treeState.value[key] = data[key];
}
}
});
watch(
treeState,
() => {
// Push the current state to the URL
route.replace({ query: { [locationTreeId]: JSON.stringify(treeState.value) } });
},
{ deep: true }
);
function closeAll() {
for (const key in treeState.value) {
treeState.value[key] = false;
}
}
</script>
<template>
<BaseContainer class="mb-16">
<BaseSectionHeader> {{ $t("menu.locations") }} </BaseSectionHeader>
<BaseCard>
<div class="p-4">
<div class="mb-2 flex justify-end">
<div class="btn-group">
<button class="btn tooltip tooltip-top btn-sm" data-tip="Collapse Tree" @click="closeAll">
<MdiCollapseAllOutline />
</button>
</div>
</div>
<LocationTreeRoot v-if="tree" :locs="tree" :tree-id="locationTreeId" />
</div>
</BaseCard>
</BaseContainer>
</template>