2023-01-28 20:53:00 +00:00
|
|
|
<script setup lang="ts">
|
|
|
|
import { useTreeState } from "./tree-state";
|
2024-03-01 18:08:14 +00:00
|
|
|
import type { TreeItem } from "~~/lib/api/types/data-contracts";
|
2024-03-01 01:20:18 +00:00
|
|
|
import MdiChevronDown from "~icons/mdi/chevron-down";
|
|
|
|
import MdiChevronRight from "~icons/mdi/chevron-right";
|
|
|
|
import MdiMapMarker from "~icons/mdi/map-marker";
|
|
|
|
import MdiPackageVariant from "~icons/mdi/package-variant";
|
2023-01-28 20:53:00 +00:00
|
|
|
|
|
|
|
type Props = {
|
|
|
|
treeId: string;
|
|
|
|
item: TreeItem;
|
|
|
|
};
|
|
|
|
const props = withDefaults(defineProps<Props>(), {});
|
|
|
|
|
|
|
|
const link = computed(() => {
|
|
|
|
return props.item.type === "location" ? `/location/${props.item.id}` : `/item/${props.item.id}`;
|
|
|
|
});
|
|
|
|
|
|
|
|
const hasChildren = computed(() => {
|
|
|
|
return props.item.children.length > 0;
|
|
|
|
});
|
|
|
|
|
|
|
|
const state = useTreeState(props.treeId);
|
|
|
|
|
|
|
|
const openRef = computed({
|
|
|
|
get() {
|
|
|
|
return state.value[nodeHash.value] ?? false;
|
|
|
|
},
|
2023-11-16 02:19:51 +00:00
|
|
|
set(value: boolean) {
|
2023-01-28 20:53:00 +00:00
|
|
|
state.value[nodeHash.value] = value;
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
|
|
|
const nodeHash = computed(() => {
|
|
|
|
// converts a UUID to a short hash
|
|
|
|
return props.item.id.replace(/-/g, "").substring(0, 8);
|
|
|
|
});
|
|
|
|
</script>
|
|
|
|
|
|
|
|
<template>
|
|
|
|
<div>
|
|
|
|
<div
|
|
|
|
class="node flex items-center gap-1 rounded p-1"
|
|
|
|
:class="{
|
|
|
|
'cursor-pointer hover:bg-base-200': hasChildren,
|
|
|
|
}"
|
|
|
|
@click="openRef = !openRef"
|
|
|
|
>
|
|
|
|
<div
|
|
|
|
class="p-1/2 rounded mr-1 flex items-center justify-center"
|
|
|
|
:class="{
|
|
|
|
'hover:bg-base-200': hasChildren,
|
|
|
|
}"
|
|
|
|
>
|
|
|
|
<div v-if="!hasChildren" class="h-6 w-6"></div>
|
|
|
|
<label
|
|
|
|
v-else
|
|
|
|
class="swap swap-rotate"
|
|
|
|
:class="{
|
|
|
|
'swap-active': openRef,
|
|
|
|
}"
|
|
|
|
>
|
2024-03-01 01:20:18 +00:00
|
|
|
<MdiChevronRight name="mdi-chevron-right" class="h-6 w-6 swap-off" />
|
|
|
|
<MdiChevronDown name="mdi-chevron-down" class="h-6 w-6 swap-on" />
|
2023-01-28 20:53:00 +00:00
|
|
|
</label>
|
|
|
|
</div>
|
2024-03-01 01:20:18 +00:00
|
|
|
<MdiMapMarker v-if="item.type === 'location'" class="h-4 w-4" />
|
|
|
|
<MdiPackageVariant v-else class="h-4 w-4" />
|
2023-01-28 20:53:00 +00:00
|
|
|
<NuxtLink class="hover:link text-lg" :to="link" @click.stop>{{ item.name }} </NuxtLink>
|
|
|
|
</div>
|
|
|
|
<div v-if="openRef" class="ml-4">
|
|
|
|
<LocationTreeNode v-for="child in item.children" :key="child.id" :item="child" :tree-id="treeId" />
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<style scoped></style>
|