From: Bill Erickson Date: Fri, 16 Apr 2021 20:37:24 +0000 (-0400) Subject: LP1904036 Grid flat data service/support X-Git-Url: https://old-git.evergreen-ils.org/?a=commitdiff_plain;h=fe8050ff7ee9f717979b1fb1a521d8ccaddfe1b6;p=Evergreen.git LP1904036 Grid flat data service/support Signed-off-by: Bill Erickson Signed-off-by: Jane Sandberg Signed-off-by: Galen Charlton --- diff --git a/Open-ILS/src/eg2/src/app/share/dialog/dialog.component.ts b/Open-ILS/src/eg2/src/app/share/dialog/dialog.component.ts index 866adec0a8..6f73bd5f24 100644 --- a/Open-ILS/src/eg2/src/app/share/dialog/dialog.component.ts +++ b/Open-ILS/src/eg2/src/app/share/dialog/dialog.component.ts @@ -58,7 +58,7 @@ export class DialogComponent implements OnInit { observer: Observer; // The modalRef allows direct control of the modal instance. - private modalRef: NgbModalRef = null; + protected modalRef: NgbModalRef = null; constructor(private modalService: NgbModal) {} diff --git a/Open-ILS/src/eg2/src/app/share/grid/grid-column-config.component.html b/Open-ILS/src/eg2/src/app/share/grid/grid-column-config.component.html index 1bb80fa6cf..be3b2b1b11 100644 --- a/Open-ILS/src/eg2/src/app/share/grid/grid-column-config.component.html +++ b/Open-ILS/src/eg2/src/app/share/grid/grid-column-config.component.html @@ -20,11 +20,11 @@
-
+
-
{{col.label}}
+
{{col.label}}
diff --git a/Open-ILS/src/eg2/src/app/share/grid/grid-column-config.component.ts b/Open-ILS/src/eg2/src/app/share/grid/grid-column-config.component.ts index 10ad606f2b..e4260bb73f 100644 --- a/Open-ILS/src/eg2/src/app/share/grid/grid-column-config.component.ts +++ b/Open-ILS/src/eg2/src/app/share/grid/grid-column-config.component.ts @@ -1,6 +1,8 @@ import {Component, Input, OnInit} from '@angular/core'; +import {Observable} from 'rxjs'; import {DialogComponent} from '@eg/share/dialog/dialog.component'; -import {GridColumnSet} from './grid'; +import {GridColumn, GridColumnSet, GridContext} from './grid'; +import {NgbModal, NgbModalOptions} from '@ng-bootstrap/ng-bootstrap'; @Component({ selector: 'eg-grid-column-config', @@ -10,7 +12,34 @@ import {GridColumnSet} from './grid'; /** */ export class GridColumnConfigComponent extends DialogComponent implements OnInit { - @Input() columnSet: GridColumnSet; + @Input() gridContext: GridContext; + columnSet: GridColumnSet; + changesPending = false; + + open(ops: NgbModalOptions): Observable { + this.changesPending = false; + this.columnSet = this.gridContext.columnSet; + return super.open(ops); + } + + toggleVisibility(col: GridColumn) { + col.visible = !col.visible; + this.changesPending = true; + } + + // Avoid reloading on each column change and instead reload the + // data if needed after all changes are complete. + // Override close() so we can reload data if needed. + // NOTE: ng-bootstrap v 8.0.0 has a 'closed' emitter, but + // we're not there yet. + close(value?: any) { + if (this.modalRef) { this.modalRef.close(); } + this.finalize(); + + if (this.changesPending && this.gridContext.reloadOnColumnChange) { + this.gridContext.reloadWithoutPagerReset(); + } + } } diff --git a/Open-ILS/src/eg2/src/app/share/grid/grid-column.component.ts b/Open-ILS/src/eg2/src/app/share/grid/grid-column.component.ts index f3651f3687..9df93553f7 100644 --- a/Open-ILS/src/eg2/src/app/share/grid/grid-column.component.ts +++ b/Open-ILS/src/eg2/src/app/share/grid/grid-column.component.ts @@ -49,6 +49,10 @@ export class GridColumnComponent implements OnInit { @Input() disableTooltip: boolean; @Input() asyncSupportsEmptyTermClick: boolean; + // Required columns are those that must be present in any auto-generated + // queries regardless of whether they are visible in the display. + @Input() required = false; + // get a reference to our container grid. constructor(@Host() private grid: GridComponent) {} @@ -64,6 +68,7 @@ export class GridColumnComponent implements OnInit { col.path = this.path; col.label = this.label; col.flex = this.flex; + col.required = this.required; col.hidden = this.hidden === true; col.asyncSupportsEmptyTermClick = this.asyncSupportsEmptyTermClick === true; col.isIndex = this.index === true; diff --git a/Open-ILS/src/eg2/src/app/share/grid/grid-flat-data.service.ts b/Open-ILS/src/eg2/src/app/share/grid/grid-flat-data.service.ts new file mode 100644 index 0000000000..dbb7f6e499 --- /dev/null +++ b/Open-ILS/src/eg2/src/app/share/grid/grid-flat-data.service.ts @@ -0,0 +1,64 @@ +import {Injectable, EventEmitter, TemplateRef} from '@angular/core'; +import {Observable, empty, throwError} from 'rxjs'; +import {tap} from 'rxjs/operators'; +import {StoreService} from '@eg/core/store.service'; +import {LocaleService} from '@eg/core/locale.service'; +import {AuthService} from '@eg/core/auth.service'; +import {NetService} from '@eg/core/net.service'; +import {GridContext, GridColumnSort} from './grid'; +import {Pager} from '@eg/share/util/pager'; + +interface FlatQueryFields { + [name: string]: string; +} + + +@Injectable() +export class GridFlatDataService { + + constructor( + private net: NetService, + private auth: AuthService + ) {} + + + getRows(gridContext: GridContext, + query: any, pager: Pager, sort: GridColumnSort[]): Observable { + + if (!gridContext.idlClass) { + return throwError('GridFlatDataService requires an idlClass'); + } + + const fields = this.compileFields(gridContext); + const flatSort = sort.map(s => { + const obj: any = {}; + obj[s.name] = s.dir; + return obj; + }); + + return this.net.request( + 'open-ils.fielder', + 'open-ils.fielder.flattened_search', + this.auth.token(), gridContext.idlClass, + fields, query, { + sort: flatSort, + limit: pager.limit, + offset: pager.offset + } + ); + } + + compileFields(gridContext: GridContext): FlatQueryFields { + const fields: FlatQueryFields = {}; + + gridContext.columnSet.requiredColumns().forEach(col => { + // Verify the column describes a proper IDL field + const path = col.path || col.name; + const info = gridContext.columnSet.idlInfoFromDotpath(path); + if (info) { fields[col.name] = path; } + }); + + return fields; + } +} + diff --git a/Open-ILS/src/eg2/src/app/share/grid/grid-toolbar.component.html b/Open-ILS/src/eg2/src/app/share/grid/grid-toolbar.component.html index db5cd3d991..1c2407b496 100644 --- a/Open-ILS/src/eg2/src/app/share/grid/grid-toolbar.component.html +++ b/Open-ILS/src/eg2/src/app/share/grid/grid-toolbar.component.html @@ -105,7 +105,7 @@ class="material-icons mat-icon-in-button">expand_less - +