From: Galen Charlton Date: Wed, 12 Aug 2020 20:02:29 +0000 (-0400) Subject: LH#38: add mechanism to detect if provider can be deleted X-Git-Url: https://old-git.evergreen-ils.org/?a=commitdiff_plain;h=67d1aac8938e50715af58c71c30947cf1f54933d;p=working%2FEvergreen.git LH#38: add mechanism to detect if provider can be deleted Signed-off-by: Galen Charlton --- 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 6b72cfd377..45a550d4f7 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 @@ -12,10 +12,12 @@ export class ProviderSummary { export class ProviderRecord { id: number; record: IdlObject; + canDelete: boolean; constructor(record: IdlObject) { this.id = Number(record.id()); this.record = record; + this.canDelete = false; } } @@ -55,10 +57,28 @@ export class ProviderRecordService { ).pipe(map(acqpro => { const provider = new ProviderRecord(acqpro); this.currentProvider = provider; + this.checkIfCanDelete(provider); return provider; })); } + checkIfCanDelete(prov: ProviderRecord) { + this.pcrud.search('acqpo', { provider: prov.id }, { limit: 1 }).toPromise() + .then(acqpo => { + if (!acqpo || acqpo.length === 0) { + this.pcrud.search('jub', { provider: prov.id }, { limit: 1 }).toPromise() + .then(jub => { + if (!jub || jub.length === 0) { + this.pcrud.search('acqinv', { provider: prov.id }, { limit: 1 }).toPromise() + .then(acqinv => { + prov.canDelete = true; + }); + } + }); + } + }); + } + current(): IdlObject { return this.currentProvider ? this.currentProvider.record : null; } diff --git a/Open-ILS/src/eg2/src/app/staff/acq/provider/summary-pane.component.html b/Open-ILS/src/eg2/src/app/staff/acq/provider/summary-pane.component.html index 07d819ff28..b428cf1651 100644 --- a/Open-ILS/src/eg2/src/app/staff/acq/provider/summary-pane.component.html +++ b/Open-ILS/src/eg2/src/app/staff/acq/provider/summary-pane.component.html @@ -116,7 +116,7 @@ diff --git a/Open-ILS/src/eg2/src/app/staff/acq/provider/summary-pane.component.ts b/Open-ILS/src/eg2/src/app/staff/acq/provider/summary-pane.component.ts index 28997b9dc0..9116a8e43d 100644 --- a/Open-ILS/src/eg2/src/app/staff/acq/provider/summary-pane.component.ts +++ b/Open-ILS/src/eg2/src/app/staff/acq/provider/summary-pane.component.ts @@ -65,6 +65,7 @@ export class AcqProviderSummaryPaneComponent implements OnInit, AfterViewInit { @Output('summaryToggled') toggled: EventEmitter = new EventEmitter(); provider: IdlObject; + provRec: ProviderRecord; constructor( private pcrud: PcrudService, @@ -131,6 +132,7 @@ export class AcqProviderSummaryPaneComponent implements OnInit, AfterViewInit { this.prov.getProviderRecord(newProvider).subscribe(providerRecord => { const provider = providerRecord.record; if (provider) { + this.provRec = providerRecord; this.provider = provider; this.provider_id = provider.id(); this.provider_name = provider.name(); @@ -183,6 +185,14 @@ export class AcqProviderSummaryPaneComponent implements OnInit, AfterViewInit { } + canDeleteProvider() { + if (this.provider && this.provider.id()) { + return this.provRec.canDelete; + } else { + return false; + } + } + toggleCollapse() { this.collapsed = ! this.collapsed; this.toggled.emit(this.collapsed);