From 6c88462a2f525bf3148c1f5b8a144687d6abe84a Mon Sep 17 00:00:00 2001 From: Bill Erickson Date: Thu, 10 May 2018 18:20:17 -0400 Subject: [PATCH] LP#1775466 Grid selection; width configs Signed-off-by: Bill Erickson --- .../share/grid/grid-column-width.component.html | 20 +++ .../app/share/grid/grid-column-width.component.ts | 34 ++++++ .../src/app/share/grid/grid-column.component.ts | 7 +- .../src/eg2/src/app/share/grid/grid-data-source.ts | 38 ++++-- .../share/grid/grid-toolbar-action.component.ts | 36 ++++++ .../src/app/share/grid/grid-toolbar.component.html | 18 ++- .../src/app/share/grid/grid-toolbar.component.ts | 16 ++- .../src/eg2/src/app/share/grid/grid.component.css | 6 + .../src/eg2/src/app/share/grid/grid.component.html | 8 +- .../src/eg2/src/app/share/grid/grid.component.ts | 136 +++++++++++++++++++-- Open-ILS/src/eg2/src/app/share/grid/grid.module.ts | 6 +- .../src/eg2/src/app/share/grid/grid.service.ts | 22 ++-- .../server/config/billing_type.component.html | 2 + .../admin/server/config/billing_type.component.ts | 6 + 14 files changed, 313 insertions(+), 42 deletions(-) create mode 100644 Open-ILS/src/eg2/src/app/share/grid/grid-column-width.component.html create mode 100644 Open-ILS/src/eg2/src/app/share/grid/grid-column-width.component.ts create mode 100644 Open-ILS/src/eg2/src/app/share/grid/grid-toolbar-action.component.ts diff --git a/Open-ILS/src/eg2/src/app/share/grid/grid-column-width.component.html b/Open-ILS/src/eg2/src/app/share/grid/grid-column-width.component.html new file mode 100644 index 0000000000..ca24c00afd --- /dev/null +++ b/Open-ILS/src/eg2/src/app/share/grid/grid-column-width.component.html @@ -0,0 +1,20 @@ +
+
+
Expand
+ +
+
+
Shrink
+ +
+
diff --git a/Open-ILS/src/eg2/src/app/share/grid/grid-column-width.component.ts b/Open-ILS/src/eg2/src/app/share/grid/grid-column-width.component.ts new file mode 100644 index 0000000000..e16457fcad --- /dev/null +++ b/Open-ILS/src/eg2/src/app/share/grid/grid-column-width.component.ts @@ -0,0 +1,34 @@ +import {Component, Input, OnInit, Host} from '@angular/core'; +import {EgGridService, EgGridColumn, EgGridColumnSet} from './grid.service'; +import {EgGridDataSource} from './grid-data-source'; +import {EgGridComponent} from './grid.component'; + +@Component({ + selector: 'eg-grid-column-width', + templateUrl: './grid-column-width.component.html' +}) + +export class EgGridColumnWidthComponent implements OnInit { + + @Input() columnSet: EgGridColumnSet; + isVisible: boolean; + + constructor( + private gridSvc: EgGridService, + @Host() private grid: EgGridComponent + ) { } + + ngOnInit() { + this.isVisible = false; + } + + expandColumn(col: EgGridColumn) { + col.flex++; + } + + shrinkColumn(col: EgGridColumn) { + if (col.flex > 1) col.flex--; + } + +} + 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 913c6def2a..a89c46ef93 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 @@ -14,9 +14,10 @@ export class EgGridColumnComponent implements OnInit { @Input() path: string; @Input() label: string; @Input() flex: number; + // is this the index field? + @Input() index: boolean; @Input() visible: boolean; @Input() hidden: boolean; - @Input() pkey: boolean; @Input() sortable: boolean; @Input() multiSortable: boolean; @Input() cellTemplate: TemplateRef; @@ -38,9 +39,9 @@ export class EgGridColumnComponent implements OnInit { col.path = this.path; col.label = this.label; col.flex = this.flex; - col.hidden = this.hidden; + col.hidden = this.hidden === true; + col.isIndex = this.index === true; col.cellTemplate = this.cellTemplate; - col.isPkey = this.pkey; col.isSortable = this.sortable; col.isMultiSortable = this.multiSortable; this.grid.columnSet.add(col); 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 f75a5f2c96..235548397f 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 @@ -36,21 +36,33 @@ export class EgGridDataSource { } // called on initial component load and user action (e.g. paging, sorting). - requestPage(pager: Pager) { + requestPage(pager: Pager): Promise { - // 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; + if ( + // already have the current page + this.getPageOfRows(pager).length > 0 + // already have all data + || this.allRowsRetrieved + // have no way to get more data. + || !this.getRows + ) { + return Promise.resolve(); + } - let idx = pager.offset; - this.getRows(pager, this.sort).subscribe( - row => this.data[idx++] = row, - err => console.error(`grid getRows() error ${err}`), - () => this.checkAllRetrieved(pager, idx) - ); + return new Promise((resolve, reject) => { + let idx = pager.offset; + return this.getRows(pager, this.sort).subscribe( + row => this.data[idx++] = row, + err => { + console.error(`grid getRows() error ${err}`); + reject(err); + }, + () => { + this.checkAllRetrieved(pager, idx); + resolve(); + } + ); + }); } // See if the last getRows() call resulted in the final set of data. diff --git a/Open-ILS/src/eg2/src/app/share/grid/grid-toolbar-action.component.ts b/Open-ILS/src/eg2/src/app/share/grid/grid-toolbar-action.component.ts new file mode 100644 index 0000000000..c73337afd6 --- /dev/null +++ b/Open-ILS/src/eg2/src/app/share/grid/grid-toolbar-action.component.ts @@ -0,0 +1,36 @@ +import {Component, Input, OnInit, Host, TemplateRef} from '@angular/core'; +import {EgGridService, EgGridToolbarAction} from './grid.service'; +import {EgGridComponent} from './grid.component'; + +@Component({ + selector: 'eg-grid-toolbar-action', + template: '' +}) + +export class EgGridToolbarActionComponent implements OnInit { + + // Note most input fields should match class fields for EgGridColumn + @Input() label: string; + @Input() action: (rows: any[]) => any; + + // get a reference to our container grid. + constructor( + private gridSvc: EgGridService, + @Host() private grid: EgGridComponent) { + } + + ngOnInit() { + + if (!this.grid) { + console.warn('EgGridToolbarActionComponent needs a [grid]'); + return; + } + + let action = new EgGridToolbarAction(); + action.label = this.label; + action.action = this.action; + + this.grid.toolbarActions.push(action); + } +} + 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 e8aba76c60..e950e253bf 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 @@ -12,7 +12,21 @@
-
+
+ + +
+ +