From: Galen Charlton Date: Sun, 28 Mar 2021 01:24:27 +0000 (-0400) Subject: attr sets: functionally complete X-Git-Url: https://old-git.evergreen-ils.org/?a=commitdiff_plain;h=1b8e3fab7e6d2b1340a54c0c619565d05ef18f71;p=working%2FEvergreen.git attr sets: functionally complete Note the TODO about the onRowActivate subscription, which will require a change to the base component Signed-off-by: Galen Charlton --- diff --git a/Open-ILS/src/eg2/src/app/staff/admin/acq/edi_attr_set/edi-attr-set-edit-dialog.component.html b/Open-ILS/src/eg2/src/app/staff/admin/acq/edi_attr_set/edi-attr-set-edit-dialog.component.html new file mode 100644 index 0000000000..81e7cc39c1 --- /dev/null +++ b/Open-ILS/src/eg2/src/app/staff/admin/acq/edi_attr_set/edi-attr-set-edit-dialog.component.html @@ -0,0 +1,46 @@ + + + + + diff --git a/Open-ILS/src/eg2/src/app/staff/admin/acq/edi_attr_set/edi-attr-set-edit-dialog.component.ts b/Open-ILS/src/eg2/src/app/staff/admin/acq/edi_attr_set/edi-attr-set-edit-dialog.component.ts new file mode 100644 index 0000000000..656a0b5612 --- /dev/null +++ b/Open-ILS/src/eg2/src/app/staff/admin/acq/edi_attr_set/edi-attr-set-edit-dialog.component.ts @@ -0,0 +1,151 @@ +import {Component, Input, ViewChild, TemplateRef, OnInit} from '@angular/core'; +import {DialogComponent} from '@eg/share/dialog/dialog.component'; +import {NgForm} from '@angular/forms'; +import {IdlService, IdlObject} from '@eg/core/idl.service'; +import {EventService} from '@eg/core/event.service'; +import {NetService} from '@eg/core/net.service'; +import {AuthService} from '@eg/core/auth.service'; +import {PcrudService} from '@eg/core/pcrud.service'; +import {Pager} from '@eg/share/util/pager'; +import {NgbModal} from '@ng-bootstrap/ng-bootstrap'; +import {StringComponent} from '@eg/share/string/string.component'; +import {ToastService} from '@eg/share/toast/toast.service'; +import {PermService} from '@eg/core/perm.service'; + +@Component({ + selector: 'eg-edi-attr-set-edit-dialog', + templateUrl: './edi-attr-set-edit-dialog.component.html' +}) + +export class EdiAttrSetEditDialogComponent + extends DialogComponent implements OnInit { + + @Input() mode: string = 'create'; + @Input() attrSetId: number; + @Input() cloneSource: number; + attrSet: IdlObject; + attrInputs: any = []; + clonedLabel = ''; + + constructor( + private idl: IdlService, + private evt: EventService, + private net: NetService, + private auth: AuthService, + private pcrud: PcrudService, + private perm: PermService, + private toast: ToastService, + private modal: NgbModal + ) { + super(modal); + } + + ngOnInit() { + this.onOpen$.subscribe(() => this._initRecord()); + } + + private _initRecord() { + this.attrSet = null; + this.attrInputs = []; + this.clonedLabel = ''; + if (this.mode === 'update') { + this.pcrud.retrieve('aeas', this.attrSetId, { + flesh: 1, + flesh_fields: { aeas: ['attr_maps'] } + }).subscribe(res => { + this.attrSet = res; + this._generateAttrInputs(); + }); + } else if (this.mode === 'clone') { + this.pcrud.retrieve('aeas', this.cloneSource, { + flesh: 1, + flesh_fields: { aeas: ['attr_maps'] } + }).subscribe(res => { + this.clonedLabel = res.label(); + this.attrSet = this.idl.create('aeas'); + this.attrSet.attr_maps([]); + res.attr_maps().forEach((m) => { + const newMap = this.idl.create('aeasm'); + newMap.attr(m.attr()); + this.attrSet.attr_maps().push(newMap); + }); + this._generateAttrInputs(); + }); + } else if (this.mode === 'create') { + this.attrSet = this.idl.create('aeas'); + this.attrSet.attr_maps([]); + this._generateAttrInputs(); + } + } + + _generateAttrInputs() { + const hasAttr: {[key: string]: boolean} = {}; + const hasAttrId: {[key: string]: number} = {}; + this.attrSet.attr_maps().forEach((m) => { + hasAttr[m.attr()] = true; + hasAttrId[m.attr()] = m.id(); + }); + this.pcrud.retrieveAll('aea', {order_by: {aea: 'key'}}).subscribe(attr => { + const inp = { + key: attr.key(), + label: attr.label(), + id: null, + selected: false + }; + if (attr.key() in hasAttr) { + inp.selected = true; + inp.id = hasAttrId[attr.key()]; + } + this.attrInputs.push(inp); + }); + } + + save() { + if (this.attrSet.id() === undefined || this.attrSet.id() === null) { + this.attrSet.isnew(true); + } else { + this.attrSet.ischanged(true); + } + this.pcrud.autoApply([this.attrSet]).subscribe(res => { + const setId = this.mode === 'update' ? res : res.id(); + const updates: IdlObject[] = []; + if (this.mode === 'create' || this.mode === 'clone') { + this.attrInputs.forEach((inp) => { + if (inp.selected) { + const aesm = this.idl.create('aeasm'); + aesm.attr(inp.key); + aesm.attr_set(setId); + aesm.isnew(true); + updates.push(aesm); + } + }); + } else { + // updating an existing set + this.attrInputs.forEach((inp) => { + if (inp.id) { + if (!inp.selected) { + // used to be wanted, but no longer + const aesm = this.idl.create('aeasm'); + aesm.id(inp.id); + aesm.isdeleted(true); + updates.push(aesm); + } + } else if (inp.selected) { + // no ID, must be newly checked + const aesm = this.idl.create('aeasm'); + aesm.attr(inp.key); + aesm.attr_set(setId); + aesm.isnew(true); + updates.push(aesm); + } + }); + } + this.pcrud.autoApply(updates).subscribe( + res => this.close(true), + err => this.close(err), + () => this.close(true) + ); + }, err => this.close(false)); + } + +} diff --git a/Open-ILS/src/eg2/src/app/staff/admin/acq/edi_attr_set/edi-attr-sets.component.html b/Open-ILS/src/eg2/src/app/staff/admin/acq/edi_attr_set/edi-attr-sets.component.html index 3a36c239ee..6fdf7f03a3 100644 --- a/Open-ILS/src/eg2/src/app/staff/admin/acq/edi_attr_set/edi-attr-sets.component.html +++ b/Open-ILS/src/eg2/src/app/staff/admin/acq/edi_attr_set/edi-attr-sets.component.html @@ -58,7 +58,9 @@ - + + + @@ -81,3 +83,13 @@ + + + + + + diff --git a/Open-ILS/src/eg2/src/app/staff/admin/acq/edi_attr_set/edi-attr-sets.component.ts b/Open-ILS/src/eg2/src/app/staff/admin/acq/edi_attr_set/edi-attr-sets.component.ts index d1529d7118..2ee9a147b1 100644 --- a/Open-ILS/src/eg2/src/app/staff/admin/acq/edi_attr_set/edi-attr-sets.component.ts +++ b/Open-ILS/src/eg2/src/app/staff/admin/acq/edi_attr_set/edi-attr-sets.component.ts @@ -15,7 +15,11 @@ import {AuthService} from '@eg/core/auth.service'; import {NetService} from '@eg/core/net.service'; import {Observable, of} from 'rxjs'; import {map, mergeMap} from 'rxjs/operators'; +import {StringComponent} from '@eg/share/string/string.component'; import {EdiAttrSetProvidersDialogComponent} from './edi-attr-set-providers-dialog.component'; +import {EdiAttrSetEditDialogComponent} from './edi-attr-set-edit-dialog.component'; +import {AlertDialogComponent} from '@eg/share/dialog/alert.component'; +import {ConfirmDialogComponent} from '@eg/share/dialog/confirm.component'; @Component({ templateUrl: './edi-attr-sets.component.html' @@ -27,6 +31,9 @@ export class EdiAttrSetsComponent extends AdminPageComponent implements OnInit { @ViewChild('grid', { static: true }) grid: GridComponent; @ViewChild('ediAttrSetProvidersDialog', { static: false }) ediAttrSetProvidersDialog: EdiAttrSetProvidersDialogComponent; + @ViewChild('ediAttrSetEditDialog', { static: false }) ediAttrSetEditDialog: EdiAttrSetEditDialogComponent; + @ViewChild('alertDialog', {static: false}) private alertDialog: AlertDialogComponent; + @ViewChild('confirmDel', { static: true }) confirmDel: ConfirmDialogComponent; cellTextGenerator: GridCellTextGenerator; @@ -105,6 +112,10 @@ export class EdiAttrSetsComponent extends AdminPageComponent implements OnInit { this.classLabel = this.idlClassDef.label; this.includeOrgDescendants = true; + // TODO - this works, but doesn't clear the base component's subscription + //this.grid.onRowActivate.subscribe( + // (idlThing: IdlObject) => this.editSelected([idlThing]) + //); } countProviders(row: IdlObject): Observable { @@ -117,4 +128,53 @@ export class EdiAttrSetsComponent extends AdminPageComponent implements OnInit { this.ediAttrSetProvidersDialog.open({size: 'lg'}); } + deleteIfPossible(rows: IdlObject[]) { + if (rows.length > 0) { + if (rows[0].num_providers > 0) { + this.alertDialog.open(); + } else { + this.confirmDel.open().subscribe(confirmed => { + if (!confirmed) { return; } + super.deleteSelected([ rows[0] ]); + }); + } + } + } + + showEditAttrSetDialog(successString: StringComponent, failString: StringComponent): Promise { + return new Promise((resolve, reject) => { + this.ediAttrSetEditDialog.open({size: 'lg', scrollable: true}).subscribe( + result => { + this.successString.current() + .then(str => this.toast.success(str)); + this.grid.reload(); + resolve(result); + }, + error => { + this.updateFailedString.current() + .then(str => this.toast.danger(str)); + reject(error); + } + ); + }); + } + + createNew() { + this.ediAttrSetEditDialog.mode = 'create'; + this.showEditAttrSetDialog(this.createString, this.createErrString); + } + + editSelected(rows: IdlObject[]) { + if (rows.length <= 0) { return; } + this.ediAttrSetEditDialog.mode = 'update'; + this.ediAttrSetEditDialog.attrSetId = rows[0].id(); + this.showEditAttrSetDialog(this.successString, this.updateFailedString); + } + + cloneSelected(rows: IdlObject[]) { + if (rows.length <= 0) { return; } + this.ediAttrSetEditDialog.mode = 'clone'; + this.ediAttrSetEditDialog.cloneSource = rows[0].id(); + this.showEditAttrSetDialog(this.createString, this.createErrString); + } } diff --git a/Open-ILS/src/eg2/src/app/staff/admin/acq/edi_attr_set/edi-attr-sets.module.ts b/Open-ILS/src/eg2/src/app/staff/admin/acq/edi_attr_set/edi-attr-sets.module.ts index e5fb854e7f..53d0967bc0 100644 --- a/Open-ILS/src/eg2/src/app/staff/admin/acq/edi_attr_set/edi-attr-sets.module.ts +++ b/Open-ILS/src/eg2/src/app/staff/admin/acq/edi_attr_set/edi-attr-sets.module.ts @@ -5,12 +5,14 @@ import {EdiAttrSetsRoutingModule} from './routing.module'; import {EdiAttrSetsComponent} from './edi-attr-sets.component'; import {EdiAttrSetProvidersDialogComponent} from './edi-attr-set-providers-dialog.component'; import {EdiAttrSetProvidersComponent} from './edi-attr-set-providers.component'; +import {EdiAttrSetEditDialogComponent} from './edi-attr-set-edit-dialog.component'; @NgModule({ declarations: [ EdiAttrSetsComponent, EdiAttrSetProvidersDialogComponent, - EdiAttrSetProvidersComponent + EdiAttrSetProvidersComponent, + EdiAttrSetEditDialogComponent ], imports: [ StaffCommonModule,