LP1823393 Org unit type Angular admin UI
[Evergreen.git] / Open-ILS / src / eg2 / src / app / share / tree / tree.component.ts
1 import {Component, OnInit, Input, Output, EventEmitter} from '@angular/core';
2 import {Tree, TreeNode} from './tree';
3
4 /*
5 Tree Widget:
6
7 <eg-tree
8     [tree]="myTree"
9     (nodeClicked)="nodeClicked($event)">
10 </eg-tree>
11
12 ----
13
14 constructor() {
15
16     const rootNode = new TreeNode({
17         id: 1,
18         label: 'Root',
19         children: [
20             new TreeNode({id: 2, label: 'Child'}),
21             new TreeNode({id: 3, label: 'Child2'})
22         ]
23     ]});
24
25     this.myTree = new Tree(rootNode);
26 }
27
28 nodeClicked(node: TreeNode) {
29     console.log('someone clicked on ' + node.label);
30 }
31 */
32
33 @Component({
34     selector: 'eg-tree',
35     templateUrl: 'tree.component.html',
36     styleUrls: ['tree.component.css']
37 })
38 export class TreeComponent implements OnInit {
39
40     @Input() tree: Tree;
41     @Output() nodeClicked: EventEmitter<TreeNode>;
42
43     constructor() {
44         this.nodeClicked = new EventEmitter<TreeNode>();
45     }
46
47     ngOnInit() {}
48
49     displayNodes(): TreeNode[] {
50         if (!this.tree) { return []; }
51         return this.tree.nodeList(true);
52     }
53
54     handleNodeClick(node: TreeNode) {
55         this.tree.selectNode(node);
56         this.nodeClicked.emit(node);
57     }
58 }
59
60
61