LP#1775466 Tree widget minor tweaks
authorBill Erickson <berickxx@gmail.com>
Mon, 23 Jul 2018 21:43:09 +0000 (17:43 -0400)
committerBill Erickson <berickxx@gmail.com>
Wed, 5 Sep 2018 14:05:23 +0000 (10:05 -0400)
Signed-off-by: Bill Erickson <berickxx@gmail.com>
Open-ILS/src/eg2/src/app/share/tree/tree.component.html
Open-ILS/src/eg2/src/app/share/tree/tree.component.ts
Open-ILS/src/eg2/src/app/share/tree/tree.ts

index 80125b3..525fece 100644 (file)
@@ -13,7 +13,7 @@
        &nbsp; 
       </div>
     </div>
-    <div class="eg-tree-node" [ngClass]="{active : node.active}">
+    <div class="eg-tree-node" [ngClass]="{active : node.selected}">
       <a [routerLink]="" (click)="handleNodeClick(node)">{{node.label}}</a>
     </div>
   </div>
index d933957..d02238d 100644 (file)
@@ -51,7 +51,7 @@ export class TreeComponent implements OnInit {
     }
 
     handleNodeClick(node: TreeNode) {
-        this.tree.activateNode(node);
+        this.tree.selectNode(node);
         this.nodeClicked.emit(node);
     }
 }
index f230780..2eb500e 100644 (file)
@@ -1,23 +1,39 @@
 
 export class TreeNode {
+    // Unique identifier
     id: any;
+
+    // Display label
     label: string;
+
+    // True if child nodes should be visible
     expanded: boolean;
+
     children: TreeNode[];
+
+    // Set by the tree.
     depth: number;
-    active: boolean;
+
+    // Set by the tree.
+    selected: boolean;
+
+    // Optional link to user-provided stuff.  
+    // This field is ignored by the tree.
+    callerData: any;
 
     constructor(values: {[key: string]: any}) {
         this.children = [];
         this.expanded = false;
         this.depth = 0;
-        this.active = false;
-        if (values) {
-            if ('id' in values) { this.id = values.id; }
-            if ('label' in values) { this.label = values.label; }
-            if ('children' in values) { this.children = values.children; }
-            if ('expanded' in values) { this.expanded = values.expanded; }
-        }
+        this.selected = false;
+
+        if (!values) { return; }
+
+        if ('id' in values) { this.id = values.id; }
+        if ('label' in values) { this.label = values.label; }
+        if ('children' in values) { this.children = values.children; }
+        if ('expanded' in values) { this.expanded = values.expanded; }
+        if ('callerData' in values) { this.callerData = values.callerData; }
     }
 
     toggleExpand() {
@@ -49,8 +65,8 @@ export class Tree {
             this.idMap[node.id + ''] = node;
 
             if (hidden) {
-                // it could be confusing for a hidden node to be active.
-                node.active = false;
+                // it could be confusing for a hidden node to be selected.
+                node.selected = false;
             }
 
             if (hidden && filterHidden) {
@@ -105,13 +121,13 @@ export class Tree {
         this.nodeList().forEach(node => node.expanded = false);
     }
 
-    activeNode(): TreeNode {
-        return this.nodeList().filter(node => node.active)[0];
+    selectedNode(): TreeNode {
+        return this.nodeList().filter(node => node.selected)[0];
     }
 
-    activateNode(node: TreeNode) {
-        this.nodeList().forEach(n => n.active = false);
-        node.active = true;
+    selectNode(node: TreeNode) {
+        this.nodeList().forEach(n => n.selected = false);
+        node.selected = true;
     }
 }