From: Galen Charlton Date: Wed, 26 Feb 2020 16:42:53 +0000 (-0500) Subject: eg-combobox: teach it to accommodate idlClass changes X-Git-Url: https://old-git.evergreen-ils.org/?a=commitdiff_plain;h=1793c9d237fbc56f817dfa2d84e3f308b4ecc53e;p=working%2FEvergreen.git eg-combobox: teach it to accommodate idlClass changes This can happen in dynamically constructed search forms such as the acquisitions search form. Signed-off-by: Galen Charlton --- diff --git a/Open-ILS/src/eg2/src/app/share/combobox/combobox.component.html b/Open-ILS/src/eg2/src/app/share/combobox/combobox.component.html index 16f2bf6d94..1d178eabfe 100644 --- a/Open-ILS/src/eg2/src/app/share/combobox/combobox.component.html +++ b/Open-ILS/src/eg2/src/app/share/combobox/combobox.component.html @@ -21,7 +21,7 @@ [required]="isRequired" [(ngModel)]="selected" [ngbTypeahead]="filter" - [resultTemplate]=" displayTemplate || idlDisplayTemplateMap[idlClass] || defaultDisplayTemplate" + [resultTemplate]="getResultTemplate()" [inputFormatter]="formatDisplayString" (click)="onClick($event)" (blur)="onBlur()" diff --git a/Open-ILS/src/eg2/src/app/share/combobox/combobox.component.ts b/Open-ILS/src/eg2/src/app/share/combobox/combobox.component.ts index 05a46ddd26..dbe17aa6df 100644 --- a/Open-ILS/src/eg2/src/app/share/combobox/combobox.component.ts +++ b/Open-ILS/src/eg2/src/app/share/combobox/combobox.component.ts @@ -5,6 +5,7 @@ */ import {Component, OnInit, Input, Output, ViewChild, Directive, ViewChildren, QueryList, AfterViewInit, + OnChanges, SimpleChanges, TemplateRef, EventEmitter, ElementRef, forwardRef} from '@angular/core'; import {ControlValueAccessor, NG_VALUE_ACCESSOR} from '@angular/forms'; import {Observable, of, Subject} from 'rxjs'; @@ -51,7 +52,7 @@ export class ComboboxComponent implements ControlValueAccessor, OnInit, AfterVie entrylist: ComboboxEntry[]; @ViewChild('instance', { static: true }) instance: NgbTypeahead; - @ViewChild('defaultDisplayTemplate', { static: true}) t: TemplateRef; + @ViewChild('defaultDisplayTemplate', { static: true}) defaultDisplayTemplate: TemplateRef; @ViewChildren(IdlClassTemplateDirective) idlClassTemplates: QueryList; // Applies a name attribute to the input. @@ -259,10 +260,40 @@ export class ComboboxComponent implements ControlValueAccessor, OnInit, AfterVie }, {}); } + ngOnChanges(changes: SimpleChanges) { + let firstTime = true; + Object.keys(changes).forEach(key => { + if (!changes[key].firstChange) { + firstTime = false; + } + }); + if (!firstTime) { + if ('idlClass' in changes) { + if (!('idlField' in changes)) { + // let ngOnInit reset it to the + // selector of the new IDL class + this.idlField = null; + } + this.asyncIds = {}; + this.entrylist.length = 0; + this.selected = null; + } + this.ngOnInit(); + } + } + onClick($event) { this.click$.next($event.target.value); } + getResultTemplate(): TemplateRef { + if (this.displayTemplate) { return this.displayTemplate }; + if (this.idlClass in this.idlDisplayTemplateMap) { + this.idlDisplayTemplateMap[this.idlClass]; + } + return this.defaultDisplayTemplate; + } + getOrgShortname(ou: any) { if (typeof ou === 'object') { return ou.shortname();