-import {Component, OnInit, AfterViewInit, Input, Output, EventEmitter, ViewChild} from '@angular/core';
+import {Component, OnInit, AfterViewInit, Input, Output, EventEmitter, ViewChild, ChangeDetectorRef} from '@angular/core';
import {empty, throwError, Observable, from} from 'rxjs';
import {map} from 'rxjs/operators';
import {Router, ActivatedRoute, ParamMap} from '@angular/router';
import {StringComponent} from '@eg/share/string/string.component';
import {ToastService} from '@eg/share/toast/toast.service';
import {ConfirmDialogComponent} from '@eg/share/dialog/confirm.component';
+import {PcrudService} from '@eg/core/pcrud.service';
@Component({
selector: 'eg-provider-edi-accounts',
edi_accounts: any[] = [];
gridSource: GridDataSource;
+ ediMessagesSource: GridDataSource;
@ViewChild('editDialog', { static: true }) editDialog: FmRecordEditorComponent;
@ViewChild('acqProviderEdiAccountsGrid', { static: true }) providerEdiAccountsGrid: GridComponent;
+ @ViewChild('acqProviderEdiMessagesGrid', { static: false }) providerEdiMessagesGrid: GridComponent;
@ViewChild('confirmSetAsDefault', { static: true }) confirmSetAsDefault: ConfirmDialogComponent;
@ViewChild('successString', { static: true }) successString: StringComponent;
@ViewChild('createString', { static: false }) createString: StringComponent;
notOneSelectedRow: (rows: IdlObject[]) => boolean;
deleteSelected: (rows: IdlObject[]) => void;
+ viewEdiMessages: boolean;
+ selectedEdiAccountId: number;
+ selectedEdiAccountLabel = '';
+
permissions: {[name: string]: boolean};
// Size of create/edito dialog. Uses large by default.
constructor(
private router: Router,
private route: ActivatedRoute,
+ private changeDetector: ChangeDetectorRef,
private net: NetService,
private idl: IdlService,
private auth: AuthService,
+ private pcrud: PcrudService,
private providerRecord: ProviderRecordService,
private toast: ToastService) {
}
ngOnInit() {
this.gridSource = this.getDataSource()
+ this.ediMessagesSource = this.getEdiMessagesSource()
+ this.viewEdiMessages = false;
+ this.selectedEdiAccountId = null;
this.cellTextGenerator = {};
this.notOneSelectedRow = (rows: IdlObject[]) => (rows.length !== 1);
this.deleteSelected = (idlThings: IdlObject[]) => {
return gridSource;
}
+ getEdiMessagesSource(): GridDataSource {
+ const gridSource = new GridDataSource();
+ gridSource.getRows = (pager: Pager, sort: any[]) => {
+ const orderBy: any = {acqedim: 'create_time desc'};
+ if (sort.length) {
+ orderBy.acqedim = sort[0].name + ' ' + sort[0].dir;
+ }
+
+ // base query to grab everything
+ const base: Object = {
+ account: this.selectedEdiAccountId
+ };
+ const query: any = new Array();
+ query.push(base);
+
+ // and add any filters
+ Object.keys(gridSource.filters).forEach(key => {
+ Object.keys(gridSource.filters[key]).forEach(key2 => {
+ query.push(gridSource.filters[key][key2]);
+ });
+ });
+ return this.pcrud.search('acqedim',
+ query, {
+ flesh: 3,
+ flesh_fields: {acqedim: ['account', 'purchase_order']},
+ offset: pager.offset,
+ limit: pager.limit,
+ order_by: orderBy
+ });
+ };
+ return gridSource;
+ }
+
showEditDialog(providerEdiAccount: IdlObject): Promise<any> {
this.editDialog.mode = 'update';
this.editDialog.recordId = providerEdiAccount['id']();
});
}
+ displayEdiMessages(providerEdiAccountFields: IdlObject[]) {
+ this.selectedEdiAccountId = providerEdiAccountFields[0].id();
+ this.selectedEdiAccountLabel = providerEdiAccountFields[0].label();
+ this.viewEdiMessages = true;
+ this.changeDetector.detectChanges();
+ this.providerEdiMessagesGrid.reload();
+ }
+
createNew() {
this.editDialog.mode = 'create';
const edi_account = this.idl.create('acqedi');