Skip to content

Commit

Permalink
PATCH: fix(meta-building): use apiClient to fetch model zones
Browse files Browse the repository at this point in the history
  • Loading branch information
NicolasRichel committed Apr 19, 2024
1 parent 9725161 commit c8f1208
Show file tree
Hide file tree
Showing 5 changed files with 63 additions and 22 deletions.
5 changes: 1 addition & 4 deletions src/BIMDataBuildingMaker/BIMDataBuildingMaker.vue
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,7 @@
</div>

<transition name="fade">
<div
class="bimdata-building-maker__loader"
v-show="loading.value"
>
<div class="bimdata-building-maker__loader" v-show="loading">
<BIMDataSpinner />
</div>
</transition>
Expand Down
54 changes: 52 additions & 2 deletions src/BIMDataMetaBuildingStructure/BIMDataMetaBuildingStructure.vue
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ import StructureView from "./StructureView/StructureView.vue";
import ZonesView from "./ZonesView/ZonesView.vue";
const props = defineProps({
apiClient: {
type: Object,
required: true,
},
space: {
type: Object,
required: true,
Expand All @@ -28,9 +32,30 @@ const props = defineProps({
},
});
const emit = defineEmits(["selection-changed", "storey-selected"]);
const emit = defineEmits([
"selection-changed",
"storey-selected"
]);
const loading = ref(false);
const modelZones = ref([]);
const selectedStorey = ref(null);
watch(
() => props.model,
async model => {
if (model) {
try {
loading.value = true;
modelZones.value = await props.apiClient.modelApi.getZones(props.space.id, model.id, props.project.id);
} finally {
loading.value = false;
}
}
},
{ immediate: true }
);
watch(
() => props.storey,
storey => (selectedStorey.value = storey),
Expand All @@ -41,7 +66,7 @@ const state = {
model: computed(() => props.model),
storeys: computed(() => props.model?.storeys ?? []),
storey: readonly(selectedStorey),
zones: computed(() => props.model?.zones.filter(zone => zone.storey_uuid === selectedStorey.value?.uuid) ?? []),
zones: computed(() => modelZones.value.filter(zone => zone.storey_uuid === selectedStorey.value?.uuid) ?? []),
selectable: computed(() => props.selectable),
onStoreySelected: event => (selectedStorey.value = event, emit("storey-selected", event)),
onSelectionChanged: event => emit("selection-changed", event),
Expand Down Expand Up @@ -102,11 +127,18 @@ const activeTab = ref(tabs[0]);
<div class="body">
<component :is="activeTab.view" />
</div>
<transition name="fade">
<div class="loading" v-show="loading">
<BIMDataSpinner />
</div>
</transition>
</div>
</template>
<style scoped>
.meta-building-structure {
position: relative;
height: 100%;
.title {
Expand Down Expand Up @@ -143,5 +175,23 @@ const activeTab = ref(tabs[0]);
justify-content: center;
align-items: center;
}
.loading {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
display: flex;
justify-content: center;
align-items: center;
background-color: rgba(255, 255, 255, 0.75);
.bimdata-spinner {
transform: scale(2);
}
}
}
</style>
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ defineOptions({
}
});
const { model, storey } = inject("BIMDataMetaBuildingStructure.state");
const { storey, zones } = inject("BIMDataMetaBuildingStructure.state");
const tree = computed(() => setupTree(buildStructureTree(model.value, storey.value)));
const tree = computed(() => setupTree(buildStructureTree(storey.value, zones.value)));
const nodes = computed(() => flattenTree(tree.value));
const searchText = ref("");
Expand Down
4 changes: 2 additions & 2 deletions src/BIMDataMetaBuildingStructure/ZonesView/ZonesView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ defineOptions({
}
});
const { model, storey } = inject("BIMDataMetaBuildingStructure.state");
const { zones } = inject("BIMDataMetaBuildingStructure.state");
const tree = computed(() => buildZonesTree(model.value, storey.value));
const tree = computed(() => buildZonesTree(zones.value));
</script>

<template>
Expand Down
18 changes: 6 additions & 12 deletions src/BIMDataMetaBuildingStructure/meta-building-structure.js
Original file line number Diff line number Diff line change
@@ -1,34 +1,28 @@
import { ref } from "vue";

export function buildStructureTree(model, storey) {
export function buildStructureTree(storey, zones) {
return [
{
id: 1,
text: "Zones",
component: "StructureRootNode",
children: buildZonesTree(model, storey),
children: buildZonesTree(zones),
},
{
id: 2,
text: "Plans",
component: "StructureRootNode",
children: buildPlansTree(model, storey),
children: buildPlansTree(storey),
}
];
}

export function buildZonesTree(model, storey) {
if (!model || !storey) return [];

const zones = model.zones.filter(zone => zone.storey_uuid === storey.uuid);

export function buildZonesTree(zones) {
return zones.map(zoneNode);
}

export function buildPlansTree(model, storey) {
if (!model || !storey) return [];

return storey.plans.map(planNode);
export function buildPlansTree(storey) {
return storey?.plans.map(planNode) ?? [];
}

export function setupTree(tree, parent) {
Expand Down

0 comments on commit c8f1208

Please sign in to comment.