<div class="row">
</div>
-<!-- List of Edit Templates -->
-
-<div class="row d-flex">
- <div class="flex-1 p-1"><h3 class="font-weight-bold" i18n>Identification</h3></div>
- <div class="flex-1 p-1"><h3 class="font-weight-bold" i18n>Location</h3></div>
- <div class="flex-1 p-1"><h3 class="font-weight-bold" i18n>Circulation</h3></div>
- <div class="flex-1 p-1"><h3 class="font-weight-bold" i18n>Miscellaneous</h3></div>
- <div class="flex-1 p-1"><h3 class="font-weight-bold" i18n>Statistics</h3></div>
-</div>
-
<div class="row d-flex">
<!-- COLUMN 1 -->
<div class="flex-1 p-1">
+ <div class="p-1"><h4 class="font-weight-bold" i18n>Identification</h4></div>
<div class="mb-1">
- <eg-batch-item-attr label="Status" i18n-label
- [readOnly]="true"
+ <eg-batch-item-attr label="Status" i18n-label [readOnly]="true"
[labelCounts]="itemAttrCounts('status')">
</eg-batch-item-attr>
</div>
<div class="mb-1">
- <eg-batch-item-attr label="Barcode" i18n-label
- [readOnly]="true"
+ <eg-batch-item-attr label="Barcode" i18n-label
+ [readOnly]="true" [emptyIsUnset]="true"
[labelCounts]="itemAttrCounts('barcode')">
</eg-batch-item-attr>
</div>
<div class="mb-1">
- <eg-batch-item-attr label="Creation Date" i18n-label
- [readOnly]="true"
+ <eg-batch-item-attr label="Creation Date" i18n-label [readOnly]="true"
[labelCounts]="itemAttrCounts('create_date')">
</eg-batch-item-attr>
</div>
<div class="mb-1">
- <eg-batch-item-attr label="Active Date" i18n-label
- [readOnly]="true"
+ <eg-batch-item-attr label="Active Date" i18n-label [readOnly]="true"
[labelCounts]="itemAttrCounts('active_date')">
</eg-batch-item-attr>
</div>
<div class="mb-1">
- <eg-batch-item-attr label="Creator" i18n-label
- [readOnly]="true"
+ <eg-batch-item-attr label="Creator" i18n-label [readOnly]="true"
[labelCounts]="itemAttrCounts('creator')">
</eg-batch-item-attr>
</div>
<div class="mb-1">
- <eg-batch-item-attr label="Last Edit Date" i18n-label
- [readOnly]="true"
+ <eg-batch-item-attr label="Last Edit Date" i18n-label [readOnly]="true"
[labelCounts]="itemAttrCounts('edit_date')">
</eg-batch-item-attr>
</div>
<div class="mb-1">
- <eg-batch-item-attr label="Last Editor" i18n-label
- [readOnly]="true"
+ <eg-batch-item-attr label="Last Editor" i18n-label [readOnly]="true"
[labelCounts]="itemAttrCounts('editor')">
</eg-batch-item-attr>
</div>
<!-- COLUMN 2 -->
<div class="flex-1 p-1">
+ <div class="p-1"><h4 class="font-weight-bold" i18n>Location</h4></div>
<div>
- <ng-template #locationEditTemplate>
- <eg-item-location-select (valueChange)="batchLocation = $event"
+ <ng-template #locationTemplate>
+ <eg-item-location-select (valueChange)="values['location'] = $event"
[required]="true" permFilter="UPDATE_COPY">
</eg-item-location-select>
</ng-template>
- <eg-batch-item-attr label="Location / Collection" i18n-label
+ <eg-batch-item-attr label="Location / Collection" i18n-label
+ [editTemplate]="locationTemplate"
[labelCounts]="itemAttrCounts('location')"
- [editTemplate]="locationEditTemplate"
- (changesSaved)="locationChanged()">
+ (changesSaved)="applyCopyValue('location')">
+ </eg-batch-item-attr>
+ </div>
+
+ <div>
+ <ng-template #circLibTemplate>
+ <eg-org-select
+ (onChange)="values['circ_lib'] = $event ? $event.id() : null"
+ [limitPerms]="['UPDATE_COPY']">
+ </eg-org-select>
+ </ng-template>
+
+ <eg-batch-item-attr label="Circulating Library" i18n-label
+ [editTemplate]="circLibTemplate"
+ [labelCounts]="itemAttrCounts('circ_lib')"
+ (changesSaved)="circLibChanged()">
+ </eg-batch-item-attr>
+ </div>
+
+ <div>
+ <ng-template #owningLibTemplate>
+ <eg-org-select
+ (onChange)="values['owning_lib'] = $event ? $event.id() : null"
+ [limitPerms]="['UPDATE_COPY']">
+ </eg-org-select>
+ </ng-template>
+
+ <eg-batch-item-attr label="Owning Library" i18n-label
+ [editTemplate]="owningLibTemplate"
+ [labelCounts]="itemAttrCounts('owning_lib')"
+ (changesSaved)="owningLibChanged()">
</eg-batch-item-attr>
</div>
- </div>
+ <div>
+ <ng-template #copyNumberTemplate>
+ <input type="number" class="form-control"
+ [(ngModel)]="values['copy_number']"/>
+ </ng-template>
+
+ <eg-batch-item-attr label="Copy Number" i18n-label
+ [emptyIsUnset]="true"
+ [editTemplate]="copyNumberTemplate"
+ [labelCounts]="itemAttrCounts('copy_number')"
+ (changesSaved)="applyCopyValue('copy_number')">
+ </eg-batch-item-attr>
+ </div>
+
+ </div>
<!-- COLUMN 3 -->
+
<div class="flex-1 p-1">
- </div>
+ <div class="p-1"><h4 class="font-weight-bold" i18n>Circulation</h4></div>
+
+ <div>
+ <ng-template #circulateTemplate>
+ <select class="form-control" [(ngModel)]="values['circulate']">
+ <option value="yes" i18n>Yes</option>
+ <option value="no" i18n>No</option>
+ </select>
+ </ng-template>
+ <eg-batch-item-attr label="Circulate" i18n-label
+ displayAs="bool"
+ [editTemplate]="circulateTemplate"
+ [labelCounts]="itemAttrCounts('circulate')"
+ (changesSaved)="applyCopyValue('circulate',
+ values['circulate'] === 'yes' ? 't': 'f')">
+ </eg-batch-item-attr>
+ </div>
+
+ <div>
+ <ng-template #holdableTemplate>
+ <select class="form-control" [(ngModel)]="values['holdable']">
+ <option value="yes" i18n>Yes</option>
+ <option value="no" i18n>No</option>
+ </select>
+ </ng-template>
+ <eg-batch-item-attr label="Holdable" i18n-label
+ displayAs="bool"
+ [editTemplate]="holdableTemplate"
+ [labelCounts]="itemAttrCounts('holdable')"
+ (changesSaved)="applyCopyValue('holdable',
+ values['holdable'] === 'yes' ? 't': 'f')">
+ </eg-batch-item-attr>
+ </div>
+
+ <div>
+ <ng-template #ageProtectTemplate>
+ <select class="form-control" [(ngModel)]="values['age_protect']">
+ <option [value]="null" i18n><Unset></option>
+ <option *ngFor="let rule of ageProtectRules"
+ value="{{rule.id()}}">{{rule.name()}}</option>
+ </select>
+ </ng-template>
+ <eg-batch-item-attr label="Aged-Based Hold Protection" i18n-label
+ [emptyIsUnset]="true"
+ [editTemplate]="ageProtectTemplate"
+ [labelCounts]="itemAttrCounts('age_protect')"
+ (changesSaved)="applyCopyValue('age_protect')">
+ </eg-batch-item-attr>
+ </div>
+
+ <div>
+ <ng-template #floatingTemplate>
+ <select class="form-control" [(ngModel)]="values['floating']">
+ <option [value]="null" i18n><Unset></option>
+ <option *ngFor="let grp of floatingGroups"
+ value="{{grp.id()}}">{{grp.name()}}</option>
+ </select>
+ </ng-template>
+ <eg-batch-item-attr label="Floating" i18n-label
+ [emptyIsUnset]="true"
+ [editTemplate]="floatingTemplate"
+ [labelCounts]="itemAttrCounts('floating')"
+ (changesSaved)="applyCopyValue('floating')">
+ </eg-batch-item-attr>
+ </div>
+
+ <div>
+ <eg-string #loanDurationShort i18n-text text="Short"></eg-string>
+ <eg-string #loanDurationNormal i18n-text text="Normal"></eg-string>
+ <eg-string #loanDurationLong i18n-text text="Long"></eg-string>
+
+ <ng-template #loanDurationTemplate>
+ <select class="form-control" [(ngModel)]="values['loan_duration']">
+ <option value="1" i18n>{{loanDurationShort.text}}</option>
+ <option value="2" i18n>{{loanDurationNormal.text}}</option>
+ <option value="3" i18n>{{loanDurationLong.text}}</option>
+ </select>
+ </ng-template>
+ <eg-batch-item-attr label="Loan Duration" i18n-label
+ [emptyIsUnset]="true"
+ [editTemplate]="loanDurationTemplate"
+ [labelCounts]="itemAttrCounts('loan_duration')"
+ (changesSaved)="applyCopyValue('loan_duration')">
+ </eg-batch-item-attr>
+ </div>
+
+ <div>
+ <eg-string #fineLevelLow i18n-text text="Low"></eg-string>
+ <eg-string #fineLevelNormal i18n-text text="Normal"></eg-string>
+ <eg-string #fineLevelHigh i18n-text text="High"></eg-string>
+
+ <ng-template #fineLevelTemplate>
+ <select class="form-control" [(ngModel)]="values['fine_level']">
+ <option value="1" i18n>{{fineLevelLow.text}}</option>
+ <option value="2" i18n>{{fineLevelNormal.text}}</option>
+ <option value="3" i18n>{{fineLevelHigh.text}}</option>
+ </select>
+ </ng-template>
+ <eg-batch-item-attr label="Fine Level" i18n-label
+ [emptyIsUnset]="true"
+ [editTemplate]="fineLevelTemplate"
+ [labelCounts]="itemAttrCounts('fine_level')"
+ (changesSaved)="applyCopyValue('fine_level')">
+ </eg-batch-item-attr>
+ </div>
+
+ <div>
+ <ng-template #ageProtectTemplate>
+ <select class="form-control" [(ngModel)]="values['age_protect']">
+ <option [value]="null" i18n><Unset></option>
+ <option *ngFor="let rule of ageProtectRules"
+ value="{{rule.id()}}">{{rule.name()}}</option>
+ </select>
+ </ng-template>
+ <eg-batch-item-attr label="Aged-Based Hold Protection" i18n-label
+ [emptyIsUnset]="true"
+ [editTemplate]="ageProtectTemplate"
+ [labelCounts]="itemAttrCounts('age_protect')"
+ (changesSaved)="applyCopyValue('age_protect')">
+ </eg-batch-item-attr>
+ </div>
+
+ <div>
+ <ng-template #circAsTypeTemplate>
+ <select class="form-control" [(ngModel)]="values['circ_as_type']">
+ <option [value]="null" i18n><Unset></option>
+ <option *ngFor="let map of itemTypeMaps"
+ value="{{map.code()}}">{{map.value()}}</option>
+ </select>
+ </ng-template>
+ <eg-batch-item-attr label="Circulate as Type" i18n-label
+ [emptyIsUnset]="true"
+ [editTemplate]="circAsTypeTemplate"
+ [labelCounts]="itemAttrCounts('circ_as_type')"
+ (changesSaved)="applyCopyValue('circ_as_type')">
+ </eg-batch-item-attr>
+ </div>
+
+ <div>
+ <ng-template #circModifierTemplate>
+ <select class="form-control" [(ngModel)]="values['circ_modifier']">
+ <option [value]="null" i18n><Unset></option>
+ <option *ngFor="let mod of circModifiers"
+ value="{{mod.code()}}">{{mod.name()}}</option>
+ </select>
+ </ng-template>
+ <eg-batch-item-attr label="Circulion Modifier" i18n-label
+ [emptyIsUnset]="true"
+ [editTemplate]="circModifierTemplate"
+ [labelCounts]="itemAttrCounts('circ_modifier')"
+ (changesSaved)="applyCopyValue('circ_modifier')">
+ </eg-batch-item-attr>
+ </div>
+
+ </div>
<!-- COLUMN 4 -->
+
<div class="flex-1 p-1">
- </div>
+
+ <div class="p-1"><h4 class="font-weight-bold" i18n>Miscellaneous</h4></div>
+
+ <div>
+ <ng-template #alertMessageTemplate>
+ <textarea rows="3" class="form-control"
+ [(ngModel)]="values['alert_message']">
+ </textarea>
+ </ng-template>
+ <eg-batch-item-attr label="Alert Message" i18n-label
+ [emptyIsUnset]="true"
+ [editTemplate]="alertMessageTemplate"
+ [labelCounts]="itemAttrCounts('alert_message')"
+ (changesSaved)="applyCopyValue('alert_message')">
+ </eg-batch-item-attr>
+ </div>
+
+ <div>
+ <ng-template #depositTemplate>
+ <select class="form-control" [(ngModel)]="values['deposit']">
+ <option value="yes" i18n>Yes</option>
+ <option value="no" i18n>No</option>
+ </select>
+ </ng-template>
+ <eg-batch-item-attr label="Deposit" i18n-label
+ displayAs="bool"
+ [editTemplate]="depositTemplate"
+ [labelCounts]="itemAttrCounts('deposit')"
+ (changesSaved)="applyCopyValue('deposit',
+ values['deposit'] === 'yes' ? 't': 'f')">
+ </eg-batch-item-attr>
+ </div>
+
+ <div>
+ <ng-template #depositAmountTemplate>
+ <input type="number" class="form-control"
+ [(ngModel)]="values['deposit_amount']"/>
+ </ng-template>
+ <eg-batch-item-attr label="Deposit Amount" i18n-label
+ displayAs="currency"
+ [editTemplate]="depositAmountTemplate"
+ [labelCounts]="itemAttrCounts('deposit_amount')"
+ (changesSaved)="applyCopyValue('deposit_amount')">
+ </eg-batch-item-attr>
+ </div>
+
+ <div>
+ <ng-template #priceTemplate>
+ <input type="number" class="form-control"
+ [(ngModel)]="values['price']"/>
+ </ng-template>
+ <eg-batch-item-attr label="Price" i18n-label
+ displayAs="currency"
+ [editTemplate]="priceTemplate"
+ [labelCounts]="itemAttrCounts('price')"
+ (changesSaved)="applyCopyValue('price')">
+ </eg-batch-item-attr>
+ </div>
+
+ <div>
+ <ng-template #opacVisibleTemplate>
+ <select class="form-control" [(ngModel)]="values['opac_visible']">
+ <option value="yes" i18n>Yes</option>
+ <option value="no" i18n>No</option>
+ </select>
+ </ng-template>
+ <eg-batch-item-attr label="OPAC Visible" i18n-label
+ displayAs="bool"
+ [editTemplate]="opacVisibleTemplate"
+ [labelCounts]="itemAttrCounts('opac_visible')"
+ (changesSaved)="applyCopyValue('opac_visible',
+ values['opac_visible'] === 'yes' ? 't': 'f')">
+ </eg-batch-item-attr>
+ </div>
+
+ <div>
+ <ng-template #refTemplate>
+ <select class="form-control" [(ngModel)]="values['ref']">
+ <option value="yes" i18n>Yes</option>
+ <option value="no" i18n>No</option>
+ </select>
+ </ng-template>
+ <eg-batch-item-attr label="Reference" i18n-label
+ displayAs="bool"
+ [editTemplate]="refTemplate"
+ [labelCounts]="itemAttrCounts('ref')"
+ (changesSaved)="applyCopyValue(
+ 'ref', values['ref'] === 'yes' ? 't': 'f')">
+ </eg-batch-item-attr>
+ </div>
+
+ <div>
+ <ng-template #costTemplate>
+ <input type="number" class="form-control"
+ [(ngModel)]="values['cost']"/>
+ </ng-template>
+ <eg-batch-item-attr label="Acquisition Cost" i18n-label
+ [emptyIsUnset]="true"
+ displayAs="currency"
+ [editTemplate]="costTemplate"
+ [labelCounts]="itemAttrCounts('cost')"
+ (changesSaved)="applyCopyValue('cost')">
+ </eg-batch-item-attr>
+ </div>
+
+ <div>
+ <eg-string #mintConditionYes i18n-text text="Good"></eg-string>
+ <eg-string #mintConditionNo i18n-text text="Damaged"></eg-string>
+
+ <ng-template #mintConditionTemplate>
+ <select class="form-control" [(ngModel)]="values['mint_condition']">
+ <option value="t" i18n>{{mintConditionYes.text}}</option>
+ <option value="f" i18n>{{mintConditionNo.text}}</option>
+ </select>
+ </ng-template>
+ <eg-batch-item-attr label="Quality" i18n-label
+ [emptyIsUnset]="true"
+ [editTemplate]="mintConditionTemplate"
+ [labelCounts]="itemAttrCounts('mint_condition')"
+ (changesSaved)="applyCopyValue('mint_condition')">
+ </eg-batch-item-attr>
+ </div>
+
+ </div>
<!-- COLUMN 5 -->
<div class="flex-1 p-1">
- </div>
+ <div class="p-1"><h4 class="font-weight-bold" i18n>Statistics</h4></div>
+ </div>
</div>
import {VolCopyContext} from './volcopy';
import {VolCopyService} from './volcopy.service';
import {FormatService} from '@eg/core/format.service';
+import {StringComponent} from '@eg/share/string/string.component';
@Component({
selector: 'eg-copy-attrs',
templateUrl: 'copy-attrs.component.html'
})
-export class CopyAttrsComponent implements OnInit {
+export class CopyAttrsComponent implements OnInit, AfterViewInit {
@Input() context: VolCopyContext;
- batchLocation: any;
+ // Batch values applied from the form.
+ // Some values are scalar, some IdlObjects depending on copy fleshyness.
+ values: {[field: string]: any} = {};
+
+ ageProtectRules: IdlObject[] = [];
+ floatingGroups: IdlObject[] = [];
+ itemTypeMaps: IdlObject[] = [];
+ circModifiers: IdlObject[] = [];
+
+ loanDurationLabelMap: {[level: number]: string} = {};
+ fineLevelLabelMap: {[level: number]: string} = {};
+
+ @ViewChild('loanDurationShort', {static: false})
+ loanDurationShort: StringComponent;
+ @ViewChild('loanDurationNormal', {static: false})
+ loanDurationNormal: StringComponent;
+ @ViewChild('loanDurationLong', {static: false})
+ loanDurationLong: StringComponent;
+
+ @ViewChild('fineLevelLow', {static: false})
+ fineLevelLow: StringComponent;
+ @ViewChild('fineLevelNormal', {static: false})
+ fineLevelNormal: StringComponent;
+ @ViewChild('fineLevelHigh', {static: false})
+ fineLevelHigh: StringComponent;
+
+ @ViewChild('mintConditionYes', {static: false})
+ mintConditionYes: StringComponent;
+ @ViewChild('mintConditionNo', {static: false})
+ mintConditionNo: StringComponent;
constructor(
private router: Router,
private format: FormatService
) { }
-
ngOnInit() {
+ this.load();
+ }
+
+ ngAfterViewInit() {
+
+ this.loanDurationLabelMap[1] = this.loanDurationShort.text;
+ this.loanDurationLabelMap[2] = this.loanDurationNormal.text;
+ this.loanDurationLabelMap[3] = this.loanDurationLong.text;
+
+ this.fineLevelLabelMap[1] = this.fineLevelLow.text;
+ this.fineLevelLabelMap[2] = this.fineLevelNormal.text;
+ this.fineLevelLabelMap[3] = this.fineLevelHigh.text;
+ }
+
+ load() {
+
+ this.pcrud.retrieveAll('crahp')
+ .pipe(tap(rule => this.ageProtectRules.push(rule))).toPromise()
+ .then(_ => {
+
+ this.ageProtectRules = this.ageProtectRules.sort(
+ (a, b) => a.name() < b.name() ? -1 : 1);
+
+ }).then(_ => {
+
+ return this.pcrud.retrieveAll('cfg')
+ .pipe(tap(rule => this.floatingGroups.push(rule))).toPromise()
+
+ }).then(_ => {
+
+ this.floatingGroups = this.floatingGroups.sort(
+ (a, b) => a.name() < b.name() ? -1 : 1);
+
+ }).then(_ => {
+
+ return this.pcrud.retrieveAll('ccm')
+ .pipe(tap(rule => this.circModifiers.push(rule))).toPromise()
+
+ }).then(_ => {
+
+ this.circModifiers = this.circModifiers.sort(
+ (a, b) => a.name() < b.name() ? -1 : 1);
+
+ }).then(_ => {
+
+ return this.pcrud.retrieveAll('citm')
+ .pipe(tap(itemType => this.itemTypeMaps.push(itemType))).toPromise()
+
+ }).then(_ => {
+
+ this.itemTypeMaps = this.itemTypeMaps.sort(
+ (a, b) => a.value() < b.value() ? -1 : 1);
+ });
}
itemAttrCounts(field: string): {[value: string]: number} {
const counts = {};
this.context.copyList().forEach(copy => {
- let value = copy[field]();
- if (value === undefined || value === null) { value = ''; }
-
- if (value !== '') {
-
- if (field === 'status') {
- if (value in this.volcopy.copyStatuses) {
- value = this.volcopy.copyStatuses[value].name();
- }
-
- } else if (field === 'location') {
- value = value.name();
-
- } else if (field.match(/date/)) {
- value = this.format.transform({
- datatype: 'timestamp',
- value: value
- });
- } else if (field === 'creator' || field === 'editor') {
- value = value.usrname();
- }
- }
+ const value = this.getFieldDisplayValue(field, copy);
if (counts[value] === undefined) {
counts[value] = 0;
return counts;
}
- applyCopyValue(field: string, value: any) {
+ getFieldDisplayValue(field: string, copy: IdlObject): string {
+
+ // Some fields don't live directly on the copy.
+ if (field === 'owning_lib') {
+ return this.org.get(
+ copy.call_number().owning_lib()).shortname() +
+ ' : ' + copy.call_number().label();
+ }
+
+ let value = copy[field]();
+
+ if (!value && value !== 0) { return ''; }
+
+ switch(field) {
+
+ case 'status':
+ return this.volcopy.copyStatuses[value].name();
+
+ case 'location':
+ return value.name() +
+ ' (' + this.org.get(value.owning_lib()).shortname() + ')';
+
+ case 'edit_date':
+ case 'create_date':
+ case 'active_date':
+ return this.format.transform(
+ {datatype: 'timestamp', value: value});
+
+ case 'editor':
+ case 'creator':
+ return value.usrname();
+
+ case 'circ_lib':
+ return this.org.get(value).shortname();
+
+ case 'age_protect':
+ const rule = this.ageProtectRules.filter(
+ r => r.id() === Number(value))[0];
+ return rule ? rule.name() : '';
+
+ case 'floating':
+ const grp = this.floatingGroups.filter(
+ g => g.id() === Number(value))[0];
+ return grp ? grp.name() : '';
+
+ case 'loan_duration':
+ return this.loanDurationLabelMap[value];
+
+ case 'fine_level':
+ return this.fineLevelLabelMap[value];
+
+ case 'circ_as_type':
+ const map = this.itemTypeMaps.filter(
+ m => m.code() === value)[0];
+ return map ? map.value() : '';
+
+ case 'circ_modifier':
+ const mod = this.circModifiers.filter(
+ m => m.code() === value)[0];
+ return mod ? mod.name() : '';
+
+ case 'mint_condition':
+ if (!this.mintConditionYes) { return ''; }
+ return value === 't' ?
+ this.mintConditionYes.text : this.mintConditionNo.text;
+ }
+
+ return value;
+ }
+
+ applyCopyValue(field: string, value?: any) {
+ if (value === undefined) { value = this.values[field]; }
+
+ console.debug('APPLYING', field, value);
+
this.context.copyList().forEach(copy => {
if (copy[field] && copy[field]() !== value) {
copy[field](value);
});
}
- locationChanged() {
- this.applyCopyValue('location', this.batchLocation);
+ circLibChanged() {
+ // TODO other stuff happens here?
+ this.applyCopyValue('circ_lib');
+ }
+
+ owningLibChanged() {
+ // TODO
+ console.log('OWNING LIB ', this.values['owning_lib']);
}
}