// Some values are scalar, some IdlObjects depending on copy fleshyness.
values: {[field: string]: any} = {};
+ // Map of stat ID to entry ID.
+ statCatValues: {[statId: number]: number} = {};
+
ageProtectRules: IdlObject[] = [];
floatingGroups: IdlObject[] = [];
itemTypeMaps: IdlObject[] = [];
circModifiers: IdlObject[] = [];
+ statCats: IdlObject[] = [];
+ statCatEntryMap: {[id: number]: IdlObject} = {}; // entry id => entry
loanDurationLabelMap: {[level: number]: string} = {};
fineLevelLabelMap: {[level: number]: string} = {};
}).then(_ => {
return this.pcrud.retrieveAll('cfg')
- .pipe(tap(rule => this.floatingGroups.push(rule))).toPromise()
+ .pipe(tap(rule => this.floatingGroups.push(rule))).toPromise();
}).then(_ => {
}).then(_ => {
return this.pcrud.retrieveAll('ccm')
- .pipe(tap(rule => this.circModifiers.push(rule))).toPromise()
+ .pipe(tap(rule => this.circModifiers.push(rule))).toPromise();
}).then(_ => {
}).then(_ => {
return this.pcrud.retrieveAll('citm')
- .pipe(tap(itemType => this.itemTypeMaps.push(itemType))).toPromise()
+ .pipe(tap(itemType => this.itemTypeMaps.push(itemType))).toPromise();
}).then(_ => {
this.itemTypeMaps = this.itemTypeMaps.sort(
(a, b) => a.value() < b.value() ? -1 : 1);
+
+ }).then(_ => {
+
+ return this.net.request('open-ils.circ',
+ 'open-ils.circ.stat_cat.asset.retrieve.all',
+ this.auth.token(), this.auth.user().ws_ou()
+ ).toPromise().then(stats => this.statCats = stats);
+
+ }).then(_ => {
+
+ // Sort most local to the front of the list.
+ this.statCats = this.statCats.sort((s1, s2) => {
+ const d1 = this.org.get(s1.owner()).ou_type().depth();
+ const d2 = this.org.get(s2.owner()).ou_type().depth();
+
+ if (d1 > d2) {
+ return -1;
+ } else if (d1 < d2) {
+ return 1;
+ } else {
+ return s1.name() < s2.name() ? -1 : 1;
+ }
+ });
+
+ this.statCats.forEach(cat => {
+ cat.entries().forEach(
+ entry => this.statCatEntryMap[entry.id()] = entry);
+ });
+ });
+ }
+
+ orgSn(orgId: number): string {
+ return orgId ? this.org.get(orgId).shortname() : '';
+ }
+
+ statCatCounts(catId: number): {[value: string]: number} {
+ catId = Number(catId);
+ const counts = {};
+
+ this.context.copyList().forEach(copy => {
+ const entry = copy.stat_cat_entries()
+ .filter(e => e.stat_cat() === catId)[0];
+
+ let value = '';
+ if (entry) {
+ if (this.statCatEntryMap[entry.id()]) {
+ value = this.statCatEntryMap[entry.id()].value();
+ } else {
+ // Map to a remote stat cat. Ignore.
+ return;
+ }
+ }
+
+ if (counts[value] === undefined) {
+ counts[value] = 0;
+ }
+ counts[value]++;
});
+
+ return counts;
}
itemAttrCounts(field: string): {[value: string]: number} {
if (counts[value] === undefined) {
counts[value] = 0;
- };
+ }
counts[value]++;
});
' : ' + copy.call_number().label();
}
- let value = copy[field]();
+ const value = copy[field]();
if (!value && value !== 0) { return ''; }
- switch(field) {
+ switch (field) {
case 'status':
return this.volcopy.copyStatuses[value].name();
owningLibChanged() {
// TODO
+ // copies.ischanged(true);
console.log('OWNING LIB ', this.values['owning_lib']);
}
+
+
+ // Create or modify a stat cat entry for each copy that does not
+ // already match the new value.
+ statCatChanged(catId: number) {
+ catId = Number(catId);
+
+ const entryId = this.statCatValues[catId];
+ this.context.copyList().forEach(copy => {
+
+ let entry = copy.stat_cat_entries()
+ .filter(e => e.stat_cat() === catId)[0];
+
+ if (entry) {
+ if (entry.id() === entryId) {
+ // Requested mapping already exists.
+ return;
+ }
+ } else {
+
+ // Copy has no entry for this stat cat yet.
+ entry = this.idl.create('asce');
+ entry.stat_cat(catId);
+ copy.stat_cat_entries().push(entry);
+ }
+
+ entry.id(entryId);
+ entry.value(this.statCatEntryMap[entryId].value());
+
+ copy.ischanged(true);
+ });
+ }
}