LP1823982 Vandelay Match Set new tree repair
authorBill Erickson <berickxx@gmail.com>
Tue, 9 Apr 2019 15:43:10 +0000 (11:43 -0400)
committerJane Sandberg <sandbej@linnbenton.edu>
Fri, 10 May 2019 18:02:00 +0000 (11:02 -0700)
When creating a new Match Set expression, provide a default root
'AND' node upon which new nodes may be added.

Signed-off-by: Bill Erickson <berickxx@gmail.com>
Signed-off-by: Jane Sandberg <sandbej@linnbenton.edu>
Open-ILS/src/eg2/src/app/staff/cat/vandelay/match-set-expression.component.html
Open-ILS/src/eg2/src/app/staff/cat/vandelay/match-set-expression.component.ts

index fe7d817..9a5ee0c 100644 (file)
@@ -49,7 +49,7 @@
     <ng-container *ngIf="tree">
       <div class="d-flex">
         <button class="btn btn-warning mr-1" (click)="deleteNode()" 
     <ng-container *ngIf="tree">
       <div class="d-flex">
         <button class="btn btn-warning mr-1" (click)="deleteNode()" 
-          [disabled]="!hasSelectedNode()" i18n>
+          [disabled]="!hasSelectedNode() || isRootNode()" i18n>
           Remove Selected Node
         </button>
         <button class="btn btn-success mr-1" (click)="saveTree()"
           Remove Selected Node
         </button>
         <button class="btn btn-success mr-1" (click)="saveTree()"
index f02ab21..f93c1e7 100644 (file)
@@ -56,9 +56,36 @@ export class MatchSetExpressionComponent implements OnInit {
         return this.pcrud.search('vmsp',
             {match_set: this.matchSet_.id()}, {},
             {atomic: true, authoritative: true}
         return this.pcrud.search('vmsp',
             {match_set: this.matchSet_.id()}, {},
             {atomic: true, authoritative: true}
-        ).toPromise().then(points => this.ingestMatchPoints(points));
+        ).toPromise().then(points => {
+            if (points.length > 0) {
+                this.ingestMatchPoints(points);
+            } else {
+                this.addRootNode();
+            }
+        });
+    }
+
+    // When creating a new tree, add a stub boolean node
+    // as the root so the tree has something to render.
+    addRootNode() {
+
+        const point = this.idl.create('vmsp');
+        point.id(this.newId--);
+        point.isnew(true);
+        point.match_set(this.matchSet_.id());
+        point.children([]);
+        point.bool_op('AND');
+
+        const node: TreeNode = new TreeNode({
+            id: point.id(),
+            callerData: {point: point}
+        });
+
+        this.tree = new Tree(node);
+        this.setNodeLabel(node, point);
     }
 
     }
 
+    // Tree-ify a set of match points.
     ingestMatchPoints(points: IdlObject[]) {
         const nodes = [];
         const idmap: any = {};
     ingestMatchPoints(points: IdlObject[]) {
         const nodes = [];
         const idmap: any = {};
@@ -118,6 +145,14 @@ export class MatchSetExpressionComponent implements OnInit {
         return Boolean(this.tree.selectedNode());
     }
 
         return Boolean(this.tree.selectedNode());
     }
 
+    isRootNode(): boolean {
+        const node = this.tree.selectedNode();
+        if (node && this.tree.findParentNode(node) === null) {
+            return true;
+        }
+        return false;
+    }
+
     selectedIsBool(): boolean {
         if (this.tree) {
             const node = this.tree.selectedNode();
     selectedIsBool(): boolean {
         if (this.tree) {
             const node = this.tree.selectedNode();