From: Jason Etheridge Date: Wed, 25 Mar 2020 13:41:22 +0000 (-0400) Subject: provider address modal X-Git-Url: https://old-git.evergreen-ils.org/?a=commitdiff_plain;h=f791969ce85ba444f037f700f8703566b5c8c875;p=working%2FEvergreen.git provider address modal Signed-off-by: Jason Etheridge Signed-off-by: Galen Charlton --- diff --git a/Open-ILS/src/eg2/src/app/staff/acq/provider/acq-provider.module.ts b/Open-ILS/src/eg2/src/app/staff/acq/provider/acq-provider.module.ts index 6073596c5c..51f61c44e8 100644 --- a/Open-ILS/src/eg2/src/app/staff/acq/provider/acq-provider.module.ts +++ b/Open-ILS/src/eg2/src/app/staff/acq/provider/acq-provider.module.ts @@ -8,6 +8,7 @@ import {ProviderResultsComponent} from './provider-results.component'; import {ProviderAddressesComponent} from './provider-addresses.component'; import {ProviderContactsComponent} from './provider-contacts.component'; import {OrgFamilySelectModule} from '@eg/share/org-family-select/org-family-select.module'; +import {FmRecordEditorModule} from '@eg/share/fm-editor/fm-editor.module'; import {ProviderRecordService} from './provider-record.service'; @NgModule({ @@ -23,6 +24,7 @@ import {ProviderRecordService} from './provider-record.service'; imports: [ StaffCommonModule, OrgFamilySelectModule, + FmRecordEditorModule, AcqProviderRoutingModule ], providers: [ diff --git a/Open-ILS/src/eg2/src/app/staff/acq/provider/provider-addresses.component.html b/Open-ILS/src/eg2/src/app/staff/acq/provider/provider-addresses.component.html index a353d2a46b..a843b20e63 100644 --- a/Open-ILS/src/eg2/src/app/staff/acq/provider/provider-addresses.component.html +++ b/Open-ILS/src/eg2/src/app/staff/acq/provider/provider-addresses.component.html @@ -1,8 +1,27 @@ + + + + + + - + + + + + + + + + diff --git a/Open-ILS/src/eg2/src/app/staff/acq/provider/provider-addresses.component.ts b/Open-ILS/src/eg2/src/app/staff/acq/provider/provider-addresses.component.ts index 5c8b287fe3..27dd4117a9 100644 --- a/Open-ILS/src/eg2/src/app/staff/acq/provider/provider-addresses.component.ts +++ b/Open-ILS/src/eg2/src/app/staff/acq/provider/provider-addresses.component.ts @@ -1,41 +1,86 @@ -import {Component, OnInit, Input, ViewChild} from '@angular/core'; +import {Component, OnInit, AfterViewInit, Input, ViewChild} from '@angular/core'; import {empty, throwError, Observable, from} from 'rxjs'; import {map} from 'rxjs/operators'; import {Router, ActivatedRoute, ParamMap} from '@angular/router'; import {Pager} from '@eg/share/util/pager'; -import {IdlObject} from '@eg/core/idl.service'; +import {IdlService, IdlObject} from '@eg/core/idl.service'; import {NetService} from '@eg/core/net.service'; import {AuthService} from '@eg/core/auth.service'; import {GridComponent} from '@eg/share/grid/grid.component'; import {GridDataSource, GridCellTextGenerator} from '@eg/share/grid/grid'; import {ProviderRecord, ProviderRecordService} from './provider-record.service'; import {AcqProviderSearchFormComponent} from './acq-provider-search-form.component'; +import {PcrudService} from '@eg/core/pcrud.service'; +import {FmRecordEditorComponent} from '@eg/share/fm-editor/fm-editor.component'; +import {StringComponent} from '@eg/share/string/string.component'; +import {ToastService} from '@eg/share/toast/toast.service'; @Component({ selector: 'eg-provider-addresses', templateUrl: 'provider-addresses.component.html', }) -export class ProviderAddressesComponent implements OnInit { +export class ProviderAddressesComponent implements OnInit, AfterViewInit { addresses: any[] = []; gridSource: GridDataSource; + @ViewChild('editDialog', { static: true }) editDialog: FmRecordEditorComponent; @ViewChild('acqProviderAddressesGrid', { static: true }) providerAddressesGrid: GridComponent; + @ViewChild('successString', { static: true }) successString: StringComponent; + @ViewChild('createString', { static: false }) createString: StringComponent; + @ViewChild('createErrString', { static: false }) createErrString: StringComponent; + @ViewChild('updateFailedString', { static: false }) updateFailedString: StringComponent; + @ViewChild('deleteFailedString', { static: true }) deleteFailedString: StringComponent; + @ViewChild('deleteSuccessString', { static: true }) deleteSuccessString: StringComponent; cellTextGenerator: GridCellTextGenerator; provider: IdlObject; + canCreate: boolean; + canDelete: boolean; + deleteSelected: (rows: IdlObject[]) => void; + + permissions: {[name: string]: boolean}; + + // Size of create/edito dialog. Uses large by default. + @Input() dialogSize: 'sm' | 'lg' = 'lg'; + constructor( private router: Router, private route: ActivatedRoute, private net: NetService, + private idl: IdlService, private auth: AuthService, - private providerRecord: ProviderRecordService) { + private providerRecord: ProviderRecordService, + private pcrud: PcrudService, + private toast: ToastService) { } ngOnInit() { this.gridSource = this.getDataSource() this.cellTextGenerator = {}; + this.deleteSelected = (idlThings: IdlObject[]) => { + idlThings.forEach(idlThing => idlThing.isdeleted(true)); + this.pcrud.autoApply(idlThings).subscribe( + val => { + console.debug('deleted: ' + val); + this.deleteSuccessString.current() + .then(str => this.toast.success(str)); + }, + err => { + this.deleteFailedString.current() + .then(str => this.toast.danger(str)); + }, + () => this.providerAddressesGrid.reload() + ); + }; + this.providerAddressesGrid.onRowActivate.subscribe( + (idlThing: IdlObject) => this.showEditDialog(idlThing) + ); + } + + ngAfterViewInit() { + console.log('this.providerRecord',this.providerRecord); } getDataSource(): GridDataSource { @@ -69,4 +114,56 @@ export class ProviderAddressesComponent implements OnInit { return gridSource; } + showEditDialog(providerAddress: IdlObject): Promise { + this.editDialog.mode = 'update'; + this.editDialog.recordId = providerAddress['id'](); + return new Promise((resolve, reject) => { + this.editDialog.open({size: this.dialogSize}).subscribe( + result => { + this.successString.current() + .then(str => this.toast.success(str)); + this.providerAddressesGrid.reload(); + resolve(result); + }, + error => { + this.updateFailedString.current() + .then(str => this.toast.danger(str)); + reject(error); + } + ); + }); + } + + editSelected(providerAddressFields: IdlObject[]) { + // Edit each IDL thing one at a time + const editOneThing = (providerAddress: IdlObject) => { + if (!providerAddress) { return; } + + this.showEditDialog(providerAddress).then( + () => editOneThing(providerAddressFields.shift())); + }; + + editOneThing(providerAddressFields.shift()); + } + + createNew() { + this.editDialog.mode = 'create'; + const address = this.idl.create('acqpa'); + address.provider(this.provider.id()); + this.editDialog.record = address; + this.editDialog.recordId = null; + this.editDialog.open({size: this.dialogSize}).subscribe( + ok => { + this.createString.current() + .then(str => this.toast.success(str)); + this.providerAddressesGrid.reload(); + }, + rejection => { + if (!rejection.dismissed) { + this.createErrString.current() + .then(str => this.toast.danger(str)); + } + } + ); + } }