From adf950c9ecdf54d4a7f94e9527c1a32b1cf47adc Mon Sep 17 00:00:00 2001 From: Mike Rylander Date: Thu, 28 Oct 2021 13:21:30 -0400 Subject: [PATCH] improve existing components for use in SR Add onChange emitter to eg-org-family-select, and augment the output so we can reconstruct it Add @sr:org_filter_field capability to eg-multi-select and eg-combobox Sponsored-by: C/W MARS Sponsored-by: Missouri Evergreen Consortium Signed-off-by: Mike Rylander Signed-off-by: Jason Boyer Signed-off-by: rfrasur --- .../app/share/interval-input/interval-input.component.ts | 7 +++++++ .../src/app/share/multi-select/multi-select.component.html | 2 +- .../src/app/share/multi-select/multi-select.component.ts | 14 +++++++++++--- .../share/org-family-select/org-family-select.component.ts | 7 ++++++- 4 files changed, 25 insertions(+), 5 deletions(-) diff --git a/Open-ILS/src/eg2/src/app/share/interval-input/interval-input.component.ts b/Open-ILS/src/eg2/src/app/share/interval-input/interval-input.component.ts index c3d8a3cef5..8752b4898b 100644 --- a/Open-ILS/src/eg2/src/app/share/interval-input/interval-input.component.ts +++ b/Open-ILS/src/eg2/src/app/share/interval-input/interval-input.component.ts @@ -19,6 +19,9 @@ import {map, tap, reduce, mergeMap, mapTo, debounceTime, distinctUntilChanged, m }) export class IntervalInputComponent implements ControlValueAccessor, OnInit { + @Input() initialValue: string; + @Output() onChange = new EventEmitter(); + period: string; unit = 'days'; @@ -27,10 +30,14 @@ export class IntervalInputComponent implements ControlValueAccessor, OnInit { propagateTouch = () => {}; ngOnInit() { + if (this.initialValue) { + this.writeValue(this.initialValue); + } } changeListener(): void { this.propagateChange(this.period + ' ' + this.unit); + this.onChange.emit(this.period + ' ' + this.unit); } writeValue(value: string) { diff --git a/Open-ILS/src/eg2/src/app/share/multi-select/multi-select.component.html b/Open-ILS/src/eg2/src/app/share/multi-select/multi-select.component.html index c4aa9e5299..1926abf220 100644 --- a/Open-ILS/src/eg2/src/app/share/multi-select/multi-select.component.html +++ b/Open-ILS/src/eg2/src/app/share/multi-select/multi-select.component.html @@ -1,6 +1,6 @@
- diff --git a/Open-ILS/src/eg2/src/app/share/multi-select/multi-select.component.ts b/Open-ILS/src/eg2/src/app/share/multi-select/multi-select.component.ts index 0c35beb4dc..3496f5551c 100644 --- a/Open-ILS/src/eg2/src/app/share/multi-select/multi-select.component.ts +++ b/Open-ILS/src/eg2/src/app/share/multi-select/multi-select.component.ts @@ -1,5 +1,5 @@ /** - * + * * */ import {Component, OnInit, Input, Output, ViewChild, EventEmitter, ElementRef} from '@angular/core'; @@ -23,6 +23,8 @@ export class MultiSelectComponent implements OnInit { entrylist: ComboboxEntry[]; @Input() idlClass: string; + @Input() idlBaseQuery: any = null; + @Input() idlKey: string; @Input() linkedLibraryLabel: string; @Input() startValue: string; @@ -58,25 +60,31 @@ export class MultiSelectComponent implements OnInit { } ngOnInit() { + if (!this.idlKey) { + this.idlKey = 'id'; + } + if (this.startValue && this.startValue !== '{}') { let valstr = this.startValue; valstr = valstr.replace(/^{/, ''); valstr = valstr.replace(/}$/, ''); const ids = valstr.split(','); + const searchHash = {}; + searchHash[this.idlKey] = ids; const extra_args = {}; if (this.linkedLibraryLabel) { const flesh_fields: Object = {}; flesh_fields[this.idlClass] = [ this.linkedLibraryLabel ]; extra_args['flesh'] = 1; extra_args['flesh_fields'] = flesh_fields; - this.pcrud.search(this.idlClass, { 'id' : ids }, extra_args).pipe(map(data => { + this.pcrud.search(this.idlClass, searchHash, extra_args).pipe(map(data => { this.entrylist.push({ 'id' : data.id(), 'label' : data.name() + ' (' + data[this.linkedLibraryLabel]().shortname() + ')' }); })).toPromise(); } else { - this.pcrud.search(this.idlClass, { 'id' : ids }, extra_args).pipe(map(data => { + this.pcrud.search(this.idlClass, searchHash, extra_args).pipe(map(data => { this.entrylist.push({ 'id' : data.id(), 'label' : data.name() }); })).toPromise(); } diff --git a/Open-ILS/src/eg2/src/app/share/org-family-select/org-family-select.component.ts b/Open-ILS/src/eg2/src/app/share/org-family-select/org-family-select.component.ts index 9ef00c1e5b..f829265805 100644 --- a/Open-ILS/src/eg2/src/app/share/org-family-select/org-family-select.component.ts +++ b/Open-ILS/src/eg2/src/app/share/org-family-select/org-family-select.component.ts @@ -52,6 +52,8 @@ export class OrgFamilySelectComponent implements ControlValueAccessor, OnInit { @Input() domId: string; + @Output() onChange = new EventEmitter(); + @ViewChildren(OrgSelectComponent) orgSelects: QueryList; // this is the most up-to-date value used for ngModel and reactive form @@ -105,9 +107,11 @@ export class OrgFamilySelectComponent implements ControlValueAccessor, OnInit { this.emitArray = () => { // Prepare and emit an array containing the primary org id and - // optionally ancestor and descendant org units. + // optionally ancestor and descendant org units, and flags that select those. this.options.orgIds = [this.options.primaryOrgId]; + this.options.includeAncestors = this.includeAncestors.value; + this.options.includeDescendants = this.includeDescendants.value; if (this.includeAncestors.value) { this.options.orgIds = this.org.ancestors(this.options.primaryOrgId, true); @@ -125,6 +129,7 @@ export class OrgFamilySelectComponent implements ControlValueAccessor, OnInit { this.options.orgIds = Object.keys(hash).map(id => Number(id)); this.propagateChange(this.options); + this.onChange.emit(this.options); }; } -- 2.11.0