From 1ebbca284d205799991874ddaa6938bfb3f225fb Mon Sep 17 00:00:00 2001 From: Mike Rylander Date: Fri, 27 Mar 2020 14:52:37 -0400 Subject: [PATCH] Attributes tab Signed-off-by: Mike Rylander Signed-off-by: Galen Charlton --- .../staff/acq/provider/acq-provider.component.html | 4 +- .../app/staff/acq/provider/acq-provider.module.ts | 2 + .../provider/provider-attributes.component.html | 26 +++ .../acq/provider/provider-attributes.component.ts | 178 +++++++++++++++++++++ .../staff/acq/provider/provider-record.service.ts | 9 +- 5 files changed, 214 insertions(+), 5 deletions(-) create mode 100644 Open-ILS/src/eg2/src/app/staff/acq/provider/provider-attributes.component.html create mode 100644 Open-ILS/src/eg2/src/app/staff/acq/provider/provider-attributes.component.ts diff --git a/Open-ILS/src/eg2/src/app/staff/acq/provider/acq-provider.component.html b/Open-ILS/src/eg2/src/app/staff/acq/provider/acq-provider.component.html index 5187113c94..a140237652 100644 --- a/Open-ILS/src/eg2/src/app/staff/acq/provider/acq-provider.component.html +++ b/Open-ILS/src/eg2/src/app/staff/acq/provider/acq-provider.component.html @@ -49,7 +49,9 @@ - PROVIDER ATTRIBUTES TAB + + + 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 368dc93005..01fca1d33f 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 @@ -9,6 +9,7 @@ import {ProviderDetailsComponent} from './provider-details.component'; import {ProviderAddressesComponent} from './provider-addresses.component'; import {ProviderContactsComponent} from './provider-contacts.component'; import {ProviderHoldingsComponent} from './provider-holdings.component'; +import {ProviderAttributesComponent} from './provider-attributes.component'; import {ProviderInvoicesComponent} from './provider-invoices.component'; import {ProviderPurchaseOrdersComponent} from './provider-purchase-orders.component'; import {OrgFamilySelectModule} from '@eg/share/org-family-select/org-family-select.module'; @@ -25,6 +26,7 @@ import {ProviderRecordService} from './provider-record.service'; ProviderAddressesComponent, ProviderContactsComponent, ProviderHoldingsComponent, + ProviderAttributesComponent, ProviderInvoicesComponent, ProviderPurchaseOrdersComponent, AcqProviderSummaryPaneComponent diff --git a/Open-ILS/src/eg2/src/app/staff/acq/provider/provider-attributes.component.html b/Open-ILS/src/eg2/src/app/staff/acq/provider/provider-attributes.component.html new file mode 100644 index 0000000000..9280f6598e --- /dev/null +++ b/Open-ILS/src/eg2/src/app/staff/acq/provider/provider-attributes.component.html @@ -0,0 +1,26 @@ + + + + + + + + + + + + + + + + + + diff --git a/Open-ILS/src/eg2/src/app/staff/acq/provider/provider-attributes.component.ts b/Open-ILS/src/eg2/src/app/staff/acq/provider/provider-attributes.component.ts new file mode 100644 index 0000000000..a9a90b099e --- /dev/null +++ b/Open-ILS/src/eg2/src/app/staff/acq/provider/provider-attributes.component.ts @@ -0,0 +1,178 @@ +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 {GridComponent} from '@eg/share/grid/grid.component'; +import {GridDataSource, GridCellTextGenerator} from '@eg/share/grid/grid'; +import {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-attributes', + templateUrl: 'provider-attributes.component.html', +}) +export class ProviderAttributesComponent implements OnInit, AfterViewInit { + + @Input() providerId: any; + attributes: any[] = []; + + gridSource: GridDataSource; + @ViewChild('editDialog', { static: true }) editDialog: FmRecordEditorComponent; + @ViewChild('acqProviderAttributesGrid', { static: true }) providerAttributesGrid: 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 auth: AuthService, + private idl: IdlService, + private providerRecord: ProviderRecordService, + private toast: ToastService) { + + } + + ngOnInit() { + this.gridSource = this.getDataSource() + this.cellTextGenerator = {}; + this.deleteSelected = (idlThings: IdlObject[]) => { + idlThings.forEach(idlThing => idlThing.isdeleted(true)); + this.providerRecord.batchUpdate(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.providerAttributesGrid.reload() + ); + } + ); + }; + this.providerAttributesGrid.onRowActivate.subscribe( + (idlThing: IdlObject) => this.showEditDialog(idlThing) + ); + } + + ngAfterViewInit() { + console.log('this.providerRecord',this.providerRecord); + } + + getDataSource(): GridDataSource { + const gridSource = new GridDataSource(); + + gridSource.getRows = (pager: Pager, sort: any[]) => { + this.provider = this.providerRecord.current(); + if (!this.provider) { + return empty(); + } + let attributes = this.provider.attributes() + + if (sort.length > 0) { + attributes = attributes.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(attributes.slice(pager.offset, pager.offset + pager.limit - 1)); + }; + return gridSource; + } + + showEditDialog(providerAttribute: IdlObject): Promise { + this.editDialog.mode = 'update'; + this.editDialog.recordId = providerAttribute['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.providerAttributesGrid.reload() + ); + resolve(result); + }, + error => { + this.updateFailedString.current() + .then(str => this.toast.danger(str)); + reject(error); + } + ); + }); + } + + editSelected(providerAttributesFields: IdlObject[]) { + // Edit each IDL thing one at a time + const editOneThing = (providerAttributes: IdlObject) => { + if (!providerAttributes) { return; } + + this.showEditDialog(providerAttributes).then( + () => editOneThing(providerAttributesFields.shift())); + }; + + editOneThing(providerAttributesFields.shift()); + } + + createNew() { + this.editDialog.mode = 'create'; + const attributes = this.idl.create('acqlipad'); + attributes.provider(this.provider.id()); + this.editDialog.record = attributes; + 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.providerAttributesGrid.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-record.service.ts b/Open-ILS/src/eg2/src/app/staff/acq/provider/provider-record.service.ts index 4ab5c89cab..a0886cb701 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 @@ -39,10 +39,11 @@ export class ProviderRecordService { return this.pcrud.search('acqpro', { id: id }, { flesh: 3, - flesh_fields: { acqpro: ['holdings_subfields', 'contacts', 'addresses', 'provider_notes'], - acqpa: ['provider'], - acqpc: ['provider'], - acqphsm:['provider'], + flesh_fields: { acqpro: ['attributes','holdings_subfields', 'contacts', 'addresses', 'provider_notes'], + acqpa: ['provider'], + acqpc: ['provider'], + acqphsm: ['provider'], + acqlipad:['provider'], } }, {} -- 2.11.0