Skip to content

Commit ceb071f

Browse files
authored
Refactor filter and configuration handling (#227)
* Added functionality to delete filters and mapping. * Refactored navigation and mapping for dynamic model handling.
1 parent 4c2c791 commit ceb071f

31 files changed

+327
-209
lines changed

src/components/Base/Navbar.vue

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@
115115
MenuItem,
116116
MenuItems
117117
} from '@headlessui/vue'
118-
import type { Step, PageType } from '@/models/pageModel'
118+
import type { PageType, Step } from '@/models/pageModel'
119119
import { useSpeckleStore } from '@/stores/speckleStore'
120120
import { useNavigationStore } from '@/stores/navigationStore'
121121
import router from '@/router'
@@ -139,15 +139,25 @@
139139
navigationStore.toggleSettingsModal()
140140
}
141141
142+
const modelId =
143+
route.params.modelId ||
144+
speckleStore.getProjectDetails?.stream.commits.items[0].id
145+
142146
const steps: Step[] = [
143147
{ name: 'Projects', href: '/projects' },
144148
{ name: 'Overview', href: `/projects/${route.params.projectId}/overview` },
145149
{
146150
name: 'Filtering',
147-
href: `/projects/${route.params.projectId}/filtering`
151+
href: `/projects/${route.params.projectId}/models/${modelId}/filtering`
152+
},
153+
{
154+
name: 'Mapping',
155+
href: `/projects/${route.params.projectId}/models/${modelId}/mapping`
156+
},
157+
{
158+
name: 'Results',
159+
href: `/projects/${route.params.projectId}/models/${modelId}/results`
148160
},
149-
{ name: 'Mapping', href: `/projects/${route.params.projectId}/mapping` },
150-
{ name: 'Results', href: `/projects/${route.params.projectId}/results` },
151161
{ name: 'Benchmark', href: '/benchmark' }
152162
]
153163
</script>

src/components/ModelViewer/SpeckleViewer.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,10 +116,10 @@
116116
117117
// Initialize and mount the viewer
118118
onMounted(async () => {
119+
// await loadProject(false)
119120
const renderParent = document.getElementById('renderParent') as HTMLElement
120121
const container = document.getElementById('renderer') as HTMLElement
121122
window.addEventListener('keydown', handleEscKey)
122-
// window.addEventListener('keydown', handleSelectAll)
123123
124124
viewer = new Viewer(container, DefaultViewerParams)
125125
await viewer.init()

src/components/ProjectSelection/ProjectGrid.vue

Lines changed: 8 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
:key="project.name"
2525
class="col-span-1 flex flex-col styled-element hoverable pressable cursor-pointer"
2626
:style="{ backgroundColor: projectColors[index] }"
27-
@click="startTransition(project, projectColors[index])"
27+
@click="onProjectClick(project, projectColors[index])"
2828
>
2929
<!-- Project Iterator. -->
3030
<div class="flex flex-1 flex-col p-8 min-h-40">
@@ -84,7 +84,6 @@
8484
import { emissionToNumber, getResultLogEmissions } from '@/utils/resultUtils'
8585
import { ColorManager } from '@/utils/colorUtils'
8686
import router from '@/router'
87-
import { useNavigationStore } from '@/stores/navigationStore'
8887
import { roundNumber } from '@/utils/mathUtils'
8988
import LoadingCubes from '@/components/LoadingCubes/LoadingCubes.vue'
9089
@@ -94,10 +93,6 @@
9493
const speckleStore = useSpeckleStore()
9594
const firebaseStore = useFirebaseStore()
9695
const settingsStore = useSettingsStore()
97-
const navStore = useNavigationStore()
98-
99-
const selectedProjectId = ref('')
100-
const selectedProjectName = ref('')
10196
10297
const loading = ref(false)
10398
@@ -201,28 +196,13 @@
201196
}
202197
203198
// Updated transition function
204-
const startTransition = async (project: ProjectId, color: string) => {
205-
activeColor.value = color
206-
selectedProjectId.value = project.id
207-
selectedProjectName.value = project.name
208-
209-
// Start flash sequence
210-
backgroundVisible.value = true
211-
212-
// Load data during the flash
213-
navStore.setActiveColor(color)
214-
215-
// Complete transition and navigate
216-
setTimeout(() => {
217-
router.push({
218-
name: 'Overview',
219-
params: {
220-
projectId: project.id,
221-
id: project.id,
222-
color: color
223-
}
224-
})
225-
}, 100)
199+
const onProjectClick = async (project: ProjectId, color: string) => {
200+
await firebaseStore.addOrUpdateProjectSettings({
201+
projectId: project.id,
202+
name: project.name,
203+
settings: { color }
204+
})
205+
await router.push({ name: 'Overview', params: { projectId: project.id } })
226206
}
227207
228208
onMounted(() => {
@@ -238,26 +218,3 @@
238218
}
239219
)
240220
</script>
241-
242-
<style scoped>
243-
.origin-center {
244-
transform-origin: center;
245-
}
246-
247-
/* Flash transition */
248-
.flash-enter-active {
249-
transition: opacity 0.15s step-end;
250-
}
251-
252-
.flash-enter-from {
253-
opacity: 0;
254-
}
255-
256-
.flash-leave-active {
257-
transition: opacity 0.15s step-start;
258-
}
259-
260-
.flash-leave-to {
261-
opacity: 0;
262-
}
263-
</style>

src/components/Settings/SettingsProjectOverview.vue

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,6 @@
9797
import router from '@/router'
9898
9999
import type { dropdownItem } from '@/components/Base/DropdownMenuItem.vue'
100-
import type { ProjectSettingsLog } from '@/models/firebaseModel'
101100
import { useFirebaseStore } from '@/stores/firebaseStore'
102101
import CheckBox from '@/components/Base/CheckBox.vue'
103102
import { EnergyType } from '@/models/materialModel'
@@ -112,8 +111,9 @@
112111
const changedVersion = ref(false)
113112
114113
onMounted(async () => {
115-
const projectSettingsLog: ProjectSettingsLog =
116-
await firebaseStore.fetchProjectSettings(projectStore.currProject.id)
114+
const projectSettingsLog = await firebaseStore.fetchProjectSettings(
115+
projectStore.currProject?.id
116+
)
117117
if (projectSettingsLog)
118118
settingsStore.updateProjectSettings(projectSettingsLog.settings)
119119
})
@@ -156,10 +156,10 @@
156156
*/
157157
const selectProject = () => {
158158
// Save the projectSettings
159-
firebaseStore.addProjectSettings(
160-
projectStore.currProject.id,
161-
settingsStore.projectSettings
162-
)
159+
firebaseStore.addOrUpdateProjectSettings({
160+
projectId: projectStore.currProject.id,
161+
settings: settingsStore.projectSettings
162+
})
163163
164164
// If version changed we load it otherwise just route it
165165
if (changedVersion.value) {

src/components/Sidebar/GroupCard.vue

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -117,10 +117,10 @@
117117
import { getMappedMaterial, mapMaterial } from '@/utils/materialUtils'
118118
119119
import { useProjectStore } from '@/stores/projectStore'
120-
import { useNavigationStore } from '@/stores/navigationStore'
121120
import { storeToRefs } from 'pinia'
122121
import { lightenHSLColor } from '@/utils/colorUtils'
123122
import { roundNumber } from '@/utils/mathUtils'
123+
import { useRoute } from 'vue-router'
124124
125125
// Add defineOptions to inherit attrs
126126
defineOptions({
@@ -142,7 +142,7 @@
142142
143143
// Store initialization
144144
const projectStore = useProjectStore()
145-
const navStore = useNavigationStore()
145+
146146
// Reactive refs
147147
const isExpanded = ref(false)
148148
const toggleExpand = () => {
@@ -151,8 +151,8 @@
151151
}
152152
153153
// Store refs
154-
const { activePage } = storeToRefs(navStore)
155154
const { selectedGroup } = storeToRefs(projectStore)
155+
const route = useRoute()
156156
157157
// Computed properties
158158
const inGroups = computed(() => ({
@@ -184,7 +184,7 @@
184184
}
185185
186186
const currGroupTotal = computed(() => {
187-
switch (activePage.value) {
187+
switch (route.name) {
188188
case 'Filtering':
189189
return OverviewGroupCard
190190
case 'Mapping':
@@ -199,7 +199,7 @@
199199
})
200200
201201
const leftInfo = computed(() => {
202-
switch (activePage.value) {
202+
switch (route.name) {
203203
case 'Filtering':
204204
return inGroups.value.objects.length + ' Elements'
205205
case 'Mapping':
@@ -214,7 +214,7 @@
214214
})
215215
216216
const rightInfo = computed(() => {
217-
switch (activePage.value) {
217+
switch (route.name) {
218218
case 'Filtering':
219219
return inGroups.value.objects.length + ' Elements'
220220
case 'Mapping':
@@ -241,7 +241,7 @@
241241
// Add drop handler
242242
const onDrop = async () => {
243243
if (inGroups.value) {
244-
mapMaterial(inGroups.value)
244+
await mapMaterial(inGroups.value)
245245
}
246246
}
247247

src/components/Sidebar/Sidebar.vue

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -38,19 +38,21 @@
3838
import ActionButton from '@/components/Base/ActionButton.vue'
3939
4040
import { useNavigationStore } from '@/stores/navigationStore'
41+
import { useRoute } from 'vue-router'
4142
4243
import { useFetchDropdownItems } from '@/composables/useFetchDropdownItems'
4344
import { useHandleSelected } from '@/composables/useHandleSelected'
4445
45-
import type { NavigationButtonConfig } from '@/models/pageModel'
46+
import type { NavigationButtonConfig, PageType } from '@/models/pageModel'
4647
4748
// Store initialization
4849
const navStore = useNavigationStore()
50+
const route = useRoute()
4951
5052
// Compute visible buttons for current page
5153
const visibleButtons = computed(() =>
5254
sidebarButtons.filter((button) =>
53-
button.showOn.includes(navStore.activePage)
55+
button.showOn.includes(route.name as PageType)
5456
)
5557
)
5658
@@ -72,16 +74,17 @@
7274
7375
// Watch for page changes to update dropdown items
7476
watch(
75-
() => navStore.activePage,
77+
() => route.name,
78+
() => {
79+
fetchDropdownItems()
80+
},
81+
{ immediate: true }
82+
)
83+
watch(
84+
() => navStore.shouldDropdownRefresh,
7685
() => {
7786
fetchDropdownItems()
7887
},
7988
{ immediate: true }
8089
)
8190
</script>
82-
83-
<style scoped>
84-
.ghost {
85-
opacity: 0.5;
86-
}
87-
</style>

src/components/SlideOver/ModifyFilter.vue

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
<template>
2-
<div class="relative flex-1 px-4">
2+
<div class="relative flex-1 px-4 mt-4">
3+
<SaveFilters :modify="true" />
4+
<h3 class="font-semibold mb-2 mt-8">Filter Groups</h3>
5+
36
<Draggable
47
v-if="callStack"
58
:list="callStack"
@@ -196,6 +199,7 @@
196199
import type { SimpleParameters } from '@/models/geometryModel'
197200
import type { dropdownItem } from '@/components/Base/Dropdown.vue'
198201
import type { CustomGeo } from '@/models/filterModel'
202+
import SaveFilters from '@/components/SlideOver/SaveFilters.vue'
199203
200204
// Store initialization
201205
const projectStore = useProjectStore()
@@ -285,11 +289,6 @@
285289
286290
// Update store when component unmounts
287291
onUnmounted(() => {
288-
projectStore.updateRegistryStack(
289-
'test',
290-
callStack.value,
291-
customGeoList.value
292-
)
293292
updateProjectGroups()
294293
})
295294
</script>

src/components/SlideOver/SaveFilters.vue

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
<template>
22
<div class="space-y-12">
3-
<h2 class="styled-header">Save to firebase</h2>
4-
<div class="mt-10 grid grid-cols-1 gap-x-6 gap-y-8 sm:grid-cols-6">
3+
<div class="mt-4 grid grid-cols-1 gap-x-6 gap-y-8 sm:grid-cols-6">
54
<div class="sm:col-span-4">
65
<label for="name" class="block styled-text normal-case"> Name </label>
76
<div class="mt-2">
@@ -19,6 +18,7 @@
1918

2019
<div class="mt-6 flex items-center justify-start gap-x-6">
2120
<ActionButton text="Save" @on-click="saveData" />
21+
<ActionButton text="Delete" v-if="props.modify" @on-click="deleteData" />
2222
</div>
2323
</template>
2424

@@ -31,27 +31,45 @@
3131
import InputText from '@/components/Base/InputText.vue'
3232
import ActionButton from '@/components/Base/ActionButton.vue'
3333
34+
const props = defineProps({
35+
modify: { type: Boolean, default: false }
36+
})
37+
3438
const navStore = useNavigationStore()
3539
const projectStore = useProjectStore()
3640
const firebaseStore = useFirebaseStore()
3741
3842
const formData = ref({
39-
name: ''
43+
name: props.modify ? projectStore.filterRegistry.filterList.name : ''
4044
})
4145
4246
const saveData = () => {
43-
const filters: Filter[] = projectStore.getRegistryStack()
47+
let filters: Filter[] = []
48+
if (props.modify) {
49+
filters = projectStore.getRegistryStack()
50+
}
51+
4452
const filterList: FilterList = {
4553
id: crypto.randomUUID(),
4654
name: formData.value.name,
4755
callStack: filters,
48-
customGeo: projectStore.filterRegistry.filterList.customGeo
56+
customGeo: projectStore.filterRegistry.filterList.customGeo || []
4957
}
5058
firebaseStore.addFilterList(
5159
projectStore.currProject.id,
5260
filterList,
5361
formData.value.name
5462
)
5563
navStore.toggleSlideover()
64+
navStore.refreshDropdown()
65+
}
66+
67+
const deleteData = () => {
68+
firebaseStore.deleteFilters(
69+
projectStore.currProject.id,
70+
projectStore.filterRegistry.filterList.name
71+
)
72+
navStore.toggleSlideover()
73+
navStore.refreshDropdown()
5674
}
5775
</script>

0 commit comments

Comments
 (0)