From: Bill Erickson <berickxx@gmail.com>
Date: Tue, 9 Apr 2019 15:43:10 +0000 (-0400)
Subject: LP1823982 Vandelay Match Set new tree repair
X-Git-Url: https://old-git.evergreen-ils.org/?a=commitdiff_plain;h=73ee4b05b38597b2d981ef7675e62cd7d9738c33;p=evergreen%2Fequinox.git

LP1823982 Vandelay Match Set new tree repair

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>
---

diff --git a/Open-ILS/src/eg2/src/app/staff/cat/vandelay/match-set-expression.component.html b/Open-ILS/src/eg2/src/app/staff/cat/vandelay/match-set-expression.component.html
index fe7d8171c9..9a5ee0ce19 100644
--- a/Open-ILS/src/eg2/src/app/staff/cat/vandelay/match-set-expression.component.html
+++ b/Open-ILS/src/eg2/src/app/staff/cat/vandelay/match-set-expression.component.html
@@ -49,7 +49,7 @@
     <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()"
diff --git a/Open-ILS/src/eg2/src/app/staff/cat/vandelay/match-set-expression.component.ts b/Open-ILS/src/eg2/src/app/staff/cat/vandelay/match-set-expression.component.ts
index f02ab214ba..f93c1e7d41 100644
--- a/Open-ILS/src/eg2/src/app/staff/cat/vandelay/match-set-expression.component.ts
+++ b/Open-ILS/src/eg2/src/app/staff/cat/vandelay/match-set-expression.component.ts
@@ -56,9 +56,36 @@ export class MatchSetExpressionComponent implements OnInit {
         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 = {};
@@ -118,6 +145,14 @@ export class MatchSetExpressionComponent implements OnInit {
         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();