Skip to content

Commit 7deddd0

Browse files
authored
Merge pull request #7199 from pmattmann/feature/activity-load-selected-checklist-items-as-collection
Feature/activity load selected checklist items as collection
2 parents ab7eaba + 9af5857 commit 7deddd0

10 files changed

+115
-65
lines changed

api/src/Entity/ChecklistItem.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@
7777
normalizationContext: ['groups' => ['read']],
7878
order: ['checklist.id', 'id'],
7979
)]
80-
#[ApiFilter(filterClass: SearchFilter::class, properties: ['checklist', 'checklist.camp'])]
80+
#[ApiFilter(filterClass: SearchFilter::class, properties: ['checklist', 'checklist.camp', 'checklistNodes'])]
8181
#[ORM\Entity(repositoryClass: ChecklistItemRepository::class)]
8282
#[ORM\UniqueConstraint(name: 'checklistitem_checklistid_parentid_position_unique', columns: ['checklistid', 'parentid', 'position'])]
8383
class ChecklistItem extends BaseEntity implements BelongsToCampInterface, CopyFromPrototypeInterface, HasParentInterface {

api/tests/Api/ContentNodes/ChecklistNode/UpdateChecklistNodeTest.php

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,7 @@ public function testAddChecklistItemForMember() {
4141
$this->assertJsonContains([
4242
'_links' => [
4343
'checklistItems' => [
44-
1 => [
45-
'href' => '/checklist_items/'.$checklistItemId,
46-
],
44+
'href' => '/checklist_items?checklistNodes=%2Fcontent_node%2Fchecklist_nodes%2F'.$this->defaultEntity->getId(),
4745
],
4846
],
4947
]);
@@ -59,9 +57,7 @@ public function testAddChecklistItemForManager() {
5957
$this->assertJsonContains([
6058
'_links' => [
6159
'checklistItems' => [
62-
1 => [
63-
'href' => '/checklist_items/'.$checklistItemId,
64-
],
60+
'href' => '/checklist_items?checklistNodes=%2Fcontent_node%2Fchecklist_nodes%2F'.$this->defaultEntity->getId(),
6561
],
6662
],
6763
]);

api/tests/Api/SnapshotTests/__snapshots__/ResponseSnapshotTest__testGetCollectionMatchesStructure with data set content_nodechecklist_nodes__1.json

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@
33
"items": [
44
{
55
"_links": {
6-
"checklistItems": [],
6+
"checklistItems": {
7+
"href": "escaped_value"
8+
},
79
"children": [],
810
"contentType": {
911
"href": "escaped_value"
@@ -27,11 +29,9 @@
2729
},
2830
{
2931
"_links": {
30-
"checklistItems": [
31-
{
32-
"href": "escaped_value"
33-
}
34-
],
32+
"checklistItems": {
33+
"href": "escaped_value"
34+
},
3535
"children": [],
3636
"contentType": {
3737
"href": "escaped_value"

api/tests/Api/SnapshotTests/__snapshots__/ResponseSnapshotTest__testGetCollectionMatchesStructure with data set content_nodes__1.json

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,9 @@
8383
},
8484
{
8585
"_links": {
86-
"checklistItems": [],
86+
"checklistItems": {
87+
"href": "escaped_value"
88+
},
8789
"children": [],
8890
"contentType": {
8991
"href": "escaped_value"
@@ -107,11 +109,9 @@
107109
},
108110
{
109111
"_links": {
110-
"checklistItems": [
111-
{
112-
"href": "escaped_value"
113-
}
114-
],
112+
"checklistItems": {
113+
"href": "escaped_value"
114+
},
115115
"children": [],
116116
"contentType": {
117117
"href": "escaped_value"

api/tests/Api/SnapshotTests/__snapshots__/ResponseSnapshotTest__testGetItemMatchesStructure with data set activities__1.json

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -94,11 +94,9 @@
9494
},
9595
{
9696
"_links": {
97-
"checklistItems": [
98-
{
99-
"href": "escaped_value"
100-
}
101-
],
97+
"checklistItems": {
98+
"href": "escaped_value"
99+
},
102100
"children": [],
103101
"contentType": {
104102
"href": "escaped_value"

api/tests/Api/SnapshotTests/__snapshots__/ResponseSnapshotTest__testGetItemMatchesStructure with data set content_nodechecklist_nodes__1.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
{
22
"_links": {
3-
"checklistItems": [],
3+
"checklistItems": {
4+
"href": "escaped_value"
5+
},
46
"children": [],
57
"contentType": {
68
"href": "escaped_value"

api/tests/Api/SnapshotTests/__snapshots__/ResponseSnapshotTest__testOpenApiSpecMatchesSnapshot__1.yml

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25691,6 +25691,18 @@ paths:
2569125691
schema:
2569225692
type: string
2569325693
style: form
25694+
-
25695+
allowEmptyValue: false
25696+
allowReserved: false
25697+
deprecated: false
25698+
description: ''
25699+
explode: false
25700+
in: query
25701+
name: checklistNodes
25702+
required: false
25703+
schema:
25704+
type: string
25705+
style: form
2569425706
-
2569525707
allowEmptyValue: false
2569625708
allowReserved: false
@@ -25705,6 +25717,20 @@ paths:
2570525717
type: string
2570625718
type: array
2570725719
style: form
25720+
-
25721+
allowEmptyValue: false
25722+
allowReserved: false
25723+
deprecated: false
25724+
description: ''
25725+
explode: true
25726+
in: query
25727+
name: 'checklistNodes[]'
25728+
required: false
25729+
schema:
25730+
items:
25731+
type: string
25732+
type: array
25733+
style: form
2570825734
-
2570925735
allowEmptyValue: false
2571025736
allowReserved: false
@@ -26282,6 +26308,18 @@ paths:
2628226308
schema:
2628326309
type: string
2628426310
style: form
26311+
-
26312+
allowEmptyValue: false
26313+
allowReserved: false
26314+
deprecated: false
26315+
description: ''
26316+
explode: false
26317+
in: query
26318+
name: checklistNodes
26319+
required: false
26320+
schema:
26321+
type: string
26322+
style: form
2628526323
-
2628626324
allowEmptyValue: false
2628726325
allowReserved: false
@@ -26296,6 +26334,20 @@ paths:
2629626334
type: string
2629726335
type: array
2629826336
style: form
26337+
-
26338+
allowEmptyValue: false
26339+
allowReserved: false
26340+
deprecated: false
26341+
description: ''
26342+
explode: true
26343+
in: query
26344+
name: 'checklistNodes[]'
26345+
required: false
26346+
schema:
26347+
items:
26348+
type: string
26349+
type: array
26350+
style: form
2629926351
-
2630026352
allowEmptyValue: false
2630126353
allowReserved: false

api/tests/Api/SnapshotTests/__snapshots__/ResponseSnapshotTest__testRootEndpointMatchesSnapshot__1.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
"templated": true
2626
},
2727
"checklistItems": {
28-
"href": "/checklist_items{/id}{?checklist,checklist[],checklist.camp,checklist.camp[]}",
28+
"href": "/checklist_items{/id}{?checklist,checklist[],checklist.camp,checklist.camp[],checklistNodes,checklistNodes[]}",
2929
"templated": true
3030
},
3131
"checklistNodes": {

frontend/src/components/checklist/ChecklistItemParent.vue

Lines changed: 37 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -66,43 +66,52 @@ export default {
6666
props: {
6767
checklistItem: { type: Object, required: true },
6868
depth: { type: Number, required: true },
69-
allChecklistNodes: { type: Array, required: true },
7069
},
7170
data() {
7271
return {
73-
checklistNodes: [],
72+
activities: [],
7473
}
7574
},
76-
computed: {
77-
activities() {
78-
const camp = this.checklistItem.checklist().camp()
79-
const activities = camp.activities().items
75+
watch: {
76+
checklistItem: {
77+
async handler(checklistItem) {
78+
const camp = checklistItem.checklist().camp()
79+
80+
await camp.activities()._meta.load
81+
const activities = await Promise.all(
82+
camp.activities().items.map(async (a) => ({
83+
activity: a,
84+
rootContentNodeUri: await a.$href('rootContentNode'),
85+
}))
86+
)
8087
81-
// Activities ordered first ScheduleEntry start-time
82-
return sortBy(
83-
activities.filter((a) =>
84-
this.checklistNodes.some((cn) => cn.root().id === a.rootContentNode().id)
85-
),
86-
(activity) =>
87-
activity
88-
.scheduleEntries()
89-
.items.map(
90-
(s) =>
91-
`${s.dayNumber}`.padStart(3, '0') +
92-
`${s.scheduleEntryNumber}`.padStart(3, '0')
88+
const checklistNodes = await Promise.all(
89+
checklistItem.checklistNodes().items.map(async (cn) => ({
90+
checklistNode: cn,
91+
rootUri: await cn.$href('root'),
92+
}))
93+
)
94+
95+
// Activities ordered by first ScheduleEntry start time
96+
const res = sortBy(
97+
activities
98+
.filter((a) =>
99+
checklistNodes.some((cn) => cn.rootUri == a.rootContentNodeUri)
93100
)
94-
.reduce((p, v) => (p < v ? p : v))
95-
)
96-
},
97-
},
98-
watch: {
99-
allChecklistNodes: {
100-
immediate: true,
101-
handler(allChecklistNodes) {
102-
this.checklistNodes = allChecklistNodes.filter((cn) =>
103-
cn.checklistItems().items.some((ci) => ci.id === this.checklistItem.id)
101+
.map((a) => a.activity),
102+
(activity) =>
103+
activity
104+
.scheduleEntries()
105+
.items.map(
106+
(s) =>
107+
`${s.dayNumber}`.padStart(3, '0') +
108+
`${s.scheduleEntryNumber}`.padStart(3, '0')
109+
)
110+
.reduce((p, v) => (p < v ? p : v))
104111
)
112+
this.activities = res
105113
},
114+
immediate: true,
106115
},
107116
},
108117

frontend/src/views/camp/checklistOverview/ChecklistOverview.vue

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
:key="value?._meta.self"
1717
:checklist-item="value"
1818
:depth="depth"
19-
:all-checklist-nodes="allChecklistNodes"
2019
/>
2120
</tbody>
2221
</table>
@@ -42,7 +41,6 @@ export default {
4241
data() {
4342
return {
4443
loading: true,
45-
allChecklistNodes: [],
4644
indexedChecklistItems: {},
4745
}
4846
},
@@ -72,20 +70,13 @@ export default {
7270
await Promise.all([
7371
this.camp.categories()._meta.load,
7472
this.camp.activities().$reload(),
75-
this.api
76-
.get()
77-
.checklistNodes({ camp: this.camp._meta.self })
78-
.$reload()
79-
.then((cns) => {
80-
this.allChecklistNodes = cns.items
81-
}),
73+
this.api.get().checklistNodes({ camp: this.camp._meta.self }).$reload(),
8274
this.api
8375
.get()
8476
.checklistItems({ 'checklist.camp': this.camp._meta.self })
8577
.$reload()
8678
.then(({ items }) => {
8779
this.processChecklistItems(items)
88-
this.loading = false
8980
}),
9081
this.api
9182
.get()
@@ -94,7 +85,9 @@ export default {
9485
camp: this.camp._meta.self,
9586
})
9687
.$loadItems(),
97-
])
88+
]).then(() => {
89+
this.loading = false
90+
})
9891
},
9992
methods: {
10093
processChecklistItems(items) {

0 commit comments

Comments
 (0)