From 0328879b1ae5ff04b1e86550d97ee0709478bb11 Mon Sep 17 00:00:00 2001 From: Bill Erickson Date: Thu, 2 Jan 2020 16:22:34 -0500 Subject: [PATCH] LP1858138 Grid IDL field definition repairs and more * Deprecate showLinkSelectors, since FormatService now performs that logic under the covers. Includes deprecation console warning. * Fix Grid field IDL class extraction off-by-one error. The code was stamping the source field with the class of the field's link target instead of the class the field actually belonged to. * Allow for IDL field info extraction from the 'name' attribute when no 'path' attribute is defined. * Avoid console errors when clearing combobox values in grid filters. Signed-off-by: Bill Erickson Signed-off-by: Galen Charlton --- .../grid/grid-filter-control.component.ts | 11 ++++- .../eg2/src/app/share/grid/grid.component.ts | 18 +++------ Open-ILS/src/eg2/src/app/share/grid/grid.ts | 40 +++++++++---------- 3 files changed, 34 insertions(+), 35 deletions(-) diff --git a/Open-ILS/src/eg2/src/app/share/grid/grid-filter-control.component.ts b/Open-ILS/src/eg2/src/app/share/grid/grid-filter-control.component.ts index f5931b4059..8ed77f7c7d 100644 --- a/Open-ILS/src/eg2/src/app/share/grid/grid-filter-control.component.ts +++ b/Open-ILS/src/eg2/src/app/share/grid/grid-filter-control.component.ts @@ -62,9 +62,16 @@ export class GridFilterControlComponent implements OnInit { col.isFiltered = true; this.context.reload(); } + applyLinkFilter($event, col: GridColumn) { - col.filterValue = $event.id; - this.applyFilter(col); + if ($event) { + col.filterValue = $event.id; + this.applyFilter(col); + + } else { + // Value was cleared from the combobox + this.clearFilter(col); + } } // TODO: this was copied from date-select and 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 29827bf234..6578dca0c2 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 @@ -89,18 +89,6 @@ export class GridComponent implements OnInit, AfterViewInit, OnDestroy { // Pass in a default page size. May be overridden by settings. @Input() pageSize: number; - // If true and an idlClass is specificed, the grid assumes - // datatype=link fields that link to classes which define a selector - // are fleshed with the linked object. And, instead of displaying - // the raw field value, displays the selector value from the linked - // object. The caller is responsible for fleshing the appropriate - // fields in the GridDataSource getRows handler. - // - // This only applies to auto-generated columns. - // - // For example, idlClass="aou" and field="ou_type", the display - // value will be ou_type().name() since "name" is the selector - // field on the "aout" class. @Input() showLinkSelectors: boolean; @Input() disablePaging: boolean; @@ -155,7 +143,6 @@ export class GridComponent implements OnInit, AfterViewInit, OnDestroy { this.context.isMultiSortable = this.multiSortable === true; this.context.useLocalSort = this.useLocalSort === true; this.context.disableSelect = this.disableSelect === true; - this.context.showLinkSelectors = this.showLinkSelectors === true; this.context.disableMultiSelect = this.disableMultiSelect === true; this.context.rowFlairIsEnabled = this.rowFlairIsEnabled === true; this.context.showDeclaredFieldsOnly = this.showDeclaredFieldsOnly; @@ -182,6 +169,11 @@ export class GridComponent implements OnInit, AfterViewInit, OnDestroy { this.context.cellClassCallback = this.cellClassCallback || function() { return ''; }; + if (this.showLinkSelectors) { + console.debug( + 'showLinkSelectors is deprecated and no longer has any effect'); + } + this.context.init(); } 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 01b5c09aa8..87dfc2bd9a 100644 --- a/Open-ILS/src/eg2/src/app/share/grid/grid.ts +++ b/Open-ILS/src/eg2/src/app/share/grid/grid.ts @@ -176,23 +176,32 @@ export class GridColumnSet { let idlParent; let idlField; - let idlClass = this.idl.classes[this.idlClass]; + let idlClass; + let nextIdlClass = this.idl.classes[this.idlClass]; const pathParts = dotpath.split(/\./); for (let i = 0; i < pathParts.length; i++) { + const part = pathParts[i]; idlParent = idlField; + idlClass = nextIdlClass; idlField = idlClass.field_map[part]; - if (idlField) { - if (idlField['class'] && ( - idlField.datatype === 'link' || - idlField.datatype === 'org_unit')) { - idlClass = this.idl.classes[idlField['class']]; - } - } else { - return null; + if (!idlField) { return null; } // invalid IDL path + + if (i === pathParts.length - 1) { + // No more links to process. + break; + } + + if (idlField['class'] && ( + idlField.datatype === 'link' || + idlField.datatype === 'org_unit')) { + // The link class on the current field refers to the + // class of the link destination, not the current field. + // Mark it for processing during the next iteration. + nextIdlClass = this.idl.classes[idlField['class']]; } } @@ -215,8 +224,8 @@ export class GridColumnSet { applyColumnDefaults(col: GridColumn) { - if (!col.idlFieldDef && col.path) { - const idlInfo = this.idlInfoFromDotpath(col.path); + if (!col.idlFieldDef) { + const idlInfo = this.idlInfoFromDotpath(col.path || col.name); if (idlInfo) { col.idlFieldDef = idlInfo.idlField; col.idlClass = idlInfo.idlClass.name; @@ -479,7 +488,6 @@ export class GridContext { defaultVisibleFields: string[]; defaultHiddenFields: string[]; overflowCells: boolean; - showLinkSelectors: boolean; disablePaging: boolean; showDeclaredFieldsOnly: boolean; @@ -1057,14 +1065,6 @@ export class GridContext { col.isIndex = (field.name === pkeyField); col.isAuto = true; - if (this.showLinkSelectors) { - const selector = this.idl.getLinkSelector( - this.columnSet.idlClass, field.name); - if (selector) { - col.path = field.name + '.' + selector; - } - } - if (this.showDeclaredFieldsOnly) { col.hidden = true; } -- 2.43.2