improve existing components for use in SR
authorMike Rylander <mrylander@gmail.com>
Thu, 28 Oct 2021 17:21:30 +0000 (13:21 -0400)
committerMike Rylander <mrylander@gmail.com>
Thu, 24 Mar 2022 19:10:00 +0000 (15:10 -0400)
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 <mrylander@gmail.com>
Signed-off-by: Jason Boyer <JBoyer@equinoxOLI.org>
Signed-off-by: rfrasur <rfrasur@library.in.gov>
Open-ILS/src/eg2/src/app/share/interval-input/interval-input.component.ts
Open-ILS/src/eg2/src/app/share/multi-select/multi-select.component.html
Open-ILS/src/eg2/src/app/share/multi-select/multi-select.component.ts
Open-ILS/src/eg2/src/app/share/org-family-select/org-family-select.component.ts

index c3d8a3c..8752b48 100644 (file)
@@ -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<string>();
+
     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) {
index c4aa9e5..1926abf 100644 (file)
@@ -1,6 +1,6 @@
 <div>
   <div class="row">
-    <eg-combobox [idlClass]="idlClass" 
+    <eg-combobox [idlBaseQuery]="idlBaseQuery" [idlClass]="idlClass" 
       [idlIncludeLibraryInLabel]="linkedLibraryLabel" [asyncSupportsEmptyTermClick]="true"
       (onChange)="valueSelected($event)">
     </eg-combobox>
index 0c35beb..3496f55 100644 (file)
@@ -1,5 +1,5 @@
 /**
- * <eg-multi-select idlClass="acpl" linkedLibraryLabel="owning_lib">
+ * <eg-multi-select idlClass="acpl" linkedLibraryLabel="owning_lib" idlKey="id">
  * </eg-multi-select>
  */
 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();
             }
index 9ef00c1..f829265 100644 (file)
@@ -52,6 +52,8 @@ export class OrgFamilySelectComponent implements ControlValueAccessor, OnInit {
 
     @Input() domId: string;
 
+    @Output() onChange = new EventEmitter<any>();
+
     @ViewChildren(OrgSelectComponent)  orgSelects: QueryList<OrgSelectComponent>;
 
     // 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);
         };
     }