LP#1831783: improvements to the Angular org-select widget
authorGalen Charlton <gmc@equinoxinitiative.org>
Tue, 4 Jun 2019 14:01:27 +0000 (10:01 -0400)
committerBill Erickson <berickxx@gmail.com>
Tue, 30 Jul 2019 19:59:08 +0000 (15:59 -0400)
- add reset() method
- add method for retrieve current selected OU. This can be invoked
  from local template references in parent templates like this:

    <button ... (click)="doAction(ousel.selectedOrg())" ...
    ...
    <eg-org-select (onChange)="doAction($event)" #ousel></eg-org-select>

Sponsored-by: MassLNC
Sponsored-by: Georgia Public Library Service
Sponsored-by: Indiana State Library
Sponsored-by: CW MARS
Sponsored-by: King County Library System
Signed-off-by: Galen Charlton <gmc@equinoxinitiative.org>
Signed-off-by: Bill Erickson <berickxx@gmail.com>
Open-ILS/src/eg2/src/app/share/org-select/org-select.component.ts

index f455c36..dee3248 100644 (file)
@@ -100,6 +100,16 @@ export class OrgSelectComponent implements OnInit {
     // Does not fire on initialOrg
     @Output() onChange = new EventEmitter<IdlObject>();
 
+    // convenience method to get an IdlObject representing the current
+    // selected org unit. One way of invoking this is via a template
+    // reference variable.
+    selectedOrg(): IdlObject {
+        if (this.selected == null) {
+            return null;
+        }
+        return this.org.get(this.selected.id);
+    }
+
     constructor(
       private auth: AuthService,
       private store: StoreService,
@@ -174,6 +184,11 @@ export class OrgSelectComponent implements OnInit {
     // Remove the tree-padding spaces when matching.
     formatter = (result: OrgDisplay) => result.label.trim();
 
+    // reset the state of the component
+    reset() {
+        this.selected = null;
+    }
+
     filter = (text$: Observable<string>): Observable<OrgDisplay[]> => {
         return text$.pipe(
             debounceTime(200),