Skip to content

Commit f2a8325

Browse files
Merge pull request #6972 from christianbeeznest/fixes-updates164
Course: fix (resource-selector), correct selection counter
2 parents 4b10890 + 5b2617b commit f2a8325

File tree

1 file changed

+21
-4
lines changed

1 file changed

+21
-4
lines changed

assets/vue/components/coursemaintenance/ResourceSelector.vue

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<div class="flex flex-col gap-3 md:flex-row md:items-center md:justify-between">
55
<div class="flex items-center gap-2 text-sm">
66
<h3 class="text-sm font-semibold text-gray-90">{{ title }}</h3>
7-
<span class="px-2 py-1 rounded-md bg-gray-15 text-gray-50"> {{ t("{0} selected", [selectedTotal]) }} </span>
7+
<span class="px-2 py-1 rounded-md bg-gray-15 text-gray-50"> {{ $t("Selected") }}: {{ selectedTotal }} </span>
88
</div>
99

1010
<div class="flex flex-wrap gap-2">
@@ -389,8 +389,25 @@ export default {
389389
? this.group.items
390390
: []
391391
},
392-
total() {
393-
return this.nodes.length
392+
393+
totalLeafCount() {
394+
const walk = (list) =>
395+
list.reduce((acc, n) => {
396+
const kids = Array.isArray(n.children) ? n.children : []
397+
const mine = this.isNodeCheckable(n) ? 1 : 0
398+
return acc + mine + walk(kids)
399+
}, 0)
400+
return walk(this.nodes)
401+
},
402+
403+
selectedLeafCount() {
404+
const walk = (list) =>
405+
list.reduce((acc, n) => {
406+
const kids = Array.isArray(n.children) ? n.children : []
407+
const mine = this.isNodeCheckable(n) && this.isChecked(n) ? 1 : 0
408+
return acc + mine + walk(kids)
409+
}, 0)
410+
return walk(this.nodes)
394411
},
395412
},
396413
watch: {
@@ -420,7 +437,7 @@ export default {
420437
<i :class="open ? 'mdi mdi-chevron-down' : 'mdi mdi-chevron-right'"></i>
421438
</button>
422439
<span class="font-medium text-gray-90">{{ group.title || group.type }}</span>
423-
<span class="text-xs text-gray-50">· {{ countSelected(group) }} / {{ total }}</span>
440+
<span class="text-xs text-gray-50">· {{ selectedLeafCount }} / {{ totalLeafCount }}</span>
424441
</div>
425442
<div class="flex gap-2">
426443
<button class="btn-secondary" @click="selectAll"><i class="mdi mdi-check-all"></i> Select group</button>

0 commit comments

Comments
 (0)