LP1739277 Angular org selector style callback
authorBill Erickson <berickxx@gmail.com>
Tue, 30 Jul 2019 16:12:12 +0000 (12:12 -0400)
committerKyle Huckins <khuckins@catalyte.io>
Tue, 13 Aug 2019 15:22:05 +0000 (15:22 +0000)
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 d49217c..9c8fb59 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 dee3248..e82fc2d 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>();
@@ -115,7 +120,9 @@ export class OrgSelectComponent implements OnInit {
       private store: StoreService,
       private org: OrgService,
       private perm: PermService
-    ) { }
+    ) {
+        this.orgClassCallback = (orgId: number): string => '';
+    }
 
     ngOnInit() {
 
index 2febd8e..a78b5ed 100644 (file)
         idlClass="cbt" mode="update" recordId="1" orgDefaultAllowed="owner">
       </eg-fm-record-editor>
     </div>
+
+<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 740d4d1..db21fdb 100644 (file)
@@ -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() {