LP1830923 Marc edit in-place additions
authorBill Erickson <berickxx@gmail.com>
Thu, 17 Oct 2019 21:57:10 +0000 (17:57 -0400)
committerGalen Charlton <gmc@equinoxinitiative.org>
Wed, 4 Dec 2019 22:47:59 +0000 (17:47 -0500)
Improve Angular MARC editor for in-place editing.

* Make inPlaceMode a proper @Input.
* Allow the caller to pass in the bib source
* The recordSaved event now reports both the MARC XML and the currently
  selected bib source.
* Option to hide the link to the AngJS Rich Editor

Signed-off-by: Bill Erickson <berickxx@gmail.com>
Signed-off-by: Galen Charlton <gmc@equinoxinitiative.org>
Open-ILS/src/eg2/src/app/staff/share/marc-edit/editor.component.html
Open-ILS/src/eg2/src/app/staff/share/marc-edit/editor.component.ts

index f8eef36..659e070 100644 (file)
@@ -29,9 +29,9 @@
 
   <ng-container *ngIf="record && record.id">
     <button *ngIf="!record.deleted" class="btn btn-warning" 
-      (click)="deleteRecord()" i18n>Delete Record</button>
+      [disabled]="inPlaceMode" (click)="deleteRecord()" i18n>Delete Record</button>
     <button *ngIf="record.deleted" class="btn btn-info" 
-      (click)="undeleteRecord()" i18n>Undelete Record</button>
+      [disabled]="inPlaceMode" (click)="undeleteRecord()" i18n>Undelete Record</button>
   </ng-container>
 
   <button class="btn btn-success ml-2" (click)="saveRecord()" 
       <ngb-tab title="Enhanced MARC Editor" i18n-title id="rich">
         <ng-template ngbTabContent>
           <div class="alert alert-info mt-3" i18n>
-          Enhanced MARC Editor is not yet implemented.  See the
-          <ng-container *ngIf="record && record.id">
-            <a target="_blank"
-              href="/eg/staff/cat/catalog/record/{{record.id}}/marc_edit">
-              AngularJS MARC Editor.
-            </a>
-          </ng-container>
-          <ng-container *ngIf="!record || !record.id">
-            <a target="_blank" href="/eg/staff/cat/catalog/new_bib">
-              AngularJS MARC Editor.
-            </a>
-          </ng-container>
+          Enhanced MARC Editor is not yet implemented.
+            <ng-container *ngIf="!hideFullEditorLink">
+              See the
+              <ng-container *ngIf="record && record.id">
+                <a target="_blank"
+                  href="/eg/staff/cat/catalog/record/{{record.id}}/marc_edit">
+                  AngularJS MARC Editor.
+                </a>
+              </ng-container>
+              <ng-container *ngIf="!record || !record.id">
+                <a target="_blank" href="/eg/staff/cat/catalog/new_bib">
+                  AngularJS MARC Editor.
+                </a>
+              </ng-container>
+            </ng-container>
           </div>
         </ng-template>
       </ngb-tab>
index fa9fbe1..128e168 100644 (file)
@@ -12,6 +12,10 @@ import {ComboboxEntry, ComboboxComponent
   } from '@eg/share/combobox/combobox.component';
 import {ConfirmDialogComponent} from '@eg/share/dialog/confirm.component';
 
+interface MarcSavedEvent {
+    marcXml: string;
+    bibSource?: number;
+}
 
 /**
  * MARC Record editor main interface.
@@ -27,6 +31,7 @@ export class MarcEditorComponent implements OnInit {
     record: MarcRecord;
     editorTab: 'rich' | 'flat';
     sources: ComboboxEntry[];
+    @Input() hideFullEditorLink: boolean;
 
     @Input() set recordId(id: number) {
         if (!id) { return; }
@@ -38,15 +43,19 @@ export class MarcEditorComponent implements OnInit {
         if (xml) { this.fromXml(xml); }
     }
 
+    // Tell us which record source to select by default.
+    // Useful for new records and in-place editing from bare XML.
+    @Input() recordSource: number;
+
     // If true, saving records to the database is assumed to
     // happen externally.  IOW, the record editor is just an
     // in-place MARC modification interface.
-    inPlaceMode: boolean;
+    @Input() inPlaceMode: boolean;
 
     // In inPlaceMode, this is emitted in lieu of saving the record
     // in th database.  When inPlaceMode is false, this is emitted after
     // the record is successfully saved.
-    @Output() recordSaved: EventEmitter<string>;
+    @Output() recordSaved: EventEmitter<MarcSavedEvent>;
 
     @ViewChild('sourceSelector') sourceSelector: ComboboxComponent;
     @ViewChild('confirmDelete') confirmDelete: ConfirmDialogComponent;
@@ -65,7 +74,7 @@ export class MarcEditorComponent implements OnInit {
         private toast: ToastService
     ) {
         this.sources = [];
-        this.recordSaved = new EventEmitter<string>();
+        this.recordSaved = new EventEmitter<MarcSavedEvent>();
     }
 
     ngOnInit() {
@@ -79,6 +88,10 @@ export class MarcEditorComponent implements OnInit {
                 this.sources = this.sources.sort((a, b) =>
                     a.label.toLowerCase() < b.label.toLowerCase() ? -1 : 1
                 );
+
+                if (this.recordSource) {
+                    this.sourceSelector.applyEntryId(this.recordSource);
+                }
             }
         );
     }
@@ -86,21 +99,26 @@ export class MarcEditorComponent implements OnInit {
     saveRecord(): Promise<any> {
         const xml = this.record.toXml();
 
+        let sourceName: string = null;
+        let sourceId: number = null;
+
+        if (this.sourceSelector.selected) {
+            sourceName = this.sourceSelector.selected.label;
+            sourceId = this.sourceSelector.selected.id;
+        }
+
         if (this.inPlaceMode) {
             // Let the caller have the modified XML and move on.
-            this.recordSaved.emit(xml);
+            this.recordSaved.emit({marcXml: xml, bibSource: sourceId});
             return Promise.resolve();
         }
 
-        const source = this.sourceSelector.selected ?
-            this.sourceSelector.selected.label : null; // 'label' not a typo
-
         if (this.record.id) { // Editing an existing record
 
             const method = 'open-ils.cat.biblio.record.marc.replace';
 
             return this.net.request('open-ils.cat', method,
-                this.auth.token(), this.record.id, xml, source
+                this.auth.token(), this.record.id, xml, sourceName
             ).toPromise().then(response => {
 
                 const evt = this.evt.parse(response);
@@ -111,7 +129,7 @@ export class MarcEditorComponent implements OnInit {
                 }
 
                 this.successMsg.current().then(msg => this.toast.success(msg));
-                this.recordSaved.emit(xml);
+                this.recordSaved.emit({marcXml: xml, bibSource: sourceId});
                 return response;
             });
 
@@ -159,7 +177,8 @@ export class MarcEditorComponent implements OnInit {
                     }
                 }
                 return this.fromId(this.record.id)
-                .then(_ => this.recordSaved.emit(this.record.toXml()));
+                .then(_ => this.recordSaved.emit(
+                    {marcXml: this.record.toXml()}));
             });
         });
     }
@@ -180,7 +199,8 @@ export class MarcEditorComponent implements OnInit {
                 if (evt) { console.error(evt); return alert(evt); }
 
                 return this.fromId(this.record.id)
-                .then(_ => this.recordSaved.emit(this.record.toXml()));
+                .then(_ => this.recordSaved.emit(
+                    {marcXml: this.record.toXml()}));
             });
         });
     }