|
| 1 | +<script setup> |
| 2 | +import { onMounted, provide, ref, watch } from "vue"; |
| 3 | +import icon from "./icon.svg"; |
| 4 | +import { createService } from "./service.js"; |
| 5 | +// Components |
| 6 | +import BuildingForm from "./BuildingForm/BuildingForm.vue"; |
| 7 | +import BuildingsList from "./BuildingsList/BuildingsList.vue"; |
| 8 | +import BuildingStoreys from "./BuildingStoreys/BuildingStoreys.vue"; |
| 9 | +
|
| 10 | +const props = defineProps({ |
| 11 | + apiClient: { |
| 12 | + type: Object, |
| 13 | + required: true, |
| 14 | + }, |
| 15 | + space: { |
| 16 | + type: Object, |
| 17 | + required: true, |
| 18 | + }, |
| 19 | + project: { |
| 20 | + type: Object, |
| 21 | + required: true, |
| 22 | + }, |
| 23 | + model: { |
| 24 | + type: Object, |
| 25 | + default: null, |
| 26 | + }, |
| 27 | +}); |
| 28 | +
|
| 29 | +const emit = defineEmits([ |
| 30 | + "metaBuilding-created", |
| 31 | + "metaBuilding-updated", |
| 32 | + "metaBuilding-deleted", |
| 33 | +]); |
| 34 | +
|
| 35 | +const VIEWS = Object.freeze({ |
| 36 | + FORM: "form", |
| 37 | + LIST: "list", |
| 38 | + VIEW: "view", |
| 39 | +}); |
| 40 | +
|
| 41 | +const service = createService(props.apiClient, props.space, props.project); |
| 42 | +const loading = ref(false); |
| 43 | +
|
| 44 | +provide("service", service); |
| 45 | +provide("loading", loading); |
| 46 | +
|
| 47 | +const currentView = ref(VIEWS.LIST); |
| 48 | +const metaBuildings = ref([]); |
| 49 | +const currentMetaBuilding = ref(null); |
| 50 | +
|
| 51 | +const loadMetaBuildings = async () => { |
| 52 | + loading.value = true; |
| 53 | + metaBuildings.value = await service.fetchMetaBuildings(); |
| 54 | + loading.value = false; |
| 55 | +}; |
| 56 | +const deleteMetaBuilding = async (metaBuilding) => { |
| 57 | + await service.deleteMetaBuilding(metaBuilding); |
| 58 | + loadMetaBuildings(); |
| 59 | + emit("metaBuilding-deleted"); |
| 60 | +}; |
| 61 | +const openForm = (metaBuilding) => { |
| 62 | + currentMetaBuilding.value = metaBuilding ?? null; |
| 63 | + currentView.value = VIEWS.FORM; |
| 64 | +}; |
| 65 | +const openMetaBuilding = (metaBuilding) => { |
| 66 | + currentMetaBuilding.value = metaBuilding; |
| 67 | + currentView.value = VIEWS.VIEW; |
| 68 | +}; |
| 69 | +const onMetaBuildingCreated = async (metaBuilding) => { |
| 70 | + await loadMetaBuildings(); |
| 71 | + openMetaBuilding(metaBuilding); |
| 72 | + emit("metaBuilding-created"); |
| 73 | +}; |
| 74 | +const onMetaBuildingUpdated = () => { |
| 75 | + loadMetaBuildings(); |
| 76 | + currentView.value = VIEWS.LIST; |
| 77 | + emit("metaBuilding-updated"); |
| 78 | +}; |
| 79 | +const back = () => { |
| 80 | + currentView.value = VIEWS.LIST; |
| 81 | +}; |
| 82 | +
|
| 83 | +watch( |
| 84 | + () => props.model, |
| 85 | + model => { if (model) openMetaBuilding(model); }, |
| 86 | + { immediate: true } |
| 87 | +); |
| 88 | +
|
| 89 | +onMounted(() => loadMetaBuildings()); |
| 90 | +</script> |
| 91 | +
|
1 | 92 | <template> |
2 | 93 | <div class="bimdata-building-maker"> |
3 | 94 | <div |
|
34 | 125 | /> |
35 | 126 | </template> |
36 | 127 |
|
37 | | - <template v-else-if="currentView === VIEWS.STOREYS && currentMetaBuilding"> |
| 128 | + <template v-else-if="currentView === VIEWS.VIEW && currentMetaBuilding"> |
38 | 129 | <BuildingStoreys |
39 | 130 | :apiClient="apiClient" |
40 | 131 | :space="space" |
|
47 | 138 | <template v-else> |
48 | 139 | <BuildingsList |
49 | 140 | :metaBuildings="metaBuildings" |
| 141 | + @open-metaBuilding="openMetaBuilding" |
50 | 142 | @create-metaBuilding="openForm" |
51 | 143 | @update-metaBuilding="openForm" |
52 | 144 | @delete-metaBuilding="deleteMetaBuilding" |
53 | | - @manage-storeys="openStoreys" |
54 | 145 | /> |
55 | 146 | </template> |
56 | 147 | </transition> |
|
64 | 155 | </div> |
65 | 156 | </template> |
66 | 157 |
|
67 | | -<script> |
68 | | -import { onMounted, provide, ref, watch } from "vue"; |
69 | | -import icon from "./icon.svg"; |
70 | | -import { createService } from "./service.js"; |
71 | | -// Components |
72 | | -import BuildingForm from "./BuildingForm/BuildingForm.vue"; |
73 | | -import BuildingsList from "./BuildingsList/BuildingsList.vue"; |
74 | | -import BuildingStoreys from "./BuildingStoreys/BuildingStoreys.vue"; |
75 | | -
|
76 | | -const VIEWS = Object.freeze({ |
77 | | - FORM: "form", |
78 | | - LIST: "list", |
79 | | - STOREYS: "storeys", |
80 | | -}); |
81 | | -
|
82 | | -export default { |
83 | | - components: { |
84 | | - BuildingForm, |
85 | | - BuildingsList, |
86 | | - BuildingStoreys, |
87 | | - }, |
88 | | - props: { |
89 | | - apiClient: { |
90 | | - type: Object, |
91 | | - required: true, |
92 | | - }, |
93 | | - space: { |
94 | | - type: Object, |
95 | | - required: true, |
96 | | - }, |
97 | | - project: { |
98 | | - type: Object, |
99 | | - required: true, |
100 | | - }, |
101 | | - model: { |
102 | | - type: Object, |
103 | | - default: null, |
104 | | - }, |
105 | | - }, |
106 | | - emits: [ |
107 | | - "metaBuilding-created", |
108 | | - "metaBuilding-updated", |
109 | | - "metaBuilding-deleted", |
110 | | - ], |
111 | | - setup(props, { emit }) { |
112 | | - const service = createService(props.apiClient, props.space, props.project); |
113 | | - const loading = ref(false); |
114 | | -
|
115 | | - provide("service", service); |
116 | | - provide("loading", loading); |
117 | | -
|
118 | | - const currentView = ref(VIEWS.LIST); |
119 | | - const metaBuildings = ref([]); |
120 | | - const currentMetaBuilding = ref(null); |
121 | | -
|
122 | | - const loadMetaBuildings = async () => { |
123 | | - loading.value = true; |
124 | | - metaBuildings.value = await service.fetchMetaBuildings(); |
125 | | - loading.value = false; |
126 | | - }; |
127 | | - const deleteMetaBuilding = async (metaBuilding) => { |
128 | | - await service.deleteMetaBuilding(metaBuilding); |
129 | | - loadMetaBuildings(); |
130 | | - emit("metaBuilding-deleted"); |
131 | | - }; |
132 | | - const openForm = (metaBuilding) => { |
133 | | - currentMetaBuilding.value = metaBuilding || null; |
134 | | - currentView.value = VIEWS.FORM; |
135 | | - }; |
136 | | - const openStoreys = (metaBuilding) => { |
137 | | - currentMetaBuilding.value = metaBuilding; |
138 | | - currentView.value = VIEWS.STOREYS; |
139 | | - }; |
140 | | - const onMetaBuildingCreated = async (metaBuilding) => { |
141 | | - await loadMetaBuildings(); |
142 | | - openStoreys(metaBuilding); |
143 | | - emit("metaBuilding-created"); |
144 | | - }; |
145 | | - const onMetaBuildingUpdated = () => { |
146 | | - loadMetaBuildings(); |
147 | | - currentView.value = VIEWS.LIST; |
148 | | - emit("metaBuilding-updated"); |
149 | | - }; |
150 | | - const back = () => { |
151 | | - currentView.value = VIEWS.LIST; |
152 | | - }; |
153 | | -
|
154 | | - watch( |
155 | | - () => props.model, |
156 | | - model => { if (model) openStoreys(model); }, |
157 | | - { immediate: true } |
158 | | - ); |
159 | | -
|
160 | | - onMounted(() => loadMetaBuildings()); |
161 | | -
|
162 | | - return { |
163 | | - // References |
164 | | - currentMetaBuilding, |
165 | | - currentView, |
166 | | - icon, |
167 | | - loading, |
168 | | - metaBuildings, |
169 | | - VIEWS, |
170 | | - // Methods |
171 | | - back, |
172 | | - deleteMetaBuilding, |
173 | | - loadMetaBuildings, |
174 | | - onMetaBuildingCreated, |
175 | | - onMetaBuildingUpdated, |
176 | | - openForm, |
177 | | - openStoreys, |
178 | | - }; |
179 | | - }, |
180 | | -}; |
181 | | -</script> |
182 | | - |
183 | | -<style scoped lang="scss" src="./BIMDataBuildingMaker.scss"></style> |
| 158 | +<style scoped src="./BIMDataBuildingMaker.css"></style> |
0 commit comments