LP1852782 Main entry link sets subfield 0
authorBill Erickson <berickxx@gmail.com>
Tue, 31 Dec 2019 15:58:55 +0000 (10:58 -0500)
committerBill Erickson <berickxx@gmail.com>
Fri, 21 Feb 2020 16:44:38 +0000 (11:44 -0500)
In the MARC editor, when applying a main entry heading, set the subfield
0 of the modified bib field to link to the authority record in question.

Signed-off-by: Bill Erickson <berickxx@gmail.com>
Signed-off-by: Jane Sandberg <sandbej@linnbenton.edu>
Open-ILS/src/eg2/src/app/staff/share/marc-edit/authority-linking-dialog.component.html
Open-ILS/src/eg2/src/app/staff/share/marc-edit/authority-linking-dialog.component.ts

index df25167..2c8c3fc 100644 (file)
 </eg-marc-editor-dialog>
 
 <!-- display a single heading as MARC or as the human friendlier string -->
-<ng-template #headingField let-field="field" let-from="from" let-also="also">
+<ng-template #headingField 
+  let-field="field" let-from="from" let-also="also" let-authId="authId">
   <button class="btn btn-sm p-1 mr-1" 
     [ngClass]="{'btn-outline-primary': !(from || also), 'btn-outline-info': (from || also)}"
-    (click)="applyHeading(field)" i18n>Apply</button>
+    (click)="applyHeading(field, authId)" i18n>Apply</button>
   <ng-container *ngIf="showAs == 'heading'">
     <span *ngIf="from" i18n>See From: {{field.heading}}</span>
     <span *ngIf="also" i18n>See Also: {{field.heading}}</span>
@@ -92,7 +93,7 @@
       <li class="d-flex">
         <div class="flex-1">
           <ng-container
-            *ngTemplateOutlet="headingField;context:{field:entry.main_heading}">
+            *ngTemplateOutlet="headingField;context:{field:entry.main_heading, authId: entry.authority_id}">
           </ng-container>
         </div>
         <div class="font-italic" i18n-title i18n
index 6504f7d..0de369f 100644 (file)
@@ -135,12 +135,20 @@ export class AuthorityLinkingDialogComponent
         ).subscribe(entry => this.browseData.push(entry));
     }
 
-    applyHeading(authField: MarcField) {
+    applyHeading(authField: MarcField, authId?: number) {
         this.net.request(
             'open-ils.cat',
             'open-ils.cat.authority.bib_field.overlay_authority',
             this.fieldHash(), this.fieldHash(authField), this.controlSet
-        ).subscribe(field => this.close(field));
+        ).subscribe(field => {
+            if (authId) {
+                // If an authId is provided, it means we are using
+                // a main entry heading and we should set the bib
+                // field's subfield 0 to refer to the main entry record.
+                this.setSubfieldZero(authId, field);
+            }
+            this.close(field);
+        });
     }
 
     isControlledBibSf(sf: string): boolean {
@@ -148,17 +156,20 @@ export class AuthorityLinkingDialogComponent
             this.authMeta.sf_list().includes(sf) : false;
     }
 
-    setSubfieldZero(authId: number) {
-        const sfZero = this.bibField.subfields.filter(sf => sf[0] === '0')[0];
+    setSubfieldZero(authId: number, bibField?: MarcField) {
+
+        if (!bibField) { bibField = this.bibField; }
+
+        const sfZero = bibField.subfields.filter(sf => sf[0] === '0')[0];
         if (sfZero) {
-            this.context.deleteSubfield(this.bibField, sfZero);
+            this.context.deleteSubfield(bibField, sfZero);
         }
-        this.context.insertSubfield(this.bibField,
-            ['0', `(${this.cni})${authId}`, this.bibField.subfields.length]);
+        this.context.insertSubfield(bibField,
+            ['0', `(${this.cni})${authId}`, bibField.subfields.length]);
 
         // Reset the validation state.
-        this.bibField.authChecked = null;
-        this.bibField.authValid = null;
+        bibField.authChecked = null;
+        bibField.authValid = null;
     }
 
     createNewAuthority(editFirst?: boolean) {