LP1839562 Ang Vandelay Match Set Replace Mode
authorBill Erickson <berickxx@gmail.com>
Tue, 11 Aug 2020 15:07:04 +0000 (11:07 -0400)
committerGalen Charlton <gmc@equinoxinitiative.org>
Tue, 18 Aug 2020 20:45:01 +0000 (16:45 -0400)
Recover "Replace Mode" functionality in the Vandelay Match Set editor
interface, so existing nodes (e.g. And) may be replaced with other nodes
(e.g. Or) without modifying the rest of the tree structure.

Values (Record Attrs / MARC Fields) can replace other values.  Booleans
can replace any type of tree node.

Signed-off-by: Bill Erickson <berickxx@gmail.com>
Signed-off-by: Mary Llewellyn <mllewell@biblio.org>
Signed-off-by: Christine Morgan <cmorgan@noblenet.org>
Signed-off-by: Galen Charlton <gmc@equinoxinitiative.org>

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 9a5ee0c..004b7c1 100644 (file)
         [disabled]="!selectedIsBool()" i18n>
         Add To Selected Node
       </button>
+
+      <button class="btn btn-success ml-3" (click)="addChildNode(true)"
+        [disabled]="!hasSelectedNode() ||
+          (newPointType != 'bool' && selectedIsBool())" i18n>
+        Replace Selected Node
+      </button>
+
     </div>
     <div class="row mt-2 ml-2 font-italic" *ngIf="newPointType">
       <ol i18n>
index 891b01a..86c4b76 100644 (file)
@@ -161,16 +161,27 @@ export class MatchSetExpressionComponent implements OnInit {
         return false;
     }
 
-    addChildNode() {
+    addChildNode(replace?: boolean) {
         this.changesMade = true;
 
-        const pnode = this.tree.selectedNode();
-        const point = this.idl.create('vmsp');
-        point.id(this.newId--);
-        point.isnew(true);
-        point.parent(pnode.id);
-        point.match_set(this.matchSet_.id());
-        point.children([]);
+        const targetNode: TreeNode = this.tree.selectedNode();
+        let point;
+
+        if (replace) {
+            point = targetNode.callerData.point;
+            point.ischanged(true);
+            // Clear previous data
+            ['bool_op', 'svf', 'tag', 'subfield', 'heading']
+                .forEach(f => point[f](null));
+
+        } else {
+            point = this.idl.create('vmsp');
+            point.id(this.newId--);
+            point.isnew(true);
+            point.parent(targetNode.id);
+            point.match_set(this.matchSet_.id());
+            point.children([]);
+        }
 
         const ptype = this.newPoint.values.pointType;
 
@@ -193,13 +204,22 @@ export class MatchSetExpressionComponent implements OnInit {
             point.quality(this.newPoint.values.matchScore);
         }
 
-        const node: TreeNode = new TreeNode({
-            id: point.id(),
-            callerData: {point: point}
-        });
+        if (replace) {
+
+            targetNode.label = null;
+            this.setNodeLabel(targetNode, point);
+
+        } else {
 
-        // Match points are added to the DB only when the tree is saved.
-        this.setNodeLabel(node, point).then(() => pnode.children.push(node));
+            const node: TreeNode = new TreeNode({
+                id: point.id(),
+                callerData: {point: point}
+            });
+
+            // Match points are added to the DB only when the tree is saved.
+            this.setNodeLabel(node, point)
+                .then(() => targetNode.children.push(node));
+        }
     }
 
     expressionAsString(): string {