source: trip-planner-front/node_modules/@angular/cdk/esm2015/tree/control/nested-tree-control.js@ bdd6491

Last change on this file since bdd6491 was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago

initial commit

  • Property mode set to 100644
File size: 8.2 KB
Line 
1/**
2 * @license
3 * Copyright Google LLC All Rights Reserved.
4 *
5 * Use of this source code is governed by an MIT-style license that can be
6 * found in the LICENSE file at https://angular.io/license
7 */
8import { isObservable } from 'rxjs';
9import { take, filter } from 'rxjs/operators';
10import { BaseTreeControl } from './base-tree-control';
11/** Nested tree control. Able to expand/collapse a subtree recursively for NestedNode type. */
12export class NestedTreeControl extends BaseTreeControl {
13 /** Construct with nested tree function getChildren. */
14 constructor(getChildren, options) {
15 super();
16 this.getChildren = getChildren;
17 this.options = options;
18 if (this.options) {
19 this.trackBy = this.options.trackBy;
20 }
21 }
22 /**
23 * Expands all dataNodes in the tree.
24 *
25 * To make this working, the `dataNodes` variable of the TreeControl must be set to all root level
26 * data nodes of the tree.
27 */
28 expandAll() {
29 this.expansionModel.clear();
30 const allNodes = this.dataNodes.reduce((accumulator, dataNode) => [...accumulator, ...this.getDescendants(dataNode), dataNode], []);
31 this.expansionModel.select(...allNodes.map(node => this._trackByValue(node)));
32 }
33 /** Gets a list of descendant dataNodes of a subtree rooted at given data node recursively. */
34 getDescendants(dataNode) {
35 const descendants = [];
36 this._getDescendants(descendants, dataNode);
37 // Remove the node itself
38 return descendants.splice(1);
39 }
40 /** A helper function to get descendants recursively. */
41 _getDescendants(descendants, dataNode) {
42 descendants.push(dataNode);
43 const childrenNodes = this.getChildren(dataNode);
44 if (Array.isArray(childrenNodes)) {
45 childrenNodes.forEach((child) => this._getDescendants(descendants, child));
46 }
47 else if (isObservable(childrenNodes)) {
48 // TypeScript as of version 3.5 doesn't seem to treat `Boolean` like a function that
49 // returns a `boolean` specifically in the context of `filter`, so we manually clarify that.
50 childrenNodes.pipe(take(1), filter(Boolean))
51 .subscribe(children => {
52 for (const child of children) {
53 this._getDescendants(descendants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gICB9IGVsc2UgaWYgKGlzT2JzZXJ2YWJsZShjaGlsZHJlbk5vZGVzKSkge1xuICAgICAgLy8gVHlwZVNjcmlwdCBhcyBvZiB2ZXJzaW9uIDMuNSBkb2Vzbid0IHNlZW0gdG8gdHJlYXQgYEJvb2xlYW5gIGxpa2UgYSBmdW5jdGlvbiB0aGF0XG4gICAgICAvLyByZXR1cm5zIGEgYGJvb2xlYW5gIHNwZWNpZmljYWxseSBpbiB0aGUgY29udGV4dCBvZiBgZmlsdGVyYCwgc28gd2UgbWFudWFsbHkgY2xhcmlmeSB0aGF0LlxuICAgICAgY2hpbGRyZW5Ob2Rlcy5waXBlKHRha2UoMSksIGZpbHRlcihCb29sZWFuIGFzICgpID0+IGJvb2xlYW4pKVxuICAgICAgICAgIC5zdWJzY3JpYmUoY2hpbGRyZW4gPT4ge1xuICAgICAgICAgICAgZm9yIChjb25zdCBjaGlsZCBvZiBjaGlsZHJlbikge1xuICAgICAgICAgICAgICB0aGlzLl9nZXREZXNjZW5kYW50cyhkZXNjZW5kYW50cywgY2hpbGQpO1xuICAgICAgICAgICAgfVxuICAgICAgICAgIH0pO1xuICAgIH1cbiAgfVxufVxuIl19
Note: See TracBrowser for help on using the repository browser.