LP#1942220: (follow-up) add color coding of funds in copy attrs drop-down
authorGalen Charlton <gmc@equinoxOLI.org>
Wed, 13 Jul 2022 02:17:15 +0000 (02:17 +0000)
committerGalen Charlton <gmc@equinoxOLI.org>
Wed, 13 Jul 2022 02:17:15 +0000 (02:17 +0000)
To reflect balance warning and stop.

Signed-off-by: Galen Charlton <gmc@equinoxOLI.org>
Open-ILS/src/eg2/src/app/staff/acq/lineitem/copy-attrs.component.html
Open-ILS/src/eg2/src/app/staff/acq/lineitem/copy-attrs.component.ts

index f0a170d..aeb04cd 100644 (file)
@@ -39,6 +39,7 @@
       [readOnly]="fieldIsDisabled('fund')"
       [asyncSupportsEmptyTermClick]="true"
       #fundSelector [entries]="fundEntries"
+      [displayTemplate]="fundTmpl"
       [selectedId]="copy.fund()" (onChange)="valueChange('fund', $event)"
       [idlQuerySort]="{acqf: 'year DESC, code'}"
       [idlQueryAnd]="{active: 't'}">
   </ng-container>
 </div>
 
+<ng-template #fundTmpl let-r="result" i18n>
+  <span [ngClass]="{'fund-balance-state-stop': checkFundBalance(r.fm.id()) === 'stop',
+                    'fund-balance-state-warning': checkFundBalance(r.fm.id()) === 'warning'}">{{r.label}}</span>
+</ng-template>
index b7359d2..aca110d 100644 (file)
@@ -12,6 +12,7 @@ import {ItemLocationSelectComponent} from '@eg/share/item-location-select/item-l
 
 @Component({
   templateUrl: 'copy-attrs.component.html',
+  styleUrls: ['copy-attrs.component.css'],
   selector: 'eg-lineitem-copy-attrs'
 })
 export class LineitemCopyAttrsComponent implements OnInit {
@@ -23,6 +24,8 @@ export class LineitemCopyAttrsComponent implements OnInit {
     @Output() becameDirty = new EventEmitter<Boolean>();
 
     fundEntries: ComboboxEntry[];
+    _fundBalanceCache: string[] = [];
+    _inflight: Promise<string>[] = [];
     circModEntries: ComboboxEntry[];
 
     private _copy: IdlObject;
@@ -178,6 +181,30 @@ export class LineitemCopyAttrsComponent implements OnInit {
         }
     }
 
+    checkFundBalance(fundId: number): string {
+        if (this._fundBalanceCache[fundId]) {
+            return this._fundBalanceCache[fundId];
+        }
+        if (this._inflight[fundId]) {
+            return 'ok';
+        }
+        this._inflight[fundId] = this.net.request(
+            'open-ils.acq',
+            'open-ils.acq.fund.check_balance_percentages',
+            this.auth.token(), fundId
+        ).toPromise().then(r => {
+            if (r[0]) {
+                this._fundBalanceCache[fundId] = 'stop';
+            } else if (r[1]) {
+                this._fundBalanceCache[fundId] = 'warning';
+            } else {
+                this._fundBalanceCache[fundId] = 'ok';
+            }
+            delete this._inflight[fundId];
+            return this._fundBalanceCache[fundId];
+        });
+    }
+
     fieldIsDisabled(field: string) {
         if (this.batchMode) { return false; }