Commit 3c6b7c38 authored by Ghislain Loas's avatar Ghislain Loas
Browse files

dev #72845 updrage dashboard to handle custom diag + implement cvs custom diag

parent 22107470
......@@ -261,8 +261,12 @@ class Class_DigitalResource_Config extends Class_Entity {
public function renderHarvestDiagOn($view) {
return $view->tag('p',
$this->_('Cette ressource ne prend pas en charge l\'affichage du l\'url de moissonnage'), ['class' => 'error']);
return $view->tagInfo($this->_('Cette ressource ne prend pas en charge l\'affichage du l\'url de moissonnage'));
}
public function renderCustomDiagOn($view) {
return '';
}
......@@ -277,7 +281,8 @@ class Class_DigitalResource_Config extends Class_Entity {
$group = $this->getTestGroup();
$group->addUser($user)->save();
return $user;
Class_Users::clearCache();
return Class_Users::find($user->getId());
}
......@@ -294,7 +299,8 @@ class Class_DigitalResource_Config extends Class_Entity {
$permission->permitTo($group, new Class_Entity());
return $group;
Class_UserGroup::clearCache();
return Class_UserGroup::find($group->getId());
}
......@@ -306,4 +312,18 @@ class Class_DigitalResource_Config extends Class_Entity {
public function getSearchUrlForRecord($record) {
return [];
}
public function getPermittedGroups() {
$groups = new Storm_Collection(Class_UserGroup::findAll());
return array_filter(
$groups
->select(function ($group)
{
$permission = $this->getPermission();
return $group->hasPermissionOn($permission, $this);
})
->getArrayCopy());
}
}
\ No newline at end of file
......@@ -18,9 +18,13 @@
* 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_BaseHelper extends Zend_View_Helper_HtmlElement {
use Trait_Translator;
public function __construct() {
$this->init();
}
......@@ -42,4 +46,24 @@ class ZendAfi_View_Helper_BaseHelper extends Zend_View_Helper_HtmlElement {
protected function _tag() {
return call_user_func_array([$this->view, 'tag'], func_get_args());
}
protected function _tagAnchor() {
return call_user_func_array([$this->view, 'tagAnchor'], func_get_args());
}
protected function _tagError($message) {
return $this->view->tagError($message);
}
protected function _tagNotice($message) {
return $this->view->tagNotice($message);
}
protected function _tagWarning($message) {
return $this->view->tagWarning($message);
}
}
\ No newline at end of file
......@@ -29,368 +29,11 @@ class ZendAfi_View_Helper_DigitalResource_Dashboard extends ZendAfi_View_Helper_
public function DigitalResource_Dashboard($config) {
$this->_config = $config;
return implode([$this->_renderStatus(),
$this->_renderSettings(),
$this->_renderRights(),
$this->_renderSso(),
$this->_renderHarvest()]);
}
protected function _renderStatus() {
return implode([$this->_globalStatus(),
$this->_harvestStatus()]);
}
protected function _globalStatus() {
$label = $this->_('Désactivé');
$class = 'digital_connectors_status';
if ($this->_config->isEnabled()) {
$label = $this->_('Activé');
$class .= ' enabled';
}
return $this->view->button((new Class_Entity)
->setText($label)
->setAttribs(['disabled' => 'disabled',
'onclick' => 'return;',
'class' => $class]));
}
protected function _harvestStatus() {
if(!$batch = $this->_config->getBatch())
return '';
$label = $this->_('Moissonnage désactivé');
$class = 'digital_connectors_status';
if (Class_Batch::findFirstBy(['type' => $batch])) {
$label = $this->_('Moissonnage activé');
$class .= ' enabled';
}
return $this->view->button((new Class_Entity)
->setText($label)
->setAttribs(['disabled' => 'disabled',
'onclick' => 'return;',
'class' => $class]));
}
protected function _renderSettings() {
$description = (new Class_TableDescription('adminvars'))
->addColumn($this->_('description'), 'description')
->addColumn($this->_('Clef'), 'id')
->addColumn($this->_('valeur'),
function($model)
{
return ($renderer = $model->getRenderer())
? $renderer($model->getValeur(), $this->view)
: $this->view->adminVar($model);
})
->addRowAction(function($model)
{
return $this->view->renderModelActions($model,
[['url' => ['module' => 'admin',
'controller' => 'index',
'action' => 'adminvaredit',
'cle' => $model->getClef()],
'icon' => 'edit',
'anchorOptions' => ['data-popup' => true],
'label' => $this->_('Modifier "%s"', $model->getClef())]]);
});
$html = ($table = $this->view->renderTable($description,
$this->_config->getAdminVarsInstances(),
['sorter' => true]))
? $table
: $this->_tag('p', $this->_('Veuillez vérifier le fichier config.php de la ressource pour pouvoir gérer le paramétrage'), ['class' => 'error']);
return $this->_tag('h3', $this->_('Paramétrage')) . $html;
}
protected function _renderRights() {
$html = [$this->_tag('h3',$this->_('Gestion des droits'))];
if (!$this->_config->isEnabled()) {
$html [] = $this->_tag('p', $this->_('Veuillez activer la ressource pour pouvoir gérer les droits d\'accès des groupes'), ['class' => 'error']);
return implode($html);
}
if(!$permission_label = $this->_config->getPermissionLabel()) {
$html [] = $this->_tag('p', $this->_('Cette ressource ne prend pas en charge la gestion des droits'), ['class' => 'error']) ;
return implode($html);
}
$html [] = $this->_tag('p', $this->_('Nom de la permission à donner : "%s"', $permission_label));
$groups = new Storm_Collection(Class_UserGroup::findAll());
$this->_permitted_groups = array_filter(
$groups
->select(function ($group)
{
$permission = $this->_config->getPermission();
return $group->hasPermissionOn($permission, $this->_config);
})
->getArrayCopy());
if (empty($this->_permitted_groups)) {
$html [] = $this->_tag('p', $this->_('Aucun groupe n\'a de droits d\'accès à la ressources'), ['class' => 'error'])
. $this->view->tagAnchor($this->view->absoluteUrl(['module' => 'admin',
'controller' => 'usergroup',
'action' => 'index'],
null,
true),
$this->_('Gérer les groupes'),
['target' => '_blank']);
return implode($html);
}
$usergroup_description = (new Class_TableDescription('usergroups'))
->addColumn($this->_('Groupes qui ont accès à la ressource'),
'libelle')
->addColumn($this->_('Nombre de membres'),
function($model) { return $model->formatedCount();})
->addRowAction(function($model)
{
return $this->view->renderModelActions($model,
[['url' => ['module' => 'admin',
'controller' => 'usergroup',
'action' => 'edit',
'id' => $model->getId()],
'icon' => 'edit',
'anchorOptions' => ['data-popup' => true],
'label' => $this->_('Modifier "%s"', $model->getLibelle())]]);
});
$html [] = $this->view->renderTable($usergroup_description, $this->_permitted_groups, ['sorter' => true]);
$count_user = 0;
foreach($this->_permitted_groups as $group)
$count_user += $group->formatedCount();
if (0 == $count_user)
$html [] = $this->_tag('p', $this->_('Aucun utilisateur rattaché aux groupes'), ['class' => 'error']);
return implode($html);
}
protected function _renderSso() {
$html = [$this->_tag('h3', $this->_('Diagnostic SSO'))];
if(!$this->_config->getSsoAction()) {
$html [] = $this->_tag('p', $this->_('Cette ressource ne prend pas en charge la connexion SSO'), ['class' => 'error']) ;
return implode($html);
}
if(!$this->_permitted_groups) {
$html [] = $this->_tag('p', $this->_('Veuillez configurer les droits de cette ressource pour obtenir une connexion SSO'), ['class' => 'error']);
return implode($html);
}
$user = $this->_config->getTestUser();
$group = $this->_config->getTestGroup();
$html [] = $this->_tag('h5', $this->_('Groupe créé pour ce test'))
. $this->_tag('ul',
$this->_tag('li', $this->_('Nom : %s', $group->getLibelle())));
Class_Users::clearCache();
$user = Class_Users::find($user->getId());
$html [] = $this->_tag('h5', $this->_('Utilisateur créé pour ce test'))
. $this->_tag('ul',
$this->_tag('li', $this->_('Login : %s', $user->getLogin()))
. $this->_tag('li', $this->_('Mot de passe : %s', $user->getLogin()))
. $this->_tag('li', $this->_('Groupes : %s', implode(', ',$user->getUserGroupsLabels()))));
$html [] = $this->view->renderModelActions($user,
[['url' => ['module' => 'admin',
'controller' => 'users',
'action' => 'edit',
'id' => $user->getId()],
'icon' => 'edit',
'anchorOptions' => ['data-popup' => true],
'label' => $this->_('Modifier "%s"',
$user->getLogin())]]);
$url = $this->_config->urlFor($user);
$html [] = $this->_tag('h4', $this->_('URL SSO générée par /modules/%s pour l\'utilisateur "%s"',
$this->_config->getSsoAction(),
$user->getLogin()))
. $this->_tag('pre', $url)
. $this->view->button((new Class_Entity)
->setUrl($this->view->url(['action' => 'try-sso']))
->setText($this->_('Essayer le SSO avec l\'utilisateur "%s"',
$user->getLogin())));
if(!$this->_config->getSsoValidateUrl()) {
$html [] = $this->_tag('p', $this->_('Cette ressource ne prend pas en charge la validation du ticket de connexion SSO'), ['class' => 'error']) ;
}
if($this->_config->getSsoValidateUrl()) {
$url = $this->_config->validateUrlFor($user);
$html [] = $this->_tag('h4', $this->_('URL de validation du ticket de connexion générée pour l\'utilisateur "%s"',
$user->getLogin()))
. $this->_tag('pre', $url);
}
if(!$album = Class_Album::findFirstby(['type_doc_id' => $this->_config->getDocType()]))
return implode($html);
$album_url = $this->_config->getAlbumSsoUrl($user, $album);
$html [] = $this->_tag('h4', $this->_('URL SSO générée pour l\'utilisateur "%s" et l\'album "%s"',
$user->getLogin(),
$album->getTitre())
. $this->view->tagAnchor(['module' => 'admin',
'controller' => 'album',
'action' => 'edit_album',
'id' => $album->getId()], $this->_('Voir l\'album'),
['style' => 'margin-left: 1em',
'data-popup' => 'true']))
. $this->view->tagAnchor($album_url, $album_url, ['target' => '_blank']);
return implode($html);
}
protected function _renderHarvest() {
$html = [$this->_tag('h3', $this->_('Diagnostic moissonnage'))];
if(!$batch_name = $this->_config->getBatch()) {
$html [] = $this->_tag('p', $this->_('Cette ressource ne prend pas en charge le moissonnage'), ['class' => 'error']) ;
return implode($html);
}
if (!$this->_config->isEnabled()) {
$html [] = $this->_tag('p', $this->_('Veuillez activer la ressource pour pouvoir gérer le moissonage'), ['class' => 'error']);
return implode($html);
}
if(!$batch = Class_Batch::findFirstBy(['type' => $batch_name])) {
$html [] = $this->_tag('p', $this->_('Le moissonnage n\'est pas programmé'), ['class' => 'error'])
. $this->view->button((new Class_Entity())
->setText($this->_('Activer le moissonnage'))
->setUrl($this->view->absoluteUrl(['module' => 'admin',
'controller' => 'batch',
'action' => 'activate',
'id' => $batch_name],
null,
true)));
}
$description = (new Class_TableDescription('batchs'))
->addColumn($this->_('Batch'), function($model) { return $model->getLabel(); })
->addColumn($this->_('Planification'),
function($model)
{
return (new Class_Repeat_WeekDays())->humanReadable($model->getPickDay());
})
->addColumn($this->_('Dernière exécution'), function($model) { return $model->getLastRun(); })
->addRowAction(function($model)
{
return $this->view->renderModelActions($model,
[
['url' => '/admin/batch/delete/id/%s',
'icon' => 'show',
'label' => $this->_('Désactiver la tâche'),
'condition' => function($model)
{
return $model->isDeletable();
},
'anchorOptions' =>
['onclick' => 'return confirm(\''
. str_replace(['\'', '"'], '\\\'',
$this->_('Etes-vous sur de vouloir désactiver cette tâche ?'))
. '\')']],
['url' => '/admin/batch/plan/id/%s',
'icon' => 'calendar',
'label' => $this->_('Plannifier la tâche'),
'condition' => function($model) {
return Class_Users::isCurrentUserSuperAdmin()
&& $model->isActive();
},
'anchorOptions' => ['data-popup' => 'true']],]);
});
if($batch)
$html [] = $this->view->renderTable($description, [new Class_Batch_Definition($this->_config->getBatchInstance())]);
$html [] = ($url = $this->_config->getHarvestUrl())
? ($this->_tag('h4',
$this->_('URL de moissonnage générée pour la première page'))
. $this->_tag('pre', $url))
: $this->_config->renderHarvestDiagOn($this->view);
$html [] = $this->_tag('h4',
$this->_('Image du type de document: ')
. $this->view->tagImg($this->view->url(['module' => 'opac',
'controller' => 'digital-resource',
'action' => 'typedoc-icon',
'id' => $this->_config->getName()])));
$count = Class_Album::countBy(['type_doc_id' => $this->_config->getDocType()]);
$first_album = Class_Album::findFirstBy(['type_doc_id' => $this->_config->getDocType(),
'order' => 'titre asc']);
$albums_link = $count
? $this->view->tagAnchor($this->view->absoluteUrl(['module' => 'admin',
'controller' => 'album',
'action' => 'index',
'cat_id' => $first_album->getRootCategoryId()], null, true),
$this->_('Voir les albums'),
['target' => '_blank'])
: '';
$html [] = $count
? $this->_tag('h4',
$this->_('Nombre d\'albums présents dans Bokeh : %d', $count))
. $albums_link
: $this->_tag('p', $this->_('Aucun album présent pour cette ressource'), ['class' => 'error']);
$html [] = $count
? ($this->_tag('h4',
$this->_('Tentative de vignettage de l\'album "%s" : ', $first_album->getTitre()))
. $this->_tag('pre',
$this->_('Image source : %s', $first_album->getPoster()))
. $this->_renderThumbnailerLog($first_album))
: $this->_tag('p', $this->_('Le vignettage n\'est pas testable sans album'), ['class' => 'error']);
$count = Class_Notice::countBy(['type_doc' => $this->_config->getDocType()]);
$records_link = $count ?
$this->view->tagAnchor($this->view->absoluteUrl(['module' => 'opac',
'controller' => 'recherche',
'action' => 'simple',
'facette' => 'T' . $this->_config->getDocType()], null, true),
$this->_('Voir les notices'),
['target' => '_blank'])
: '';
$html [] = $count
? $this->_tag('h4',
$this->_('Nombre de notices présentes dans Bokeh : %d', $count))
. $records_link
: $this->_tag('p', $this->_('Aucune notice présente pour cette ressource'), ['class' => 'error']);
return implode($html);
}
protected function _renderThumbnailerLog($album) {
$thumbnailer = Class_WebService_BibNumerique_Vignette::getInstance();
$thumbnailer->setLogger(new Class_Log);
if(!$errors = $thumbnailer->getDownloadPosterLog($album))
return $this->_tag('p', $this->_('Vignette de l\'album : '
. $this->view->tagImg(Class_Url::absolute($album->getThumbnailUrl()))));
return $this->_tag('p', implode(BR, $errors), ['class' => 'error']);
return implode([$this->view->DigitalResource_Dashboard_Status($config),
$this->view->DigitalResource_Dashboard_Settings($config),
$this->view->DigitalResource_Dashboard_Rights($config),
$this->view->DigitalResource_Dashboard_SSO($config),
$this->view->DigitalResource_Dashboard_Harvest($config),
$this->view->DigitalResource_Dashboard_Custom($config)]);
}
}
\ No newline at end of file
<?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_DigitalResource_Dashboard_Custom extends ZendAfi_View_Helper_BaseHelper {
public function DigitalResource_Dashboard_Custom($config) {
return $config->renderCustomDiagOn($this->view);
}
}
\ No newline at end of file
<?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_DigitalResource_Dashboard_Harvest extends ZendAfi_View_Helper_BaseHelper {
public function DigitalResource_Dashboard_Harvest($config) {
$html = [$this->_tag('h3', $this->_('Diagnostic moissonnage'))];
if(!$batch_name = $config->getBatch()) {
$html [] = $this->_tagNotice($this->_('Cette ressource ne prend pas en charge le moissonnage')) ;
return implode($html);
}
if (!$config->isEnabled()) {
$html [] = $this->_tagWarning($this->_('Veuillez activer la ressource pour pouvoir gérer le moissonage'));
return implode($html);
}
$html [] = $this->_getBatchHtml($config);
$html [] = $this->_getHarvestHtml($config);
$html [] = $this->_tag('h4',
$this->_('Image du type de document: ')
. $this->view->tagImg($this->view->url(['module' => 'opac',
'controller' => 'digital-resource',
'action' => 'typedoc-icon',
'id' => $config->getName()])));
$html [] = $this->_getAlbumsHtml($config);
$html [] = $this->_getRecordsHtml($config);
return implode($html);
}
protected function _renderThumbnailerLog($album) {
$thumbnailer = Class_WebService_BibNumerique_Vignette::getInstance();
$thumbnailer->setLogger(new Class_Log);
if(!$errors = $thumbnailer->getDownloadPosterLog($album))
return $this->_tag('p', $this->_('Vignette de l\'album : '
. $this->view->tagImg(Class_Url::absolute($album->getThumbnailUrl()))));
return $this->_tag('p', implode(BR, $errors), ['class' => 'error']);
}
protected function _getBatchHtml($config) {
if(!$batch = Class_Batch::findFirstBy(['type' => $batch_name]))
return implode([$this->_tagWarning($this->_('Le moissonnage n\'est pas programmé')),
$this->view->button((new Class_Entity())
->setText($this->_('Activer le moissonnage'))
->setUrl($this->view->absoluteUrl(['module' => 'admin',
'controller' => 'batch',
'action' => 'activate',