From c7ae6f0ee93b4b71a12813f5f8eeecae1bb7b626 Mon Sep 17 00:00:00 2001 From: Bill Erickson Date: Thu, 30 Nov 2017 20:41:45 -0500 Subject: [PATCH] LP#626157 Ang2 experiments Signed-off-by: Bill Erickson --- .../admin/workstation/workstations.component.html | 1 + .../admin/workstation/workstations.component.ts | 4 +++ .../src/app/staff/share/org-select.component.ts | 32 ++++++++++++---------- 3 files changed, 23 insertions(+), 14 deletions(-) diff --git a/Open-ILS/webby-src/src/app/staff/admin/workstation/workstations.component.html b/Open-ILS/webby-src/src/app/staff/admin/workstation/workstations.component.html index cc6fc30048..c5ec3fdd4b 100644 --- a/Open-ILS/webby-src/src/app/staff/admin/workstation/workstations.component.html +++ b/Open-ILS/webby-src/src/app/staff/admin/workstation/workstations.component.html @@ -16,6 +16,7 @@ [onChange]="orgOnChange" [shouldHide]="shouldHideOrg" [shouldDisable]="shouldDisableOrg" + [initialOrg]="initialOrg" [placeholder]="'Owner'" > diff --git a/Open-ILS/webby-src/src/app/staff/admin/workstation/workstations.component.ts b/Open-ILS/webby-src/src/app/staff/admin/workstation/workstations.component.ts index 7467124075..861d388b91 100644 --- a/Open-ILS/webby-src/src/app/staff/admin/workstation/workstations.component.ts +++ b/Open-ILS/webby-src/src/app/staff/admin/workstation/workstations.component.ts @@ -24,6 +24,8 @@ export class EgWorkstationsComponent implements OnInit { newOwner: EgIdlObject; newName: String; + //initialOrg: EgIdlObject; // XXX testing + // Org selector callbacks shouldDisableOrg = (org: EgIdlObject): boolean => { // TODO: check register perms too @@ -49,6 +51,8 @@ export class EgWorkstationsComponent implements OnInit { ngOnInit() { this.store.getItem('eg.workstation.all') .then(res => this.workstations = res); + + // this.initialOrg = this.org.root().children()[0]; } selected(): Workstation { diff --git a/Open-ILS/webby-src/src/app/staff/share/org-select.component.ts b/Open-ILS/webby-src/src/app/staff/share/org-select.component.ts index d5a361af10..d16d7b02ff 100644 --- a/Open-ILS/webby-src/src/app/staff/share/org-select.component.ts +++ b/Open-ILS/webby-src/src/app/staff/share/org-select.component.ts @@ -26,13 +26,13 @@ export class EgOrgSelectComponent implements OnInit { selected: OrgDisplay; // Read-only properties optionally provided by the calling component. - @Input() placeholder: String; + @Input() placeholder: string; @Input() initialOrg: EgIdlObject; - @Input() stickySetting: String; - @Input() displayField: String = 'shortname'; + @Input() stickySetting: string; + @Input() displayField: string = 'shortname'; // Call-backs - // Note onChange could be handled via an EventEmitter, but + // Note: onChange could be handled via an EventEmitter, but // should* functions require real time two-way communication. @Input() onChange: (org:EgIdlObject) => void; @Input() shouldDisable: (org:EgIdlObject) => boolean; @@ -45,6 +45,18 @@ export class EgOrgSelectComponent implements OnInit { ) {} ngOnInit() { + if (this.initialOrg) { + this.selected = this.formatForDisplay(this.initialOrg); + } + } + + formatForDisplay(org: EgIdlObject): OrgDisplay { + return { + id : org.id(), + label : PAD_SPACE.repeat(org.ou_type().depth()) + + org[this.displayField](), + disabled : false + }; } orgChanged(selEvent: NgbTypeaheadSelectItemEvent) { @@ -62,25 +74,17 @@ export class EgOrgSelectComponent implements OnInit { .distinctUntilChanged() .map(term => { - // TODO: displayField / shortname return this.org.list().filter(org => { // Find orgs matching the search term - return org.shortname() + return org[this.displayField]() .toLowerCase().indexOf(term.toLowerCase()) > -1 }).filter(org => { // Exclude hidden orgs return !this.shouldHide || !this.shouldHide(org) - }).map(org => { - - return { - id : org.id(), - label : PAD_SPACE.repeat(org.ou_type().depth()) + org.shortname(), - disabled : this.shouldDisable && this.shouldDisable(org) - } - }) + }).map(org => { return this.formatForDisplay(org) }) }); } } -- 2.11.0