LPXXX MARC Batch update Angular port user/berick/lpxxx-marc-batch-angular
authorBill Erickson <berickxx@gmail.com>
Thu, 21 May 2020 22:17:00 +0000 (18:17 -0400)
committerBill Erickson <berickxx@gmail.com>
Thu, 21 May 2020 22:17:00 +0000 (18:17 -0400)
Signed-off-by: Bill Erickson <berickxx@gmail.com>
Open-ILS/src/eg2/src/app/staff/cat/marcbatch/marcbatch.component.html
Open-ILS/src/eg2/src/app/staff/cat/marcbatch/marcbatch.component.ts
Open-ILS/src/eg2/src/app/staff/share/marc-edit/marcrecord.ts

index aeaf002..0bd0bde 100644 (file)
@@ -85,7 +85,7 @@
         <div class="col-lg-12 d-flex justify-content-end">
           <button class="btn btn-outline-danger label-with-material-icon"
             (click)="removeRule(idx)" i18n>
-            <span>Remove this Template Rule</span>
+            <span>Remove this Merge Rule</span>
             <span class="material-icons ml-2">delete</span>
           </button>
         </div>
   <div class="col-lg-5">
     <div class="row pb-2 pt-2 border">
       <div class="col-lg-12">
-        <div class="font-weight-bold" i18n>Template Preview</div>
+        <div class="font-weight-bold" i18n>Merge Template Preview</div>
         <div>
           <textarea class="form-control" [ngModel]="breaker()" 
             disabled rows="{{breakerRows()}}"></textarea>
       </div>
     </div>
     <div class="row mt-2 p-2" *ngIf="!processing && progressMax">
-      <div class="col-lg-10 offset-lg-1">
+      <div class="col-lg-12 alert alert-success">
         <div i18n>Processing Complete</div>
-        <div i18n>Success count: {{this.numSucceeded}}</div>
-        <div i18n>Failed count: {{this.numFailed}}</div>
+        <div class="row">
+          <div class="col-lg-3" i18n>Success count: </div>
+          <div class="col-lg-3">{{this.numSucceeded}}</div>
+        </div>
+        <div class="row">
+          <div class="col-lg-3" i18n>Failed count: </div>
+          <div class="col-lg-3">{{this.numFailed}}</div>
+        </div>
       </div>
     </div>
   </div>
index 478aa2f..2a83825 100644 (file)
@@ -68,6 +68,8 @@ export class MarcBatchComponent implements OnInit {
 
         this.templateRules.forEach(rule => {
 
+            if (!rule.marcTag) { return; }
+
             let ruleText = rule.marcTag + (rule.marcSubfields || '');
             if (rule.advSubfield) {
                 ruleText +=
@@ -84,10 +86,13 @@ export class MarcBatchComponent implements OnInit {
 
             this.record.insertOrderedFields(ruleTag);
 
-            if (rule.ruleType === 'd') { return; }
+            if (rule.ruleType === 'd') {
+                rule.marcData = '';
+                return;
+            }
 
             const dataRec = new MarcRecord();
-            if (resetRuleData) {
+            if (resetRuleData || !rule.marcData) {
 
                 // Build a new value for the 'MARC Data' field based on
                 // changes to the selected tag or subfields.
@@ -150,12 +155,12 @@ export class MarcBatchComponent implements OnInit {
             'open-ils.actor',
             'open-ils.actor.container.retrieve_by_class',
             this.auth.token(), this.auth.user().id(),
-            'biblio', ['staff_client','vandelay_queue']
+            'biblio', ['staff_client', 'vandelay_queue']
 
         ).pipe(tap(buckets => {
             this.buckets = buckets
             .sort((b1, b2) => b1.name() < b2.name() ? -1 : 1)
-            .map(b => ({id: b.id(), label: b.name()}))
+            .map(b => ({id: b.id(), label: b.name()}));
 
         })).toPromise();
     }
@@ -173,11 +178,6 @@ export class MarcBatchComponent implements OnInit {
             return true;
         }
 
-        if (!this.processing && this.progressMax) {
-            // Just completed a session.
-            return true;
-        }
-
         if (this.source === 'b') {
             return !this.bucket;
 
@@ -189,17 +189,30 @@ export class MarcBatchComponent implements OnInit {
         }
     }
 
-
     process() {
         this.processing = true;
         this.progressValue = null;
         this.progressMax = null;
         this.numSucceeded = 0;
         this.numFailed = 0;
-
+        this.setReplaceMode();
         this.postForm().then(_ => this.pollProgress());
     }
 
+    setReplaceMode() {
+        if (this.record.subfield('905', 'r').length === 0) {
+            // Force replace mode w/ no-op replace rule.
+            this.record.appendFields(
+                this.record.newField({
+                    tag : '905',
+                    ind1 : ' ',
+                    ind2 : ' ',
+                    subfields : [['r', '901c']]
+                })
+            );
+        }
+    }
+
     postForm(): Promise<any> {
 
         const formData: FormData = new FormData();
index 4ba850b..493eaad 100644 (file)
@@ -191,5 +191,10 @@ export class MarcRecord {
         subfields.forEach(sf => root.push([].concat(sf)));
         return root;
     }
+
+    // Returns a list of values for the tag + subfield combo
+    subfield(tag: string, subfield: string): string {
+        return this.record.subfield(tag, subfield);
+    }
 }