LP#1806087 Catalog pub date filter
authorBill Erickson <berickxx@gmail.com>
Tue, 11 Dec 2018 01:33:44 +0000 (20:33 -0500)
committerBill Erickson <berickxx@gmail.com>
Mon, 7 Jan 2019 14:58:44 +0000 (09:58 -0500)
Signed-off-by: Bill Erickson <berickxx@gmail.com>
Open-ILS/src/eg2/src/app/share/catalog/catalog-url.service.ts
Open-ILS/src/eg2/src/app/share/catalog/search-context.ts
Open-ILS/src/eg2/src/app/staff/catalog/browse.component.ts
Open-ILS/src/eg2/src/app/staff/catalog/search-form.component.html

index 42432ee..ff1d773 100644 (file)
@@ -80,17 +80,12 @@ export class CatalogUrlService {
             params.joinOp = [];
             params.matchOp = [];
 
-            if (ts.format) {
-                params.format = ts.format;
-            }
-
-            if (ts.available) {
-                params.available = ts.available;
-            }
-
-            if (ts.hasBrowseEntry) {
-                params.hasBrowseEntry = ts.hasBrowseEntry;
-            }
+            ['format', 'available', 'hasBrowseEntry', 'date1', 'date2', 'dateOp']
+            .forEach(field => {
+                if (ts[field]) {
+                    params[field] = ts[field];
+                }
+            });
 
             ts.query.forEach((val, idx) => {
                 if (val !== '') {
@@ -192,22 +187,26 @@ export class CatalogUrlService {
         const ts = context.termSearch;
 
         if (params.has('hasBrowseEntry')) {
+
+            // Browse entry display is (currently) a standalone filter.
+            // Other filters could be applied if needed.
             ts.hasBrowseEntry = params.get('hasBrowseEntry');
 
         } else if (params.has('query')) {
 
-            if (params.has('format')) {
-                ts.format = params.get('format');
-            }
-
-            if (params.get('available')) {
-                ts.available = Boolean(params.get('available'));
-            }
+            // Scalars
+            ['format', 'available', 'date1', 'date2', 'dateOp']
+            .forEach(field => {
+                if (params.has(field)) {
+                    ts[field] = params.get(field);
+                }
+            });
 
+            // Arrays
             ['query', 'fieldClass', 'joinOp', 'matchOp'].forEach(field => {
                 const arr = params.getAll(field);
                 if (params.has(field)) {
-                    ts[field] = params.getAll(field); // array
+                    ts[field] = params.getAll(field); 
                 }
             });
 
index 51aa72d..64698a4 100644 (file)
@@ -109,6 +109,9 @@ export class CatalogTermContext {
     copyLocations: string[]; // ID's, but treated as strings in the UI.
     isMetarecord: boolean; // TODO
     hasBrowseEntry: string; // "entryId,fieldId"
+    date1: number;
+    date2: number;
+    dateOp: string; // before, after, between, is
 
     reset() {
         this.query = [''];
@@ -120,6 +123,9 @@ export class CatalogTermContext {
         this.copyLocations = [''];
         this.format = '';
         this.hasBrowseEntry = '';
+        this.date1 = null;
+        this.date2 = null;
+        this.dateOp = 'is';
     }
 
     isSearchable(): boolean {
@@ -152,7 +158,6 @@ export class CatalogTermContext {
             this.facetFilters.push(facet);
         }
     }
-
 }
 
 
@@ -356,6 +361,24 @@ export class CatalogSearchContext {
             str += ' sort(' + parts[0] + ')';
         }
 
+        if (ts.date1 && ts.dateOp) {
+            switch (ts.dateOp) {
+                case 'is':
+                    str += ` date1(${ts.date1})`;
+                    break;
+                case 'before':
+                    str += ` before(${ts.date1})`;
+                    break;
+                case 'after':
+                    str += ` after(${ts.date1})`;
+                    break;
+                case 'between':
+                    if (ts.date2) {
+                        str += ` between(${ts.date1},${ts.date2})`;
+                    }
+            }
+        }
+
         // -------
         // Compile boolean sub-query components
         if (str.length) { str += ' '; }
index 41bf67a..67e5eed 100644 (file)
@@ -24,7 +24,5 @@ export class BrowseComponent implements OnInit {
 
         this.searchForm.searchTab = 'browse';
     }
-
-    ngAfterViewInit() {
 }
 
index 34e11f7..8b6cc8c 100644 (file)
@@ -194,6 +194,24 @@ TODO focus search input
               </select>
             </div>
           </div>
+          <div class="row mt-3" *ngIf="showFilters()">
+            <div class="col-lg-12">
+              <div class="form-inline" i18n>
+                <label for="pub-date1-input">Publication Year is</label>
+                <select class="form-control ml-2" [(ngModel)]="context.termSearch.dateOp">
+                  <option value='is'>Is</option>
+                  <option value='before'>Before</option>
+                  <option value='after'>After</option>
+                  <option value='between'>Between</option>
+                </select>
+                <input class="form-control ml-2" type="number"
+                  [(ngModel)]="context.termSearch.date1"/>
+                <input class="form-control ml-2" type="number"
+                  *ngIf="context.termSearch.dateOp == 'between'"
+                  [(ngModel)]="context.termSearch.date2"/>
+              </div>
+            </div>
+          </div>
         </ng-template>
       </ngb-tab>
       <ngb-tab title="Numeric Search" i18n-title id="ident">