From 28cb78a8b03519d9c422c0e7bf7b346e0b152475 Mon Sep 17 00:00:00 2001 From: Mike Rylander Date: Wed, 25 Mar 2020 16:08:17 -0400 Subject: [PATCH] Holdings Subfield tab Signed-off-by: Mike Rylander foo Signed-off-by: Mike Rylander Signed-off-by: Galen Charlton --- Open-ILS/examples/fm_IDL.xml | 2 + .../staff/acq/provider/acq-provider.component.html | 4 +- .../app/staff/acq/provider/acq-provider.module.ts | 2 + .../acq/provider/provider-holdings.component.html | 46 ++++++ .../acq/provider/provider-holdings.component.ts | 178 +++++++++++++++++++++ .../staff/acq/provider/provider-record.service.ts | 3 +- 6 files changed, 233 insertions(+), 2 deletions(-) create mode 100644 Open-ILS/src/eg2/src/app/staff/acq/provider/provider-holdings.component.html create mode 100644 Open-ILS/src/eg2/src/app/staff/acq/provider/provider-holdings.component.ts diff --git a/Open-ILS/examples/fm_IDL.xml b/Open-ILS/examples/fm_IDL.xml index 28c3ca2391..0534127799 100644 --- a/Open-ILS/examples/fm_IDL.xml +++ b/Open-ILS/examples/fm_IDL.xml @@ -8750,6 +8750,7 @@ SELECT usr, + @@ -8759,6 +8760,7 @@ SELECT usr, + 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 a0356ee58e..8a92b77cc8 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 @@ -43,7 +43,9 @@ PROVIDER ATTRIBUTES TAB - PROVIDER HOLDINGS TAB + + + PROVIDER EDI 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 a8a6925ee7..aa52908712 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 @@ -7,6 +7,7 @@ import {AcqProviderSummaryPaneComponent} from './summary-pane.component'; import {ProviderResultsComponent} from './provider-results.component'; import {ProviderAddressesComponent} from './provider-addresses.component'; import {ProviderContactsComponent} from './provider-contacts.component'; +import {ProviderHoldingsComponent} from './provider-holdings.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'; @@ -21,6 +22,7 @@ import {ProviderRecordService} from './provider-record.service'; ProviderResultsComponent, ProviderAddressesComponent, ProviderContactsComponent, + ProviderHoldingsComponent, ProviderInvoicesComponent, ProviderPurchaseOrdersComponent, AcqProviderSummaryPaneComponent diff --git a/Open-ILS/src/eg2/src/app/staff/acq/provider/provider-holdings.component.html b/Open-ILS/src/eg2/src/app/staff/acq/provider/provider-holdings.component.html new file mode 100644 index 0000000000..2caac69a43 --- /dev/null +++ b/Open-ILS/src/eg2/src/app/staff/acq/provider/provider-holdings.component.html @@ -0,0 +1,46 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Open-ILS/src/eg2/src/app/staff/acq/provider/provider-holdings.component.ts b/Open-ILS/src/eg2/src/app/staff/acq/provider/provider-holdings.component.ts new file mode 100644 index 0000000000..55007e9b64 --- /dev/null +++ b/Open-ILS/src/eg2/src/app/staff/acq/provider/provider-holdings.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-holdings', + templateUrl: 'provider-holdings.component.html', +}) +export class ProviderHoldingsComponent implements OnInit, AfterViewInit { + + @Input() providerId: any; + holdings: any[] = []; + + gridSource: GridDataSource; + @ViewChild('editDialog', { static: true }) editDialog: FmRecordEditorComponent; + @ViewChild('acqProviderHoldingsGrid', { static: true }) providerHoldingsGrid: 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.providerHoldingsGrid.reload() + ); + } + ); + }; + this.providerHoldingsGrid.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 holdings = this.provider.holdings_subfields() + + if (sort.length > 0) { + holdings = holdings.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(holdings.slice(pager.offset, pager.offset + pager.limit - 1)); + }; + return gridSource; + } + + showEditDialog(providerHolding: IdlObject): Promise { + this.editDialog.mode = 'update'; + this.editDialog.recordId = providerHolding['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.providerHoldingsGrid.reload() + ); + resolve(result); + }, + error => { + this.updateFailedString.current() + .then(str => this.toast.danger(str)); + reject(error); + } + ); + }); + } + + editSelected(providerHoldingsFields: IdlObject[]) { + // Edit each IDL thing one at a time + const editOneThing = (providerHoldings: IdlObject) => { + if (!providerHoldings) { return; } + + this.showEditDialog(providerHoldings).then( + () => editOneThing(providerHoldingsFields.shift())); + }; + + editOneThing(providerHoldingsFields.shift()); + } + + createNew() { + this.editDialog.mode = 'create'; + const holdings = this.idl.create('acqphsm'); + holdings.provider(this.provider.id()); + this.editDialog.record = holdings; + 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.providerHoldingsGrid.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 49893edbe2..4ab5c89cab 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,9 +39,10 @@ export class ProviderRecordService { return this.pcrud.search('acqpro', { id: id }, { flesh: 3, - flesh_fields: { acqpro: ['contacts', 'addresses', 'provider_notes'], + flesh_fields: { acqpro: ['holdings_subfields', 'contacts', 'addresses', 'provider_notes'], acqpa: ['provider'], acqpc: ['provider'], + acqphsm:['provider'], } }, {} -- 2.11.0