From 2027b14b2ebea24e86861cecd63f681fe2881154 Mon Sep 17 00:00:00 2001 From: Bill Erickson Date: Tue, 23 Jun 2020 16:57:11 -0400 Subject: [PATCH] LPXXX Angular Volcopy Signed-off-by: Bill Erickson --- .../staff/cat/volcopy/copy-attrs.component.html | 14 ++++- .../app/staff/cat/volcopy/copy-attrs.component.ts | 65 ++++++++++++++++++++-- .../src/app/staff/cat/volcopy/volcopy.service.ts | 10 ++++ Open-ILS/src/eg2/src/app/staff/common.module.ts | 4 +- 4 files changed, 86 insertions(+), 7 deletions(-) diff --git a/Open-ILS/src/eg2/src/app/staff/cat/volcopy/copy-attrs.component.html b/Open-ILS/src/eg2/src/app/staff/cat/volcopy/copy-attrs.component.html index 4ea94abcb6..2f5811b76d 100644 --- a/Open-ILS/src/eg2/src/app/staff/cat/volcopy/copy-attrs.component.html +++ b/Open-ILS/src/eg2/src/app/staff/cat/volcopy/copy-attrs.component.html @@ -32,13 +32,23 @@
Templates:
- + +
- + + + + + + +
diff --git a/Open-ILS/src/eg2/src/app/staff/cat/volcopy/copy-attrs.component.ts b/Open-ILS/src/eg2/src/app/staff/cat/volcopy/copy-attrs.component.ts index 44d2858bbb..2eb0ef2153 100644 --- a/Open-ILS/src/eg2/src/app/staff/cat/volcopy/copy-attrs.component.ts +++ b/Open-ILS/src/eg2/src/app/staff/cat/volcopy/copy-attrs.component.ts @@ -1,6 +1,7 @@ import {Component, Input, OnInit, AfterViewInit, ViewChild, QueryList, ViewChildren} from '@angular/core'; import {Router, ActivatedRoute, ParamMap} from '@angular/router'; +import {SafeUrl} from '@angular/platform-browser'; import {tap} from 'rxjs/operators'; import {IdlObject, IdlService} from '@eg/core/idl.service'; import {EventService} from '@eg/core/event.service'; @@ -18,6 +19,7 @@ import {CopyAlertsDialogComponent } from '@eg/staff/share/holdings/copy-alerts-dialog.component'; import {ComboboxComponent, ComboboxEntry} from '@eg/share/combobox/combobox.component'; import {BatchItemAttrComponent} from '@eg/staff/share/holdings/batch-item-attr.component'; +import {FileExportService} from '@eg/share/util/file-export.service'; @Component({ selector: 'eg-copy-attrs', @@ -83,6 +85,7 @@ export class CopyAttrsComponent implements OnInit, AfterViewInit { private holdings: HoldingsService, private format: FormatService, private store: StoreService, + private fileExport: FileExportService, public volcopy: VolCopyService ) { } @@ -92,7 +95,10 @@ export class CopyAttrsComponent implements OnInit, AfterViewInit { ngAfterViewInit() { const tmpl = this.store.getLocalItem('cat.copy.last_template'); - if (tmpl) { this.copyTemplateCbox.selectedId = tmpl; } + if (tmpl) { + // avoid Express Changed warning w/ timeout + setTimeout(() => this.copyTemplateCbox.selectedId = tmpl); + } this.loanDurationLabelMap[1] = this.loanDurationShort.text; this.loanDurationLabelMap[2] = this.loanDurationNormal.text; @@ -233,8 +239,6 @@ export class CopyAttrsComponent implements OnInit, AfterViewInit { // TODO: handle circ_lib, owning_lib changes specially - console.debug('APPLYING', field, value); - this.context.copyList().forEach(copy => { if (copy[field] && copy[field]() !== value) { copy[field](value); @@ -299,6 +303,8 @@ export class CopyAttrsComponent implements OnInit, AfterViewInit { this.store.setLocalItem('cat.copy.last_template', entry.id); + // TODO: handle owning_lib and statcats differently. + const template = this.volcopy.templates[entry.id]; Object.keys(template).forEach(field => { @@ -307,13 +313,64 @@ export class CopyAttrsComponent implements OnInit, AfterViewInit { if (value === null || value === undefined) { return; } this.applyCopyValue(field, value); + + // Indicate in the form these values have changed + this.batchAttrs + .filter(ba => ba.name === field) + .forEach(attr => attr.hasChanged = true); }); } saveTemplate() { + const entry: ComboboxEntry = this.copyTemplateCbox.selected; + if (!entry) { return; } + + let name; + let template; + + if (entry.freetext) { + name = entry.label; + template = {}; + } else { + name = entry.id; + template = this.volcopy.templates[name]; + } + + // Changes will have applied to all items. + const copy = this.context.copyList()[0]; + this.batchAttrs.forEach(comp => { - console.log(comp.editInputDomId); + if (comp.hasChanged) { + const value = copy[comp.name](); + if (value === null) { + delete template[comp.name]; + } else { + template[comp.name] = value; + } + } }); + + console.debug('Saving template', template); + + this.volcopy.templates[name] = template; + this.volcopy.saveTemplates(); + } + + exportTemplate($event) { + if (this.fileExport.inProgress()) { return; } + + const entry: ComboboxEntry = this.copyTemplateCbox.selected; + if (!entry) { return; } + + const template = this.volcopy.templates[entry.id]; + + this.fileExport.exportFile( + $event, JSON.stringify(template), 'text/json'); + } + + // Returns null when no export is in progress. + exportTemplateUrl(): SafeUrl { + return this.fileExport.safeUrl; } displayAttr(field: string): boolean { diff --git a/Open-ILS/src/eg2/src/app/staff/cat/volcopy/volcopy.service.ts b/Open-ILS/src/eg2/src/app/staff/cat/volcopy/volcopy.service.ts index d9ce8a0594..b411fd13a0 100644 --- a/Open-ILS/src/eg2/src/app/staff/cat/volcopy/volcopy.service.ts +++ b/Open-ILS/src/eg2/src/app/staff/cat/volcopy/volcopy.service.ts @@ -15,6 +15,8 @@ import {ComboboxComponent, ComboboxEntry} from '@eg/share/combobox/combobox.comp /* Managing volcopy data */ + + interface VolCopyDefaults { values: {[field: string]: any}, hidden: {[field: string]: boolean} @@ -171,6 +173,14 @@ export class VolCopyService { return Promise.resolve(); } + + saveTemplates(): Promise { + // TODO: templates should be stored on the server. + this.store.setLocalItem('cat.copy.templates', this.templates); + // Re-sort, etc. + return this.fetchTemplates(); + } + fetchDefaults(): Promise { if (this.defaults) { return Promise.resolve(); } diff --git a/Open-ILS/src/eg2/src/app/staff/common.module.ts b/Open-ILS/src/eg2/src/app/staff/common.module.ts index 85dd7fcd4b..f6f4140d1b 100644 --- a/Open-ILS/src/eg2/src/app/staff/common.module.ts +++ b/Open-ILS/src/eg2/src/app/staff/common.module.ts @@ -18,6 +18,7 @@ import {MultiSelectComponent} from '@eg/share/multi-select/multi-select.componen import {NotBeforeMomentValidatorDirective} from '@eg/share/validators/not_before_moment_validator.directive'; import {PatronBarcodeValidatorDirective} from '@eg/share/validators/patron_barcode_validator.directive'; import {BroadcastService} from '@eg/share/util/broadcast.service'; +import {FileExportService} from '@eg/share/util/file-export.service'; /** * Imports the EG common modules and adds modules common to all staff UI's. @@ -71,7 +72,8 @@ export class StaffCommonModule { providers: [ // Export staff-wide services AccessKeyService, AudioService, - BroadcastService + BroadcastService, + FileExportService ] }; } -- 2.11.0