LP#1779158 Ang vand add-to-bucket and delete-queue
authorBill Erickson <berickxx@gmail.com>
Tue, 10 Jul 2018 15:00:05 +0000 (11:00 -0400)
committerBill Erickson <berickxx@gmail.com>
Thu, 11 Oct 2018 18:56:30 +0000 (14:56 -0400)
Signed-off-by: Bill Erickson <berickxx@gmail.com>
Open-ILS/src/eg2/src/app/staff/cat/vandelay/import.component.html
Open-ILS/src/eg2/src/app/staff/cat/vandelay/import.component.ts
Open-ILS/src/eg2/src/app/staff/cat/vandelay/queue.component.html
Open-ILS/src/eg2/src/app/staff/cat/vandelay/queue.component.ts
Open-ILS/src/eg2/src/app/staff/cat/vandelay/vandelay.module.ts
Open-ILS/src/eg2/src/app/staff/share/buckets/record-bucket-dialog.component.html
Open-ILS/src/eg2/src/app/staff/share/buckets/record-bucket-dialog.component.ts

index 68c0116..8b8d6da 100644 (file)
@@ -1,6 +1,4 @@
 
-<eg-progress-dialog #progressDialog></eg-progress-dialog>
-
 <div class="import-form form-validated">
   <h2 i18n>MARC File Upload</h2>
   <div class="row">
         Importing {{importSelection().recordIds.length}} Record(s)</span>
       <span *ngIf="importSelection().importQueue" i18n>
         Importing Queue {{importSelection().queue.name()}}</span>
+    </div>
+    <div class="col-lg-3">
       <button class="btn btn-outline-info ml-2" (click)="clearSelection()" i18n>
         Clear Selection
       </button>
index 69b32b7..e7ed230 100644 (file)
@@ -331,7 +331,6 @@ export class ImportComponent implements OnInit, AfterViewInit {
             },
 
             (err: HttpErrorResponse) => {
-                //this.progressDialog.close();
                 console.error(err);
                 this.toast.danger(err.error.error);
             }
@@ -386,6 +385,7 @@ export class ImportComponent implements OnInit, AfterViewInit {
 
     importRecordQueue(recIds?: number[]): Promise<any> {
         const rtype = this.recordType === 'bib' ? 'bib' : 'auth';
+
         let method = `open-ils.vandelay.${rtype}_queue.import`;
         const options: ImportOptions = this.compileImportOptions();
 
index 707ccd5..ae48900 100644 (file)
@@ -1,4 +1,15 @@
-<ng-container *ngIf="queueSummary">
+
+<eg-progress-dialog #progressDlg></eg-progress-dialog>
+
+<ng-container *ngIf="queueSummary && queueSummary.queue">
+
+  <eg-confirm-dialog 
+    #confirmDelDlg
+    i18n-dialogTitle i18n-dialogBody
+    dialogTitle="Confirm Delete"
+    dialogBody="Delete Queue {{queueSummary.queue.name()}}?">
+  </eg-confirm-dialog>
+
   <h2 i18n>Queue {{queueSummary.queue.name()}}</h2>
   <div class="row pb-2">
     <div class="col-lg-6">
@@ -43,7 +54,7 @@
                   i18n>Import Selected Records</a>
               </div>
               <div class="flex-1">
-                <a i18n>Import All Records</a>
+                <a [routerLink]="" (click)="importAll()" i18n>Import All Records</a>
               </div>
             </div>
           </li>
           </li>
           <li class="list-group-item">
             <div class="d-flex">
+              <eg-record-bucket-dialog #bucketDialog [queueId]="queueId">
+              </eg-record-bucket-dialog>
               <div class="flex-1">
-                <a i18n>Copy Queue To Bucket</a>
+                <a [routerLink]="" (click)="bucketDialog.open({size:'lg'})" i18n>
+                  Copy Queue To Bucket
+                </a>
               </div>
               <div class="flex-1">
-                <a i18n>Delete Queue</a>
+                <a [routerLink]="" (click)="deleteQueue()" i18n>Delete Queue</a>
               </div>
             </div>
           </li>
index 5758f58..600ef25 100644 (file)
@@ -2,11 +2,15 @@ import {Component, OnInit, AfterViewInit, ViewChild} from '@angular/core';
 import {Observable} from 'rxjs/Observable';
 import 'rxjs/add/observable/of';
 import {map} from 'rxjs/operators/map';
+import {filter} from 'rxjs/operators/filter';
 import {Router, ActivatedRoute, ParamMap} from '@angular/router';              
 import {Pager} from '@eg/share/util/pager';                                    
 import {IdlObject} from '@eg/core/idl.service';
+import {EventService} from '@eg/core/event.service';
 import {NetService} from '@eg/core/net.service';
 import {AuthService} from '@eg/core/auth.service';
+import {ConfirmDialogComponent} from '@eg/share/dialog/confirm.component';
+import {ProgressDialogComponent} from '@eg/share/dialog/progress.component';
 import {GridComponent} from '@eg/share/grid/grid.component';
 import {GridDataSource, GridColumn} from '@eg/share/grid/grid';
 import {VandelayService, VandelayImportSelection} from './vandelay.service';
@@ -36,10 +40,13 @@ export class QueueComponent implements AfterViewInit {
     attrDefs: IdlObject[];
 
     @ViewChild('queueGrid') queueGrid: GridComponent;
+    @ViewChild('confirmDelDlg') confirmDelDlg: ConfirmDialogComponent;
+    @ViewChild('progressDlg') progressDlg: ProgressDialogComponent;
 
     constructor(
         private router: Router,
         private route: ActivatedRoute,
+        private evt: EventService,
         private net: NetService,
         private auth: AuthService,
         private vandelay: VandelayService) {
@@ -100,10 +107,13 @@ export class QueueComponent implements AfterViewInit {
         );
     }
 
+    qtypeShort(): string {
+        return this.queueType === 'bib' ? 'bib' : 'auth';    
+    }
+
     loadQueueSummary(): Promise<any> {
-        const qtype = this.queueType === 'bib' ? 'bib' : 'auth';
         const method = 
-            `open-ils.vandelay.${qtype}_queue.summary.retrieve`;
+            `open-ils.vandelay.${this.qtypeShort()}_queue.summary.retrieve`;
 
         return this.net.request(
             'open-ils.vandelay', method, this.auth.token(), this.queueId)
@@ -122,9 +132,16 @@ export class QueueComponent implements AfterViewInit {
         }
 
         return this.vandelay.getQueuedRecords(
-            this.queueId, this.queueType, options, this.filters.matches)
-        .pipe(map(rec => {
-
+            this.queueId, this.queueType, options, this.filters.matches).pipe(
+        filter(rec => {
+            // avoid sending mishapen data to the grid
+            // this happens (among other reasons) when the grid
+            // no longer exists
+            const e = this.evt.parse(rec);
+            if (e) { console.error(e); return false; }
+            return true;
+        }), 
+        map(rec => {
             const recHash: any = {
                 id: rec.id(),
                 import_error: rec.import_error(),
@@ -153,5 +170,45 @@ export class QueueComponent implements AfterViewInit {
         this.vandelay.importSelection = selection;
         this.router.navigate(['/staff/cat/vandelay/import']);
     }
+
+    importAll() {
+        const selection = new VandelayImportSelection();
+        selection.queue = this.queueSummary.queue;
+        selection.importQueue = true;
+        this.vandelay.importSelection = selection;
+        this.router.navigate(['/staff/cat/vandelay/import']);
+    }
+
+    deleteQueue() {
+        this.confirmDelDlg.open().then(
+            yes => {
+                this.progressDlg.open();
+                return this.net.request(
+                    'open-ils.vandelay',
+                    `open-ils.vandelay.${this.qtypeShort()}_queue.delete`,
+                    this.auth.token(), this.queueId
+                ).toPromise();
+            },
+            no => {
+                this.progressDlg.close();
+                return Promise.reject('delete failed');
+            }
+        ).then(
+            resp => {
+                this.progressDlg.close();
+                const e = this.evt.parse(resp);
+                if (e) {
+                    console.error(e);
+                    alert(e);
+                } else {
+                    // Jump back to the main queue page.
+                    this.router.navigate(['/staff/cat/vandelay/queue']);
+                }
+            },
+            err => {
+                this.progressDlg.close();
+            }
+        );
+    }
 }
 
index bd8fecc..aed9845 100644 (file)
@@ -9,6 +9,7 @@ import {QueueComponent} from './queue.component';
 import {QueueListComponent} from './queue-list.component';
 import {GridModule} from '@eg/share/grid/grid.module';
 import {HttpClientModule} from '@angular/common/http';
+import {RecordBucketDialogComponent} from '@eg/staff/share/buckets/record-bucket-dialog.component';
 
 @NgModule({
   declarations: [
@@ -16,7 +17,8 @@ import {HttpClientModule} from '@angular/common/http';
     ImportComponent,
     ExportComponent,
     QueueComponent,
-    QueueListComponent
+    QueueListComponent,
+    RecordBucketDialogComponent
   ],
   imports: [
     StaffCommonModule,
index f5e4c94..4399111 100644 (file)
@@ -1,6 +1,7 @@
 <ng-template #dialogContent>
   <div class="modal-header bg-info">
-    <h4 class="modal-title" i18n>Add To Record #{{recId}} to Bucket</h4>
+    <h4 class="modal-title" *ngIf="recId" i18n>Add To Record #{{recId}} to Bucket</h4>
+    <h4 class="modal-title" *ngIf="qId" i18n>Add Records from queue #{{qId}} to Bucket</h4>
     <button type="button" class="close" 
       i18n-aria-label aria-label="Close" 
       (click)="dismiss('cross_click')">
index 1f127b4..eb99aec 100644 (file)
@@ -24,11 +24,19 @@ export class RecordBucketDialogComponent
     newBucketDesc: string;
     buckets: any[];
 
+    @Input() bucketType: string;
+
     recId: number;
     @Input() set recordId(id: number) {
         this.recId = id;
     }
 
+    // Add items from a (vandelay) bib queue to a bucket
+    qId: number;
+    @Input() set queueId(id: number) {
+        this.qId = id;
+    }
+
     constructor(
         private modal: NgbModal, // required for passing to parent
         private renderer: Renderer2,
@@ -41,6 +49,12 @@ export class RecordBucketDialogComponent
     }
 
     ngOnInit() {
+        
+        if (this.qId) {
+            this.bucketType = 'vandelay_queue';
+        } else {
+            this.bucketType = 'staff_client';
+        }
 
         this.onOpen$.subscribe(ok => {
             // Reset data on dialog open
@@ -53,7 +67,7 @@ export class RecordBucketDialogComponent
                 'open-ils.actor',
                 'open-ils.actor.container.retrieve_by_class.authoritative',
                 this.auth.token(), this.auth.user().id(),
-                'biblio', 'staff_client'
+                'biblio', this.bucketType
             ).subscribe(buckets => this.buckets = buckets);
         });
     }
@@ -69,7 +83,7 @@ export class RecordBucketDialogComponent
         bucket.owner(this.auth.user().id());
         bucket.name(this.newBucketName);
         bucket.description(this.newBucketDesc);
-        bucket.btype('staff_client');
+        bucket.btype(this.bucketType);
 
         this.net.request(
             'open-ils.actor',
@@ -80,6 +94,11 @@ export class RecordBucketDialogComponent
             if (evt) {
                 this.toast.danger(evt.desc);
             } else {
+                // make it find-able to the queue-add method which
+                // requires the bucket name.
+                bucket.id(bktId);
+                this.buckets.push(bucket);
+
                 this.addToBucket(bktId);
             }
         });
@@ -87,8 +106,16 @@ export class RecordBucketDialogComponent
 
     // Add the record to the selected existing bucket
     addToBucket(id: number) {
+        if (this.recId) {
+            this.addRecordToBucket(id);
+        } else if (this.qId) {
+            this.addQueueToBucket(id);
+        }
+    }
+
+    addRecordToBucket(bucketId: number) {
         const item = this.idl.create('cbrebi');
-        item.bucket(id);
+        item.bucket(bucketId);
         item.target_biblio_record_entry(this.recId);
         this.net.request(
             'open-ils.actor',
@@ -103,6 +130,24 @@ export class RecordBucketDialogComponent
             }
         });
     }
+
+    addQueueToBucket(bucketId: number) {
+        const bucket = this.buckets.filter(b => b.id() === bucketId)[0];
+        if (!bucket) { return; }
+
+        this.net.request(
+            'open-ils.vandelay',
+            'open-ils.vandelay.bib_queue.to_bucket',
+            this.auth.token(), this.qId, bucket.name()
+        ).toPromise().then(resp => {
+            const evt = this.evt.parse(resp);
+            if (evt) {
+                this.toast.danger(evt.toString());
+            } else {
+                this.close();
+            }
+        });
+    }
 }