added simple sort to angular catalog to mirror the traditional catalog's method where... user/lew/lp-1950518-simple-sort-master-fix
authorLlewellyn Marshall <llewellyn.marshall@ncdcr.gov>
Fri, 11 Mar 2022 19:42:25 +0000 (14:42 -0500)
committerLlewellyn Marshall <llewellyn.marshall@ncdcr.gov>
Fri, 11 Mar 2022 19:42:25 +0000 (14:42 -0500)
Open-ILS/src/eg2/src/app/staff/catalog/search-form.component.html
Open-ILS/src/eg2/src/app/staff/catalog/search-form.component.ts

index 18bae19..5765383 100644 (file)
@@ -1,15 +1,14 @@
-<ng-template #ccvmOption let-list="list">
-  <ng-container *ngFor="let ccv of list">
-  <option *ngIf="ccv.is_simple() === 't'" value="{{ccv.code()}}">
+<ng-template #ccvmOption let-list="list" let-simple="simple">
+  <option *ngFor="let ccv of simple" value="{{ccv.code()}}">
     {{ccv.search_label() || ccv.value()}}
     <ng-container *ngIf="ccv.opac_visible() === 'f'" i18n>(Hidden)</ng-container>
   </option>
-  </ng-container>
+  <option *ngIf="simple.length && list.length" disabled='true'>-----</option>
   <ng-container *ngFor="let ccv of list">
-  <option *ngIf="ccv.is_simple() === 'f'" value="{{ccv.code()}}">
-    {{ccv.search_label() || ccv.value()}}
-    <ng-container *ngIf="ccv.opac_visible() === 'f'" i18n>(Hidden)</ng-container>
-  </option>
+    <option  *ngIf="ccv.is_simple()  === 'f'" value="{{ccv.code()}}">
+      {{ccv.search_label() || ccv.value()}}
+      <ng-container *ngIf="ccv.opac_visible() === 'f'" i18n>(Hidden)</ng-container>
+    </option>
   </ng-container>
 </ng-template>
 
@@ -42,7 +41,7 @@
                 <select class="form-control" [(ngModel)]="context.termSearch.format">
                   <option i18n value=''>All Formats</option>
                   <ng-container
-                    *ngTemplateOutlet="ccvmOption;context:{list:ccvmMap.search_format}">
+                    *ngTemplateOutlet="ccvmOption;context:{list:ccvmMap.search_format, simple:ccvmSimpleMap.search_format}">
                   </ng-container> 
                 </select>
               </div>
                 [(ngModel)]="context.termSearch.ccvmFilters.item_type">
                 <option value='' i18n>All Item Types</option>
                 <ng-container
-                  *ngTemplateOutlet="ccvmOption;context:{list:ccvmMap.item_type}">
+                  *ngTemplateOutlet="ccvmOption;context:{list:ccvmMap.item_type, simple:ccvmSimpleMap.item_type}">
                 </ng-container> 
               </select>
             </div>
                 [(ngModel)]="context.termSearch.ccvmFilters.item_form">
                 <option value='' i18n>All Item Forms</option>
                 <ng-container
-                  *ngTemplateOutlet="ccvmOption;context:{list:ccvmMap.item_form}">
+                  *ngTemplateOutlet="ccvmOption;context:{list:ccvmMap.item_form, simple:ccvmSimpleMap.item_form}">
                 </ng-container> 
               </select>
             </div>
                 [(ngModel)]="context.termSearch.ccvmFilters.item_lang" multiple="true">
                 <option value='' i18n>All Languages</option>
                 <ng-container
-                  *ngTemplateOutlet="ccvmOption;context:{list:ccvmMap.item_lang}">
+                  *ngTemplateOutlet="ccvmOption;context:{list:ccvmMap.item_lang, simple:ccvmSimpleMap.item_lang}">
                 </ng-container> 
               </select>
             </div>
                 [(ngModel)]="context.termSearch.ccvmFilters.audience" multiple="true">
                 <option value='' i18n>All Audiences</option>
                 <ng-container
-                  *ngTemplateOutlet="ccvmOption;context:{list:ccvmMap.audience}">
+                  *ngTemplateOutlet="ccvmOption;context:{list:ccvmMap.audience, simple:ccvmSimpleMap.audience}">
                 </ng-container> 
               </select>
             </div>
                 [(ngModel)]="context.termSearch.ccvmFilters.vr_format" multiple="true">
                 <option value='' i18n>All Video Formats</option>
                 <ng-container
-                  *ngTemplateOutlet="ccvmOption;context:{list:ccvmMap.vr_format}">
+                  *ngTemplateOutlet="ccvmOption;context:{list:ccvmMap.vr_format, simple:ccvmSimpleMap.vr_format}">
                 </ng-container> 
               </select>
             </div>
                 [(ngModel)]="context.termSearch.ccvmFilters.bib_level" multiple="true">
                 <option value='' i18n>All Bib Levels</option>
                 <ng-container
-                  *ngTemplateOutlet="ccvmOption;context:{list:ccvmMap.bib_level}">
+                  *ngTemplateOutlet="ccvmOption;context:{list:ccvmMap.bib_level, simple:ccvmSimpleMap.bib_level}">
                 </ng-container> 
               </select>
             </div>
                 [(ngModel)]="context.termSearch.ccvmFilters.lit_form" multiple="true">
                 <option value='' i18n>All Literary Forms</option>
                 <ng-container
-                  *ngTemplateOutlet="ccvmOption;context:{list:ccvmMap.lit_form}">
+                  *ngTemplateOutlet="ccvmOption;context:{list:ccvmMap.lit_form, simple:ccvmSimpleMap.lit_form}">
                 </ng-container> 
               </select>
             </div>
index c7d9898..9615b49 100644 (file)
@@ -30,6 +30,7 @@ export class SearchFormComponent implements OnInit, AfterViewInit {
 
     context: CatalogSearchContext;
     ccvmMap: {[ccvm: string]: IdlObject[]} = {};
+    ccvmSimpleMap: {[ccvm: string]: IdlObject[]} = {};
     cmfMap: {[cmf: string]: IdlObject} = {};
     showSearchFilters = false;
     copyLocations: IdlObject[];
@@ -61,6 +62,9 @@ export class SearchFormComponent implements OnInit, AfterViewInit {
         // Start with advanced search options open
         // if any filters are active.
         this.showSearchFilters = this.filtersActive();
+        
+        //create our simple sort list
+        this.CompileSimpleSelector();
 
         // Some search scenarios, like rendering a search template,
         // will not be searchable and thus not resovle to a specific
@@ -312,6 +316,28 @@ export class SearchFormComponent implements OnInit, AfterViewInit {
     searchFilters(): string[] {
         return this.staffCat.searchFilters;
     }
+
+    //filters out CCVMs based on their is_simple attribute
+    CompileSimpleSelector(): void {
+        Object.keys(this.ccvmMap).forEach(cType => {
+            if (!this.ccvmSimpleMap[cType]) {
+                //creates simple sort list even if there might be no entries
+                this.ccvmSimpleMap[cType] = [];
+            }
+        this.ccvmMap[cType].forEach(ccvm => {
+              if(ccvm.is_simple() === 't'){
+                  //push the is_simple ccvms to the simple map
+                  this.ccvmSimpleMap[cType].push(ccvm);
+              }});
+        });
+        //order the simple sort list
+        Object.keys(this.ccvmSimpleMap).forEach(cType => {
+            this.ccvmSimpleMap[cType] =
+                this.ccvmSimpleMap[cType].sort((a, b) => {
+                    return a.value() < b.value() ? -1 : 1;
+                });
+        });
+    }
 }