Skip to content

Commit bfff5f0

Browse files
committed
address comments
1 parent 9be93a3 commit bfff5f0

File tree

8 files changed

+51
-17
lines changed

8 files changed

+51
-17
lines changed

src/demo-app/tree/tree-demo.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@
4343
</button>
4444
{{node.key}}
4545
</div>
46-
<ul [class]="nestedTreeControl.isExpanded(node) ? '' : 'tree-demo-invisible'">
46+
<ul [class.tree-demo-invisible]="!nestedTreeControl.isExpanded(node)">
4747
<ng-container matTreeNodeOutlet></ng-container>
4848
</ul>
4949
</li>

src/demo-app/tree/tree-demo.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ import {of as ofObservable} from 'rxjs/observable/of';
1414
import {JsonNode, JsonDatabase} from './json-database';
1515
import {JsonFlatNode} from './flat-data-source';
1616

17-
1817
@Component({
1918
moduleId: module.id,
2019
selector: 'tree-demo',
@@ -48,7 +47,6 @@ export class TreeDemo {
4847
this.nestedDataSource = new MatTreeNestedDataSource();
4948

5049
database.dataChange.subscribe(data => {
51-
console.log(`datachanges in demo`)
5250
this.dataSource.data = data;
5351
this.nestedDataSource.data = data;
5452
})

src/material-examples/tree-flat-overview/tree-flat-overview-example.css

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
1-
.tree-demo-invisible {
2-
display: none;
3-
}
4-
5-
ul, li {
1+
.example-tree ul,
2+
.example-tree li {
63
-webkit-margin-before: 0;
74
-webkit-margin-after: 0;
85
list-style-type: none;

src/material-examples/tree-flat-overview/tree-flat-overview-example.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<mat-tree [dataSource]="dataSource" [treeControl]="treeControl">
1+
<mat-tree [dataSource]="dataSource" [treeControl]="treeControl" class="example-tree">
22
<mat-tree-node *matTreeNodeDef="let node" matTreeNodeToggle matTreeNodePadding>
33
{{node.key}} : {{node.value}}
44
</mat-tree-node>

src/material-examples/tree-flat-overview/tree-flat-overview-example.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import {MatTreeFlattener, MatTreeFlatDataSource} from '@angular/material-experim
44
import {of} from 'rxjs/observable/of';
55
import {BehaviorSubject} from 'rxjs/BehaviorSubject';
66

7+
/** Json node data with nested structure. Each node has a key and a value or a list of children. */
78
export class JsonNode {
89
children: JsonNode[];
910
key: string;
@@ -18,6 +19,10 @@ export class JsonFlatNode {
1819
expandable: boolean;
1920
}
2021

22+
23+
/**
24+
* The Json tree data in string. The data could be parsed into Json object
25+
*/
2126
const TREE_DATA = `{"Tina":
2227
{
2328
"Documents": {
@@ -55,6 +60,11 @@ const TREE_DATA = `{"Tina":
5560
}
5661
}}`;
5762

63+
/**
64+
* Json database, it can build a tree structured Json object from string.
65+
* The input will be a json object string, and the output is a list of `JsonNode` with nested
66+
* structure.
67+
*/
5868
@Injectable()
5969
export class JsonDatabase {
6070
dataChange: BehaviorSubject<JsonNode[]> = new BehaviorSubject<JsonNode[]>([]);
@@ -66,11 +76,21 @@ export class JsonDatabase {
6676
}
6777

6878
initialize() {
79+
// Parse the string to json object.
6980
const dataObject = JSON.parse(TREE_DATA);
81+
82+
// Build the tree nodes from Json object. The result is a list of `JsonNode` with nested
83+
// Json node as children.
7084
const data = this.buildJsonTree(dataObject, 0);
85+
86+
// Notify the change.
7187
this.dataChange.next(data);
7288
}
7389

90+
/**
91+
* Build the Json tree. The `value` is the Json object, or a sub-tree of a Json object.
92+
* The return value is the list of `JsonNode`.
93+
*/
7494
buildJsonTree(value: any, level: number) {
7595
let data: any[] = [];
7696
for (let k in value) {

src/material-examples/tree-nested-overview/tree-nested-overview-example.css

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1-
.tree-demo-invisible {
1+
.example-tree-invisible {
22
display: none;
33
}
44

5-
ul, li {
5+
.example-tree ul,
6+
.example-tree li {
67
-webkit-margin-before: 0;
78
-webkit-margin-after: 0;
89
list-style-type: none;

src/material-examples/tree-nested-overview/tree-nested-overview-example.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<mat-tree [dataSource]="nestedDataSource" [treeControl]="nestedTreeControl">
1+
<mat-tree [dataSource]="nestedDataSource" [treeControl]="nestedTreeControl" class="example-tree">
22
<mat-tree-node *matTreeNodeDef="let node" matTreeNodeToggle>
33
<li>
44
<div>{{node.key}}: {{node.value}}</div>
@@ -16,7 +16,7 @@
1616
</button>
1717
{{node.key}}
1818
</div>
19-
<ul [class]="nestedTreeControl.isExpanded(node) ? '' : 'tree-demo-invisible'">
19+
<ul [class.example-tree-invisible]="!nestedTreeControl.isExpanded(node)">
2020
<ng-container matTreeNodeOutlet></ng-container>
2121
</ul>
2222
</li>

src/material-examples/tree-nested-overview/tree-nested-overview-example.ts

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,18 @@ import {MatTreeNestedDataSource} from '@angular/material-experimental/tree';
44
import {of} from 'rxjs/observable/of';
55
import {BehaviorSubject} from 'rxjs/BehaviorSubject';
66

7+
/**
8+
* Json node data with nested structure. Each node has a key and a value or a list of children
9+
*/
710
export class JsonNode {
811
children: JsonNode[];
912
key: string;
1013
value: any;
1114
}
1215

16+
/**
17+
* The Json tree data in string. The data could be parsed into Json object
18+
*/
1319
const TREE_DATA = `{"Tina":
1420
{
1521
"Documents": {
@@ -47,6 +53,11 @@ const TREE_DATA = `{"Tina":
4753
}
4854
}}`;
4955

56+
/**
57+
* Json database, it can build a tree structured Json object from string.
58+
* The input will be a json object string, and the output is a list of `JsonNode` with nested
59+
* structure.
60+
*/
5061
@Injectable()
5162
export class JsonDatabase {
5263
dataChange: BehaviorSubject<JsonNode[]> = new BehaviorSubject<JsonNode[]>([]);
@@ -58,11 +69,21 @@ export class JsonDatabase {
5869
}
5970

6071
initialize() {
72+
// Parse the string to json object.
6173
const dataObject = JSON.parse(TREE_DATA);
74+
75+
// Build the tree nodes from Json object. The result is a list of `JsonNode` with nested
76+
// Json node as children.
6277
const data = this.buildJsonTree(dataObject, 0);
78+
79+
// Notify the change.
6380
this.dataChange.next(data);
6481
}
6582

83+
/**
84+
* Build the Json tree. The `value` is the Json object, or a sub-tree of a Json object.
85+
* The return value is the list of `JsonNode`.
86+
*/
6687
buildJsonTree(value: any, level: number) {
6788
let data: any[] = [];
6889
for (let k in value) {
@@ -100,13 +121,10 @@ export class TreeNestedOverviewExample {
100121
this.nestedTreeControl = new NestedTreeControl<JsonNode>(this._getChildren);
101122
this.nestedDataSource = new MatTreeNestedDataSource();
102123

103-
database.dataChange.subscribe(data => {
104-
this.nestedDataSource.data = data;
105-
})
124+
database.dataChange.subscribe(data => this.nestedDataSource.data = data);
106125
}
107126

108127
private _getChildren = (node: JsonNode) => { return of(node.children); };
109128

110-
111129
hasNestedChild = (_: number, nodeData: JsonNode) => {return !(nodeData.value); };
112130
}

0 commit comments

Comments
 (0)