Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 31 additions & 4 deletions frontend/src/components/material/MaterialTable.vue
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@
<!-- Activity link (only visible in full period view) -->
<ScheduleEntryLinks
v-if="period && item.entityObject && item.entityObject.materialNode"
:activity-promise="findOneActivityByContentNode(item.entityObject.materialNode())"
:activity-promise="findOneActivityByContentNode(item.entityObject)"
/>

<!-- Action buttons -->
Expand Down Expand Up @@ -270,6 +270,7 @@ export default {
newMaterialItems: {},
periodOnly: false,
clientWidth: 1000,
loadMaterialNodesPromise: Promise.resolve(),
}
},
computed: {
Expand Down Expand Up @@ -391,8 +392,12 @@ export default {
}
},
},
mounted() {
async mounted() {
this.clientWidth = this.$el.clientWidth

if (this.period) {
this.loadMaterialNodesPromise = this.loadMaterialNodes()
}
},
methods: {
onResize({ width }) {
Expand Down Expand Up @@ -451,14 +456,36 @@ export default {
})
},

async findOneActivityByContentNode(contentNode) {
await this.camp.activities().$loadItems()
async findOneActivityByContentNode(entityObject) {
await Promise.all([
this.camp.activities().$loadItems(),
this.loadMaterialNodesPromise,
])
const contentNode = entityObject.materialNode()
const root = await contentNode.$href('root')

return this.camp.activities().items.find((activity) => {
return activity.rootContentNode()._meta.self === root
})
},

async loadMaterialNodes() {
await this.api.get().contentTypes().$loadItems()
const contentTypeMaterial = this.api
.get()
.contentTypes()
.items.find((ct) => ct.name === 'Material')
if (!contentTypeMaterial) {
throw new Error('Material content type not found')
}
await this.api
.get()
.contentNodes({
camp: this.camp._meta.self,
contentType: contentTypeMaterial._meta.self,
})
.$loadItems()
},
},
}
</script>
Expand Down
1 change: 1 addition & 0 deletions frontend/src/components/material/useMaterialViewHelper.js
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ export function useMaterialViewHelper(camp, list) {
})
.$loadItems(),
...collection.value.map(({ materialItems }) => materialItems.$reload()),
camp.categories().$loadItems(),
])
})

Expand Down
Loading