-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';
private idl: IdlService,
private providerRecord: ProviderRecordService,
private toast: ToastService,
- private store: StoreService
+ private store: StoreService,
+ private changeDetector: ChangeDetectorRef
) {
}
};
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) => {
};
}
- ngAfterViewInit() {}
+ ngAfterViewInit() {
+ this.changeDetector.detectChanges();
+ }
setDefaultTab() {
this.defaultTabType = this.activeTab;
-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';
permissions: {[name: string]: boolean};
+ subscription: Subscription;
+
// Size of create/edito dialog. Uses large by default.
@Input() dialogSize: 'sm' | 'lg' = 'lg';
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();
-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';
permissions: {[name: string]: boolean};
+ subscription: Subscription;
+
// Size of create/edito dialog. Uses large by default.
@Input() dialogSize: 'sm' | 'lg' = 'lg';
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();
-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';
permissions: {[name: string]: boolean};
+ subscription: Subscription;
+
// Size of create/edito dialog. Uses large by default.
@Input() dialogSize: 'sm' | 'lg' = 'lg';
private idl: IdlService,
private providerRecord: ProviderRecordService,
private toast: ToastService) {
-
}
ngOnInit() {
this.providerContactsGrid.onRowActivate.subscribe(
(idlThing: IdlObject) => this.showEditDialog(idlThing)
);
+ this.subscription = this.providerRecord.providerUpdated$.subscribe(
+ id => {
+ this.providerContactsGrid.reload();
+ }
+ );
}
ngAfterViewInit() {
);
}
+ ngOnDestroy() {
+ this.subscription.unsubscribe();
+ }
+
generateSearch(filters): any {
const query: any = new Array();
}
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();
}
}
-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';
permissions: {[name: string]: boolean};
+ subscription: Subscription;
+
// Size of create/edito dialog. Uses large by default.
@Input() dialogSize: 'sm' | 'lg' = 'lg';
@Output('desireSummarize') summarize: EventEmitter<number> = new EventEmitter<number>();
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();
-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';
permissions: {[name: string]: boolean};
+ subscription: Subscription;
+
// Size of create/edito dialog. Uses large by default.
@Input() dialogSize: 'sm' | 'lg' = 'lg';
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();
-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';
cellTextGenerator: GridCellTextGenerator;
+ subscription: Subscription;
+
constructor(
private router: Router,
private route: ActivatedRoute,
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
-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';
cellTextGenerator: GridCellTextGenerator;
+ subscription: Subscription;
+
constructor(
private router: Router,
private route: ActivatedRoute,
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();
}
}
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';
private currentProvider: ProviderRecord;
private currentProviderId: number = null;
+ private providerUpdatedSource = new Subject<number>();
+ providerUpdated$ = this.providerUpdatedSource.asObservable();
+
constructor(
private idl: IdlService,
private net: NetService,
current(): IdlObject {
return this.currentProvider ? this.currentProvider.record : null;
}
+ currentProviderRecord(): ProviderRecord {
+ return this.currentProvider ? this.currentProvider : null;
+ }
fetch(id: number): Promise<any> {
return new Promise((resolve, reject) => {
batchUpdate(list: IdlObject | IdlObject[]): Observable<any> {
return this.pcrud.autoApply(list);
}
+
+ announceProviderUpdated() {
+ this.providerUpdatedSource.next(this.currentProviderId);
+ }
+
}
}
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();
}