diff --git a/src/components/Misc/Settings/SettingsMaterial.vue b/src/components/Misc/Settings/SettingsMaterial.vue
index e6a90be..f7deb84 100644
--- a/src/components/Misc/Settings/SettingsMaterial.vue
+++ b/src/components/Misc/Settings/SettingsMaterial.vue
@@ -27,6 +27,17 @@
+
+
Fetch global assemblies
+
+
+
+
+
Filter parameters
diff --git a/src/components/Modals/AssemblyModal.vue b/src/components/Modals/AssemblyModal.vue
index bc22821..408e674 100644
--- a/src/components/Modals/AssemblyModal.vue
+++ b/src/components/Modals/AssemblyModal.vue
@@ -253,8 +253,6 @@ export default defineComponent({
const materialType = ref('')
const assemblyId = ref(crypto.randomUUID().toString())
const codes = BSAB96
-
- //const filteredProducts = ref([])
const filterParameters = settingsStore.materialSettings.filterParams
const sortingParameters = settingsStore.materialSettings.sortingParams
@@ -267,6 +265,7 @@ export default defineComponent({
// This is the assembly we are constructing
const assemblyMaterials = ref([])
+ // TODO: Make a static list of categories as a type
const categories = ref({
materialTypes: [
{ label: 'Wood', value: 'wood', selected: false },
diff --git a/src/models/settings.ts b/src/models/settings.ts
index c72fc59..7f606b7 100644
--- a/src/models/settings.ts
+++ b/src/models/settings.ts
@@ -28,6 +28,7 @@ export interface CalculationSettings {
export interface MaterialSettings {
Source: Source
includeCollections: boolean
+ globalAssemblies: boolean
filterParams: MaterialFilterParam[]
sortingParams: MaterialSortingParam[]
}
@@ -136,6 +137,7 @@ export const standardCalculationSettings: CalculationSettings = {
export const standardMaterialSettings: MaterialSettings = {
Source: Source.Revalu,
includeCollections: true,
+ globalAssemblies: false,
filterParams: [
{
paramName: 'metaData.Collection',
diff --git a/src/stores/firebase.ts b/src/stores/firebase.ts
index 629bfe7..5af2ea8 100644
--- a/src/stores/firebase.ts
+++ b/src/stores/firebase.ts
@@ -13,7 +13,8 @@ import {
orderBy,
limit,
getDocs,
- writeBatch
+ writeBatch,
+ doc
} from 'firebase/firestore'
import type {
Mapping,
@@ -333,20 +334,35 @@ export const useFirebaseStore = defineStore('firebase', {
/**
* Fetches the whole assembly list for a project
- * @param projectId
- * @returns
+ * @param projectId optional projectId to filter on if omitted gets all assemblies
+ * @returns list of assemblies
*/
- async fetchAssemblyList(projectId: string): Promise {
+ async fetchAssemblyList(projectId: string | boolean): Promise {
this.loading = true
this.error = null
try {
- const q = query(
- collection(db, 'projectAssemblies'),
- where('projectId', '==', projectId)
- )
+ let q
+ if (projectId === true) {
+ q = query(
+ collection(db, 'projectAssemblies')
+ )
+ } else {
+ q = query(
+ collection(db, 'projectAssemblies'),
+ where('projectId', '==', projectId)
+ )
+ }
+
const querySnapshot = await getDocs(q)
if (!querySnapshot.empty) {
- const assemblyList = querySnapshot.docs[0].data() as AssemblyList
+ const assemblyList: AssemblyList = {
+ projectId: projectId as string,
+ assemblies: []
+ }
+ querySnapshot.forEach(doc => {
+ const data = doc.data() as AssemblyList
+ assemblyList.assemblies.push(... data.assemblies)
+ })
return assemblyList
} else {
return null
@@ -371,7 +387,8 @@ export const useFirebaseStore = defineStore('firebase', {
try {
const querySnapshot = await getDocs(
- query(collection(db, 'projectAssemblies'), where('projectId', '==', projectId))
+ query(collection(db, 'projectAssemblies'),
+ where('projectId', '==', projectId))
)
const assemblyList: AssemblyList = {
diff --git a/src/utils/material.ts b/src/utils/material.ts
index 5f1ace0..6b94a96 100644
--- a/src/utils/material.ts
+++ b/src/utils/material.ts
@@ -9,6 +9,7 @@ import { useSpeckleStore } from "@/stores/speckle"
import { useFirebaseStore } from "@/stores/firebase"
import { setMappingColorGroup, updateProjectGroups } from "@/utils/projectUtils"
+import { useSettingsStore } from "@/stores/settings"
/**
* Updates from a selected mapping to a new one, with all materials and objectIds
@@ -199,12 +200,21 @@ export async function getAssemblyList() {
const materialStore = useMaterialStore()
const projectStore = useProjectStore()
const firebaseStore = useFirebaseStore()
+ const settingsStore = useSettingsStore()
try {
- const assemblyList: AssemblyList = await firebaseStore.fetchAssemblyList(projectStore.currProject.id)
- if (assemblyList) {
- materialStore.assemblies = assemblyList.assemblies
+ if (!settingsStore.materialSettings.globalAssemblies){
+ const assemblyList: AssemblyList = await firebaseStore.fetchAssemblyList(projectStore.currProject.id)
+ if (assemblyList) {
+ materialStore.assemblies = assemblyList.assemblies
+ }
+ } else {
+ const assemblyList: AssemblyList = await firebaseStore.fetchAssemblyList(true)
+ if (assemblyList) {
+ materialStore.assemblies = assemblyList.assemblies
+ }
}
+
} catch (error) {
console.error('Error fetching assembly list:', error)
}
diff --git a/src/utils/resultUtils.ts b/src/utils/resultUtils.ts
index da258ff..78f9430 100644
--- a/src/utils/resultUtils.ts
+++ b/src/utils/resultUtils.ts
@@ -400,7 +400,7 @@ export class ResultCalculator {
}
for (const phase in emission[impactCategory]) {
if (!this.totalEmission[impactCategory][phase]) {
- this.totalEmission[impactCategory][phase] = { amount: 0 }
+ this.totalEmission[impactCategory][phase] = 0
}
const emissionAmount = emission[impactCategory][phase] || 0
const currentTotal = this.totalEmission[impactCategory][phase] || 0