Skip to content

Commit

Permalink
MINOR: feat: add highlightedId and selectedId models to meta-building…
Browse files Browse the repository at this point in the history
… structure component
  • Loading branch information
NicolasRichel committed May 31, 2024
1 parent a451bad commit 44aabbd
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ const props = defineProps({
},
selectable: {
type: Boolean,
default: true,
default: false,
},
});
Expand All @@ -37,6 +37,9 @@ const emit = defineEmits([
"storey-selected"
]);
const highlightedId = defineModel("highlightedId", { default: null });
const selectedId = defineModel("selectedId", { default: null });
const loading = ref(false);
const modelStoreys = ref([]);
const modelZones = ref([]);
Expand Down Expand Up @@ -80,6 +83,8 @@ const state = {
storey: readonly(selectedStorey),
zones: computed(() => modelZones.value.filter(zone => zone.storey_uuid === selectedStorey.value?.uuid)),
selectable: computed(() => props.selectable),
highlightedId,
selectedId,
onStoreySelected: event => (selectedStorey.value = event, emit("storey-selected", event)),
onSelectionChanged: event => emit("selection-changed", event),
};
Expand Down
31 changes: 29 additions & 2 deletions src/BIMDataMetaBuildingStructure/StructureView/StructureView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ defineOptions({
}
});
const { storey, zones } = inject("BIMDataMetaBuildingStructure.state");
const state = inject("BIMDataMetaBuildingStructure.state");
const { storey, zones, highlightedId, selectedId } = state;
const tree = computed(() => setupTree(buildStructureTree(storey.value, zones.value)));
const nodes = computed(() => flattenTree(tree.value));
Expand All @@ -29,6 +30,26 @@ watch(searchText, value => {
node.visibleRef.value = !text || node.text.toLowerCase().includes(text);
});
});
watch(highlightedId, id => {
let parent = nodes.value.find(x => x.id === id)?.parent;
while (parent) {
parent.expandedRef.value = true;
parent = parent.parent;
}
});
const onNodeHover = node => {
highlightedId.value = node?.id;
};
const onNodeClick = node => {
if (selectedId.value === node?.id) {
selectedId.value = null;
} else {
selectedId.value = node?.id;
}
};
</script>
<template>
Expand All @@ -39,7 +60,13 @@ watch(searchText, value => {
:placeholder="$t('MetaBuildingStructure.StructureView.search')"
v-model="searchText"
/>
<BIMDataTree :data="tree">
<BIMDataTree
:data="tree"
:highlighted-id="highlightedId"
:selected-id="selectedId"
@hover="onNodeHover"
@click="onNodeClick"
>
<template #node="{ node, depth }">
<component
:is="node.component"
Expand Down

0 comments on commit 44aabbd

Please sign in to comment.