Skip to content

Commit ef4d19a

Browse files
committed
Added intermediate state for tree chekbox
1 parent 1a68744 commit ef4d19a

File tree

1 file changed

+21
-1
lines changed

1 file changed

+21
-1
lines changed

client/src/components/subjects/tree-item.vue

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
<template>
22
<ul>
33
<label :class="subject.$type">
4-
<input type="checkbox" v-model="isChecked" />
4+
<input
5+
type="checkbox"
6+
v-model="isChecked"
7+
:intermediate="containsSelected"
8+
/>
59
<span>{{ subject.name }}</span>
610
<badge v-if="subject.$type == 'group'">{{ selectedUsers }}</badge>
711
</label>
@@ -61,6 +65,22 @@ export default {
6165
this.emitChanged(this.subject.id, value);
6266
},
6367
},
68+
containsSelected() {
69+
if (this.isChecked) return false;
70+
if (this.subject.$type == "user") return false;
71+
72+
const compute = (s) => {
73+
if (s.$type == "user") return [s.id];
74+
return this.getChildren(s)
75+
.map((x) => compute(x))
76+
.reduce((x, y) => x.concat(y), []);
77+
};
78+
const allUsersIds = compute(this.subject).reduce(
79+
(x, y) => x.concat(y),
80+
[]
81+
);
82+
return allUsersIds.some((x) => this.selected.includes(x));
83+
},
6484
},
6585
6686
methods: {

0 commit comments

Comments
 (0)