From: Mike Rylander Date: Wed, 1 Apr 2020 16:32:26 +0000 (-0400) Subject: contact addresses X-Git-Url: https://old-git.evergreen-ils.org/?a=commitdiff_plain;h=f5140154f8a5f53e9036cc9d3bfbc326ff785f27;p=working%2FEvergreen.git contact addresses Signed-off-by: Mike Rylander Signed-off-by: Galen Charlton --- diff --git a/Open-ILS/examples/fm_IDL.xml b/Open-ILS/examples/fm_IDL.xml index 4ff63ac993..437f828e0b 100644 --- a/Open-ILS/examples/fm_IDL.xml +++ b/Open-ILS/examples/fm_IDL.xml @@ -8968,8 +8968,10 @@ SELECT usr, + + 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 01fca1d33f..fe1a25c7e7 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 {ProviderDetailsComponent} from './provider-details.component'; import {ProviderAddressesComponent} from './provider-addresses.component'; import {ProviderContactsComponent} from './provider-contacts.component'; +import {ProviderContactAddressesComponent} from './provider-contact-addresses.component'; import {ProviderHoldingsComponent} from './provider-holdings.component'; import {ProviderAttributesComponent} from './provider-attributes.component'; import {ProviderInvoicesComponent} from './provider-invoices.component'; @@ -25,6 +26,7 @@ import {ProviderRecordService} from './provider-record.service'; ProviderDetailsComponent, ProviderAddressesComponent, ProviderContactsComponent, + ProviderContactAddressesComponent, ProviderHoldingsComponent, ProviderAttributesComponent, ProviderInvoicesComponent, diff --git a/Open-ILS/src/eg2/src/app/staff/acq/provider/provider-contact-addresses.component.html b/Open-ILS/src/eg2/src/app/staff/acq/provider/provider-contact-addresses.component.html new file mode 100644 index 0000000000..cbfd8d394b --- /dev/null +++ b/Open-ILS/src/eg2/src/app/staff/acq/provider/provider-contact-addresses.component.html @@ -0,0 +1,28 @@ + + + + + + + + + + + + + + + + + + + diff --git a/Open-ILS/src/eg2/src/app/staff/acq/provider/provider-contact-addresses.component.ts b/Open-ILS/src/eg2/src/app/staff/acq/provider/provider-contact-addresses.component.ts new file mode 100644 index 0000000000..e4cb436b51 --- /dev/null +++ b/Open-ILS/src/eg2/src/app/staff/acq/provider/provider-contact-addresses.component.ts @@ -0,0 +1,180 @@ +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 {IdlService, IdlObject} from '@eg/core/idl.service'; +import {NetService} from '@eg/core/net.service'; +import {AuthService} from '@eg/core/auth.service'; +import {PcrudService} from '@eg/core/pcrud.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 {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-contact-addresses', + templateUrl: 'provider-contact-addresses.component.html', +}) +export class ProviderContactAddressesComponent implements OnInit, AfterViewInit { + + addresses: any[] = []; + + gridSource: GridDataSource; + @ViewChild('editDialog', { static: true }) editDialog: FmRecordEditorComponent; + @ViewChild('acqProviderContactAddressesGrid', { static: true }) providerContactAddressesGrid: 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; + + canCreate: boolean; + canDelete: boolean; + deleteSelected: (rows: IdlObject[]) => void; + reloadGrid: () => void; + + permissions: {[name: string]: boolean}; + + // Size of create/edito dialog. Uses large by default. + @Input() dialogSize: 'sm' | 'lg' = 'lg'; + @Input() contact: IdlObject; + + constructor( + private router: Router, + private route: ActivatedRoute, + private net: NetService, + private idl: IdlService, + private auth: AuthService, + private providerRecord: ProviderRecordService, + private toast: ToastService, + private pcrud: PcrudService) { + } + + ngOnInit() { + this.gridSource = this.getDataSource() + this.cellTextGenerator = {}; + this.reloadGrid = () => this.providerContactAddressesGrid.reload(); + 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.providerRecord.refreshCurrent().then( + () => this.providerContactAddressesGrid.reload() + ); + } + ); + }; + this.providerContactAddressesGrid.onRowActivate.subscribe( + (idlThing: IdlObject) => this.showEditDialog(idlThing) + ); + } + + + ngAfterViewInit() { + console.log('this.contact',this.contact); + } + + getDataSource(): GridDataSource { + const gridSource = new GridDataSource(); + + gridSource.getRows = (pager: Pager, sort: any[]) => { + if (!this.contact) { + return empty(); + } + let addresses = this.contact.addresses() + + if (sort.length > 0) { + addresses = addresses.sort((a, b) => { + for (let i = 0; i < sort.length; i++) { + let lt = -1; + let sfield = sort[i].name; + if (sort[i].dir.substring(0,1).toLowerCase() === 'd') { + lt *= -1; + } + if (a[sfield]() < b[sfield]()) { return lt } + if (a[sfield]() > b[sfield]()) { return lt * -1 } + } + return 0; + }); + + } + + return from(addresses.slice(pager.offset, pager.offset + pager.limit - 1)); + }; + return gridSource; + } + + showEditDialog(providerContactAddress: IdlObject): Promise { + this.editDialog.mode = 'update'; + this.editDialog.recordId = providerContactAddress['id'](); + return new Promise((resolve, reject) => { + this.editDialog.open({size: this.dialogSize}).subscribe( + result => { + this.successString.current() + .then(str => this.toast.success(str)); + this.providerRecord.refreshCurrent().then( + () => this.providerContactAddressesGrid.reload() + ); + resolve(result); + }, + error => { + this.updateFailedString.current() + .then(str => this.toast.danger(str)); + reject(error); + } + ); + }); + } + + editSelected(providerContactAddressFields: IdlObject[]) { + // Edit each IDL thing one at a time + const editOneThing = (providerContactAddress: IdlObject) => { + if (!providerContactAddress) { return; } + + this.showEditDialog(providerContactAddress).then( + () => editOneThing(providerContactAddressFields.shift())); + }; + + editOneThing(providerContactAddressFields.shift()); + } + + createNew() { + this.editDialog.mode = 'create'; + const address = this.idl.create('acqpca'); + address.contact(this.contact.id()); + address.valid(true); + 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.providerRecord.refreshCurrent().then( + () => this.providerContactAddressesGrid.reload() + ); + }, + rejection => { + if (!rejection.dismissed) { + this.createErrString.current() + .then(str => this.toast.danger(str)); + } + } + ); + } +} diff --git a/Open-ILS/src/eg2/src/app/staff/acq/provider/provider-contacts.component.html b/Open-ILS/src/eg2/src/app/staff/acq/provider/provider-contacts.component.html index fc0f733c6f..bc7987bc9d 100644 --- a/Open-ILS/src/eg2/src/app/staff/acq/provider/provider-contacts.component.html +++ b/Open-ILS/src/eg2/src/app/staff/acq/provider/provider-contacts.component.html @@ -18,6 +18,7 @@ persistKey="acq.provider.contacts.grid" idlClass="acqpc" [dataSource]="gridSource" [sortable]="true" + [disableMultiSelect]="true" hideFields="provider" [cellTextGenerator]="cellTextGenerator"> @@ -29,6 +30,14 @@ + +

Addresses for: {{selectedContact.name()}}

+ + +
+ { + this.selectedContact = idlThing; + console.debug('selected contact',this.selectedContact); + this.providerContactAddresses.reloadGrid(); + } + ); } getDataSource(): GridDataSource { diff --git a/Open-ILS/src/eg2/src/app/staff/acq/provider/provider-record.service.ts b/Open-ILS/src/eg2/src/app/staff/acq/provider/provider-record.service.ts index a0886cb701..bf971960de 100644 --- a/Open-ILS/src/eg2/src/app/staff/acq/provider/provider-record.service.ts +++ b/Open-ILS/src/eg2/src/app/staff/acq/provider/provider-record.service.ts @@ -41,7 +41,7 @@ export class ProviderRecordService { flesh: 3, flesh_fields: { acqpro: ['attributes','holdings_subfields', 'contacts', 'addresses', 'provider_notes'], acqpa: ['provider'], - acqpc: ['provider'], + acqpc: ['provider','addresses'], acqphsm: ['provider'], acqlipad:['provider'], }