From: Bill Erickson Date: Thu, 23 Jul 2020 18:03:23 +0000 (-0400) Subject: volcopy detect saveable state X-Git-Url: https://old-git.evergreen-ils.org/?a=commitdiff_plain;h=8ab683df6df6bf20205a0e6939d4074a71a37b88;p=working%2FEvergreen.git volcopy detect saveable state Signed-off-by: Bill Erickson --- 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 25743a9d05..0534ac9e76 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,5 +1,5 @@ import {Component, Input, OnInit, AfterViewInit, ViewChild, - QueryList, ViewChildren} from '@angular/core'; + EventEmitter, Output, QueryList, ViewChildren} from '@angular/core'; import {Router, ActivatedRoute, ParamMap} from '@angular/router'; import {SafeUrl} from '@angular/platform-browser'; import {tap} from 'rxjs/operators'; @@ -81,6 +81,9 @@ export class CopyAttrsComponent implements OnInit, AfterViewInit { @ViewChildren(BatchItemAttrComponent) batchAttrs: QueryList; + // Emitted when the save-ability of this form changes. + @Output() canSaveChange: EventEmitter = new EventEmitter(); + constructor( private router: Router, private route: ActivatedRoute, @@ -116,6 +119,7 @@ export class CopyAttrsComponent implements OnInit, AfterViewInit { this.fineLevelLabelMap[1] = this.fineLevelLow.text; this.fineLevelLabelMap[2] = this.fineLevelNormal.text; this.fineLevelLabelMap[3] = this.fineLevelHigh.text; + } statCats(): IdlObject[] { @@ -262,23 +266,27 @@ export class CopyAttrsComponent implements OnInit, AfterViewInit { } if (field === 'owning_lib') { - return this.owningLibChanged(value, changeSelection); - } + this.owningLibChanged(value, changeSelection); - this.context.copyList().forEach(copy => { - if (!copy[field] || copy[field]() === value) { return; } + } else { - // Change selection indicates which items should be modified - // based on the display value for the selected field at - // time of editing. - if (changeSelection && - !this.copyWantsChange(copy, field, changeSelection)) { - return; - } + this.context.copyList().forEach(copy => { + if (!copy[field] || copy[field]() === value) { return; } - copy[field](value); - copy.ischanged(true); - }); + // Change selection indicates which items should be modified + // based on the display value for the selected field at + // time of editing. + if (changeSelection && + !this.copyWantsChange(copy, field, changeSelection)) { + return; + } + + copy[field](value); + copy.ischanged(true); + }); + } + + this.emitSaveChange(); } owningLibChanged(orgId: number, changeSelection?: BatchChangeSelection) { @@ -392,7 +400,8 @@ export class CopyAttrsComponent implements OnInit, AfterViewInit { openCopyAlerts() { this.copyAlertsDialog.inPlaceMode = true; - this.copyAlertsDialog.mode = 'create'; + this.copyAlertsDialog.copyIds = this.context.copyList().map(c => c.id()); + this.copyAlertsDialog.open({size: 'lg'}).subscribe( newAlert => { if (newAlert) { @@ -442,8 +451,6 @@ export class CopyAttrsComponent implements OnInit, AfterViewInit { this.store.setLocalItem('cat.copy.last_template', entry.id); - // TODO: handle owning_lib - const template = this.volcopy.templates[entry.id]; Object.keys(template).forEach(field => { @@ -590,6 +597,18 @@ export class CopyAttrsComponent implements OnInit, AfterViewInit { } return true; } + + emitSaveChange() { + + // Timeout allows the digest cycle which created the change to complete. + setTimeout(() => { + + const canSave = this.batchAttrs.filter( + attr => attr.warnOnRequired()).length === 0; + + this.canSaveChange.emit(canSave) + }); + } } diff --git a/Open-ILS/src/eg2/src/app/staff/cat/volcopy/vol-edit.component.ts b/Open-ILS/src/eg2/src/app/staff/cat/volcopy/vol-edit.component.ts index 35ee7db417..60c52a6309 100644 --- a/Open-ILS/src/eg2/src/app/staff/cat/volcopy/vol-edit.component.ts +++ b/Open-ILS/src/eg2/src/app/staff/cat/volcopy/vol-edit.component.ts @@ -1,4 +1,4 @@ -import {Component, OnInit, AfterViewInit, ViewChild, Input, Renderer2} from '@angular/core'; +import {Component, OnInit, AfterViewInit, ViewChild, Input, Renderer2, Output, EventEmitter} from '@angular/core'; import {Router, ActivatedRoute, ParamMap} from '@angular/router'; import {tap} from 'rxjs/operators'; import {IdlService, IdlObject} from '@eg/core/idl.service'; @@ -26,7 +26,7 @@ export class VolEditComponent implements OnInit { // There are 10 columns in the editor form. Set the flex values // here so they don't have to be hard-coded and repeated in the // markup. Changing a flex value here will propagate to all - // rows in the form. + // rows in the form. Column numbers are 1-based. flexSettings: {[column: number]: number} = { 1: 1, 2: 1, 3: 2, 4: 1, 5: 2, 6: 1, 7: 1, 8: 2, 9: 1, 10: 1}; @@ -53,6 +53,9 @@ export class VolEditComponent implements OnInit { @ViewChild('confirmDelCopy', {static: false}) confirmDelCopy: ConfirmDialogComponent; + // Emitted when the save-ability of this form changes. + @Output() canSaveChange: EventEmitter = new EventEmitter(); + constructor( private renderer: Renderer2, private idl: IdlService, @@ -224,6 +227,8 @@ export class VolEditComponent implements OnInit { vol[key](value); vol.ischanged(true); } + + this.emitSaveChange(); } applyCopyValue(copy: IdlObject, key: string, value: any) { @@ -360,7 +365,12 @@ export class VolEditComponent implements OnInit { copy.ischanged(true); copy._dupe_barcode = false; - if (barcode && !this.autoBarcodeInProgress) { + if (!barcode) { + this.emitSaveChange(); + return; + } + + if (!this.autoBarcodeInProgress) { // Manual barcode entry requires dupe check copy._dupe_barcode = false; @@ -368,9 +378,13 @@ export class VolEditComponent implements OnInit { deleted: 'f', barcode: barcode, id: {'!=': copy.id()} - }).subscribe(resp => { - if (resp) { copy._dupe_barcode = true; } - }); + }).subscribe( + resp => { + if (resp) { copy._dupe_barcode = true; } + }, + err => {}, + () => this.emitSaveChange() + ); } } @@ -487,5 +501,33 @@ export class VolEditComponent implements OnInit { this.volcopy.defaults.values.use_checkdigit = this.useCheckdigit === true; this.volcopy.saveDefaults(); } + + canSave(): boolean { + + const copies = this.context.copyList(); + + const badCopies = copies.filter(copy => { + return copy._dupe_barcode || (!copy.isnew() && !copy.barcode()); + }).length > 0; + + if (badCopies) { return false; } + + const badVols = this.context.volNodes().filter(volNode => { + const vol = volNode.target; + return !( + vol.prefix() && vol.label() && vol.suffix && vol.label_class() + ); + }).length > 0; + + return !badVols; + } + + emitSaveChange() { + + // Timeout allows the digest cycle which created the change to complete. + setTimeout(() => { + this.canSaveChange.emit(this.canSave()); + }); + } } diff --git a/Open-ILS/src/eg2/src/app/staff/cat/volcopy/volcopy.component.html b/Open-ILS/src/eg2/src/app/staff/cat/volcopy/volcopy.component.html index e6a13790c2..be7ff284c8 100644 --- a/Open-ILS/src/eg2/src/app/staff/cat/volcopy/volcopy.component.html +++ b/Open-ILS/src/eg2/src/app/staff/cat/volcopy/volcopy.component.html @@ -17,9 +17,15 @@
  • Holdings -
    +
    + +
    -
    +
    + +
  • @@ -27,7 +33,10 @@
  • Item Attributes -
    +
    + +
  • @@ -53,9 +62,12 @@ i18n>Print Labels?
    - - + + diff --git a/Open-ILS/src/eg2/src/app/staff/cat/volcopy/volcopy.component.ts b/Open-ILS/src/eg2/src/app/staff/cat/volcopy/volcopy.component.ts index 1d15c9c2dd..f782effb89 100644 --- a/Open-ILS/src/eg2/src/app/staff/cat/volcopy/volcopy.component.ts +++ b/Open-ILS/src/eg2/src/app/staff/cat/volcopy/volcopy.component.ts @@ -58,6 +58,9 @@ export class VolCopyComponent implements OnInit { target: string; // item | callnumber | record | session targetId: string; // id value or session string + volsCanSave = true; + attrsCanSave = true; + constructor( private router: Router, private route: ActivatedRoute, @@ -195,10 +198,6 @@ export class VolCopyComponent implements OnInit { this.context.recordId = editSession.record_id; - // These are currently ignored, since visibility is tab-based - this.context.hideVols = editSession.hide_vols === true; - this.context.hideCopies = editSession.hide_copies === true; - if (editSession.copies && editSession.copies.length > 0) { return this.fetchCopies(editSession.copies); } @@ -467,6 +466,10 @@ export class VolCopyComponent implements OnInit { setTimeout(() => window.open(url, '_blank')); }); } + + isNotSaveable(): boolean { + return !(this.volsCanSave && this.attrsCanSave); + } } 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 855ba586ac..6d351cfdc3 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,8 +15,6 @@ import {ComboboxComponent, ComboboxEntry} from '@eg/share/combobox/combobox.comp /* Managing volcopy data */ - - interface VolCopyDefaults { values: {[field: string]: any}; hidden: {[field: string]: boolean}; diff --git a/Open-ILS/src/eg2/src/app/staff/cat/volcopy/volcopy.ts b/Open-ILS/src/eg2/src/app/staff/cat/volcopy/volcopy.ts index b47b59dd5d..c76e78659c 100644 --- a/Open-ILS/src/eg2/src/app/staff/cat/volcopy/volcopy.ts +++ b/Open-ILS/src/eg2/src/app/staff/cat/volcopy/volcopy.ts @@ -45,9 +45,6 @@ export class VolCopyContext { volsToDelete: IdlObject[] = []; copiesToDelete: IdlObject[] = []; - hideVols: boolean; - hideCopies: boolean; - reset() { this.holdings = new HoldingsTree(); this.volsToDelete = []; @@ -192,12 +189,7 @@ export class VolCopyContext { o1.target.shortname() < o2.target.shortname() ? -1 : 1); } - // Changes pending and no unresolved issues. - isSaveable(): boolean { - const dupeBc = this.copyList().filter(c => c._dupe_barcode).length; - - if (dupeBc) { return false; } - + changesPending(): boolean { const modified = (o: IdlObject): boolean => { return o.isnew() || o.ischanged() || o.isdeleted(); }; diff --git a/Open-ILS/src/eg2/src/app/staff/share/holdings/copy-alerts-dialog.component.html b/Open-ILS/src/eg2/src/app/staff/share/holdings/copy-alerts-dialog.component.html index 25fe9195d8..5ccf7ff28d 100644 --- a/Open-ILS/src/eg2/src/app/staff/share/holdings/copy-alerts-dialog.component.html +++ b/Open-ILS/src/eg2/src/app/staff/share/holdings/copy-alerts-dialog.component.html @@ -5,7 +5,7 @@