From 7a837070e6615b8a358da43c1821d9ef4e8f4ff9 Mon Sep 17 00:00:00 2001
From: Dorian Merz <merz@ub.uni-leipzig.de>
Date: Thu, 16 Jan 2020 10:02:05 +0100
Subject: [PATCH] refs #16750 [fid_adlr] SwitchTab recommendation

* adds switch tab side recommendation
* shows short label of selected search tab in dropdown button
* fix translation of button label
* style switchtab recommendation
---
 fid_adlr/config/vufind/searches.ini           |  6 ++++-
 themes/fid_adlr/languages/SearchTabs/de.ini   |  2 ++
 themes/fid_adlr/languages/SearchTabs/en.ini   |  2 ++
 themes/fid_adlr/languages/de.ini              |  6 ++++-
 themes/fid_adlr/languages/en.ini              |  6 ++++-
 themes/fid_adlr/scss/compiled.scss            | 21 +++++++++++++++++
 .../templates/Recommend/SwitchTab.phtml       | 23 +++++++++++++++++++
 .../templates/search/searchTabs.phtml         | 12 ++++++++--
 .../fid_adlr/templates/search/searchbox.phtml |  2 +-
 9 files changed, 74 insertions(+), 6 deletions(-)
 create mode 100644 themes/fid_adlr/languages/SearchTabs/de.ini
 create mode 100644 themes/fid_adlr/languages/SearchTabs/en.ini
 create mode 100644 themes/fid_adlr/templates/Recommend/SwitchTab.phtml

diff --git a/fid_adlr/config/vufind/searches.ini b/fid_adlr/config/vufind/searches.ini
index 016ae576851..191a8d938fd 100644
--- a/fid_adlr/config/vufind/searches.ini
+++ b/fid_adlr/config/vufind/searches.ini
@@ -60,4 +60,8 @@ side[] = "SideFacets:Results:CheckboxFacets"
 
 [General]
 highlighting = false
-snippets = false
\ No newline at end of file
+snippets = false
+
+[SideRecommendations]
+AllFields[] = SwitchTab
+AllFields[] = SideFacets:Results:CheckboxFacets
\ No newline at end of file
diff --git a/themes/fid_adlr/languages/SearchTabs/de.ini b/themes/fid_adlr/languages/SearchTabs/de.ini
new file mode 100644
index 00000000000..53260275c54
--- /dev/null
+++ b/themes/fid_adlr/languages/SearchTabs/de.ini
@@ -0,0 +1,2 @@
+AV Media = AV
+Releases = Neu
\ No newline at end of file
diff --git a/themes/fid_adlr/languages/SearchTabs/en.ini b/themes/fid_adlr/languages/SearchTabs/en.ini
new file mode 100644
index 00000000000..2ec012f8cb1
--- /dev/null
+++ b/themes/fid_adlr/languages/SearchTabs/en.ini
@@ -0,0 +1,2 @@
+AV Media = AV
+Releases = New
\ No newline at end of file
diff --git a/themes/fid_adlr/languages/de.ini b/themes/fid_adlr/languages/de.ini
index 724a9df7ad2..e81a0b2f5c4 100644
--- a/themes/fid_adlr/languages/de.ini
+++ b/themes/fid_adlr/languages/de.ini
@@ -84,4 +84,8 @@ From = "Von (E-Mail-Adresse)"
 To = "An (E-Mail-Adresse)"
 Email Record = "Diesen Eintrag als E-Mail versenden"
 email_record_information = "Sie können diesen Datensatz hier per E-Mail versenden. Optional können Sie eine Nachricht hinzufügen."
-email_search_information = "Sie können hier die aktuelle Suche per E-Mail versenden. Optional können Sie eine Nachricht hinzufügen."
\ No newline at end of file
+email_search_information = "Sie können hier die aktuelle Suche per E-Mail versenden. Optional können Sie eine Nachricht hinzufügen."
+
+#16750 SwitchTab recommendation
+nohit_change_tab = Sie haben nur in der Kategorie <b>%%activeTab%%</b> gesucht. Wählen Sie bei Bedarf eine andere Kategorie oder nutzen Sie die Facettierung:
+switchtab_headline = "Kategorie"
\ No newline at end of file
diff --git a/themes/fid_adlr/languages/en.ini b/themes/fid_adlr/languages/en.ini
index 96efff26a58..d0cebc5d06f 100644
--- a/themes/fid_adlr/languages/en.ini
+++ b/themes/fid_adlr/languages/en.ini
@@ -86,4 +86,8 @@ From = "From (Email address)"
 To = "To (Email address)"
 Email Record = "E-Mail this Record"
 email_record_information = "Here you can send the current record by e-mail. Optionally you can add a message."
-email_search_information = "Here you can send the current search by e-mail. Optionally you can add a message."
\ No newline at end of file
+email_search_information = "Here you can send the current search by e-mail. Optionally you can add a message."
+
+#16750 SwitchTab recommendation
+nohit_change_tab = You have searched only in the category <b>%%activeTab%%</b>. If necessary, choose another category or use the faceting:
+switchtab_headline = "Category"
\ No newline at end of file
diff --git a/themes/fid_adlr/scss/compiled.scss b/themes/fid_adlr/scss/compiled.scss
index 2b737af8ddb..4d1312317a7 100644
--- a/themes/fid_adlr/scss/compiled.scss
+++ b/themes/fid_adlr/scss/compiled.scss
@@ -2942,6 +2942,27 @@ footer {
   margin-left: -.5em;
 }
 
+.switchtab-info {
+  @media (max-width: $screen-xs-max) {
+    display:none;
+  }
+  padding-left: 1em;
+  padding-right: 1em;
+  .switchtab-text, .switchtab-heading, .switchtab-links {
+    padding-top: .75em;
+    padding-bottom: .75em;
+  }
+  .switchtab-text {
+    hyphens: none;
+  }
+  .switchtab-heading {
+    font-family: $font-family-monospace;
+    font-weight: bold;
+    text-decoration: none;
+    text-transform: uppercase;
+  }
+}
+
 .table-responsive {
   @media screen and (max-width: $screen-xs-max) {
     border: 0;
diff --git a/themes/fid_adlr/templates/Recommend/SwitchTab.phtml b/themes/fid_adlr/templates/Recommend/SwitchTab.phtml
new file mode 100644
index 00000000000..2e680d58d11
--- /dev/null
+++ b/themes/fid_adlr/templates/Recommend/SwitchTab.phtml
@@ -0,0 +1,23 @@
+<!-- fid_adlr: Recommend - SwitchTab -->
+<?php
+  $tabConfig = is_object($this->params)
+    ? $this->searchTabs()->getTabConfigForParams($this->params) : [];
+?>
+<?php if (count($tabConfig) > 0): ?>
+  <div class="facet-group switchtab-info flex-column-default">
+        <div class="switchtab-heading"><i class="icon icon-filter2 icon-1.5x" aria-hidden="true"></i>
+        <?=$this->transEsc('switchtab_headline')?></div>
+        <span class="switchtab-text"><?=$this->translate('nohit_change_tab', ['%%activeTab%%' => $this->translate($this->recommend->getActiveTab($tabConfig)['label'])])?></span>
+    <ul class="switchtab-links">
+    <?php $inactiveTabs = $this->recommend->getInactiveTabs($tabConfig); ?>
+    <?php foreach ($inactiveTabs as $tab): ?>
+      <li>
+        <?php if (!$tab['selected']): ?><a href="<?=$this->escapeHtmlAttr($tab['url'])?>"><?php endif; ?>
+          <?=$this->transEsc($tab['label']); ?>
+        <?php if (!$tab['selected']): ?></a><?php endif; ?>
+      </li>
+    <?php endforeach; ?>
+    </ul>
+  </div>
+<?php endif; ?>
+<!-- fid_adlr: Recommend - SwitchTab - END -->
\ No newline at end of file
diff --git a/themes/fid_adlr/templates/search/searchTabs.phtml b/themes/fid_adlr/templates/search/searchTabs.phtml
index 2bae5bf86e2..f42d1321c75 100644
--- a/themes/fid_adlr/templates/search/searchTabs.phtml
+++ b/themes/fid_adlr/templates/search/searchTabs.phtml
@@ -1,11 +1,19 @@
 <!-- fid_adlr: search - searchTabs -->
 <?php $filterDelimiter = ';' ?>
-<?php if (isset($searchTabs) && count($searchTabs) > 0): ?>
+<?php
+    $selectedLabel = "Filter";
+    if (isset($selectedTab)) {
+        $selectedLabel = $this->translate($selectedTab['label']);
+        if (isset($selectedTab['shortLabel'])) {
+            $selectedLabel = $this->translate($selectedTab['shortLabel'],[],$selectedLabel);
+        }
+    }
+    if (isset($searchTabs) && count($searchTabs) > 0): ?>
   <div class="nav nav-tabs">
     <a href="#" class="button-quickfilter-format dropdown-toggle additional-text-lg" id="quickfilter-format"
        data-toggle="dropdown" aria-controls="quickfilter-format-menu" >
       <span class="sr-only">Select format pre-filter</span>
-      &nbsp;Filter<i class="icon icon-caret-down" aria-hidden="true"></i>
+      &nbsp;<?=$selectedLabel?><i class="icon icon-caret-down" aria-hidden="true"></i>
       <!--i class="icon icon-chevron-up" aria-hidden="true"></i-->
     </a>
     <div id="quickfilter-format-menu" class="dropdown-menu" aria-labelledby="quickfilter-format">
diff --git a/themes/fid_adlr/templates/search/searchbox.phtml b/themes/fid_adlr/templates/search/searchbox.phtml
index b943d77e3b5..eb90be31b96 100644
--- a/themes/fid_adlr/templates/search/searchbox.phtml
+++ b/themes/fid_adlr/templates/search/searchbox.phtml
@@ -27,7 +27,7 @@ $hiddenFilterParams = $this->searchTabs()->getCurrentHiddenFilterParams($this->s
 <?php $tabConfig = $this->searchTabs()->getTabConfig($this->searchClassId, $this->lookfor, $this->searchIndex, $this->searchType, $hiddenFilters); ?>
 
   <form id="searchForm" class="searchForm navbar-left flip" method="get" action="<?=$this->url($basicSearch)?>" name="searchForm" autocomplete="off">
-    <?= $this->context($this)->renderInContext('search/searchTabs', ['searchTabs' => $tabConfig['tabs']]); ?>
+    <?= $this->context($this)->renderInContext('search/searchTabs', ['searchTabs' => $tabConfig['tabs'], 'selectedTab' => $tabConfig['selected']]); ?>
     <?php $placeholder = $this->searchbox()->getPlaceholderText($tabConfig['selected']['id'] ?? null); ?>
     <?php /* finc: keep "required" */ ?>
     <input id="searchForm_lookfor" class="searchForm_lookfor form-control search-query<?php if($this->searchbox()->autocompleteEnabled($this->searchClassId)):?> autocomplete searcher:<?=$this->escapeHtmlAttr($this->searchClassId) ?><?=$this->searchbox()->autocompleteAutoSubmit($this->searchClassId) ? ' ac-auto-submit' : '' ?><?php endif ?>" type="text" name="lookfor" value="<?= ($this->searchType != "advanced") ? $this->escapeHtmlAttr($this->lookfor) : ""?>"<?php if ($placeholder): ?> placeholder="<?=$this->transEsc($placeholder) ?>"<?php endif ?> aria-label="<?=$this->transEsc("search_terms")?>" required="required" placeholder="<?=$this->transEsc("enter-search-term")?>" />
-- 
GitLab