|
33 | 33 | node-key="id"
|
34 | 34 | show-checkbox
|
35 | 35 | check-on-click-node
|
36 |
| - :default-expand-all="false" |
37 | 36 | :default-checked-keys="defaultCheckedKeys"
|
| 37 | + :auto-expand-parent="false" |
38 | 38 | :expand-on-click-node="false"
|
39 | 39 | :filter-node-method="filterNodes"
|
40 | 40 | :props="treeProps"
|
|
44 | 44 | </el-scrollbar>
|
45 | 45 | </el-form>
|
46 | 46 | <div
|
47 |
| - v-if="showExpandOptionsContainer && !optionsExpanded" |
| 47 | + v-show="showExpandOptionsContainer && !optionsExpanded" |
48 | 48 | v-on:click="setOptionsExpanded(true)"
|
49 | 49 | class="expand-options-container"
|
50 | 50 | >
|
51 | 51 | + Expand
|
52 | 52 | </div>
|
53 | 53 | <div
|
54 |
| - v-if="showExpandOptionsContainer && optionsExpanded" |
| 54 | + v-show="showExpandOptionsContainer && optionsExpanded" |
55 | 55 | v-on:click="setOptionsExpanded(false)"
|
56 | 56 | class="expand-options-container"
|
57 | 57 | >
|
@@ -101,6 +101,7 @@ export default {
|
101 | 101 | return {
|
102 | 102 | showAll: true,
|
103 | 103 | treeProps: {
|
| 104 | + children: 'children', |
104 | 105 | label: 'label'
|
105 | 106 | },
|
106 | 107 | optionsExpanded: true,
|
@@ -180,19 +181,17 @@ export default {
|
180 | 181 | },
|
181 | 182 | },
|
182 | 183 | watch: {
|
183 |
| - allVisibleDataIds(val) { |
| 184 | + allVisibleDataIds() { |
184 | 185 | this.numOptionsShown = 0;
|
185 |
| - this.$refs.tree.filter(val) |
| 186 | + this.$refs.tree.filter() |
186 | 187 | },
|
187 | 188 | 'visibleData': function() {
|
188 | 189 | this.setShowAll();
|
189 | 190 | }
|
190 | 191 | },
|
191 | 192 | mounted() {
|
192 | 193 | if (this.defaultCheckedKeys.length) {
|
193 |
| - this.$nextTick(() => { |
194 |
| - this.onCheckChange() |
195 |
| - }) |
| 194 | + this.onCheckChange() |
196 | 195 | }
|
197 | 196 | if (this.showExpandOptionsContainer || this.visibleData !== undefined) {
|
198 | 197 | this.numOptionsShown = 0;
|
@@ -244,21 +243,73 @@ export default {
|
244 | 243 | this.$refs.tree.filter()
|
245 | 244 | },
|
246 | 245 | updateParentFacetsSelectedStatus() {
|
| 246 | + let visibleCheckedParents = this.visibleCheckedNodes.filter(visibleNode => { |
| 247 | + return !visibleNode.label.includes('.') |
| 248 | + }) |
| 249 | + let visibleCheckedChildren = this.visibleCheckedNodes.filter(visibleNode => { |
| 250 | + return visibleNode.label.includes('.') |
| 251 | + }) |
| 252 | +
|
| 253 | + // First check for any subfacets that have a parent that is not set |
| 254 | + visibleCheckedChildren.forEach(checkedChild => { |
| 255 | + const parentLabel = checkedChild.label.split('.')[0] |
| 256 | + if (!visibleCheckedParents.some(parent => parent.label == parentLabel)) { |
| 257 | + this.$refs.tree.setChecked(checkedChild.id, true, true) |
| 258 | + } |
| 259 | + }) |
| 260 | +
|
247 | 261 | const halfCheckedNodes = this.$refs.tree.getHalfCheckedNodes()
|
248 | 262 | // set the half checked nodes checked status based upon what facets are actually visible since navigating between tabs might
|
249 | 263 | // cause some to be hidden so the parent facet should now possibly be checked/unchecked instead of half checked
|
250 | 264 | halfCheckedNodes.forEach(halfCheckedNode => {
|
| 265 | + const visibleChildren = halfCheckedNode.children.filter((child) => { |
| 266 | + return this.allVisibleDataIds.includes(child.label) |
| 267 | + }) |
| 268 | + const visibleCheckedChildren = halfCheckedNode.children.filter((child) => { |
| 269 | + return this.visibleCheckedNodes.some(visibleNode => visibleNode.label == child.label) |
| 270 | + }) |
| 271 | + if (!this.allVisibleDataIds.includes(halfCheckedNode.label)) { |
| 272 | + return |
| 273 | + } |
251 | 274 | if (this.visibleCheckedNodes.every(visibleNode => !halfCheckedNode.children.some(child => visibleNode.label == child.label))) {
|
252 | 275 | this.$refs.tree.setChecked(halfCheckedNode.id, false)
|
253 | 276 | }
|
254 |
| - else if (this.visibleCheckedNodes.every(visibleNode => halfCheckedNode.children.some(child => visibleNode.label == child.label))) { |
| 277 | + // If number of visible checked nodes in halfCheckedNode is equal to number of children that are visible (number of children thast are visible is equal to allVisibleDataIds with halfCheckedNode label as a parent) |
| 278 | + else if (visibleChildren.length == visibleCheckedChildren.length) { |
255 | 279 | this.$refs.tree.setChecked(halfCheckedNode.id, true)
|
256 | 280 | }
|
257 | 281 | })
|
258 |
| - // set any subfacets again so that their parent facets get updated to checked/half checked in case their parent selection was cleared |
259 |
| - // by the previous tab navigation (i.e. show all was set automatically all the visible facets aviable in the new tab were selected) |
260 |
| - this.visibleCheckedNodes.filter(node => node.label.includes('.')).forEach(subfacet => { |
261 |
| - this.$refs.tree.setChecked(subfacet.id, true, true) |
| 282 | +
|
| 283 | + visibleCheckedParents = this.visibleCheckedNodes.filter(visibleNode => { |
| 284 | + return !visibleNode.label.includes('.') |
| 285 | + }) |
| 286 | + visibleCheckedChildren = this.visibleCheckedNodes.filter(visibleNode => { |
| 287 | + return visibleNode.label.includes('.') |
| 288 | + }) |
| 289 | +
|
| 290 | + visibleCheckedParents.forEach(checkedParent => { |
| 291 | + // If any children are unselected then select one deep so that the parent is half-checked |
| 292 | + const visibleChildren = checkedParent.children.filter(child => this.allVisibleDataIds.includes(child.label)) |
| 293 | + if (visibleChildren.some(visibleChild => { |
| 294 | + let isChecked = false |
| 295 | + visibleCheckedChildren.forEach(checkedChild => { |
| 296 | + if (checkedChild.label == visibleChild.label) { |
| 297 | + isChecked = true |
| 298 | + return |
| 299 | + } |
| 300 | + }) |
| 301 | + return !isChecked |
| 302 | + })) { |
| 303 | + const alreadyCheckedChild = visibleCheckedChildren.find(child => { |
| 304 | + const childsParentLabel = child.label.split('.')[0] |
| 305 | + return childsParentLabel == checkedParent.label |
| 306 | + }) |
| 307 | + if (alreadyCheckedChild != undefined) { |
| 308 | + this.$refs.tree.setChecked(alreadyCheckedChild.id, true, true) |
| 309 | + } else { |
| 310 | + this.$refs.tree.setChecked(checkedParent.id, false) |
| 311 | + } |
| 312 | + } |
262 | 313 | })
|
263 | 314 | },
|
264 | 315 | setShowAll: function() {
|
|
0 commit comments