LP1904036 Patron editor: stat cats
authorBill Erickson <berickxx@gmail.com>
Fri, 19 Mar 2021 22:11:31 +0000 (18:11 -0400)
committerGalen Charlton <gmc@equinoxOLI.org>
Fri, 28 Oct 2022 00:13:27 +0000 (20:13 -0400)
Signed-off-by: Bill Erickson <berickxx@gmail.com>
Signed-off-by: Jane Sandberg <js7389@princeton.edu>
Signed-off-by: Galen Charlton <gmc@equinoxOLI.org>
Open-ILS/src/eg2/src/app/staff/circ/patron/edit.component.ts
Open-ILS/src/eg2/src/app/staff/share/patron/patron.service.ts

index 1e2a9f1..0d26483 100644 (file)
@@ -54,6 +54,11 @@ const FLESH_PATRON_FIELDS = {
   }
 };
 
+interface StatCat {
+    cat: IdlObject;
+    entries: ComboboxEntry[];
+}
+
 @Component({
   templateUrl: 'edit.component.html',
   selector: 'eg-patron-edit',
@@ -82,8 +87,9 @@ export class EditComponent implements OnInit {
     userSettings: {[name: string]: any} = {};
     userSettingTypes: {[name: string]: IdlObject} = {};
     optInSettingTypes: {[name: string]: IdlObject} = {};
-    expireDate: Date;
     secondaryGroups: IdlObject[];
+    statCats: StatCat[] = [];
+    expireDate: Date;
 
     // All locations we have the specified permissions
     permOrgs: {[name: string]: number[]};
@@ -122,10 +128,27 @@ export class EditComponent implements OnInit {
         .then(_ => this.setInetLevels())
         .then(_ => this.setOptInSettings())
         .then(_ => this.setOrgSettings())
+        .then(_ => this.setStatCats())
         .then(_ => this.setSmsCarriers())
         .finally(() => this.loading = false);
     }
 
+    setStatCats(): Promise<any> {
+        this.statCats = [];
+        return this.patronService.getStatCats().then(cats => {
+            cats.forEach(cat => {
+                const entries = cat.entries.map(entry => {
+                    return {id: entry.id(), label: entry.value()};
+                });
+
+                this.statCats.push({
+                    cat: cat,
+                    entries: entries
+                });
+            });
+        });
+    }
+
     setOrgSettings(): Promise<any> {
         return this.serverStore.getItemBatch(ORG_SETTING_TYPES)
         .then(settings => this.orgSettings = settings);
index 459975a..ea1fb63 100644 (file)
@@ -17,6 +17,7 @@ export class PatronService {
     inetLevels: IdlObject[];
     profileGroups: IdlObject[];
     smsCarriers: IdlObject[];
+    statCats: IdlObject[];
 
     constructor(
         private net: NetService,
@@ -135,5 +136,26 @@ export class PatronService {
             .pipe(tap(carrier => this.smsCarriers.push(carrier))
         ).toPromise().then(_ => this.smsCarriers);
     }
+
+    // Local stat cats fleshed with entries; sorted.
+    getStatCats(): Promise<IdlObject[]> {
+        if (this.statCats) {
+            return Promise.resolve(this.statCats);
+        }
+
+        return this.net.request(
+            'open-ils.circ',
+            'open-ils.circ.stat_cat.actor.retrieve.all',
+            this.auth.token(), this.auth.user().ws_ou()
+        ).toPromise().then(cats => {
+            cats = cats.sort((a, b) => a.name() < b.name() ? -1 : 1);
+            cats.forEach(cat => {
+                cat.entries(
+                    cat.entries().sort((a,b) => a.value() < b.value() ? -1 : 1)
+                );
+            });
+            return cats;
+        });
+    }
 }