From 1b97e2f633d912d3c3eec29e86d309b960d3ad47 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 Signed-off-by: Jennifer Bruch Signed-off-by: Jane Sandberg --- .../src/app/share/org-select/org-select.component.html | 2 +- .../eg2/src/app/share/org-select/org-select.component.ts | 9 ++++++++- .../src/eg2/src/app/staff/sandbox/sandbox.component.html | 6 ++++++ .../src/eg2/src/app/staff/sandbox/sandbox.component.ts | 7 ++++++- 4 files changed, 21 insertions(+), 3 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 cf120ecc41..0a662c0eba 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 dab8e37fa2..005c07625c 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 @@ -118,6 +118,11 @@ export class OrgSelectComponent implements OnInit { this.applyPermLimitOrgs(perms); } + // 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(); @@ -145,7 +150,9 @@ export class OrgSelectComponent implements OnInit { private serverStore: ServerStoreService, 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 647cb0cf41..260961cd00 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 @@ -410,6 +410,12 @@ 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 874e76933e..6b70751b90 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 @@ -111,11 +111,11 @@ export class SandboxComponent implements OnInit { // cross-tab communications example private sbChannel: any; sbChannelText: string; - myTimeForm: FormGroup; locId = 1; // Stacks aLocation: IdlObject; // acpl + orgClassCallback: (orgId: number) => string; constructor( private idl: IdlService, @@ -132,6 +132,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.43.2