-
-
Notifications
You must be signed in to change notification settings - Fork 123
/
Copy pathlocations.vue
79 lines (64 loc) · 1.85 KB
/
locations.vue
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
<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>