From cb12d0f66cfb9b39a30d7f48a15e9ebf41d66457 Mon Sep 17 00:00:00 2001
From: gloas <gloas@afi-sa.fr>
Date: Tue, 7 Mar 2017 11:59:04 +0100
Subject: [PATCH] fix widget order + improve css

---
 .../Class/Profil/Preferences/SearchResult.php | 24 +++++++++++++++----
 public/opac/css/global.css                    | 16 +++++++------
 .../SearchResult/SearchResultTest.php         |  8 +++----
 3 files changed, 32 insertions(+), 16 deletions(-)

diff --git a/library/Class/Profil/Preferences/SearchResult.php b/library/Class/Profil/Preferences/SearchResult.php
index a2b34136f74..89b71f18d5e 100644
--- a/library/Class/Profil/Preferences/SearchResult.php
+++ b/library/Class/Profil/Preferences/SearchResult.php
@@ -23,6 +23,8 @@
 class Class_Profil_Preferences_SearchResult {
   use Trait_Translator;
 
+  protected $_settings;
+
   public function getLegacy() {
     $ret = [];
     $ret["barre_nav"] = "Résultat";               // Barre de nav
@@ -108,10 +110,19 @@ class Class_Profil_Preferences_SearchResult {
     if(!$profile)
       return [];
 
-    return $this->_getHeaderItems($profile, function($item, $settings)
-                                  {
-                                    return in_array($item->getId(), $settings);
-                                  });
+    $selected = [];
+    foreach($this->_getHeaderCompositionAsArray($profile) as $id)
+      $selected[] = $this->_getEntity($id);
+
+    return array_filter($selected);
+  }
+
+
+  protected function _getEntity($id) {
+    foreach($this->_getDefaultHeaderItems() as $instance)
+      if($id == $instance->getId())
+        return $instance;
+    return null;
   }
 
 
@@ -128,7 +139,10 @@ class Class_Profil_Preferences_SearchResult {
 
 
   protected function _getHeaderCompositionAsArray($profile) {
-    return explode(';', $profile->getCfgModulesPreferences('recherche', 'resultat', 'simple')['header_composition']);
+    if(!$this->_settings)
+      $this->_settings = explode(';', $profile->getCfgModulesPreferences('recherche', 'resultat', 'simple')['header_composition']);
+
+    return $this->_settings;
   }
 
 
diff --git a/public/opac/css/global.css b/public/opac/css/global.css
index 1084a215e16..18996297a37 100644
--- a/public/opac/css/global.css
+++ b/public/opac/css/global.css
@@ -3467,18 +3467,21 @@ th.actions {
     margin-bottom: 1em;
 }
 
+.opac .boiteMilieu .contenu {
+    overflow: visible;
+}
+
 .opac.recherche_simple div[class*="_widget"] .widget_wrapper {
     background: white;
     box-shadow: 0px 0px 5px black;
-    left: 1em;
     margin-top: 1em;
     max-height: 0;
-    overflow: auto;
+    overflow: hidden;
     position: absolute;
     transition-duration: .5s;
-    transition-property: all;
-    width: 95%;
+    transition-property: max-height;
     z-index: 101;
+    width: 95%;
 }
 
 .opac.recherche_simple div[class*="_widget"].show .widget_wrapper {
@@ -3535,10 +3538,9 @@ th.actions {
 }
 
 .opac.recherche_simple .resultats_page .history_search_widget .widget_wrapper {
-    left: auto;
     overflow-y: auto;
-    right: 1em;
-    width: auto;
+    position: absolute;
+    width: 300px;
 }
 
 .admin_tools_lock {
diff --git a/tests/scenarios/SearchResult/SearchResultTest.php b/tests/scenarios/SearchResult/SearchResultTest.php
index 55c3d0cbb2b..9e55213c4c6 100644
--- a/tests/scenarios/SearchResult/SearchResultTest.php
+++ b/tests/scenarios/SearchResult/SearchResultTest.php
@@ -47,13 +47,13 @@ class SearchResultTest extends AbstractControllerTestCase {
 
   /** @test */
   public function numberOfResultsShouldContainsMultipleOptions() {
-    $this->assertXPath('//div[@class="selector_widget"]//form//select[@name="page_size"]//option[@value="40"]');
+    $this->assertXPath('//div[@class="selector_widget"][3]//form//select[@name="page_size"]//option[@value="40"]');
   }
 
 
   /** @test */
   public function listeFormatShouldContainsMur() {
-    $this->assertXPath('//div[@class="selector_widget"]//form//select//option[@label="Mur"]');
+    $this->assertXPath('//div[@class="selector_widget"][1]//form//select//option[@label="Mur"]');
   }
 
 
@@ -65,13 +65,13 @@ class SearchResultTest extends AbstractControllerTestCase {
 
   /** @test */
   public function orderShouldContainsTitre() {
-    $this->assertXPath('//div[@class="selector_widget"]//form//select//option[@label="Titre"]');
+    $this->assertXPath('//div[@class="selector_widget"][2]//form//select//option[@label="Titre"]');
   }
 
 
   /** @test */
   public function adavancedSearchWidgetShouldContainsMatieres() {
-    $this->assertXPath('//div[@class="advanced_search_widget"]//div//form//input[@name="rech_matieres"]');
+    $this->assertXPath('//div[@class="advanced_search_widget"][1]//div//form//input[@name="rech_matieres"]');
   }
 
 
-- 
GitLab