diff --git a/FEATURES/67009 b/FEATURES/67009 new file mode 100644 index 0000000000000000000000000000000000000000..80ef3b31df7baf8d154024db09149ca826529509 --- /dev/null +++ b/FEATURES/67009 @@ -0,0 +1,10 @@ + '67009' => + ['Label' => $this->_('Configuration de la Boîte bibliothèque numérique dans le contexte actuelle à + de 100000 albums'), + 'Desc' => '', + 'Image' => '', + 'Video' => '', + 'Category' => '', + 'Right' => function($feature_description, $user) {return true;}, + 'Wiki' => '', + 'Test' => '', + 'Date' => '2017-12-11'], \ No newline at end of file diff --git a/VERSIONS_WIP/67009 b/VERSIONS_WIP/67009 new file mode 100644 index 0000000000000000000000000000000000000000..5b67df9497931307e83e13c0659d2e03e4374799 --- /dev/null +++ b/VERSIONS_WIP/67009 @@ -0,0 +1 @@ + - ticket #67009 : Configuration de la Boîte bibliothèque numérique dans le contexte actuelle à + de 100000 albums \ No newline at end of file diff --git a/library/Class/Album.php b/library/Class/Album.php index 7094ffb93cc75e636cc5b91fc9de50ca09bc87b7..700d860a0a9318f160edae3abfe80f053f240e53 100644 --- a/library/Class/Album.php +++ b/library/Class/Album.php @@ -1463,6 +1463,18 @@ class Class_Album extends Storm_Model_Abstract { return 'liste'; } + + public function getLabel() { + return $this->getTitre(); + } + + + public function getFullLabel() { + return $this->_('%s de %s', + $this->getAbsolutePath(), + $this->getMainAuthorName()); + } + /** * Main author * @return string @@ -1629,5 +1641,4 @@ class Class_Album extends Storm_Model_Abstract { public static function getPublicDomain() { return (new self())->_('Domaine public'); } -} -?> \ No newline at end of file +} \ No newline at end of file diff --git a/library/ZendAfi/Controller/Plugin/Manager/Manager.php b/library/ZendAfi/Controller/Plugin/Manager/Manager.php index c7fd4d158980547427b4b9a9ead80c6d27207733..a85cf9d93a018d88ca6ed73124c46ce18660064c 100644 --- a/library/ZendAfi/Controller/Plugin/Manager/Manager.php +++ b/library/ZendAfi/Controller/Plugin/Manager/Manager.php @@ -87,6 +87,32 @@ class ZendAfi_Controller_Plugin_Manager_Manager extends ZendAfi_Controller_Plugi } + public function ajaxSearchAction() { + if(!$term = $this->_getParam('term')) + return $this->_helper->json(['error' => $this->_('Veuillez préciser un terme ( url : /search/term/somethings )')]); + + $models = call_user_func([$this->_getModelLoader(), + 'findAllBy'], + $this->_getSearchParams($term)); + $response = []; + + foreach($models as $model) + $response [] = ['label' => $model->getFullLabel(), + 'value' => $model->getId()]; + + $this->_helper->json($response); + } + + + protected function _getSearchParams($term) { + $term = Zend_Db_Table::getDefaultAdapter()->quote('%' . $term . '%'); + $where = $this->_getModelLabel() . ' like ' . $term; + return ['where' => $where, + 'order' => $this->_getModelOrder(), + 'limit' => 10]; + } + + public function addAction() { if ($this->_response->isRedirect()) return; @@ -520,4 +546,37 @@ class ZendAfi_Controller_Plugin_Manager_Manager extends ZendAfi_Controller_Plugi protected function _getModelActions() { return call_user_func($this->_model_actions); } + + + public function visitModelLoader($callback) { + $this->_model_loader = $callback; + return $this; + } + + + protected function _getModelLoader() { + return call_user_func($this->_model_loader); + } + + + public function visitModelLabel($callback) { + $this->_model_label = $callback; + return $this; + } + + + protected function _getModelLabel() { + return call_user_func($this->_model_label); + } + + + public function visitModelOrder($callback) { + $this->_model_order = $callback; + return $this; + } + + + protected function _getModelOrder() { + return call_user_func($this->_model_order); + } } \ No newline at end of file diff --git a/library/ZendAfi/Controller/Plugin/ResourceDefinition/Abstract.php b/library/ZendAfi/Controller/Plugin/ResourceDefinition/Abstract.php index d757272d377bc4abee6df4495d784040b81d396e..7da0526457c9b7d0900e1aab7a7e0717be8ede0c 100644 --- a/library/ZendAfi/Controller/Plugin/ResourceDefinition/Abstract.php +++ b/library/ZendAfi/Controller/Plugin/ResourceDefinition/Abstract.php @@ -165,6 +165,13 @@ abstract class ZendAfi_Controller_Plugin_ResourceDefinition_Abstract extends Zen } + public function getModelLabel() { + if (isset($this->_attribs['model']['model_label'])) + return $this->_attribs['model']['model_label']; + return 'libelle'; + } + + public function getOrder() { if (isset($this->_attribs['model']['order'])) return $this->_attribs['model']['order']; @@ -340,6 +347,14 @@ abstract class ZendAfi_Controller_Plugin_ResourceDefinition_Abstract extends Zen { return $this->getModelId(); }) + ->visitModelLabel(function() + { + return $this->getModelLabel(); + }) + ->visitModelOrder(function() + { + return $this->getOrder(); + }) ->visitModelActions(function() { return $this->getModelActions(); diff --git a/library/ZendAfi/Controller/Plugin/ResourceDefinition/Album.php b/library/ZendAfi/Controller/Plugin/ResourceDefinition/Album.php index 8375b1fbc2a3fbd989ad9bda29afd56d3c83cd3e..58f30e2437a8d93cc9e418e12b91aa1e21ca79f4 100644 --- a/library/ZendAfi/Controller/Plugin/ResourceDefinition/Album.php +++ b/library/ZendAfi/Controller/Plugin/ResourceDefinition/Album.php @@ -25,8 +25,8 @@ class ZendAfi_Controller_Plugin_ResourceDefinition_Album extends ZendAfi_Control public function getDefinitions() { return ['model' => ['class' => 'Class_Album', 'name' => 'album', - 'order' => 'libelle', - 'model_id' => 'id']]; + 'order' => 'titre', + 'model_id' => 'id', + 'model_label' => 'titre']]; } -} -?> \ No newline at end of file +} \ No newline at end of file diff --git a/library/ZendAfi/Form/Configuration/Widget/Albums.php b/library/ZendAfi/Form/Configuration/Widget/Albums.php index b6a0046e5d2b98359014adebed44414266bc6896..2855cae978d42b28db823af6ff294a0ea73ec4dd 100644 --- a/library/ZendAfi/Form/Configuration/Widget/Albums.php +++ b/library/ZendAfi/Form/Configuration/Widget/Albums.php @@ -44,10 +44,11 @@ class ZendAfi_Form_Configuration_Widget_Albums extends ZendAfi_Form_Configuratio ['label' => $this->_('Collection'), 'multiOptions' => $this->_getCollections()]) - ->addElement('select', + ->addElement('ajaxSearch', 'id_albums', ['label' => $this->_('Album'), - 'multiOptions' => $this->_getAlbums()]) + 'source' => Class_Url::absolute('/admin/album/ajax-search'), + 'placeholder' => $this->_('Rechercher un album')]) ->addElement('imagesViewer', 'style_liste', @@ -150,7 +151,7 @@ formSelectToggleVisibilityForElement("#type_aff", $("#id_categorie, #nb_aff_by_p protected function _getAlbums() { - $albums = []; + return $albums = []; foreach (Class_AlbumCategorie::findAlbumsRecursively() as $album) $albums[$album->getId()] = $this->_getAlbum($album); diff --git a/library/ZendAfi/Form/Decorator/AjaxSearch.php b/library/ZendAfi/Form/Decorator/AjaxSearch.php new file mode 100644 index 0000000000000000000000000000000000000000..705ab905c0a200894ca68bde23d565fb645a77f7 --- /dev/null +++ b/library/ZendAfi/Form/Decorator/AjaxSearch.php @@ -0,0 +1,34 @@ +<?php +/** + * Copyright (c) 2012-2017, Agence Française Informatique (AFI). All rights reserved. + * + * BOKEH is free software; you can redistribute it and/or modify + * it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE as published by + * the Free Software Foundation. + * + * There are special exceptions to the terms and conditions of the AGPL as it + * is applied to this software (see README file). + * + * BOKEH is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU AFFERO GENERAL PUBLIC LICENSE for more details. + * + * You should have received a copy of the GNU AFFERO GENERAL PUBLIC LICENSE + * along with BOKEH; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + */ + + +class ZendAfi_Form_Decorator_AjaxSearch extends Zend_Form_Decorator_Abstract { + + public function render($content) { + $settings = new Class_Entity(array_merge( + ['InputName' => $this->_element->getName(), + 'InputValue' => $this->_element->getValue(), + 'Source' => $this->_element->getSource()], + $this->_element->getAttribs())); + + return $this->_element->getView()->ajaxSearch($settings); + } +} \ No newline at end of file diff --git a/library/ZendAfi/Form/Element/AjaxSearch.php b/library/ZendAfi/Form/Element/AjaxSearch.php new file mode 100644 index 0000000000000000000000000000000000000000..835705f58258f9aa2c9b627e3c1f13230bf2b891 --- /dev/null +++ b/library/ZendAfi/Form/Element/AjaxSearch.php @@ -0,0 +1,48 @@ +<?php +/** + * Copyright (c) 2012-2017, Agence Française Informatique (AFI). All rights reserved. + * + * BOKEH is free software; you can redistribute it and/or modify + * it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE as published by + * the Free Software Foundation. + * + * There are special exceptions to the terms and conditions of the AGPL as it + * is applied to this software (see README file). + * + * BOKEH is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU AFFERO GENERAL PUBLIC LICENSE for more details. + * + * You should have received a copy of the GNU AFFERO GENERAL PUBLIC LICENSE + * along with BOKEH; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + */ + + +class ZendAfi_Form_Element_AjaxSearch extends Zend_Form_Element { + protected + $_source; + + public function __construct($spec, $options = null) { + parent::__construct($spec, $options); + + $decorators = $this->_decorators; + $this->_decorators = ['AjaxSearch' => new ZendAfi_Form_Decorator_AjaxSearch()]; + + foreach ($decorators as $name => $value) + $this->_decorators[$name] = $value; + $this->removeDecorator('ViewHelper'); + } + + + public function setSource($source) { + $this->_source = $source; + return $this; + } + + + public function getSource() { + return $this->_source; + } +} \ No newline at end of file diff --git a/library/ZendAfi/View/Helper/AjaxSearch.php b/library/ZendAfi/View/Helper/AjaxSearch.php new file mode 100644 index 0000000000000000000000000000000000000000..5a1e301d23bc1d5fbbf00115621257d836654e13 --- /dev/null +++ b/library/ZendAfi/View/Helper/AjaxSearch.php @@ -0,0 +1,40 @@ +<?php +/** + * Copyright (c) 2012-2017, Agence Française Informatique (AFI). All rights reserved. + * + * BOKEH is free software; you can redistribute it and/or modify + * it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE as published by + * the Free Software Foundation. + * + * There are special exceptions to the terms and conditions of the AGPL as it + * is applied to this software (see README file). + * + * BOKEH is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU AFFERO GENERAL PUBLIC LICENSE for more details. + * + * You should have received a copy of the GNU AFFERO GENERAL PUBLIC LICENSE + * along with BOKEH; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + */ + + +class ZendAfi_View_Helper_AjaxSearch extends ZendAfi_View_Helper_BaseHelper { + public function ajaxSearch($settings) { + $name = $settings->getInputName(); + + Class_ScriptLoader::getInstance() + ->addJQueryReady(sprintf('$("#%s").autocomplete({ source: "%s" , delay: 300 , minLength: 2 });', + $name, + $settings->getSource())); + + return $this->_tag('input', + null, + ['type' => 'text', + 'id' => $name, + 'name' => $name, + 'value' => $settings->getInputValue(), + 'placeholder' => $settings->getplaceholder()]); + } +} \ No newline at end of file diff --git a/tests/application/modules/admin/controllers/AlbumControllerTest.php b/tests/application/modules/admin/controllers/AlbumControllerTest.php index c190e16986421fa16f135fb1e03705859639bd15..0843269f6c2215dc21e1962f8dc444edda9ac7c5 100644 --- a/tests/application/modules/admin/controllers/AlbumControllerTest.php +++ b/tests/application/modules/admin/controllers/AlbumControllerTest.php @@ -3378,4 +3378,29 @@ class Admin_AbstractControllerAlbumDeleteVignetteTest extends Admin_AlbumControl public function godotRecordShouldNotHaveThumbnailAnymore() { $this->assertEquals('', $this->_album->getNotice()->getUrlVignette()); } +} + + + + +class Admin_AlbumControllerAjaxSearchTest extends Admin_AbstractControllerTestCase { + public function setUp() { + parent::setUp(); + + $album = $this->fixture('Class_Album', + ['id' => 1, + 'titre' => 'Hello world']); + + $second_album = $this->fixture('Class_Album', + ['id' => 2, + 'titre' => 'Hello moon']); + + $this->dispatch('/admin/album/ajax-search/term/hello', true); + } + + + /** @test */ + public function shouldReturnAlbumsJson() { + $this->assertEquals('[{"label":"Albums non class\u00e9s>Hello moon de ","value":2},{"label":"Albums non class\u00e9s>Hello world de ","value":1}]', $this->_response->getBody()); + } } \ No newline at end of file diff --git a/tests/scenarios/Widgets/WidgetsTest.php b/tests/scenarios/Widgets/WidgetsTest.php index 717a1925ba057ef3c0ab0363b393a38005141d9f..310cde346628ae2c43d02b8114130c2547c31dbc 100644 --- a/tests/scenarios/Widgets/WidgetsTest.php +++ b/tests/scenarios/Widgets/WidgetsTest.php @@ -601,4 +601,26 @@ class WidgetsButtonsTest extends WidgetsNavSimpleTestCase { public function continueButtonShouldNotBePresent() { $this->assertNotXPathContentContains('//button', 'Valider et continuer'); } +} + + + +class WidgetsEditAlbumsWidgetTest extends WidgetsSimpleTestCase { + public function setUp() { + parent::setUp(); + + $simple_widgets = ['modules' => ['4' => ['division' => '1', + 'type_module' => Class_Systeme_ModulesAccueil_BibliothequeNumerique::CODE]]];; + + Class_Profil::getCurrentProfil() + ->setCfgAccueil($simple_widgets) + ->save(); + $this->dispatch('admin/widget/edit-widget/id/4/id_profil/2', true); + } + + + /** @test */ + public function ajaxSearchShouldBePresent() { + $this->assertXPathContentContains('//script', '$("#id_albums").autocomplete'); + } } \ No newline at end of file