From 1623058e0b084e15998da9ea93021ecc8c7961d9 Mon Sep 17 00:00:00 2001
From: Bill Erickson <berickxx@gmail.com>
Date: Thu, 17 Oct 2019 17:59:08 -0400
Subject: [PATCH] LP1830923 Vandelay queued record editing

This patch adds MARC record editing the the Angular
Vandelay interface using the Angular MARC editor
component, which as of the date of this patch offers
a flat-text mode.

Signed-off-by: Bill Erickson <berickxx@gmail.com>
Signed-off-by: Remington Steed <rjs7@calvin.edu>
Signed-off-by: Galen Charlton <gmc@equinoxinitiative.org>
---
 .../cat/vandelay/queued-record.component.html      |  9 ++++++++
 .../staff/cat/vandelay/queued-record.component.ts  | 25 +++++++++++++++++++++-
 .../src/app/staff/cat/vandelay/vandelay.module.ts  |  2 ++
 3 files changed, 35 insertions(+), 1 deletion(-)

diff --git a/Open-ILS/src/eg2/src/app/staff/cat/vandelay/queued-record.component.html b/Open-ILS/src/eg2/src/app/staff/cat/vandelay/queued-record.component.html
index d9e85347e0..ceb70a1704 100644
--- a/Open-ILS/src/eg2/src/app/staff/cat/vandelay/queued-record.component.html
+++ b/Open-ILS/src/eg2/src/app/staff/cat/vandelay/queued-record.component.html
@@ -16,6 +16,15 @@
       </eg-marc-html>
 		</ng-template>
 	</ngb-tab>
+	<ngb-tab title="Edit Record" i18n-title id="edit">
+		<ng-template ngbTabContent>
+      <ng-container *ngIf="queuedRecord">
+        <eg-marc-editor [inPlaceMode]="true" [recordXml]="queuedRecord.marc()" 
+          [recordSource]="queuedRecord.bib_source()"
+          (recordSaved)="handleMarcRecordSaved($event)"></eg-marc-editor>   
+      </ng-container>
+		</ng-template>
+	</ngb-tab>
 	<ngb-tab title="Record Matches" i18n-title id="matches">
 		<ng-template ngbTabContent>
       <eg-queued-record-matches [recordId]="recordId" [queueType]="queueType">
diff --git a/Open-ILS/src/eg2/src/app/staff/cat/vandelay/queued-record.component.ts b/Open-ILS/src/eg2/src/app/staff/cat/vandelay/queued-record.component.ts
index 7bbf5a8d8e..f0705a719d 100644
--- a/Open-ILS/src/eg2/src/app/staff/cat/vandelay/queued-record.component.ts
+++ b/Open-ILS/src/eg2/src/app/staff/cat/vandelay/queued-record.component.ts
@@ -1,6 +1,8 @@
 import {Component, OnInit, ViewChild} from '@angular/core';
 import {Router, ActivatedRoute, ParamMap} from '@angular/router';
 import {NgbTabset, NgbTabChangeEvent} from '@ng-bootstrap/ng-bootstrap';
+import {PcrudService} from '@eg/core/pcrud.service';
+import {IdlObject} from '@eg/core/idl.service';
 
 @Component({
   templateUrl: 'queued-record.component.html'
@@ -11,16 +13,21 @@ export class QueuedRecordComponent {
     queueType: string;
     recordId: number;
     recordTab: string;
+    queuedRecord: IdlObject;
 
     constructor(
         private router: Router,
-        private route: ActivatedRoute) {
+        private route: ActivatedRoute,
+        private pcrud: PcrudService) {
 
         this.route.paramMap.subscribe((params: ParamMap) => {
             this.queueId = +params.get('id');
             this.recordId = +params.get('recordId');
             this.queueType = params.get('qtype');
             this.recordTab = params.get('recordTab');
+            if (this.recordTab === 'edit') {
+                this.loadRecord();
+            }
         });
     }
 
@@ -38,5 +45,21 @@ export class QueuedRecordComponent {
 
         this.router.navigate([url]);
     }
+
+    loadRecord() {
+        this.queuedRecord = null;
+        this.pcrud.retrieve('vqbr', this.recordId)
+        .subscribe(rec => this.queuedRecord = rec);
+    }
+
+    handleMarcRecordSaved(saveEvent: any) {
+        this.queuedRecord.marc(saveEvent.marcXml);
+        this.queuedRecord.bib_source(saveEvent.bibSource);
+        this.pcrud.update(this.queuedRecord).subscribe(
+            response => {
+                console.log('response = ', response);
+            }
+        );
+    }
 }
 
diff --git a/Open-ILS/src/eg2/src/app/staff/cat/vandelay/vandelay.module.ts b/Open-ILS/src/eg2/src/app/staff/cat/vandelay/vandelay.module.ts
index 0f394285e3..5b01400a33 100644
--- a/Open-ILS/src/eg2/src/app/staff/cat/vandelay/vandelay.module.ts
+++ b/Open-ILS/src/eg2/src/app/staff/cat/vandelay/vandelay.module.ts
@@ -25,6 +25,7 @@ import {MatchSetExpressionComponent} from './match-set-expression.component';
 import {MatchSetQualityComponent} from './match-set-quality.component';
 import {MatchSetNewPointComponent} from './match-set-new-point.component';
 import {RecentImportsComponent} from './recent-imports.component';
+import {MarcEditModule} from '@eg/staff/share/marc-edit/marc-edit.module';
 
 @NgModule({
   declarations: [
@@ -52,6 +53,7 @@ import {RecentImportsComponent} from './recent-imports.component';
     StaffCommonModule,
     FmRecordEditorModule,
     AdminPageModule,
+    MarcEditModule,
     CatalogCommonModule,
     VandelayRoutingModule,
     HttpClientModule,
-- 
2.11.0