LP#1775466 Grid showFields option
authorBill Erickson <berickxx@gmail.com>
Mon, 16 Jul 2018 20:26:30 +0000 (16:26 -0400)
committerBill Erickson <berickxx@gmail.com>
Wed, 5 Sep 2018 14:05:23 +0000 (10:05 -0400)
Signed-off-by: Bill Erickson <berickxx@gmail.com>
Open-ILS/src/eg2/src/app/share/grid/grid.component.ts
Open-ILS/src/eg2/src/app/share/grid/grid.ts

index 9135e7c..e169d03 100644 (file)
@@ -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 <eg-grid-column/>
-    // 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(',');
         }
index 45d2525..eda329a 100644 (file)
@@ -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();
     }