LP1739277 Angular org selector style callback user/berick/lp1739277-org-select-class-callback
authorBill Erickson <berickxx@gmail.com>
Tue, 30 Jul 2019 16:12:12 +0000 (12:12 -0400)
committerBill Erickson <berickxx@gmail.com>
Tue, 30 Jul 2019 16:12:14 +0000 (12:12 -0400)
Allow the caller of an <eg-org-select> 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 <berickxx@gmail.com>
Open-ILS/src/eg2/src/app/share/org-select/org-select.component.html
Open-ILS/src/eg2/src/app/share/org-select/org-select.component.ts
Open-ILS/src/eg2/src/app/staff/sandbox/sandbox.component.html
Open-ILS/src/eg2/src/app/staff/sandbox/sandbox.component.ts

index cf7b93d..4d8c418 100644 (file)
@@ -1,7 +1,7 @@
 
 <!-- todo disabled -->
 <ng-template #displayTemplate let-r="result">
-{{r.label}}
+<span class="{{orgClassCallback(r.id)}}">{{r.label}}</span>
 </ng-template>
 
 <ng-container *ngIf="readOnly">
index f455c36..6ae6d02 100644 (file)
@@ -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<IdlObject>();
@@ -105,7 +110,9 @@ export class OrgSelectComponent implements OnInit {
       private store: StoreService,
       private org: OrgService,
       private perm: PermService
-    ) { }
+    ) {
+        this.orgClassCallback = (orgId: number): string => '';
+    }
 
     ngOnInit() {
 
index 4ff0950..3f0cd27 100644 (file)
 <ng-template #confirmMsg>
   <span i18n>Are you sure you want to confirm {numThings, plural, =1 {this thing} other {these {{numThings}} things}}?</span>
 </ng-template>
+
+<div class="m-4">
+  <div class="col-lg-4">
+    <h4>Org Unit Selector With Styled Orgs</h4>
+    <eg-org-select [orgClassCallback]="orgClassCallback">
+    </eg-org-select>
+  </div>
+</div>
index d2d4ead..4e88fec 100644 (file)
@@ -79,6 +79,8 @@ export class SandboxComponent implements OnInit {
     private sbChannel: any;
     sbChannelText: string;
 
+    orgClassCallback: (orgId: number) => string;
+
     constructor(
         private idl: IdlService,
         private org: OrgService,
@@ -92,6 +94,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() {