first pass at AcqSearchService
authorGalen Charlton <gmc@equinoxinitiative.org>
Fri, 1 Nov 2019 15:16:26 +0000 (11:16 -0400)
committerGalen Charlton <gmc@equinoxinitiative.org>
Thu, 16 Jan 2020 21:38:28 +0000 (16:38 -0500)
This adds AcqSearchService, which knows how to produce
a GridDataSource of the appropriate type and default
search parameters and options. This also adds results
components for purchase orders, invoices, and selection lists.
Note that the new results components don't customize
the columns that are displayed.

AcqSearchService is intentionally _not_ set up as a singleton,
and instead is used as a provider by the four results components.
This can be changed if a reason turns up later to have the service
retain some state for the duration of the application session
(as opposed to the duration of the results component; note that this
may mean that the results component will need to embed the search
form component so that it can readily share the grid data source
with it).

Signed-off-by: Galen Charlton <gmc@equinoxinitiative.org>
Open-ILS/src/eg2/src/app/staff/acq/search/acq-search.component.html
Open-ILS/src/eg2/src/app/staff/acq/search/acq-search.component.ts
Open-ILS/src/eg2/src/app/staff/acq/search/acq-search.module.ts
Open-ILS/src/eg2/src/app/staff/acq/search/acq-search.service.ts [new file with mode: 0644]
Open-ILS/src/eg2/src/app/staff/acq/search/invoice-results.component.html [new file with mode: 0644]
Open-ILS/src/eg2/src/app/staff/acq/search/invoice-results.component.ts [new file with mode: 0644]
Open-ILS/src/eg2/src/app/staff/acq/search/lineitem-results.component.ts
Open-ILS/src/eg2/src/app/staff/acq/search/picklist-results.component.html [new file with mode: 0644]
Open-ILS/src/eg2/src/app/staff/acq/search/picklist-results.component.ts [new file with mode: 0644]
Open-ILS/src/eg2/src/app/staff/acq/search/purchase-order-results.component.html [new file with mode: 0644]
Open-ILS/src/eg2/src/app/staff/acq/search/purchase-order-results.component.ts [new file with mode: 0644]

index 43439ae..d1d43ee 100644 (file)
         <ng-template ngbTabContent><eg-lineitem-results></eg-lineitem-results></ng-template>
       </ngb-tab>
       <ngb-tab title="Purchase Orders Search" i18n-title id="purchaseorders">
+        <ng-template ngbTabContent><eg-purchase-order-results></eg-purchase-order-results></ng-template>
       </ngb-tab>
       <ngb-tab title="Invoices Search" i18n-title id="invoices">
+        <ng-template ngbTabContent><eg-invoice-results></eg-invoice-results></ng-template>
       </ngb-tab>
       <ngb-tab title="Selection Lists Search" i18n-title id="selectionlists">
+        <ng-template ngbTabContent><eg-picklist-results></eg-picklist-results></ng-template>
       </ngb-tab>
     </ngb-tabset>
   </div>
index f294a10..9e92d5b 100644 (file)
@@ -3,6 +3,9 @@ import {NgbTabset, NgbTabChangeEvent} from '@ng-bootstrap/ng-bootstrap';
 import {Router, ActivatedRoute} from '@angular/router';
 import {StaffCommonModule} from '@eg/staff/common.module';
 import {LineitemResultsComponent} from './lineitem-results.component';
+import {PurchaseOrderResultsComponent} from './purchase-order-results.component';
+import {InvoiceResultsComponent} from './invoice-results.component';
+import {PicklistResultsComponent} from './picklist-results.component';
 
 @Component({
   templateUrl: './acq-search.component.html'
index b0d73e8..85515ba 100644 (file)
@@ -3,16 +3,22 @@ import {StaffCommonModule} from '@eg/staff/common.module';
 import {AcqSearchRoutingModule} from './routing.module';
 import {AcqSearchComponent} from './acq-search.component';
 import {LineitemResultsComponent} from './lineitem-results.component';
+import {PurchaseOrderResultsComponent} from './purchase-order-results.component';
+import {InvoiceResultsComponent} from './invoice-results.component';
+import {PicklistResultsComponent} from './picklist-results.component';
 
 @NgModule({
   declarations: [
     AcqSearchComponent,
-    LineitemResultsComponent
+    LineitemResultsComponent,
+    PurchaseOrderResultsComponent,
+    InvoiceResultsComponent,
+    PicklistResultsComponent
   ],
   imports: [
     StaffCommonModule,
     AcqSearchRoutingModule
-  ],
+  ]
 })
 
 export class AcqSearchModule {
diff --git a/Open-ILS/src/eg2/src/app/staff/acq/search/acq-search.service.ts b/Open-ILS/src/eg2/src/app/staff/acq/search/acq-search.service.ts
new file mode 100644 (file)
index 0000000..dbe224c
--- /dev/null
@@ -0,0 +1,85 @@
+import {Injectable} from '@angular/core';
+import {NetService} from '@eg/core/net.service';
+import {AuthService} from '@eg/core/auth.service';
+import {GridDataSource} from '@eg/share/grid/grid';
+import {Pager} from '@eg/share/util/pager';
+
+// TODO: replace with search parameters coming from
+//       search form and grid filters
+const defaultSearch = {
+    lineitem: {
+        jub: [{
+            id: "0",
+            __gte: true
+        }]
+    },
+    purchase_order: {
+        acqpo: [{
+            id: "0",
+            __gte: true
+        }]
+    },
+    picklist: {
+        acqpl: [{
+            id: "0",
+            __gte: true
+        }]
+    },
+    invoice: {
+        acqinv: [{
+            id: "0",
+            __gte: true
+        }]
+    },
+}
+
+const searchOptions = {
+    lineitem: {
+        flesh_attrs: true,
+        flesh_cancel_reason: true,
+        flesh_notes: true,
+        flesh_provider: true,
+        flesh_claim_policy: true,
+        flesh_queued_record: true,
+    },
+    purchase_order: {
+        no_flesh_cancel_reason: true,
+    },
+    picklist: {
+        flesh_lineitem_count: true,
+        flesh_owner: true
+    },
+    invoice: {
+        no_flesh_misc: true
+    }
+};
+
+@Injectable()
+export class AcqSearchService {
+
+    constructor(
+        private net: NetService,
+        private auth: AuthService
+    ) {
+    }
+
+    getAcqSearchDataSource(searchType: string): GridDataSource {
+        let gridSource = new GridDataSource();
+
+        gridSource.getRows = (pager: Pager) => {
+            let opts = { ...searchOptions[searchType] };
+            opts['offset'] = pager.offset;
+            opts['limit'] = pager.limit;
+            return this.net.request(
+                'open-ils.acq',
+                'open-ils.acq.' + searchType + '.unified_search',
+                    this.auth.token(),
+                    defaultSearch[searchType],
+                    null,
+                    null,
+                    opts
+            );
+        };
+        return gridSource;
+    }
+}
diff --git a/Open-ILS/src/eg2/src/app/staff/acq/search/invoice-results.component.html b/Open-ILS/src/eg2/src/app/staff/acq/search/invoice-results.component.html
new file mode 100644 (file)
index 0000000..fd8b592
--- /dev/null
@@ -0,0 +1,4 @@
+<eg-grid #acqSearchInvoicesGrid
+  persistKey="acq.search.invoices"
+  idlClass="acqinv" [dataSource]="gridSource">
+</eg-grid>
diff --git a/Open-ILS/src/eg2/src/app/staff/acq/search/invoice-results.component.ts b/Open-ILS/src/eg2/src/app/staff/acq/search/invoice-results.component.ts
new file mode 100644 (file)
index 0000000..d06c90d
--- /dev/null
@@ -0,0 +1,35 @@
+import {Component, OnInit, ViewChild} from '@angular/core';
+import {Observable} from 'rxjs';
+import {map} from 'rxjs/operators';
+import {Router, ActivatedRoute, ParamMap} from '@angular/router';
+import {Pager} from '@eg/share/util/pager';
+import {IdlObject} from '@eg/core/idl.service';
+import {NetService} from '@eg/core/net.service';
+import {AuthService} from '@eg/core/auth.service';
+import {GridComponent} from '@eg/share/grid/grid.component';
+import {GridDataSource} from '@eg/share/grid/grid';
+import {AcqSearchService} from './acq-search.service';
+
+@Component({
+  selector: 'eg-invoice-results',
+  templateUrl: 'invoice-results.component.html',
+  providers: [AcqSearchService]
+})
+export class InvoiceResultsComponent {
+
+    gridSource: GridDataSource;
+    @ViewChild('acqSearchInvoicesGrid', { static: true }) invoiceResultsGrid: GridComponent;
+
+    constructor(
+        private router: Router,
+        private route: ActivatedRoute,
+        private net: NetService,
+        private auth: AuthService,
+        private acqSearch: AcqSearchService) {
+    }
+
+    ngOnInit() {
+        this.gridSource = this.acqSearch.getAcqSearchDataSource('invoice');
+    }
+
+}
index ba63b50..fa96b96 100644 (file)
@@ -8,10 +8,12 @@ import {NetService} from '@eg/core/net.service';
 import {AuthService} from '@eg/core/auth.service';
 import {GridComponent} from '@eg/share/grid/grid.component';
 import {GridDataSource} from '@eg/share/grid/grid';
+import {AcqSearchService} from './acq-search.service';
 
 @Component({
   selector: 'eg-lineitem-results',
-  templateUrl: 'lineitem-results.component.html'
+  templateUrl: 'lineitem-results.component.html',
+  providers: [AcqSearchService]
 })
 export class LineitemResultsComponent {
 
@@ -22,35 +24,12 @@ export class LineitemResultsComponent {
         private router: Router,
         private route: ActivatedRoute,
         private net: NetService,
-        private auth: AuthService) {
-
-        this.gridSource = new GridDataSource();
+        private auth: AuthService,
+        private acqSearch: AcqSearchService) {
+    }
 
-        this.gridSource.getRows = (pager: Pager) => {
-            return this.net.request(
-                'open-ils.acq',
-                'open-ils.acq.lineitem.unified_search',
-                    this.auth.token(),
-                    {
-                        jub: [{
-                            id: "0",
-                            __gte: true
-                        }]
-                    },
-                    null,
-                    null,
-                    {
-                        flesh_attrs: true,
-                        flesh_cancel_reason: true,
-                        flesh_notes: true,
-                        flesh_provider: true,
-                        flesh_claim_policy: true,
-                        flesh_queued_record: true,
-                        offset: pager.offset,
-                        limit: pager.limit
-                    }
-            );
-        };
+    ngOnInit() {
+        this.gridSource = this.acqSearch.getAcqSearchDataSource('lineitem');
     }
 
 }
diff --git a/Open-ILS/src/eg2/src/app/staff/acq/search/picklist-results.component.html b/Open-ILS/src/eg2/src/app/staff/acq/search/picklist-results.component.html
new file mode 100644 (file)
index 0000000..fab0164
--- /dev/null
@@ -0,0 +1,4 @@
+<eg-grid #acqSearchPicklistsGrid
+  persistKey="acq.search.selectionlists"
+  idlClass="acqpl" [dataSource]="gridSource">
+</eg-grid>
diff --git a/Open-ILS/src/eg2/src/app/staff/acq/search/picklist-results.component.ts b/Open-ILS/src/eg2/src/app/staff/acq/search/picklist-results.component.ts
new file mode 100644 (file)
index 0000000..cfd2634
--- /dev/null
@@ -0,0 +1,35 @@
+import {Component, OnInit, ViewChild} from '@angular/core';
+import {Observable} from 'rxjs';
+import {map} from 'rxjs/operators';
+import {Router, ActivatedRoute, ParamMap} from '@angular/router';
+import {Pager} from '@eg/share/util/pager';
+import {IdlObject} from '@eg/core/idl.service';
+import {NetService} from '@eg/core/net.service';
+import {AuthService} from '@eg/core/auth.service';
+import {GridComponent} from '@eg/share/grid/grid.component';
+import {GridDataSource} from '@eg/share/grid/grid';
+import {AcqSearchService} from './acq-search.service';
+
+@Component({
+  selector: 'eg-picklist-results',
+  templateUrl: 'picklist-results.component.html',
+  providers: [AcqSearchService]
+})
+export class PicklistResultsComponent {
+
+    gridSource: GridDataSource;
+    @ViewChild('acqSearchPicklistsGrid', { static: true }) picklistResultsGrid: GridComponent;
+
+    constructor(
+        private router: Router,
+        private route: ActivatedRoute,
+        private net: NetService,
+        private auth: AuthService,
+        private acqSearch: AcqSearchService) {
+    }
+
+    ngOnInit() {
+        this.gridSource = this.acqSearch.getAcqSearchDataSource('picklist');
+    }
+
+}
diff --git a/Open-ILS/src/eg2/src/app/staff/acq/search/purchase-order-results.component.html b/Open-ILS/src/eg2/src/app/staff/acq/search/purchase-order-results.component.html
new file mode 100644 (file)
index 0000000..87e768e
--- /dev/null
@@ -0,0 +1,4 @@
+<eg-grid #acqSearchPurchaseOrdersGrid
+  persistKey="acq.search.purchaseorders"
+  idlClass="acqpo" [dataSource]="gridSource">
+</eg-grid>
diff --git a/Open-ILS/src/eg2/src/app/staff/acq/search/purchase-order-results.component.ts b/Open-ILS/src/eg2/src/app/staff/acq/search/purchase-order-results.component.ts
new file mode 100644 (file)
index 0000000..dcb1d24
--- /dev/null
@@ -0,0 +1,35 @@
+import {Component, OnInit, ViewChild} from '@angular/core';
+import {Observable} from 'rxjs';
+import {map} from 'rxjs/operators';
+import {Router, ActivatedRoute, ParamMap} from '@angular/router';
+import {Pager} from '@eg/share/util/pager';
+import {IdlObject} from '@eg/core/idl.service';
+import {NetService} from '@eg/core/net.service';
+import {AuthService} from '@eg/core/auth.service';
+import {GridComponent} from '@eg/share/grid/grid.component';
+import {GridDataSource} from '@eg/share/grid/grid';
+import {AcqSearchService} from './acq-search.service';
+
+@Component({
+  selector: 'eg-purchase-order-results',
+  templateUrl: 'purchase-order-results.component.html',
+  providers: [AcqSearchService]
+})
+export class PurchaseOrderResultsComponent {
+
+    gridSource: GridDataSource;
+    @ViewChild('acqSearchPurchaseOrdersGrid', { static: true }) purchaseOrderResultsGrid: GridComponent;
+
+    constructor(
+        private router: Router,
+        private route: ActivatedRoute,
+        private net: NetService,
+        private auth: AuthService,
+        private acqSearch: AcqSearchService) {
+    }
+
+    ngOnInit() {
+        this.gridSource = this.acqSearch.getAcqSearchDataSource('purchase_order');
+    }
+
+}