LP1843837 Vandelay overlay target retains selection user/berick/lp1843837-vand-merge-target-selected
authorBill Erickson <berickxx@gmail.com>
Fri, 11 Oct 2019 21:55:50 +0000 (17:55 -0400)
committerBill Erickson <berickxx@gmail.com>
Mon, 14 Oct 2019 14:23:23 +0000 (10:23 -0400)
After selecting an overlay target for a queued record in the MARC
Import/Export Inspect Queue interface, the queued record row in question
will be marked as selected upon returning to the Inspect Queue page.
This is managed via a new grid @Input() attribute selectRowsOnLoad, which
marks grid rows as selected as each row is rendered.

Signed-off-by: Bill Erickson <berickxx@gmail.com>
Open-ILS/src/eg2/src/app/share/grid/grid.component.ts
Open-ILS/src/eg2/src/app/share/grid/grid.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

index 29827bf..e5f1a14 100644 (file)
@@ -119,6 +119,12 @@ export class GridComponent implements OnInit, AfterViewInit, OnDestroy {
     // would go out of view
     @Input() stickyHeader: boolean;
 
+    // Array of row index values.  Rows with the provided indexes
+    // will be marked as selected in the grid once they are loaded.
+    // Rows are only marked as selected at load time, at which point
+    // the grid's selection logic takes over.
+    @Input() selectRowsOnLoad: any[] = [];
+
     context: GridContext;
 
     // These events are emitted from our grid-body component.
@@ -161,6 +167,8 @@ export class GridComponent implements OnInit, AfterViewInit, OnDestroy {
         this.context.showDeclaredFieldsOnly = this.showDeclaredFieldsOnly;
         this.context.rowFlairCallback = this.rowFlairCallback;
         this.context.disablePaging = this.disablePaging === true;
+        this.context.selectRowsOnLoad = this.selectRowsOnLoad;
+
         if (this.showFields) {
             this.context.defaultVisibleFields = this.showFields.split(',');
         }
index 01b5c09..46ebd13 100644 (file)
@@ -482,6 +482,7 @@ export class GridContext {
     showLinkSelectors: boolean;
     disablePaging: boolean;
     showDeclaredFieldsOnly: boolean;
+    selectRowsOnLoad: any[] = [];
 
     // Allow calling code to know when the select-all-rows-in-page
     // action has occurred.
@@ -526,8 +527,34 @@ export class GridContext {
         this.generateColumns();
     }
 
+    // Watch for pages of data as they arrive so we can analyze.
+    onDataSourcePageLoad() {
+        if (this.selectRowsOnLoad.length) {
+            // Select a row from selectRowsOnLoad exactly once and only
+            // after the row has been fetched.  Note rows will retain
+            // selection through page navigation.  They will only be cleared
+            // if the data source is reset.  Note the rows must be selected
+            // in this manner, because this.getSelectedRows performs
+            // maintenance on the rowSelector, deleting selections for
+            // rows which have been deleted (or not yet retrieved).
+            const selected = [];
+            const pending = [];
+            this.selectRowsOnLoad.forEach(index => {
+                if (this.getRowByIndex(index)) {
+                    selected.push(index);
+                } else {
+                    pending.push(index);
+                }
+            });
+            this.rowSelector.select(selected);
+            this.selectRowsOnLoad = pending;
+        }
+    }
+
     // Load initial settings and data.
     initData() {
+        this.dataSource.onPageLoaded.subscribe(_ => this.onDataSourcePageLoad());
+
         this.applyGridConfig()
         .then(ok => this.dataSource.requestPage(this.pager))
         .then(ok => this.listenToPager());
@@ -1128,6 +1155,7 @@ export class GridDataSource {
     allRowsRetrieved: boolean;
     requestingData: boolean;
     getRows: (pager: Pager, sort: any[]) => Observable<any>;
+    onPageLoaded: EventEmitter<any> = new EventEmitter<any>();
 
     constructor() {
         this.sort = [];
@@ -1152,6 +1180,10 @@ export class GridDataSource {
 
     // called on initial component load and user action (e.g. paging, sorting).
     requestPage(pager: Pager): Promise<any> {
+        return this.requestPageBody(pager).then(_ => this.onPageLoaded.emit());
+    }
+
+    requestPageBody(pager: Pager): Promise<any> {
 
         if (
             this.getPageOfRows(pager).length === pager.limit
index 2c1b3c3..9575f90 100644 (file)
@@ -131,6 +131,7 @@ because there are a lot of them.
   persistKey="cat.vandelay.queue.{{queueType}}"
   (onRowActivate)="openRecord($event)"
   [pageOffset]="queuePageOffset()"
+  [selectRowsOnLoad]="selectRowsOnLoad"
   hideFields="language,pagination,price,rec_identifier,eg_tcn_source,eg_identifier,item_barcode,zsource">
 
   <eg-grid-toolbar-checkbox i18n-label label="Records With Matches"
index 19f08ad..dcf0b57 100644 (file)
@@ -24,6 +24,7 @@ export class QueueComponent implements OnInit, AfterViewInit {
     queueSource: GridDataSource;
     queuedRecClass: string;
     queueSummary: any;
+    selectRowsOnLoad: any[] = [];
 
     filters = {
         matches: false,
@@ -60,6 +61,14 @@ export class QueueComponent implements OnInit, AfterViewInit {
     }
 
     ngOnInit() {
+
+        if (this.vandelay.importSelection) {
+            // If a queued record has a merge/overlay target selected,
+            // make sure the queued record is also marked as selected
+            // for processing.
+            this.selectRowsOnLoad =
+                Object.keys(this.vandelay.importSelection.overlayMap);
+        }
     }
 
     limitToMatches(checked: boolean) {