LP#1849212 Angular Search Course Material Facet
authorZavier Banks <zbanks@catalyte.io>
Thu, 21 Nov 2019 22:54:46 +0000 (22:54 +0000)
committerKyle Huckins <khuckins@catalyte.io>
Thu, 21 Nov 2019 22:58:43 +0000 (22:58 +0000)
I added a course material facet that allows you
to filter the records of a library, based on if
they are associated with a course.

Signed-off-by: Zavier Banks <zbanks@catalyte.io>
Open-ILS/src/eg2/src/app/share/catalog/catalog-url.service.ts
Open-ILS/src/eg2/src/app/share/catalog/catalog.service.ts
Open-ILS/src/eg2/src/app/share/catalog/search-context.ts
Open-ILS/src/eg2/src/app/staff/catalog/search-form.component.html

index 4c45a4e..b4d0ad5 100644 (file)
@@ -82,7 +82,7 @@ export class CatalogUrlService {
             params.matchOp = [];
 
             ['format', 'available', 'hasBrowseEntry', 'date1',
-                'date2', 'dateOp', 'groupByMetarecord', 'fromMetarecord']
+                'date2', 'dateOp', 'groupByMetarecord', 'fromMetarecord', 'isCourseFiltered']
             .forEach(field => {
                 if (ts[field]) {
                     params[field] = ts[field];
@@ -223,6 +223,18 @@ export class CatalogUrlService {
                 }
             });
 
+            //Booleans
+            ['isCourseFiltered'].forEach(field =>{
+                if(params.has(field)){
+                    if(params.get(field) == "true" || params.get(field)){
+                        ts[field] = true;
+                    }
+                    if(params.get(field) == "false" || !params.get(field)){
+                        ts[field] = false;
+                    }
+                }
+            });
+
             // Arrays
             ['query', 'fieldClass', 'joinOp', 'matchOp'].forEach(field => {
                 const arr = params.getAll(field);
@@ -245,6 +257,4 @@ export class CatalogUrlService {
             }
         }
     }
-}
-
-
+}
\ No newline at end of file
index 2aaaf1f..8af653e 100644 (file)
@@ -26,6 +26,7 @@ export class CatalogService {
 
     // Allow anyone to watch for completed searches.
     onSearchComplete: EventEmitter<CatalogSearchContext>;
+    course_filtered_query: any;
 
     constructor(
         private idl: IdlService,
@@ -37,12 +38,12 @@ export class CatalogService {
         private basket: BasketService
     ) {
         this.onSearchComplete = new EventEmitter<CatalogSearchContext>();
-
+        this.retrieveCourseMaterials();
     }
 
     search(ctx: CatalogSearchContext): Promise<void> {
         ctx.searchState = CatalogSearchState.SEARCHING;
-
+        
         if (ctx.showBasket) {
             return this.basketSearch(ctx);
         } else if (ctx.marcSearch.isSearchable()) {
@@ -109,10 +110,8 @@ export class CatalogService {
     }
 
     termSearch(ctx: CatalogSearchContext): Promise<void> {
-
         let method = 'open-ils.search.biblio.multiclass.query';
         let fullQuery;
-
         if (ctx.identSearch.isSearchable()) {
             fullQuery = ctx.compileIdentSearchQuery();
 
@@ -128,13 +127,19 @@ export class CatalogService {
                 this.fetchBrowseEntry(ctx);
             }
         }
-
         console.debug(`search query: ${fullQuery}`);
-
         if (ctx.isStaff) {
             method += '.staff';
         }
+        if(ctx.termSearch.isCourseFiltered){
+            return this.netRequest(ctx, method, fullQuery + this.course_filtered_query +")");//Pass the course filter, combined with the full query
+        }else{
+           return this.netRequest(ctx, method, fullQuery);
+        }
+        
+    }
 
+    netRequest(ctx, method, fullQuery): Promise<void> {
         return new Promise((resolve, reject) => {
             this.net.request(
                 'open-ils.search', method, {
@@ -142,14 +147,34 @@ export class CatalogService {
                     offset : ctx.pager.offset
                 }, fullQuery, true
             ).subscribe(result => {
-                this.applyResultData(ctx, result);
+                if(ctx.termSearch.isCourseFiltered){
+                    this.applyResultData(ctx, result)
+                }
+                else{
+                    this.applyResultData(ctx, result)
+                }
                 ctx.searchState = CatalogSearchState.COMPLETE;
                 this.onSearchComplete.emit(ctx);
                 resolve();
             });
         });
-
     }
+    
+    /**
+     * Retrieves course materials info, and adds the ids of the course books to a filter.
+     */
+    retrieveCourseMaterials(){
+        this.course_filtered_query = " (";
+        var index = 0;
+        this.pcrud.retrieveAll("acmcm").subscribe(result =>{
+            if(index==0){
+                this.course_filtered_query += '(id:'+ result.item()+')'
+            }
+            this.course_filtered_query += ' || (id:'+ result.item()+')'
+            index++;
+        });
+    }
+
 
     // When showing titles linked to a browse entry, fetch
     // the entry data as well so the UI can display it.
index 041d710..5f6c770 100644 (file)
@@ -189,6 +189,7 @@ export class CatalogTermContext {
     ccvmFilters: {[ccvmCode: string]: string[]};
     facetFilters: FacetFilter[];
     copyLocations: string[]; // ID's, but treated as strings in the UI.
+    isCourseFiltered:boolean;
 
     // True when searching for metarecords
     groupByMetarecord: boolean;
@@ -215,6 +216,7 @@ export class CatalogTermContext {
         this.date2 = null;
         this.dateOp = 'is';
         this.fromMetarecord = null;
+        this.isCourseFiltered = false;
 
         // Apply empty string values for each ccvm filter
         this.ccvmFilters = {};
@@ -235,6 +237,7 @@ export class CatalogTermContext {
         ctx.date2 = this.date2;
         ctx.dateOp = this.dateOp;
         ctx.fromMetarecord = this.fromMetarecord;
+        ctx.isCourseFiltered =this.isCourseFiltered;
 
         ctx.facetFilters = this.facetFilters.map(f => f.clone());
 
index d032f3d..a2ef565 100644 (file)
@@ -123,6 +123,14 @@ TODO focus search input
                     <span class="pl-1" i18n>Results from All Libraries</span>
                   </label>
                 </div>
+                <div class="checkbox pl-3">
+                <!-- Course Reserve Search -->
+                  <label>
+                    <input type="checkbox" [(ngModel)]="context.termSearch.isCourseFiltered"/>
+                    <span class="pl-1" i18n>Filter With Course Reserves?</span>
+                  </label>
+                <!-- Course Reserve Search -->
+                </div>
               </div>
           </div>
           <div class="row mt-3" *ngIf="showFilters()">