From fe006765c86348c15eb5d386c906b4e4cc7b858e Mon Sep 17 00:00:00 2001 From: Bill Erickson Date: Mon, 16 Jul 2018 16:26:30 -0400 Subject: [PATCH] LP#1775466 Grid showFields option Signed-off-by: Bill Erickson --- Open-ILS/src/eg2/src/app/share/grid/grid.component.ts | 13 +++++++++++-- Open-ILS/src/eg2/src/app/share/grid/grid.ts | 18 +++++++++++++++--- 2 files changed, 26 insertions(+), 5 deletions(-) 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 9135e7cb8c..e169d03162 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 @@ -58,9 +58,15 @@ export class GridComponent implements OnInit, AfterViewInit, OnDestroy { // a given cell or all cells in a column. @Input() cellClassCallback: (row: any, col: GridColumn) => string; + // comma-separated list of fields to show by default. + // This field takes precedence over hideFields. + // When a value is applied, any field not in this list will + // be hidden. + @Input() showFields: string; + // comma-separated list of fields to hide. - // This is less verbose than having to define an - // just to mark it hidden. + // This does not imply all other fields should be visible, only that + // the selected fields will be hidden. @Input() hideFields: string; // Allow the caller to jump directly to a specific page of @@ -100,6 +106,9 @@ export class GridComponent implements OnInit, AfterViewInit, OnDestroy { this.context.disableMultiSelect = this.disableMultiSelect === true; this.context.rowFlairIsEnabled = this.rowFlairIsEnabled === true; this.context.rowFlairCallback = this.rowFlairCallback; + if (this.showFields) { + this.context.defaultVisibleFields = this.showFields.split(','); + } if (this.hideFields) { this.context.defaultHiddenFields = this.hideFields.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 45d25252ad..eda329a2db 100644 --- a/Open-ILS/src/eg2/src/app/share/grid/grid.ts +++ b/Open-ILS/src/eg2/src/app/share/grid/grid.ts @@ -50,6 +50,7 @@ export class GridColumnSet { stockVisible: string[]; idl: IdlService; defaultHiddenFields: string[]; + defaultVisibleFields: string[]; constructor(idl: IdlService, idlClass?: string) { this.idl = idl; @@ -234,10 +235,19 @@ export class GridColumnSet { applyColumnSettings(conf: GridColumnPersistConf[]) { if (!conf || conf.length === 0) { + // No configuration is available, but we have a list of + // fields to show or hide by default + + if (this.defaultVisibleFields) { + this.columns.forEach(col => { + if (this.defaultVisibleFields.includes(col.name)) { + col.visible = true; + } else { + col.visible = false; + } + }); - // If no configuration is available, but we have a list of - // fields to hide by default, hide them. - if (this.defaultHiddenFields) { + } else if (this.defaultHiddenFields) { this.defaultHiddenFields.forEach(name => { const col = this.getColByName(name); if (col) { @@ -351,6 +361,7 @@ export class GridContext { rowFlairCallback: (row: any) => GridRowFlairEntry; rowClassCallback: (row: any) => string; cellClassCallback: (row: any, col: GridColumn) => string; + defaultVisibleFields: string[]; defaultHiddenFields: string[]; overflowCells: boolean; @@ -381,6 +392,7 @@ export class GridContext { this.columnSet.isSortable = this.isSortable === true; this.columnSet.isMultiSortable = this.isMultiSortable === true; this.columnSet.defaultHiddenFields = this.defaultHiddenFields; + this.columnSet.defaultVisibleFields = this.defaultVisibleFields; this.generateColumns(); } -- 2.11.0