LP1779158 Cache new queues / display active queues
authorBill Erickson <berickxx@gmail.com>
Fri, 4 Jan 2019 16:07:31 +0000 (11:07 -0500)
committerDan Wells <dbw2@calvin.edu>
Tue, 19 Feb 2019 22:56:49 +0000 (17:56 -0500)
* Only list active (non-complete) queues in the Vandelay queue selector
  combobox.
* Display an alert message when the user attempts to create a queue
  whose name collides with an existing queue for the user.
* Be sure newly created queues are added to the local cache of queues in
  the Vandelay service.
* Remove unused activeQueue list from vandelay.service to avoid having
  to maintain 2 separate queue caches.

Signed-off-by: Bill Erickson <berickxx@gmail.com>
Signed-off-by: Dan Wells <dbw2@calvin.edu>

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/vandelay.service.ts

index a00b35f..5f7352f 100644 (file)
@@ -8,6 +8,10 @@
   </div>
 </div>
 
+<eg-alert-dialog #dupeQueueAlert i18n-dialogBody 
+  dialogBody="A queue with the requested name already exists.">
+</eg-alert-dialog>
+
 <h2 i18n>MARC File Upload</h2>
 <div class="common-form striped-odd form-validated ml-3 mr-3">
   <div class="row">
@@ -74,7 +78,7 @@
       <label for="queue-select" i18n>Select or Create a Queue</label>
     </div>
     <div class="col-lg-3">
-      <eg-combobox [entries]="formatEntries('allQueues')"
+      <eg-combobox [entries]="formatEntries('activeQueues')"
         id="queue-select"
         [startId]="startQueueId"
         [startIdFiresOnChange]="true"
index 185d88b..e9eb3f8 100644 (file)
@@ -13,6 +13,7 @@ import {VandelayService, VandelayImportSelection,
 import {HttpClient, HttpRequest, HttpEventType} from '@angular/common/http';
 import {HttpResponse, HttpErrorResponse} from '@angular/common/http';
 import {ProgressInlineComponent} from '@eg/share/dialog/progress-inline.component';
+import {AlertDialogComponent} from '@eg/share/dialog/alert.component';
 import {Subject} from 'rxjs/Subject';
 import {ServerStoreService} from '@eg/core/server-store.service';
 
@@ -126,6 +127,9 @@ export class ImportComponent implements OnInit, AfterViewInit, OnDestroy {
     @ViewChild('fallThruMergeProfileSelector')
         private fallThruMergeProfileSelector: ComboboxComponent;
 
+    @ViewChild('dupeQueueAlert')
+        private dupeQueueAlert: AlertDialogComponent;
+
     constructor(
         private http: HttpClient,
         private toast: ToastService,
@@ -248,8 +252,9 @@ export class ImportComponent implements OnInit, AfterViewInit, OnDestroy {
                 list = this.vandelay.bibBuckets;
                 break;
 
-            case 'allQueues':
-                list = this.vandelay.allQueues[rtype];
+            case 'activeQueues':
+                list = (this.vandelay.allQueues[rtype] || [])
+                        .filter(q => q.complete() === 'f');
                 break;
 
             case 'matchSets':
@@ -372,9 +377,6 @@ export class ImportComponent implements OnInit, AfterViewInit, OnDestroy {
     resolveQueue(): Promise<number> {
 
         if (this.selectedQueue.freetext) {
-        /*
-        if (this.selectedQueue && this.selectedQueue.freetext) {
-        */
             // Free text queue selector means create a new entry.
             // TODO: first check for name dupes
 
@@ -384,15 +386,23 @@ export class ImportComponent implements OnInit, AfterViewInit, OnDestroy {
                 this.selectedHoldingsProfile,
                 this.selectedMatchSet,
                 this.selectedBucket
-            );
+            ).then(
+                id => id,
+                err => {
+                    const evt = this.evt.parse(err);
+                    if (evt) {
+                        if (evt.textcode.match(/QUEUE_EXISTS/)) {
+                            this.dupeQueueAlert.open();
+                        } else {
+                            alert(evt); // server error
+                        }
+                    } 
 
+                    return Promise.reject('Queue Create Failed');
+                }
+            );
         } else {
             return Promise.resolve(this.selectedQueue.id);
-            /*
-            var queue_id = this.startQueueId;
-            if (this.selectedQueue) queue_id = this.selectedQueue.id;
-            return Promise.resolve(queue_id);
-            */
         }
     }
 
index 45d1de5..3f4a197 100644 (file)
@@ -1,4 +1,4 @@
-import {Injectable, EventEmitter} from '@angular/core';
+import {Injectable} from '@angular/core';
 import {Observable} from 'rxjs/Observable';
 import {tap} from 'rxjs/operators/tap';
 import {map} from 'rxjs/operators/map';
@@ -32,7 +32,6 @@ export class VandelayImportSelection {
 export class VandelayService {
 
     allQueues: {[qtype: string]: IdlObject[]};
-    activeQueues: {[qtype: string]: IdlObject[]}; 
     attrDefs: {[atype: string]: IdlObject[]};
     bibSources: IdlObject[];
     bibBuckets: IdlObject[];
@@ -62,7 +61,6 @@ export class VandelayService {
         private perm: PermService
     ) {
         this.attrDefs = {};
-        this.activeQueues = {};
         this.allQueues = {};
         this.matchSets = {};
         this.importSelection = null;
@@ -99,8 +97,6 @@ export class VandelayService {
     }
 
     // Returns a promise resolved with the list of queues.
-    // Also emits the onQueueListUpdate event so listeners
-    // can detect queue content changes.
     getAllQueues(qtype: string): Promise<IdlObject[]> {
         if (this.allQueues[qtype]) {
             return Promise.resolve(this.allQueues[qtype]);
@@ -118,27 +114,6 @@ export class VandelayService {
         )).toPromise().then(() => this.allQueues[qtype]);
     }
 
-
-    // Returns a promise resolved with the list of queues.
-    // Also emits the onQueueListUpdate event so listeners
-    // can detect queue content changes.
-    getActiveQueues(qtype: string): Promise<IdlObject[]> {
-        if (this.activeQueues[qtype]) {
-            return Promise.resolve(this.activeQueues[qtype]);
-        } else {
-            this.activeQueues[qtype] = [];
-        }
-
-        // could be a big list, invoke in streaming mode
-        return this.net.request(
-            'open-ils.vandelay',
-            `open-ils.vandelay.${qtype}_queue.owner.retrieve`,
-            this.auth.token(), null, {complete: 'f'}
-        ).pipe(tap(
-            queue => this.activeQueues[qtype].push(queue)
-        )).toPromise().then(() => this.activeQueues[qtype]);
-    }
-
     getBibSources(): Promise<IdlObject[]> {
         if (this.bibSources) {
             return Promise.resolve(this.bibSources);
@@ -256,9 +231,11 @@ export class VandelayService {
             ).subscribe(queue => {
                 const e = this.evt.parse(queue);
                 if (e) { 
-                    alert(e);
                     reject(e);
                 } else {
+                    // createQueue is always called after queues have
+                    // been fetched and cached.  
+                    this.allQueues[qType].push(queue);
                     resolve(queue.id());
                 }
             });