WIP: start work on hooking up grid filters
authorGalen Charlton <gmc@equinoxinitiative.org>
Wed, 13 Nov 2019 23:13:46 +0000 (18:13 -0500)
committerGalen Charlton <gmc@equinoxinitiative.org>
Thu, 16 Jan 2020 21:38:28 +0000 (16:38 -0500)
Notes:

- changed provider.name to provider
- need to do more fleshing of linked user fields
  on the line item grid
- need to figure out how to completely suppress certain
  columns from grid display (e.g., LI MARC, although I
  could envision a later widget that pops up a human-readable
  view)
- Wish typescript or Angular had a native deep copy
  of nested properties.

Signed-off-by: Galen Charlton <gmc@equinoxinitiative.org>
Open-ILS/src/eg2/src/app/staff/acq/search/acq-search.service.ts
Open-ILS/src/eg2/src/app/staff/acq/search/lineitem-results.component.html

index 45ea4e3..140b29c 100644 (file)
@@ -61,6 +61,10 @@ const searchOptions = {
     }
 };
 
+const operatorMap = {
+    "=": "",
+}
+
 @Injectable()
 export class AcqSearchService {
 
@@ -70,10 +74,29 @@ export class AcqSearchService {
     ) {
     }
 
+    generateAcqSearch(searchType, filters): any {
+        const baseSearch = JSON.parse(JSON.stringify(defaultSearch[searchType])); // deep copy
+        Object.keys(filters).forEach(filterField => {
+            const coreRecType = Object.keys(defaultSearch[searchType])[0];
+            const filterOp = Object.keys(filters[filterField][0][filterField])[0];
+            const filterVal = filters[filterField][0][filterField][filterOp];
+
+            const searchTerm: Object = {};
+            searchTerm[filterField] = filterVal;
+            searchTerm[operatorMap[filterOp]] = true;
+            baseSearch[coreRecType].push(searchTerm);
+        });
+        console.debug(baseSearch);
+        return baseSearch;
+    }
+
     getAcqSearchDataSource(searchType: string): GridDataSource {
         const gridSource = new GridDataSource();
 
         gridSource.getRows = (pager: Pager) => {
+
+            const currentSearch = this.generateAcqSearch(searchType, gridSource.filters);
+
             const opts = { ...searchOptions[searchType] };
             opts['offset'] = pager.offset;
             opts['limit'] = pager.limit;
@@ -81,7 +104,7 @@ export class AcqSearchService {
                 'open-ils.acq',
                 'open-ils.acq.' + searchType + '.unified_search',
                     this.auth.token(),
-                    defaultSearch[searchType],
+                    currentSearch,
                     null,
                     null,
                     opts
index 3a6c81d..07091e5 100644 (file)
   persistKey="acq.search.lineitems"
   idlClass="jub" [dataSource]="gridSource"
   [stickyHeader]="true"
+  [filterable]="true"
   [showDeclaredFieldsOnly]="true">
 
   <eg-grid-column path="id" [cellTemplate]="idTmpl" [disableTooltip]="true"></eg-grid-column>
   <eg-grid-column i18n-label label="Title" path="title" [cellTemplate]="liAttrTmpl"></eg-grid-column>
   <eg-grid-column i18n-label label="Author" path="author" [cellTemplate]="liAttrTmpl"></eg-grid-column>
-  <eg-grid-column path="provider.name" [cellTemplate]="providerTmpl"></eg-grid-column>
-  <eg-grid-column i18n-label label="Links" path="_links" [cellTemplate]="liLinksTmpl" [disableTooltip]="true"></eg-grid-column>
+  <eg-grid-column path="provider" [cellTemplate]="providerTmpl"></eg-grid-column>
+  <eg-grid-column i18n-label label="Links" path="_links" [cellTemplate]="liLinksTmpl" [disableTooltip]="true" [filterable]="false"></eg-grid-column>
   <eg-grid-column path="claim_policy.name"></eg-grid-column>
   <eg-grid-column i18n-label label="Status" path="state" [disableTooltip]="true"></eg-grid-column>
   <eg-grid-column path="estimated_unit_price" [disableTooltip]="true"></eg-grid-column>