add grid for displaying EDI messages for a selected account
authorGalen Charlton <gmc@equinoxinitiative.org>
Wed, 1 Apr 2020 22:39:49 +0000 (18:39 -0400)
committerGalen Charlton <gmc@equinoxinitiative.org>
Wed, 1 Apr 2020 22:39:49 +0000 (18:39 -0400)
Signed-off-by: Galen Charlton <gmc@equinoxinitiative.org>
Open-ILS/src/eg2/src/app/staff/acq/provider/provider-edi-accounts.component.html
Open-ILS/src/eg2/src/app/staff/acq/provider/provider-edi-accounts.component.ts

index 34e5a31..6e8a3af 100644 (file)
   </eg-grid-toolbar-action>
   <eg-grid-toolbar-action label="Set as Default" i18n-label (onClick)="setAsDefault($event)" [disableOnRows]="notOneSelectedRow">
   </eg-grid-toolbar-action>
+  <eg-grid-toolbar-action label="View EDI Messages" i18n-label (onClick)="displayEdiMessages($event)" [disableOnRows]="notOneSelectedRow">
+  </eg-grid-toolbar-action>
 </eg-grid>
 
+<ng-container *ngIf="viewEdiMessages">
+  <h2 i18n>EDI messages for account {{selectedEdiAccountLabel}}</h2>
+  <eg-grid #acqProviderEdiMessagesGrid
+    persistKey="acq.provider.edi_messages.grid"
+    idlClass="acqedim" [dataSource]="ediMessagesSource"
+    [sortable]="true"
+    [filterable]="true">
+  </eg-grid>
+</ng-container>
+
 <eg-fm-record-editor #editDialog
   idlClass="acqedi"
   readonlyFields="id,provider"
index 365fadd..14490fc 100644 (file)
@@ -1,4 +1,4 @@
-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';
@@ -14,6 +14,7 @@ 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';
 import {ConfirmDialogComponent} from '@eg/share/dialog/confirm.component';
+import {PcrudService} from '@eg/core/pcrud.service';
 
 @Component({
   selector: 'eg-provider-edi-accounts',
@@ -24,8 +25,10 @@ export class ProviderEdiAccountsComponent implements OnInit, AfterViewInit {
     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;
@@ -45,6 +48,10 @@ export class ProviderEdiAccountsComponent implements OnInit, AfterViewInit {
     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.
@@ -54,15 +61,20 @@ export class ProviderEdiAccountsComponent implements OnInit, AfterViewInit {
     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[]) => {
@@ -126,6 +138,39 @@ export class ProviderEdiAccountsComponent implements OnInit, AfterViewInit {
         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']();
@@ -185,6 +230,14 @@ export class ProviderEdiAccountsComponent implements OnInit, AfterViewInit {
         });
     }
 
+    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');