LP1913338 Catalog search form visibility stickiness
authorBill Erickson <berickxx@gmail.com>
Thu, 28 Jan 2021 15:32:11 +0000 (10:32 -0500)
committerGalen Charlton <gmc@equinoxOLI.org>
Wed, 26 May 2021 20:14:24 +0000 (16:14 -0400)
On pages in the Angular staff catalog where the search form is collapsed
by default, users may now also manually expand and re-collapse the form.
The last used choice will be sticky via new workstation setting.

Signed-off-by: Bill Erickson <berickxx@gmail.com>
Signed-off-by: Elaine Hardy <ehardy@georgialibraries.org>
Signed-off-by: Chris Sharp <csharp@georgialibraries.org>
Signed-off-by: Gina Monti <gmonti@biblio.org>
Signed-off-by: Galen Charlton <gmc@equinoxOLI.org>

Open-ILS/src/eg2/src/app/staff/catalog/resolver.service.ts
Open-ILS/src/eg2/src/app/staff/catalog/search-form.component.html
Open-ILS/src/eg2/src/app/staff/catalog/search-form.component.ts
Open-ILS/src/sql/Pg/950.data.seed-values.sql
Open-ILS/src/sql/Pg/upgrade/XXXX.data.staffcat-sticky-search-form.sql [new file with mode: 0644]

index e613fb3..5ec91d5 100644 (file)
@@ -56,6 +56,7 @@ export class CatalogResolver implements Resolve<Promise<any[]>> {
             'opac.staff_saved_search.size',
             'opac.search.enable_bookplate_search',
             'eg.staffcat.exclude_electronic',
+            'eg.catalog.search.form.open',
             'circ.staff_placed_holds_fallback_to_ws_ou'
         ]).then(settings => {
             this.staffCat.defaultSearchOrg =
index 244cc21..21a3e4f 100644 (file)
@@ -7,16 +7,21 @@
 
 <div id='staffcat-search-form'>
 
-  <div *ngIf="!showThyself" class="row pt-1 pb-1 mb-2 pr-2">
+  <div *ngIf="canBeHidden()" class="row pt-1 pr-2">
     <div class="col-lg-12 d-flex">
       <div class="flex-1"></div><!-- push right -->
-      <a (click)="showThyself=true" class="label-with-material-icon no-href" i18n>
-        Show Search Form <span class="material-icons">unfold_more</span>
+      <a (click)="toggleFormDisplay()" class="label-with-material-icon no-href">
+        <ng-container *ngIf="hideForm()" i18n>
+          Show Search Form <span class="material-icons">unfold_more</span>
+        </ng-container>
+        <ng-container *ngIf="!hideForm()" i18n>
+          Hide Search Form <span class="material-icons">unfold_less</span>
+        </ng-container>
       </a>
     </div>
   </div>
   
-  <div *ngIf="showThyself" class="row pt-3 pb-1 mb-1">
+  <div *ngIf="!hideForm()" class="row pt-3 pb-1 mb-1">
   <div class="col-lg-8">
     <ngb-tabset #searchTabs [activeId]="searchTab" (tabChange)="onTabChange($event)">
       <ngb-tab title="Keyword Search" i18n-title id="term">
index 6b0e37c..16a124d 100644 (file)
@@ -17,8 +17,8 @@ const LEGACY_TAB_NAME_MAP = {
 
 // Automatically collapse the search form on these pages
 const COLLAPSE_ON_PAGES = [
-    new RegExp(/catalog\/record\//),
-    new RegExp(/catalog\/hold\//)
+    new RegExp(/staff\/catalog\/record\//),
+    new RegExp(/staff\/catalog\/hold\//)
 ];
 
 @Component({
@@ -35,8 +35,10 @@ export class SearchFormComponent implements OnInit, AfterViewInit {
     copyLocations: IdlObject[];
     searchTab: string;
 
-    // Display the full form if true, otherwise display the expandy.
-    showThyself = true;
+    // What does the user want us to do?
+    // On pages where we can be hidded, start out hidden, unless the
+    // user has opted to show us.
+    showSearchFormSetting = false;
 
     constructor(
         private renderer: Renderer2,
@@ -44,10 +46,22 @@ export class SearchFormComponent implements OnInit, AfterViewInit {
         private route: ActivatedRoute,
         private org: OrgService,
         private cat: CatalogService,
+        private store: ServerStoreService,
         private staffCat: StaffCatalogService
     ) {
         this.copyLocations = [];
 
+    }
+
+    ngOnInit() {
+        this.ccvmMap = this.cat.ccvmMap;
+        this.cmfMap = this.cat.cmfMap;
+        this.context = this.staffCat.searchContext;
+
+        // Start with advanced search options open
+        // if any filters are active.
+        this.showSearchFilters = this.filtersActive();
+
         // Some search scenarios, like rendering a search template,
         // will not be searchable and thus not resovle to a specific
         // search tab.  Check to see if a specific tab is requested
@@ -58,26 +72,28 @@ export class SearchFormComponent implements OnInit, AfterViewInit {
             }
         });
 
-        this.router.events.subscribe(routeEvent => {
-            if (routeEvent instanceof NavigationEnd) {
-                this.showThyself = true;
-                COLLAPSE_ON_PAGES.forEach(pageRegex => {
-                    if (routeEvent.url.match(pageRegex)) {
-                        this.showThyself = false;
-                    }
-                });
+        this.store.getItem('eg.catalog.search.form.open')
+        .then(value => this.showSearchFormSetting = value);
+    }
+
+    // Are we on a page where the form is allowed to be collapsed.
+    canBeHidden(): boolean {
+        for (let idx = 0; idx < COLLAPSE_ON_PAGES.length; idx++) {
+            const pageRegex = COLLAPSE_ON_PAGES[idx];
+            if (this.router.url.match(pageRegex)) {
+                return true;
             }
-        });
+        }
+        return false;
     }
 
-    ngOnInit() {
-        this.ccvmMap = this.cat.ccvmMap;
-        this.cmfMap = this.cat.cmfMap;
-        this.context = this.staffCat.searchContext;
+    hideForm(): boolean {
+        return this.canBeHidden() && !this.showSearchFormSetting;
+    }
 
-        // Start with advanced search options open
-        // if any filters are active.
-        this.showSearchFilters = this.filtersActive();
+    toggleFormDisplay() {
+        this.showSearchFormSetting = !this.showSearchFormSetting;
+        this.store.setItem('eg.catalog.search.form.open', this.showSearchFormSetting);
     }
 
     ngAfterViewInit() {
index 85d9ace..3e4ff8d 100644 (file)
@@ -21528,6 +21528,15 @@ VALUES (
     oils_i18n_gettext(
         'eg.orgselect.catalog.holdings',
         'Default org unit for catalog holdings tab',
+    )
+);
+
+INSERT INTO config.workstation_setting_type (name, grp, datatype, label)
+VALUES (
+    'eg.catalog.search.form.open', 'gui', 'bool',
+    oils_i18n_gettext(
+        'eg.catalog.search.form.open',
+        'Catalog Search Form Visibility Sticky Setting',
         'cwst', 'label'
     )
 );
diff --git a/Open-ILS/src/sql/Pg/upgrade/XXXX.data.staffcat-sticky-search-form.sql b/Open-ILS/src/sql/Pg/upgrade/XXXX.data.staffcat-sticky-search-form.sql
new file mode 100644 (file)
index 0000000..be47ba6
--- /dev/null
@@ -0,0 +1,15 @@
+BEGIN;
+
+-- SELECT evergreen.upgrade_deps_block_check('TODO', :eg_version);
+
+INSERT INTO config.workstation_setting_type (name, grp, datatype, label)
+VALUES (
+    'eg.catalog.search.form.open', 'gui', 'bool',
+    oils_i18n_gettext(
+        'eg.catalog.search.form.open',
+        'Catalog Search Form Visibility Sticky Setting',
+        'cwst', 'label'
+    )
+);
+
+COMMIT;