From 403772684a8857cc4deb4ba204807edbf8e33bd4 Mon Sep 17 00:00:00 2001 From: Bill Erickson Date: Tue, 30 Jul 2019 12:12:12 -0400 Subject: [PATCH] LP1739277 Angular org selector style callback Allow the caller of an to pass a function which is called against each org unit in the list to determine what CSS class(es) should be applied to the org unit label in the list. Includes sandbox example. Signed-off-by: Bill Erickson --- .../src/eg2/src/app/share/org-select/org-select.component.html | 2 +- .../src/eg2/src/app/share/org-select/org-select.component.ts | 9 ++++++++- Open-ILS/src/eg2/src/app/staff/sandbox/sandbox.component.html | 6 ++++++ Open-ILS/src/eg2/src/app/staff/sandbox/sandbox.component.ts | 7 +++++++ 4 files changed, 22 insertions(+), 2 deletions(-) diff --git a/Open-ILS/src/eg2/src/app/share/org-select/org-select.component.html b/Open-ILS/src/eg2/src/app/share/org-select/org-select.component.html index d49217c6fb..9c8fb591f8 100644 --- a/Open-ILS/src/eg2/src/app/share/org-select/org-select.component.html +++ b/Open-ILS/src/eg2/src/app/share/org-select/org-select.component.html @@ -1,7 +1,7 @@ -{{r.label}} +{{r.label}} diff --git a/Open-ILS/src/eg2/src/app/share/org-select/org-select.component.ts b/Open-ILS/src/eg2/src/app/share/org-select/org-select.component.ts index dee3248939..e82fc2dcad 100644 --- a/Open-ILS/src/eg2/src/app/share/org-select/org-select.component.ts +++ b/Open-ILS/src/eg2/src/app/share/org-select/org-select.component.ts @@ -96,6 +96,11 @@ export class OrgSelectComponent implements OnInit { } } + // Function which should return a string value representing + // a CSS class name to use for styling each org unit label + // in the selector. + @Input() orgClassCallback: (orgId: number) => string; + // Emitted when the org unit value is changed via the selector. // Does not fire on initialOrg @Output() onChange = new EventEmitter(); @@ -115,7 +120,9 @@ export class OrgSelectComponent implements OnInit { private store: StoreService, private org: OrgService, private perm: PermService - ) { } + ) { + this.orgClassCallback = (orgId: number): string => ''; + } ngOnInit() { diff --git a/Open-ILS/src/eg2/src/app/staff/sandbox/sandbox.component.html b/Open-ILS/src/eg2/src/app/staff/sandbox/sandbox.component.html index 2febd8eb3b..a78b5ed180 100644 --- a/Open-ILS/src/eg2/src/app/staff/sandbox/sandbox.component.html +++ b/Open-ILS/src/eg2/src/app/staff/sandbox/sandbox.component.html @@ -361,5 +361,11 @@ idlClass="cbt" mode="update" recordId="1" orgDefaultAllowed="owner"> + +
+
+

Org Unit Selector With Styled Orgs

+ +
diff --git a/Open-ILS/src/eg2/src/app/staff/sandbox/sandbox.component.ts b/Open-ILS/src/eg2/src/app/staff/sandbox/sandbox.component.ts index 740d4d14b8..db21fdbbd7 100644 --- a/Open-ILS/src/eg2/src/app/staff/sandbox/sandbox.component.ts +++ b/Open-ILS/src/eg2/src/app/staff/sandbox/sandbox.component.ts @@ -98,6 +98,8 @@ export class SandboxComponent implements OnInit { private sbChannel: any; sbChannelText: string; + orgClassCallback: (orgId: number) => string; + constructor( private idl: IdlService, private org: OrgService, @@ -111,6 +113,11 @@ export class SandboxComponent implements OnInit { this.sbChannel = (typeof BroadcastChannel === 'undefined') ? {} : new BroadcastChannel('eg.sbChannel'); this.sbChannel.onmessage = (e) => this.sbChannelHandler(e); + + this.orgClassCallback = (orgId: number): string => { + if (orgId === 1) { return 'font-weight-bold'; } + return orgId <= 3 ? 'text-info' : 'text-danger'; + }; } ngOnInit() { -- 2.11.0