From: Galen Charlton Date: Fri, 14 Aug 2020 22:44:48 +0000 (-0400) Subject: improve record retrieval and refreshes X-Git-Url: https://old-git.evergreen-ils.org/?a=commitdiff_plain;h=f9bb62734dd5aee3faea5c75a5df88687885b196;p=working%2FEvergreen.git improve record retrieval and refreshes - reduce the number of redundant fetches - use subscriptions to inform child components when they need to refresh themselves Signed-off-by: Galen Charlton --- diff --git a/Open-ILS/src/eg2/src/app/staff/acq/provider/acq-provider.component.ts b/Open-ILS/src/eg2/src/app/staff/acq/provider/acq-provider.component.ts index b928e395f2..3130ccbe7e 100644 --- a/Open-ILS/src/eg2/src/app/staff/acq/provider/acq-provider.component.ts +++ b/Open-ILS/src/eg2/src/app/staff/acq/provider/acq-provider.component.ts @@ -1,4 +1,4 @@ -import {Component, OnInit, AfterViewInit, ViewChild} from '@angular/core'; +import {Component, OnInit, AfterViewInit, ViewChild, ChangeDetectorRef} from '@angular/core'; import {NgbTabset, NgbTabChangeEvent} from '@ng-bootstrap/ng-bootstrap'; import {Router, ActivatedRoute, ParamMap, RouterEvent, NavigationEnd} from '@angular/router'; import {StaffCommonModule} from '@eg/staff/common.module'; @@ -43,7 +43,8 @@ export class AcqProviderComponent implements OnInit, AfterViewInit { private idl: IdlService, private providerRecord: ProviderRecordService, private toast: ToastService, - private store: StoreService + private store: StoreService, + private changeDetector: ChangeDetectorRef ) { } @@ -86,19 +87,21 @@ export class AcqProviderComponent implements OnInit, AfterViewInit { }; this.onDesireSummarize = ($event, updateSummaryOnly = false) => { - // $event is a provider ID - this.providerSummaryPane.update($event); - if (this.providerDetails) { - this.providerDetails.refresh(); - } - if (updateSummaryOnly) { - return; - } this.id = $event; - this.providerRecord.fetch(this.id); - this.showSearchForm = false; - this.activeTab = this.defaultTabType; - this.router.navigate(['/staff', 'acq', 'provider', this.id, this.activeTab]); + this.providerRecord.fetch(this.id).then(() => { + // $event is a provider ID + this.providerSummaryPane.update($event); + if (this.providerDetails) { + this.providerDetails.refresh(); + } + if (updateSummaryOnly) { + return; + } + this.providerRecord.announceProviderUpdated(); + this.showSearchForm = false; + this.activeTab = this.defaultTabType; + this.router.navigate(['/staff', 'acq', 'provider', this.id, this.activeTab]); + }); }; this.onSummaryToggled = ($event) => { @@ -106,7 +109,9 @@ export class AcqProviderComponent implements OnInit, AfterViewInit { }; } - ngAfterViewInit() {} + ngAfterViewInit() { + this.changeDetector.detectChanges(); + } setDefaultTab() { this.defaultTabType = this.activeTab; 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 4095c58aa9..c13f66170c 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,5 +1,5 @@ -import {Component, OnInit, AfterViewInit, Input, ViewChild} from '@angular/core'; -import {empty, throwError, Observable, from} from 'rxjs'; +import {Component, OnInit, AfterViewInit, OnDestroy, Input, ViewChild} from '@angular/core'; +import {empty, throwError, Observable, from, Subscription} from 'rxjs'; import {map} from 'rxjs/operators'; import {Router, ActivatedRoute, ParamMap} from '@angular/router'; import {Pager} from '@eg/share/util/pager'; @@ -43,6 +43,8 @@ export class ProviderAddressesComponent implements OnInit, AfterViewInit { permissions: {[name: string]: boolean}; + subscription: Subscription; + // Size of create/edito dialog. Uses large by default. @Input() dialogSize: 'sm' | 'lg' = 'lg'; @@ -83,12 +85,21 @@ export class ProviderAddressesComponent implements OnInit, AfterViewInit { this.providerAddressesGrid.onRowActivate.subscribe( (idlThing: IdlObject) => this.showEditDialog(idlThing) ); + this.subscription = this.providerRecord.providerUpdated$.subscribe( + id => { + this.providerAddressesGrid.reload(); + } + ); } ngAfterViewInit() { console.log('this.providerRecord',this.providerRecord); } + ngOnDestroy() { + this.subscription.unsubscribe(); + } + generateSearch(filters): any { const query: any = new Array(); 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 index 4c1d32d60f..b2cef2b87d 100644 --- 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 @@ -1,5 +1,5 @@ -import {Component, OnInit, AfterViewInit, Input, ViewChild} from '@angular/core'; -import {empty, throwError, Observable, from} from 'rxjs'; +import {Component, OnInit, AfterViewInit, OnDestroy, Input, ViewChild} from '@angular/core'; +import {empty, throwError, Observable, from, Subscription} from 'rxjs'; import {map} from 'rxjs/operators'; import {Router, ActivatedRoute, ParamMap} from '@angular/router'; import {Pager} from '@eg/share/util/pager'; @@ -43,6 +43,8 @@ export class ProviderAttributesComponent implements OnInit, AfterViewInit { permissions: {[name: string]: boolean}; + subscription: Subscription; + // Size of create/edito dialog. Uses large by default. @Input() dialogSize: 'sm' | 'lg' = 'lg'; @@ -82,12 +84,22 @@ export class ProviderAttributesComponent implements OnInit, AfterViewInit { this.providerAttributesGrid.onRowActivate.subscribe( (idlThing: IdlObject) => this.showEditDialog(idlThing) ); + this.subscription = this.providerRecord.providerUpdated$.subscribe( + id => { + this.providerAttributesGrid.reload(); + } + ); + } ngAfterViewInit() { console.log('this.providerRecord',this.providerRecord); } + ngOnDestroy() { + this.subscription.unsubscribe(); + } + getDataSource(): GridDataSource { const gridSource = new GridDataSource(); diff --git a/Open-ILS/src/eg2/src/app/staff/acq/provider/provider-contacts.component.ts b/Open-ILS/src/eg2/src/app/staff/acq/provider/provider-contacts.component.ts index 091fa87b8f..70ddbc59b6 100644 --- a/Open-ILS/src/eg2/src/app/staff/acq/provider/provider-contacts.component.ts +++ b/Open-ILS/src/eg2/src/app/staff/acq/provider/provider-contacts.component.ts @@ -1,5 +1,5 @@ -import {Component, OnInit, AfterViewInit, Input, Output, ViewChild, EventEmitter, ChangeDetectorRef} from '@angular/core'; -import {empty, throwError, Observable, from} from 'rxjs'; +import {Component, OnInit, AfterViewInit, OnDestroy, Input, Output, ViewChild, EventEmitter, ChangeDetectorRef} from '@angular/core'; +import {empty, throwError, Observable, from, Subscription} from 'rxjs'; import {map} from 'rxjs/operators'; import {Router, ActivatedRoute, ParamMap} from '@angular/router'; import {Pager} from '@eg/share/util/pager'; @@ -50,6 +50,8 @@ export class ProviderContactsComponent implements OnInit, AfterViewInit { permissions: {[name: string]: boolean}; + subscription: Subscription; + // Size of create/edito dialog. Uses large by default. @Input() dialogSize: 'sm' | 'lg' = 'lg'; @@ -64,7 +66,6 @@ export class ProviderContactsComponent implements OnInit, AfterViewInit { private idl: IdlService, private providerRecord: ProviderRecordService, private toast: ToastService) { - } ngOnInit() { @@ -93,6 +94,11 @@ export class ProviderContactsComponent implements OnInit, AfterViewInit { this.providerContactsGrid.onRowActivate.subscribe( (idlThing: IdlObject) => this.showEditDialog(idlThing) ); + this.subscription = this.providerRecord.providerUpdated$.subscribe( + id => { + this.providerContactsGrid.reload(); + } + ); } ngAfterViewInit() { @@ -109,6 +115,10 @@ export class ProviderContactsComponent implements OnInit, AfterViewInit { ); } + ngOnDestroy() { + this.subscription.unsubscribe(); + } + generateSearch(filters): any { const query: any = new Array(); diff --git a/Open-ILS/src/eg2/src/app/staff/acq/provider/provider-details.component.ts b/Open-ILS/src/eg2/src/app/staff/acq/provider/provider-details.component.ts index 4852fd421a..fbcae5c0a6 100644 --- a/Open-ILS/src/eg2/src/app/staff/acq/provider/provider-details.component.ts +++ b/Open-ILS/src/eg2/src/app/staff/acq/provider/provider-details.component.ts @@ -54,18 +54,12 @@ export class ProviderDetailsComponent implements OnInit { } updateProvider(providerId: any) { - this.providerRecord.refreshCurrent().then(() => { - this.provider = this.providerRecord.current(); - this._deflesh(); - this.summarize.emit(this.provider.id()); - }); + this.summarize.emit(this.provider.id()); } refresh() { - this.providerRecord.refreshCurrent().then(() => { - this.provider = this.providerRecord.current(); - this._deflesh(); - }); + this.provider = this.idl.clone(this.providerRecord.current()); + this._deflesh(); } } diff --git a/Open-ILS/src/eg2/src/app/staff/acq/provider/provider-edi-accounts.component.ts b/Open-ILS/src/eg2/src/app/staff/acq/provider/provider-edi-accounts.component.ts index 284d7c4722..18ebd8bad2 100644 --- a/Open-ILS/src/eg2/src/app/staff/acq/provider/provider-edi-accounts.component.ts +++ b/Open-ILS/src/eg2/src/app/staff/acq/provider/provider-edi-accounts.component.ts @@ -1,5 +1,5 @@ -import {Component, OnInit, AfterViewInit, Input, Output, EventEmitter, ViewChild, ChangeDetectorRef} from '@angular/core'; -import {empty, throwError, Observable, from} from 'rxjs'; +import {Component, OnInit, AfterViewInit, OnDestroy, Input, Output, EventEmitter, ViewChild, ChangeDetectorRef} from '@angular/core'; +import {empty, throwError, Observable, from, Subscription} from 'rxjs'; import {map} from 'rxjs/operators'; import {Router, ActivatedRoute, ParamMap} from '@angular/router'; import {Pager} from '@eg/share/util/pager'; @@ -54,6 +54,8 @@ export class ProviderEdiAccountsComponent implements OnInit, AfterViewInit { permissions: {[name: string]: boolean}; + subscription: Subscription; + // Size of create/edito dialog. Uses large by default. @Input() dialogSize: 'sm' | 'lg' = 'lg'; @Output('desireSummarize') summarize: EventEmitter = new EventEmitter(); @@ -101,12 +103,21 @@ export class ProviderEdiAccountsComponent implements OnInit, AfterViewInit { this.providerEdiAccountsGrid.onRowActivate.subscribe( (idlThing: IdlObject) => this.showEditDialog(idlThing) ); + this.subscription = this.providerRecord.providerUpdated$.subscribe( + id => { + this.providerEdiAccountsGrid.reload(); + } + ); } ngAfterViewInit() { console.log('this.providerRecord',this.providerRecord); } + ngOnDestroy() { + this.subscription.unsubscribe(); + } + getDataSource(): GridDataSource { const gridSource = new GridDataSource(); 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 index 2599826863..699b2004ca 100644 --- 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 @@ -1,5 +1,5 @@ -import {Component, OnInit, AfterViewInit, Input, ViewChild} from '@angular/core'; -import {empty, throwError, Observable, from} from 'rxjs'; +import {Component, OnInit, AfterViewInit, OnDestroy, Input, ViewChild} from '@angular/core'; +import {empty, throwError, Observable, from, Subscription} from 'rxjs'; import {map} from 'rxjs/operators'; import {Router, ActivatedRoute, ParamMap} from '@angular/router'; import {Pager} from '@eg/share/util/pager'; @@ -43,6 +43,8 @@ export class ProviderHoldingsComponent implements OnInit, AfterViewInit { permissions: {[name: string]: boolean}; + subscription: Subscription; + // Size of create/edito dialog. Uses large by default. @Input() dialogSize: 'sm' | 'lg' = 'lg'; @@ -82,12 +84,22 @@ export class ProviderHoldingsComponent implements OnInit, AfterViewInit { this.providerHoldingsGrid.onRowActivate.subscribe( (idlThing: IdlObject) => this.showEditDialog(idlThing) ); + this.subscription = this.providerRecord.providerUpdated$.subscribe( + id => { + this.providerHoldingsGrid.reload(); + } + ); } ngAfterViewInit() { console.log('this.providerRecord',this.providerRecord); } + + ngOnDestroy() { + this.subscription.unsubscribe(); + } + updateProvider(providerId: any) { this.providerRecord.refreshCurrent().then(() => { this.provider = this.providerRecord.current(); diff --git a/Open-ILS/src/eg2/src/app/staff/acq/provider/provider-invoices.component.ts b/Open-ILS/src/eg2/src/app/staff/acq/provider/provider-invoices.component.ts index 6134a1b649..ec39a5439c 100644 --- a/Open-ILS/src/eg2/src/app/staff/acq/provider/provider-invoices.component.ts +++ b/Open-ILS/src/eg2/src/app/staff/acq/provider/provider-invoices.component.ts @@ -1,5 +1,5 @@ -import {Component, OnInit, AfterViewInit, Input, ViewChild} from '@angular/core'; -import {Observable} from 'rxjs'; +import {Component, OnInit, AfterViewInit, OnDestroy, Input, ViewChild} from '@angular/core'; +import {Observable, Subscription} from 'rxjs'; import {map} from 'rxjs/operators'; import {Router, ActivatedRoute, ParamMap} from '@angular/router'; import {Pager} from '@eg/share/util/pager'; @@ -31,6 +31,8 @@ export class ProviderInvoicesComponent implements OnInit { cellTextGenerator: GridCellTextGenerator; + subscription: Subscription; + constructor( private router: Router, private route: ActivatedRoute, @@ -50,26 +52,37 @@ export class ProviderInvoicesComponent implements OnInit { provider: row => row.provider().code(), shipper: row => row.shipper().code(), }; + this.subscription = this.providerRecord.providerUpdated$.subscribe( + id => { + this.resetSearch(); + } + ); } ngAfterViewInit() { - this.providerRecord.refreshCurrent().then(() => { - const provider = this.providerRecord.current(); - if (provider) { - setTimeout(() => { - this.acqSearch.setSearch({ - terms: [{ - field: 'acqinv:provider', - op: '', - value1: provider.id(), - value2: '', - }], - conjunction: 'all', - }); - this.providerInvoicesGrid.reload(); + this.resetSearch(); + } + + ngOnDestroy() { + this.subscription.unsubscribe(); + } + + resetSearch() { + const provider = this.providerRecord.current(); + if (provider) { + setTimeout(() => { + this.acqSearch.setSearch({ + terms: [{ + field: 'acqinv:provider', + op: '', + value1: provider.id(), + value2: '', + }], + conjunction: 'all', }); - } - }); + this.providerInvoicesGrid.reload(); + }); + } } // TODO - copied from InvoiceResultsComponent, could be diff --git a/Open-ILS/src/eg2/src/app/staff/acq/provider/provider-purchase-orders.component.ts b/Open-ILS/src/eg2/src/app/staff/acq/provider/provider-purchase-orders.component.ts index 9fac4abe6e..e764a73a30 100644 --- a/Open-ILS/src/eg2/src/app/staff/acq/provider/provider-purchase-orders.component.ts +++ b/Open-ILS/src/eg2/src/app/staff/acq/provider/provider-purchase-orders.component.ts @@ -1,5 +1,5 @@ -import {Component, OnInit, AfterViewInit, Input, ViewChild} from '@angular/core'; -import {Observable} from 'rxjs'; +import {Component, OnInit, AfterViewInit, OnDestroy, Input, ViewChild} from '@angular/core'; +import {Observable, Subscription} from 'rxjs'; import {map} from 'rxjs/operators'; import {Router, ActivatedRoute, ParamMap} from '@angular/router'; import {Pager} from '@eg/share/util/pager'; @@ -31,6 +31,8 @@ export class ProviderPurchaseOrdersComponent implements OnInit { cellTextGenerator: GridCellTextGenerator; + subscription: Subscription; + constructor( private router: Router, private route: ActivatedRoute, @@ -50,26 +52,38 @@ export class ProviderPurchaseOrdersComponent implements OnInit { provider: row => row.provider().code(), shipper: row => row.shipper().code(), }; + this.subscription = this.providerRecord.providerUpdated$.subscribe( + id => { + this.resetSearch(); + } + ); } ngAfterViewInit() { - this.providerRecord.refreshCurrent().then(() => { - const provider = this.providerRecord.current(); - if (provider) { - setTimeout(() => { - this.acqSearch.setSearch({ - terms: [{ - field: 'acqpo:provider', - op: '', - value1: provider.id(), - value2: '', - }], - conjunction: 'all', - }); - this.providerPurchaseOrdersGrid.reload(); + this.resetSearch(); + } + + resetSearch() { + const provider = this.providerRecord.current(); + if (provider) { + setTimeout(() => { + this.acqSearch.setSearch({ + terms: [{ + field: 'acqpo:provider', + op: '', + value1: provider.id(), + value2: '', + }], + conjunction: 'all', }); - } - }); + this.providerPurchaseOrdersGrid.reload(); + }); + } + } + + + ngOnDestroy() { + this.subscription.unsubscribe(); } } 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 990dbeb36e..fdb398e0b5 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 @@ -1,6 +1,6 @@ import {Injectable} from '@angular/core'; import {Observable, from} from 'rxjs'; -import {empty, throwError} from 'rxjs'; +import {empty, throwError, Subject} from 'rxjs'; import {map} from 'rxjs/operators'; import {PcrudService} from '@eg/core/pcrud.service'; import {IdlService, IdlObject} from '@eg/core/idl.service'; @@ -27,6 +27,9 @@ export class ProviderRecordService { private currentProvider: ProviderRecord; private currentProviderId: number = null; + private providerUpdatedSource = new Subject(); + providerUpdated$ = this.providerUpdatedSource.asObservable(); + constructor( private idl: IdlService, private net: NetService, @@ -90,6 +93,9 @@ export class ProviderRecordService { current(): IdlObject { return this.currentProvider ? this.currentProvider.record : null; } + currentProviderRecord(): ProviderRecord { + return this.currentProvider ? this.currentProvider : null; + } fetch(id: number): Promise { return new Promise((resolve, reject) => { @@ -115,4 +121,9 @@ export class ProviderRecordService { batchUpdate(list: IdlObject | IdlObject[]): Observable { return this.pcrud.autoApply(list); } + + announceProviderUpdated() { + this.providerUpdatedSource.next(this.currentProviderId); + } + } 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 9116a8e43d..970e542e49 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 @@ -129,35 +129,34 @@ export class AcqProviderSummaryPaneComponent implements OnInit, AfterViewInit { } if (newProvider) { - 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(); - this.provider_code = provider.code(); - this.provider_owner = this.org.get(provider.owner()).shortname(); - this.provider_currency_type = provider.currency_type() ? provider.currency_type().label() : ''; - this.provider_holding_tag = provider.holding_tag(); - this.provider_addresses = provider.addresses(); - this.provider_san = provider.san(); - this.provider_edi_default = provider.edi_default() ? provider.edi_default().label() : ''; - this.provider_active = provider.active(); - this.provider_prepayment_required = provider.prepayment_required(); - this.provider_url = provider.url(); - this.provider_email = provider.email(); - this.provider_phone = provider.phone(); - this.provider_fax_phone = provider.fax_phone(); - this.provider_default_claim_policy = provider.default_claim_policy(); - this.provider_default_copy_count = provider.default_copy_count(); - this.provider_contacts = provider.contacts(); - this.provider_provider_notes = provider.provider_notes(); - } else { - this.provider = null; - no_provider(); - } - }); + const providerRecord = this.prov.currentProviderRecord(); + const provider = providerRecord.record; + if (provider) { + this.provRec = providerRecord; + this.provider = provider; + this.provider_id = provider.id(); + this.provider_name = provider.name(); + this.provider_code = provider.code(); + this.provider_owner = this.org.get(provider.owner()).shortname(); + this.provider_currency_type = provider.currency_type() ? provider.currency_type().label() : ''; + this.provider_holding_tag = provider.holding_tag(); + this.provider_addresses = provider.addresses(); + this.provider_san = provider.san(); + this.provider_edi_default = provider.edi_default() ? provider.edi_default().label() : ''; + this.provider_active = provider.active(); + this.provider_prepayment_required = provider.prepayment_required(); + this.provider_url = provider.url(); + this.provider_email = provider.email(); + this.provider_phone = provider.phone(); + this.provider_fax_phone = provider.fax_phone(); + this.provider_default_claim_policy = provider.default_claim_policy(); + this.provider_default_copy_count = provider.default_copy_count(); + this.provider_contacts = provider.contacts(); + this.provider_provider_notes = provider.provider_notes(); + } else { + this.provider = null; + no_provider(); + } } else { no_provider(); }