Skip to content

Commit 0fd0649

Browse files
committed
add search-filter for checklistNodes
load checklist_items, checklist_nodes, root-content_nodes each in one request
1 parent af1a2af commit 0fd0649

10 files changed

+113
-78
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: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -38,15 +38,6 @@ public function testAddChecklistItemForMember() {
3838
], 'headers' => ['Content-Type' => 'application/merge-patch+json']])
3939
;
4040
$this->assertResponseStatusCodeSame(200);
41-
$this->assertJsonContains([
42-
'_links' => [
43-
'checklistItems' => [
44-
1 => [
45-
'href' => '/checklist_items/'.$checklistItemId,
46-
],
47-
],
48-
],
49-
]);
5041
}
5142

5243
public function testAddChecklistItemForManager() {
@@ -56,15 +47,6 @@ public function testAddChecklistItemForManager() {
5647
], 'headers' => ['Content-Type' => 'application/merge-patch+json']]);
5748

5849
$this->assertResponseStatusCodeSame(200);
59-
$this->assertJsonContains([
60-
'_links' => [
61-
'checklistItems' => [
62-
1 => [
63-
'href' => '/checklist_items/'.$checklistItemId,
64-
],
65-
],
66-
],
67-
]);
6850
}
6951

7052
public function testRemoveChecklistItemIsDeniedForGuest() {

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
@@ -80,7 +80,9 @@
8080
},
8181
{
8282
"_links": {
83-
"checklistItems": [],
83+
"checklistItems": {
84+
"href": "escaped_value"
85+
},
8486
"children": [],
8587
"contentType": {
8688
"href": "escaped_value"
@@ -104,11 +106,9 @@
104106
},
105107
{
106108
"_links": {
107-
"checklistItems": [
108-
{
109-
"href": "escaped_value"
110-
}
111-
],
109+
"checklistItems": {
110+
"href": "escaped_value"
111+
},
112112
"children": [],
113113
"contentType": {
114114
"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
@@ -91,11 +91,9 @@
9191
},
9292
{
9393
"_links": {
94-
"checklistItems": [
95-
{
96-
"href": "escaped_value"
97-
}
98-
],
94+
"checklistItems": {
95+
"href": "escaped_value"
96+
},
9997
"children": [],
10098
"contentType": {
10199
"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
@@ -25435,6 +25435,18 @@ paths:
2543525435
schema:
2543625436
type: string
2543725437
style: form
25438+
-
25439+
allowEmptyValue: false
25440+
allowReserved: false
25441+
deprecated: false
25442+
description: ''
25443+
explode: false
25444+
in: query
25445+
name: checklistNodes
25446+
required: false
25447+
schema:
25448+
type: string
25449+
style: form
2543825450
-
2543925451
allowEmptyValue: false
2544025452
allowReserved: false
@@ -25449,6 +25461,20 @@ paths:
2544925461
type: string
2545025462
type: array
2545125463
style: form
25464+
-
25465+
allowEmptyValue: false
25466+
allowReserved: false
25467+
deprecated: false
25468+
description: ''
25469+
explode: true
25470+
in: query
25471+
name: 'checklistNodes[]'
25472+
required: false
25473+
schema:
25474+
items:
25475+
type: string
25476+
type: array
25477+
style: form
2545225478
-
2545325479
allowEmptyValue: false
2545425480
allowReserved: false
@@ -26026,6 +26052,18 @@ paths:
2602626052
schema:
2602726053
type: string
2602826054
style: form
26055+
-
26056+
allowEmptyValue: false
26057+
allowReserved: false
26058+
deprecated: false
26059+
description: ''
26060+
explode: false
26061+
in: query
26062+
name: checklistNodes
26063+
required: false
26064+
schema:
26065+
type: string
26066+
style: form
2602926067
-
2603026068
allowEmptyValue: false
2603126069
allowReserved: false
@@ -26040,6 +26078,20 @@ paths:
2604026078
type: string
2604126079
type: array
2604226080
style: form
26081+
-
26082+
allowEmptyValue: false
26083+
allowReserved: false
26084+
deprecated: false
26085+
description: ''
26086+
explode: true
26087+
in: query
26088+
name: 'checklistNodes[]'
26089+
required: false
26090+
schema:
26091+
items:
26092+
type: string
26093+
type: array
26094+
style: form
2604326095
-
2604426096
allowEmptyValue: false
2604526097
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 & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -66,43 +66,51 @@ 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
80-
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')
93-
)
94-
.reduce((p, v) => (p < v ? p : v))
95-
)
96-
},
97-
},
9875
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)
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+
rootContentNodeId: await a.$href('rootContentNode'),
85+
}))
10486
)
87+
88+
const checklistNodes = await Promise.all(
89+
checklistItem.checklistNodes().items.map(async (cn) => ({
90+
checklistNode: cn,
91+
rootId: await cn.$href('root'),
92+
}))
93+
)
94+
95+
// Activities ordered first ScheduleEntry start-time
96+
const res = sortBy(
97+
activities
98+
.filter((a) => checklistNodes.some((cn) => cn.rootId == a.rootContentNodeId))
99+
.map((a) => a.activity),
100+
(activity) =>
101+
activity
102+
.scheduleEntries()
103+
.items.map(
104+
(s) =>
105+
`${s.dayNumber}`.padStart(3, '0') +
106+
`${s.scheduleEntryNumber}`.padStart(3, '0')
107+
)
108+
.reduce((p, v) => (p < v ? p : v))
109+
)
110+
//console.log(res)
111+
this.activities = res
105112
},
113+
immediate: true,
106114
},
107115
},
108116

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)