diff --git a/application/modules/opac/controllers/RechercheController.php b/application/modules/opac/controllers/RechercheController.php index a3b267889d5eebdb4ce93f06cd242682a9eb9b89..58f8c2cb2a08ca2406bb1d8720ede0ef2a9963fd 100644 --- a/application/modules/opac/controllers/RechercheController.php +++ b/application/modules/opac/controllers/RechercheController.php @@ -150,7 +150,8 @@ class RechercheController extends ZendAfi_Controller_Action { if (($ig = Zend_Controller_Front::getInstance() ->getPlugin('ZendAfi_Controller_Plugin_InspectorGadget')) && $ig->isEnabled()) - $ig->logRecord($this->view->searchInspector($this->moteur)); + $ig->logRecord($this->_('Configuration de la recherche'), + $this->view->searchInspector($this->moteur)); } @@ -302,7 +303,8 @@ class RechercheController extends ZendAfi_Controller_Action { if (($ig = Zend_Controller_Front::getInstance() ->getPlugin('ZendAfi_Controller_Plugin_InspectorGadget')) && $ig->isEnabled()) - $ig->logRecord($this->view->notice_Unimarc($notice)); + $ig->logRecord($this->_('Notice Bokeh'), + $this->view->notice_Unimarc($notice)); $notice_navigation = new Class_Notice_NavigationRecherche( $this->newCriteresRecherches($this->_request->getParams()), diff --git a/library/ZendAfi/Controller/Plugin/InspectorGadget.php b/library/ZendAfi/Controller/Plugin/InspectorGadget.php index 03078e3990a05a2128c85199d01bf3d66728f33b..5a460a7895227917e1b38b29b59b8baf7508bfe3 100644 --- a/library/ZendAfi/Controller/Plugin/InspectorGadget.php +++ b/library/ZendAfi/Controller/Plugin/InspectorGadget.php @@ -20,11 +20,16 @@ */ class ZendAfi_Controller_Plugin_InspectorGadget extends Zend_Controller_Plugin_Abstract { + use Trait_Translator; + const PARAM_NAME = 'inspector_gadget'; + protected $_enabled = false, $_calls = [], $_record, - $_session; + $_record_label, + $_session, + $_view; public function preDispatch(Zend_Controller_Request_Abstract $request) { $this->_session = Zend_Registry::get('session'); @@ -38,6 +43,13 @@ class ZendAfi_Controller_Plugin_InspectorGadget extends Zend_Controller_Plugin_A Class_WebService_SIGB_AbstractService::setLogger($this); if (class_exists('SoapClient')) Class_WebService_MappedSoapClient::setLogger($this); + + $sl = Class_ScriptLoader::getInstance(); + $sl->addOPACPluginScript('form_to_tabs/form_to_tabs.js'); + Class_Admin_Skin::current() + ->renderButtonCssOn($sl) + ->renderJQueryCssOn($sl) + ->renderFormCssOn($sl); } @@ -61,6 +73,9 @@ class ZendAfi_Controller_Plugin_InspectorGadget extends Zend_Controller_Plugin_A public function postDispatch(Zend_Controller_Request_Abstract $request) { + if (!$this->isEnabled()) + return; + if (!$this->shouldRender()) return; @@ -87,15 +102,19 @@ class ZendAfi_Controller_Plugin_InspectorGadget extends Zend_Controller_Plugin_A return; } - $this->_session->inspectorCalls = []; - $this->_response->setBody(str_replace('</body>', $html . '</body>', $this->_response->getBody())); } protected function shouldRender() { - return $this->isEnabled() + $renderer = Zend_Controller_Action_HelperBroker::hasHelper('ViewRenderer') + ? Zend_Controller_Action_HelperBroker::getExistingHelper('ViewRenderer') + : null; + if ($renderer) + $this->_view = $renderer->view; + + return $this->_view && (!empty($this->_calls) || null !== $this->_record); } @@ -109,10 +128,9 @@ class ZendAfi_Controller_Plugin_InspectorGadget extends Zend_Controller_Plugin_A if (null == $this->_record) return ''; - return $this->renderButton('u') - . '<div data-type="' . self::PARAM_NAME . '-u" style="display:none;">' - . $this->_record - . '</div>'; + return $this->renderDialog($this->_record_label, + ['title' => $this->_record_label, + 'content' => $this->_record]); } @@ -120,25 +138,34 @@ class ZendAfi_Controller_Plugin_InspectorGadget extends Zend_Controller_Plugin_A if (empty($this->_calls)) return ''; - $html = $this->renderButton('i') - . '<div data-type="' . self::PARAM_NAME . '-i" style="display:none;"><ol>'; - $this->_calls = array_map( function($call) { return unserialize($call); }, $this->_calls); + $items = []; foreach(array_filter($this->_calls, 'is_object') as $call) - $html .= '<li>' . $call->render() . '</li>'; + $items[] = $this->_view->tag('li', $call->renderOn($this->_view)); - return $html . '</ol></div>'; + $this->_session->inspectorCalls = []; + $content = $this->_view->tag('ol', implode('', $items)); + + return $this + ->renderDialog($this->_('Appels webservices (%s)', count($items)), + ['title' => $this->_('Liste des appels webservices'), + 'content' => $content]) + ; } - protected function renderButton($content) { - return '<button style="width:20px;height:20px;text-align:center;" -onclick="$(\'[data-type=' . self::PARAM_NAME . '-' . $content . ']\').dialog({title:\'Inspector\', width:625});">' . $content . '</button>'; + protected function renderDialog($label, $datas) { + $button = (new Class_Entity) + ->setText($label) + ->setImage(Class_Admin_Skin::current()->renderActionIconOn('loupe', $this->_view)) + ->setAttribs(['onclick' => 'opacDialogFromData('. $this->_view->escape(json_encode($datas)) .');$(\'.ig-tabs\').tabs({activate: function(event, ui) {if (ui.newPanel.attr(\'id\') == \'ig-tab-items\') ui.newPanel.accordion();}});']); + + return $this->_view->admin_Button($button); } @@ -150,34 +177,51 @@ onclick="$(\'[data-type=' . self::PARAM_NAME . '-' . $content . ']\').dialog({ti $response_body = $response->getBody(); } - $this->_calls[] = serialize(new ZendAfi_Controller_Plugin_InspectorGadget_HttpCall($httpClient->getLastRequest(), $response_code, $response_body)); - $this->_session->inspectorCalls = $this->_calls; + $call = new ZendAfi_Controller_Plugin_InspectorGadget_ServiceCall + ($httpClient->getLastRequest(), + '', + '', + $response_body, + $response_code); + + $this->addCall($call); } public function logError($url, $message) { - $this->_calls[] = serialize(new ZendAfi_Controller_Plugin_InspectorGadget_HttpCall($url, - 'n/a', - $message)); - $this->_session->inspectorCalls = $this->_calls; + $call = new ZendAfi_Controller_Plugin_InspectorGadget_ServiceCall($url, + '', + '', + $message, + ''); + $this->addCall($call); } public function logSoap($client) { - $this->_calls[] = serialize(new ZendAfi_Controller_Plugin_InspectorGadget_SoapCall - ($client->__getLastRequestHeaders(), $client->__getLastRequest(), - $client->__getLastResponseHeaders(), $client->__getLastResponse())); + $call = new ZendAfi_Controller_Plugin_InspectorGadget_SoapCall + ($client->__getLastRequestHeaders(), + $client->__getLastRequest(), + $client->__getLastResponseHeaders(), + $client->__getLastResponse(), + ''); + + $this->addCall($call); + } + + + protected function addCall($call) { + $this->_calls[] = serialize($call); $this->_session->inspectorCalls = $this->_calls; } - public function logRecord($html) { + public function logRecord($label, $html) { if (!$this->isEnabled()) return $this; $this->_record = $html; + $this->_record_label = $label; return $this; } } - -?> \ No newline at end of file diff --git a/library/ZendAfi/Controller/Plugin/InspectorGadget/HttpCall.php b/library/ZendAfi/Controller/Plugin/InspectorGadget/HttpCall.php deleted file mode 100644 index 599e32a72bbe337a88474ae8a4e19398751cc50c..0000000000000000000000000000000000000000 --- a/library/ZendAfi/Controller/Plugin/InspectorGadget/HttpCall.php +++ /dev/null @@ -1,37 +0,0 @@ -<?php -/** - * Copyright (c) 2012, 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_Controller_Plugin_InspectorGadget_HttpCall { - protected $_request, $_response_code, $_response_body; - - public function __construct($request, $response_code, $response_body) { - $this->_request = $request; - $this->_response_code = $response_code; - $this->_response_body = $response_body; - } - - - public function render() { - return - '<h3>Requête</h3>' . $this->_request . ' (' . $this->_response_code . ')' - . '<h3>Réponse</h3><textarea style="width:600px">' . $this->_response_body . '</textarea>'; - } -} \ No newline at end of file diff --git a/library/ZendAfi/Controller/Plugin/InspectorGadget/ServiceCall.php b/library/ZendAfi/Controller/Plugin/InspectorGadget/ServiceCall.php new file mode 100644 index 0000000000000000000000000000000000000000..5d441e5bf2b94ed7f89100f48ebe331c924e9e61 --- /dev/null +++ b/library/ZendAfi/Controller/Plugin/InspectorGadget/ServiceCall.php @@ -0,0 +1,73 @@ +<?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_Controller_Plugin_InspectorGadget_ServiceCall { + use Trait_Translator; + + protected + $_request_headers, + $_request_body, + $_response_headers, + $_response_body, + $_response_code; + + public function __construct($request_headers, $request_body, + $response_headers, $response_body, $response_code) { + $this->_request_headers = $request_headers; + $this->_request_body = $request_body; + $this->_response_headers = $response_headers; + $this->_response_body = $response_body; + $this->_response_code = $response_code; + } + + + public function renderOn($view) { + return + $this->renderRequestOn($view) . $this->renderResponseOn($view); + } + + + protected function renderRequestOn($view) { + return $view->tag('h3', $this->_('Requête')) + . $view->tag('pre', $this->_request_headers) + . $this->renderBodyOn($this->_request_body, $view) + ; + } + + + protected function renderResponseOn($view) { + return $view->tag('h3', + $this->_response_code + ? $this->_('Réponse (%s)', $this->_response_code) + : $this->_('Réponse')) + . ($this->_response_headers ? $view->tag('pre', $this->_response_headers) : '') + . $this->renderBodyOn($this->_response_body, $view) + ; + } + + + protected function renderBodyOn($body, $view) { + return $body + ? $view->tag('textarea', $body, ['style' => 'width:600px;', 'rows' => 5]) + : ''; + } +} diff --git a/library/ZendAfi/Controller/Plugin/InspectorGadget/SoapCall.php b/library/ZendAfi/Controller/Plugin/InspectorGadget/SoapCall.php deleted file mode 100644 index a3baab2d30e1334e69a32ae5045eb9e40d42553f..0000000000000000000000000000000000000000 --- a/library/ZendAfi/Controller/Plugin/InspectorGadget/SoapCall.php +++ /dev/null @@ -1,42 +0,0 @@ -<?php -/** - * Copyright (c) 2012, 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_Controller_Plugin_InspectorGadget_SoapCall { - protected $_request_headers, $_request_body, - $_response_headers, $_response_body; - - public function __construct($request_headers, $request_body, - $response_headers, $response_body) { - $this->_request_headers = $request_headers; - $this->_request_body = $request_body; - $this->_response_headers = $response_headers; - $this->_response_body = $response_body; - } - - - public function render() { - return - '<h3>Requête</h3>' . $this->_request_headers - . '<hr><textarea style="width:600px">' . $this->_request_body . '</textarea>' - . '<h3>Réponse</h3>' . $this->_response_headers - . '<hr><textarea style="width:600px">' . $this->_response_body . '</textarea>'; - } -} diff --git a/library/ZendAfi/View/Helper/Notice/Unimarc.php b/library/ZendAfi/View/Helper/Notice/Unimarc.php index 16f604cadacf9a2a5a4e1f6b960d673247bc39d6..9bcacc4ee1ddb6034df9facc5fba44797488941d 100644 --- a/library/ZendAfi/View/Helper/Notice/Unimarc.php +++ b/library/ZendAfi/View/Helper/Notice/Unimarc.php @@ -32,33 +32,45 @@ class ZendAfi_View_Helper_Notice_Unimarc extends Zend_View_Helper_HtmlElement { $reader->setNotice($notice->getUnimarc(), 0); $reader->acceptVisitor($this); - Class_ScriptLoader::getInstance() - ->addJQueryReady('$(".ig-tabs").tabs({activate: function(event, ui) { -if (ui.newPanel.attr("id") == "ig-tab-items") - ui.newPanel.accordion(); -}});'); - - return $this->renderHeader($notice) . $this->_tag('hr') + return + $this->_tag('h2', $this->_('Indexation')) . $this->renderNotice($notice) . $this->_tag('hr') + . $this->_tag('h2', $this->_('Unimarc pivot')) . $this->_tag('div', $this->renderTabs() - . $this->renderZones() + . $this->renderZones($notice) . $this->renderItems($notice), ['class' => 'ig-tabs']); } protected function renderNotice($notice) { - $fields = ['facettes' => $this->_('Facettes'), - 'date_creation' => $this->_('Création / nouveauté'), - 'date_maj' => $this->_('Mis à jour le'), - 'clef_alpha' => $this->_('Clé alpha'), - 'clef_oeuvre' => $this->_('Clé oeuvre')]; - $html = ''; + $fields = + [ + 'date_maj' => $this->_('Mis à jour le'), + 'date_creation' => $this->_('Nouveauté jusqu\'au'), + 'alpha_titre' => $this->_('Alpha titres'), + 'alpha_auteur' => $this->_('Alpha auteur'), + 'titres' => $this->_('Titres'), + 'auteurs' => $this->_('Auteurs'), + 'editeur' => $this->_('Éditeur'), + 'facettes' => $this->_('Facettes'), + 'clef_alpha' => $this->_('Clé alpha'), + 'clef_oeuvre' => $this->_('Clé oeuvre'), + 'clef_chapeau' => $this->_('Clé chapeau'), + 'url_vignette' => $this->_('Url vignette'), + 'url_image' => $this->_('Url image'), + ]; + $lines = []; foreach ($fields as $field => $label) - $html .= $label . ': ' . $notice->callGetterByAttributeName($field) . '<br>'; + $lines[] = $this->_tag('tr', + $this->_tag('th', $label, + ['scope' => 'row', + 'style' => 'text-align:right;min-width:12em']) + . $this->_tag('td', + $notice->callGetterByAttributeName($field))); - return $html; + return $this->_tag('table', implode('', $lines)); } @@ -71,29 +83,29 @@ if (ui.newPanel.attr("id") == "ig-tab-items") } - protected function renderHeader($notice) { - $html = ''; - foreach($this->_headers as $k => $v) - $html .= $k . ' : ' . $v . '<br>'; + protected function renderDownload($notice) { + $download_url = $this->view->url(['controller' => 'recherche', + 'action' => 'download-record', + 'id' => $notice->getId()], + null, true); - $button = $this->_tag('button', $this->_('Télécharger'), - ['style' => 'float:right;font-size:80%', - 'onclick' => 'document.location.href=\'' - .$this->view->url(['controller' => 'recherche', - 'action' => 'download-record', - 'id' => $notice->getId()], - null, true).'\'']); + $button = (new Class_Entity) + ->setText($this->_('Télécharger')) + ->setImage(Class_Admin_Skin::current()->renderActionIconOn('down', $this->view)) + ->setAttribs(['style' => 'float:right;', + 'onclick' => 'document.location.href=\'' . $download_url .'\'']); - return $this->_tag('h2', $this->_('Notice unimarc') . $button) . $html; + return $this->view->admin_Button($button); } - protected function renderZones() { + protected function renderZones($notice) { $html = ''; foreach ($this->_zones as $zone) $html .= $zone->render(); - return $this->_tag('div', $this->_tag('table', $html), + return $this->_tag('div', + $this->renderDownload($notice) . $this->_tag('table', $html), ['id' => 'ig-tab-zones']); } diff --git a/tests/library/ZendAfi/View/Helper/Notice/UnimarcTest.php b/tests/library/ZendAfi/View/Helper/Notice/UnimarcTest.php index f9cb30df65f89db83d8ab87b2df16da72221c05b..97ac9d39ab57dbed35f39c1f39bab343ebd1ec29 100644 --- a/tests/library/ZendAfi/View/Helper/Notice/UnimarcTest.php +++ b/tests/library/ZendAfi/View/Helper/Notice/UnimarcTest.php @@ -25,30 +25,47 @@ parent::setUp(); $this->_helper = new ZendAfi_View_Helper_Notice_Unimarc(); $this->_helper->setView(new ZendAfi_Controller_Action_Helper_View()); - $this->_html = $this->_helper->notice_Unimarc($this->fixture('Class_Notice', - ['id' => 1, - 'titre' => 'Pomme et Ananas', - 'clef_alpha' => 'POMMEETANANAS', - 'facettes' => 'A1 Q9', - 'date_maj' => '01/01/2015', - 'unimarc' => ''])); + $this->_html = $this->_helper + ->notice_Unimarc($this->fixture('Class_Notice', + ['id' => 1, + 'titre' => 'Pomme et Ananas', + 'clef_alpha' => 'POMMEETANANAS', + 'alpha_titre' => 'POM POMS ANANA ANANAS', + 'alpha_auteur' => 'AUTEUR AUTEURS', + 'facettes' => 'A1 Q9', + 'date_maj' => '01/01/2015', + 'date_creation' => '09/10/2017', + 'unimarc' => '', + 'url_vignette' => 'https://thumbs.net/xXv9873ct'])); } /** @test */ public function alphaKeyShouldBePresent() { - $this->assertContains('Clé alpha: POMMEETANANAS', $this->_html); + $this->assertXPathContentContains($this->_html, '//td', 'POMMEETANANAS'); } /** @test */ public function dateMajShouldBePresent() { - $this->assertContains('Mis à jour le: 01/01/2015', $this->_html); + $this->assertXPathContentContains($this->_html, '//td', '01/01/2015'); + } + + + /** @test */ + public function noverltyDateShouldBePresent() { + $this->assertXPathContentContains($this->_html, '//td', '09/10/2017'); } /** @test */ public function facetsShouldBePresent() { - $this->assertContains('Facettes: A1 Q9', $this->_html); + $this->assertXPathContentContains($this->_html, '//td', 'A1 Q9'); + } + + + /** @test */ + public function thumbnailUrlShouldBePresent() { + $this->assertXPathContentContains($this->_html, '//td', 'https://thumbs.net/xXv9873ct'); } }