From: Bill Erickson Date: Tue, 17 Jul 2018 17:05:12 +0000 (-0400) Subject: LP#1775466 Grid column position improvements X-Git-Url: https://old-git.evergreen-ils.org/?a=commitdiff_plain;h=4e0f616bc5264977b46b739a38429d89d5528da0;p=working%2FEvergreen.git LP#1775466 Grid column position improvements Signed-off-by: Bill Erickson --- 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 a8556f424a..dffede14b7 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 @@ -50,6 +50,7 @@ export class GridColumnComponent implements OnInit { col.isSortable = this.sortable; col.isMultiSortable = this.multiSortable; col.datatype = this.datatype; + col.isAuto = false; this.grid.context.columnSet.add(col); } } 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 eda329a2db..9262c28d35 100644 --- a/Open-ILS/src/eg2/src/app/share/grid/grid.ts +++ b/Open-ILS/src/eg2/src/app/share/grid/grid.ts @@ -30,6 +30,10 @@ export class GridColumn { isDragTarget: boolean; isSortable: boolean; isMultiSortable: boolean; + + // True if the column was automatically generated. + isAuto: boolean; + flesher: (obj: any, col: GridColumn, item: any) => any; getCellContext(row: any) { @@ -62,8 +66,11 @@ export class GridColumnSet { add(col: GridColumn) { this.applyColumnDefaults(col); - - if (this.getColByName(col.name)) { return; } // avoid dupes + + if (!this.insertColumn(col)) { + // Column was rejected as a duplicate. + return; + } if (col.isIndex) { this.indexColumn = col; } @@ -73,8 +80,60 @@ export class GridColumnSet { } this.applyColumnSortability(col); + } + + // Returns true if the new column was inserted, false otherwise. + // Declared columns take precedence over auto-generated columns + // when collisions occur. + // Declared columns are inserted in front of auto columns. + insertColumn(col: GridColumn): boolean { + + if (col.isAuto) { + if (this.getColByName(col.name)) { + // New auto-generated column conflicts with existing + // column. Skip it. + return false; + } else { + // No collisions. Add to the end of the list + this.columns.push(col); + return true; + } + } + + // Adding a declared column. + + // Check for dupes. + for (let idx = 0; idx < this.columns.length; idx++) { + const testCol = this.columns[idx]; + if (testCol.name === col.name) { // match found + if (testCol.isAuto) { + // new column takes precedence, remove the existing column. + this.columns.splice(idx, 1); + break; + } else { + // New column does not take precedence. Avoid + // inserting it. + return false; + } + } + } + // Delcared columns are inserted just before the first auto-column + for (let idx = 0; idx < this.columns.length; idx++) { + const testCol = this.columns[idx]; + if (testCol.isAuto) { + if (idx === 0) { + this.columns.unshift(col); + } else { + this.columns.splice(idx - 1, 0, col); + } + return true; + } + } + + // No insertion point found. Toss the new column on the end. this.columns.push(col); + return true; } getColByName(name: string): GridColumn { @@ -712,6 +771,7 @@ export class GridContext { col.idlFieldDef = field; col.datatype = field.datatype; col.isIndex = (field.name === pkeyField); + col.isAuto = true; this.columnSet.add(col); }); }