From: Bill Erickson Date: Tue, 1 May 2018 22:39:59 +0000 (-0400) Subject: LP#1626157 grid experiment X-Git-Url: https://old-git.evergreen-ils.org/?a=commitdiff_plain;h=01355bbe1aca8adbe755c3ea42f3e0ac48f93363;p=working%2FEvergreen.git LP#1626157 grid experiment Signed-off-by: Bill Erickson --- diff --git a/Open-ILS/src/eg2/src/app/share/grid/grid-body.component.html b/Open-ILS/src/eg2/src/app/share/grid/grid-body.component.html index c659033eca..97008bff1e 100644 --- a/Open-ILS/src/eg2/src/app/share/grid/grid-body.component.html +++ b/Open-ILS/src/eg2/src/app/share/grid/grid-body.component.html @@ -1,7 +1,7 @@
+ *ngFor="let row of dataSource.getPageOfRows(pager); let idx = index">
diff --git a/Open-ILS/src/eg2/src/app/share/grid/grid-body.component.ts b/Open-ILS/src/eg2/src/app/share/grid/grid-body.component.ts index 16a873825a..82031aa752 100644 --- a/Open-ILS/src/eg2/src/app/share/grid/grid-body.component.ts +++ b/Open-ILS/src/eg2/src/app/share/grid/grid-body.component.ts @@ -10,12 +10,15 @@ import {Pager} from '@eg/share/util/pager'; export class EgGridBodyComponent implements OnInit { + @Input() pager: Pager; @Input() dataSource: EgGridDataSource; @Input() columnSet: EgGridColumnSet; - @Input() pager: Pager; @Input() selector: {[idx:number] : boolean}; ngOnInit() { + + // fetch the first page of data + this.dataSource.requestPage(this.pager); } } diff --git a/Open-ILS/src/eg2/src/app/share/grid/grid-data-source.ts b/Open-ILS/src/eg2/src/app/share/grid/grid-data-source.ts index a498100cb0..66da827a78 100644 --- a/Open-ILS/src/eg2/src/app/share/grid/grid-data-source.ts +++ b/Open-ILS/src/eg2/src/app/share/grid/grid-data-source.ts @@ -1,29 +1,62 @@ +import {EventEmitter} from '@angular/core'; import {Observable} from 'rxjs/Rx'; import {Pager} from '@eg/share/util/pager'; export class EgGridDataSource { data: any[]; - sortSpec: any[]; - - // Do we know how many items we have in total? - indeterminate: boolean + pager: Pager; + allRowsRetrieved: boolean; + getRows: (pager: Pager) => Observable; constructor() { this.data = []; - this.sortSpec = []; + this.allRowsRetrieved = false; } - applySort() { + setAllRetrieved() { + this.allRowsRetrieved = true; + this.pager.resultCount = this.data.length; } - getPage(pager: Pager): Observable> { + // called from the template -- no data fetching + getPageOfRows(pager: Pager): any[] { + if (this && this.data) { + return this.data.slice( + pager.offset, pager.limit + pager.offset); + } + return []; + } + + // called on initial component load and user action (e.g. paging, sorting). + requestPage(pager: Pager) { + + // see if the page of data is already present in the data + if (this.getPageOfRows(pager).length > 0) return; + + if (this.allRowsRetrieved) return; + + if (!this.getRows) return; + + let idx = pager.offset; + this.getRows(pager).subscribe( + row => this.data[idx++] = row, + err => console.error(`grid getRows() error ${err}`), + () => this.checkAllRetrieved(pager, idx) + ); + } - if (!this.data) return Observable.from([]); + // See if the last getRows() call resulted in the final set of data. + checkAllRetrieved(pager: Pager, idx: number) { + if (this.allRowsRetrieved) return; - if (this.data[pager.offset] !== undefined) { - return Observable.of( - this.data.slice(pager.offset, pager.limit + pager.offset)); + if (idx == 0 || idx < (pager.limit + pager.offset)) { + // last query returned nothing or less than one page. + // confirm we have all of the preceding pages. + if (!this.data.includes(undefined)) { + this.allRowsRetrieved = true; + pager.resultCount = this.data.length; + } } } } diff --git a/Open-ILS/src/eg2/src/app/share/grid/grid.component.html b/Open-ILS/src/eg2/src/app/share/grid/grid.component.html index 813e6bc419..3d0434f316 100644 --- a/Open-ILS/src/eg2/src/app/share/grid/grid.component.html +++ b/Open-ILS/src/eg2/src/app/share/grid/grid.component.html @@ -1,6 +1,7 @@
- + + this.btSource.data.push(bt)); + this.btSource.getRows = (pager: Pager) => { + return this.pcrud.retrieveAll('cbt', { + offset: pager.offset, + limit: pager.limit, + order_by: {cbt: 'name'} + }); + } } showProgress() {