LP#1857150: org-family-select: have ngModel changes update the control
authorGalen Charlton <gmc@equinoxinitiative.org>
Thu, 9 Jul 2020 21:15:58 +0000 (17:15 -0400)
committerJason Etheridge <jason@EquinoxInitiative.org>
Thu, 10 Sep 2020 20:36:07 +0000 (16:36 -0400)
Sponsored-by: Evergreen Community Development Initiative
Signed-off-by: Galen Charlton <gmc@equinoxinitiative.org>
Signed-off-by: Ruth Frasur <rfrasur@library.in.gov>
Signed-off-by: Bill Erickson <berickxx@gmail.com>
Signed-off-by: Jason Etheridge <jason@EquinoxInitiative.org>
Open-ILS/src/eg2/src/app/share/org-family-select/org-family-select.component.html
Open-ILS/src/eg2/src/app/share/org-family-select/org-family-select.component.spec.ts
Open-ILS/src/eg2/src/app/share/org-family-select/org-family-select.component.ts

index 5ffaf5a..308199e 100644 (file)
@@ -6,7 +6,7 @@
     <eg-org-select [domId]="domId"
       (onChange)="orgOnChange($event)"
       [limitPerms]="limitPerms"
-      [initialOrgId]="selectedOrgId">
+      [applyOrgId]="selectedOrgId">
     </eg-org-select>
   </div>
 
index f389e7a..c5bd4ab 100644 (file)
@@ -13,7 +13,7 @@ import {OrgService} from '@eg/core/org.service';
 class MockOrgSelectComponent {
     @Input() domId: string;
     @Input() limitPerms: string;
-    @Input() initialOrgId: number;
+    @Input() applyOrgId(id: number) {}
 }
 
 describe('Component: OrgFamilySelect', () => {
index bf10232..9ef00c1 100644 (file)
@@ -1,8 +1,9 @@
-import {Component, EventEmitter, OnInit, Input, Output, ViewChild, forwardRef} from '@angular/core';
+import {Component, EventEmitter, OnInit, Input, Output, ViewChildren, QueryList, forwardRef} from '@angular/core';
 import {ControlValueAccessor, FormGroup, FormControl, NG_VALUE_ACCESSOR} from '@angular/forms';
 import {AuthService} from '@eg/core/auth.service';
 import {IdlObject} from '@eg/core/idl.service';
 import {OrgService} from '@eg/core/org.service';
+import {OrgSelectComponent} from '@eg/share/org-select/org-select.component';
 
 export interface OrgFamily {
   primaryOrgId: number;
@@ -51,6 +52,8 @@ export class OrgFamilySelectComponent implements ControlValueAccessor, OnInit {
 
     @Input() domId: string;
 
+    @ViewChildren(OrgSelectComponent)  orgSelects: QueryList<OrgSelectComponent>;
+
     // this is the most up-to-date value used for ngModel and reactive form
     // subscriptions
     options: OrgFamily;
@@ -128,6 +131,10 @@ export class OrgFamilySelectComponent implements ControlValueAccessor, OnInit {
     writeValue(value: OrgFamily) {
         if (value) {
             this.selectedOrgId = value['primaryOrgId'];
+            if (this.orgSelects) {
+                this.orgSelects.toArray()[0].applyOrgId = this.selectedOrgId;
+                this.options = {primaryOrgId: this.selectedOrgId};
+            }
             this.familySelectors.patchValue({
                 'includeAncestors': value['includeAncestors'] ? value['includeAncestors'] : false,
                 'includeDescendants': value['includeDescendants'] ? value['includeDescendants'] : false,