From: Bill Erickson Date: Fri, 11 Oct 2019 21:55:50 +0000 (-0400) Subject: LP1843837 Vandelay overlay target retains selection X-Git-Url: https://old-git.evergreen-ils.org/?a=commitdiff_plain;h=a2c68726cafc6e4e3be970556690e467c57b23e9;p=working%2FEvergreen.git LP1843837 Vandelay overlay target retains selection 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 --- diff --git a/Open-ILS/src/eg2/src/app/share/grid/grid.component.ts b/Open-ILS/src/eg2/src/app/share/grid/grid.component.ts index 29827bf234..e5f1a14596 100644 --- a/Open-ILS/src/eg2/src/app/share/grid/grid.component.ts +++ b/Open-ILS/src/eg2/src/app/share/grid/grid.component.ts @@ -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(','); } diff --git a/Open-ILS/src/eg2/src/app/share/grid/grid.ts b/Open-ILS/src/eg2/src/app/share/grid/grid.ts index 01b5c09aa8..46ebd13b2f 100644 --- a/Open-ILS/src/eg2/src/app/share/grid/grid.ts +++ b/Open-ILS/src/eg2/src/app/share/grid/grid.ts @@ -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; + onPageLoaded: EventEmitter = new EventEmitter(); 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 { + return this.requestPageBody(pager).then(_ => this.onPageLoaded.emit()); + } + + requestPageBody(pager: Pager): Promise { if ( this.getPageOfRows(pager).length === pager.limit diff --git a/Open-ILS/src/eg2/src/app/staff/cat/vandelay/queue.component.html b/Open-ILS/src/eg2/src/app/staff/cat/vandelay/queue.component.html index 2c1b3c3215..9575f90bb9 100644 --- a/Open-ILS/src/eg2/src/app/staff/cat/vandelay/queue.component.html +++ b/Open-ILS/src/eg2/src/app/staff/cat/vandelay/queue.component.html @@ -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">