LP1823982 Vandelay Match Set new tree repair
[Evergreen.git] / Open-ILS / src / eg2 / src / app / staff / cat / vandelay / match-set-expression.component.ts
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}
-        ).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();