Skip to content
Snippets Groups Projects
Commit bcd41b85 authored by Jean-Philippe Metivier's avatar Jean-Philippe Metivier
Browse files

Snapshots

parent 7e698478
No related branches found
No related tags found
No related merge requests found
Pipeline #37630 failed
Showing with 155 additions and 76 deletions
...@@ -46,9 +46,9 @@ ...@@ -46,9 +46,9 @@
Ce qui reste à faire Ce qui reste à faire
<ul> <ul>
<li style="text-decoration: line-through">Faire les insertions par batch plutôt qu'un par un.</li> <li style="text-decoration: line-through">Faire les insertions par batch plutôt qu'un par un.</li>
<li>Gestion avec un csv</li> <li style="text-decoration: line-through">Permettre des snapshots</li>
<li>Dater insertion + dater suppression</li> <li>Dater insertion + dater suppression</li>
<li>Permettre des snapshots</li> <li>Gestion avec un csv</li>
<li>Purge des données plus vielle qu'un seuil</li> <li>Purge des données plus vielle qu'un seuil</li>
<li><code>try_catch</code> sur les opérations.</li> <li><code>try_catch</code> sur les opérations.</li>
<li>Interface de déclaration des ORM/Applications + formulaire </li> <li>Interface de déclaration des ORM/Applications + formulaire </li>
......
...@@ -9,6 +9,7 @@ use Indicateur\Form\Snapshot\SnapshotHydratorFactory; ...@@ -9,6 +9,7 @@ use Indicateur\Form\Snapshot\SnapshotHydratorFactory;
use Indicateur\Provider\Privilege\SnapshotPrivileges; use Indicateur\Provider\Privilege\SnapshotPrivileges;
use Indicateur\Service\Snapshot\SnapshotService; use Indicateur\Service\Snapshot\SnapshotService;
use Indicateur\Service\Snapshot\SnapshotServiceFactory; use Indicateur\Service\Snapshot\SnapshotServiceFactory;
use Indicateur\View\Helper\SnapshotsViewHelper;
use Laminas\Router\Http\Literal; use Laminas\Router\Http\Literal;
use Laminas\Router\Http\Segment; use Laminas\Router\Http\Segment;
use UnicaenPrivilege\Guard\PrivilegeController; use UnicaenPrivilege\Guard\PrivilegeController;
...@@ -145,7 +146,8 @@ return [ ...@@ -145,7 +146,8 @@ return [
], ],
], ],
'view_helpers' => [ 'view_helpers' => [
'factories' => [ 'invokables' => [
'snapshots' => SnapshotsViewHelper::class
], ],
], ],
]; ];
\ No newline at end of file
...@@ -3,6 +3,7 @@ ...@@ -3,6 +3,7 @@
namespace Indicateur\Controller; namespace Indicateur\Controller;
use DateTime; use DateTime;
use Indicateur\Service\Snapshot\SnapshotServiceAwareTrait;
use Laminas\Http\Response; use Laminas\Http\Response;
use Indicateur\Entity\Db\Indicateur; use Indicateur\Entity\Db\Indicateur;
use Indicateur\Entity\Db\Categorie; use Indicateur\Entity\Db\Categorie;
...@@ -23,6 +24,7 @@ class IndicateurController extends AbstractActionController { ...@@ -23,6 +24,7 @@ class IndicateurController extends AbstractActionController {
use AbonnementServiceAwareTrait; use AbonnementServiceAwareTrait;
use MailServiceAwareTrait; use MailServiceAwareTrait;
use PerimetreServiceAwareTrait; use PerimetreServiceAwareTrait;
use SnapshotServiceAwareTrait;
use IndicateurFormAwareTrait; use IndicateurFormAwareTrait;
...@@ -75,12 +77,15 @@ class IndicateurController extends AbstractActionController { ...@@ -75,12 +77,15 @@ class IndicateurController extends AbstractActionController {
// if ($exists === true) $result = $this->getIndicateurService()->getIndicateurData($indicateur, $perimetres); // if ($exists === true) $result = $this->getIndicateurService()->getIndicateurData($indicateur, $perimetres);
$result = $this->getIndicateurService()->getIndicateurData($indicateur, $perimetres); $result = $this->getIndicateurService()->getIndicateurData($indicateur, $perimetres);
$snapshots = $this->getSnapshotService()->getSnapshots($indicateur);
return new ViewModel([ return new ViewModel([
'indicateur' => $indicateur, 'indicateur' => $indicateur,
'exists' => $exists, 'exists' => $exists,
'header' => ($exists)?$result[0]:null, 'header' => ($exists)?$result[0]:null,
'data' => ($exists)?$result[1]:null, 'data' => ($exists)?$result[1]:null,
'mails' => $mails, 'mails' => $mails,
'snapshots' => $snapshots,
]); ]);
} }
......
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
namespace Indicateur\Controller; namespace Indicateur\Controller;
use Indicateur\Service\Snapshot\SnapshotService;
use Psr\Container\ContainerExceptionInterface; use Psr\Container\ContainerExceptionInterface;
use Psr\Container\NotFoundExceptionInterface; use Psr\Container\NotFoundExceptionInterface;
use Indicateur\Form\Indicateur\IndicateurForm; use Indicateur\Form\Indicateur\IndicateurForm;
...@@ -28,11 +29,13 @@ class IndicateurControllerFactory { ...@@ -28,11 +29,13 @@ class IndicateurControllerFactory {
* @var MailService $mailService * @var MailService $mailService
* @var UserService $userService * @var UserService $userService
* @var PerimetreServiceInterface $perimetreService * @var PerimetreServiceInterface $perimetreService
* @var SnapshotService $snapshotService
*/ */
$abonnementService = $container->get(AbonnementService::class); $abonnementService = $container->get(AbonnementService::class);
$indicateurService = $container->get(IndicateurService::class); $indicateurService = $container->get(IndicateurService::class);
$mailService = $container->get(MailService::class); $mailService = $container->get(MailService::class);
$userService = $container->get(UserService::class); $userService = $container->get(UserService::class);
$snapshotService = $container->get(SnapshotService::class);
$config = $container->get('config'); $config = $container->get('config');
$perimetreServiceKey = $container->get($config['unicaen-indicateur']['perimetreService']); $perimetreServiceKey = $container->get($config['unicaen-indicateur']['perimetreService']);
...@@ -49,6 +52,7 @@ class IndicateurControllerFactory { ...@@ -49,6 +52,7 @@ class IndicateurControllerFactory {
$controller->setIndicateurService($indicateurService); $controller->setIndicateurService($indicateurService);
$controller->setMailService($mailService); $controller->setMailService($mailService);
$controller->setPerimetreService($perimetreService); $controller->setPerimetreService($perimetreService);
$controller->setSnapshotService($snapshotService);
$controller->setUserService($userService); $controller->setUserService($userService);
$controller->setIndicateurForm($indicateurForm); $controller->setIndicateurForm($indicateurForm);
return $controller; return $controller;
......
...@@ -48,7 +48,7 @@ class Snapshot ...@@ -48,7 +48,7 @@ class Snapshot
public function generateTablename(): string public function generateTablename(): string
{ {
return "snapshot_".$this->indicateur->getCode()."_".$this->date->format("YmdHis"); return "snapshot_".str_replace(' ','_',$this->getIndicateur()->getOrm())."_".$this->indicateur->getCode()."_".$this->date->format("YmdHis");
} }
} }
\ No newline at end of file
...@@ -41,11 +41,10 @@ class SnapshotService ...@@ -41,11 +41,10 @@ class SnapshotService
public function getQueryBuilder(): QueryBuilder public function getQueryBuilder(): QueryBuilder
{ {
$qb = $this->getObjectManager()->getRepository(Snapshot::class)->createQueryBuilder('snapshot') return $this->getObjectManager()->getRepository(Snapshot::class)->createQueryBuilder('snapshot')
->join('snapshot.indicateur', 'indicateur')->addSelect('indicateur') ->join('snapshot.indicateur', 'indicateur')->addSelect('indicateur')
->orderBy('snapshot.date', 'DESC') ->orderBy('snapshot.date', 'DESC')
; ;
return $qb;
} }
public function getSnapshot(?int $id): ?Snapshot public function getSnapshot(?int $id): ?Snapshot
...@@ -83,8 +82,11 @@ class SnapshotService ...@@ -83,8 +82,11 @@ class SnapshotService
public function createSnapshot(Snapshot $snapshot): void public function createSnapshot(Snapshot $snapshot): void
{ {
$indicateur = $snapshot->getIndicateur();
$this->getIndicateurService()->refresh($indicateur);
$tablename = $snapshot->generateTablename(); $tablename = $snapshot->generateTablename();
$array = $this->getIndicateurService()->fetch($snapshot->getIndicateur()); $array = $this->getIndicateurService()->fetch($indicateur);
$champs = array_keys($array[0]); $champs = array_keys($array[0]);
$this->getSqlService()->createTable($tablename, $champs); $this->getSqlService()->createTable($tablename, $champs);
......
<?php
namespace Indicateur\View\Helper;
use Indicateur\Entity\Db\Snapshot;
use Laminas\View\Helper\AbstractHelper;
use Laminas\View\Helper\Partial;
use Laminas\View\Renderer\PhpRenderer;
use Laminas\View\Resolver\TemplatePathStack;
class SnapshotsViewHelper extends AbstractHelper {
/**
* @param Snapshot[] $snapshots
* @param array $options
* @return Partial|string
*/
public function __invoke(array $snapshots,array $options = [])
{
/** @var PhpRenderer $view */
$view = $this->getView();
$view->resolver()->attach(new TemplatePathStack(['script_paths' => [__DIR__ . "/partial"]]));
return $view->partial('snapshots', ['snapshots' => $snapshots, 'options' => $options]);
}
}
\ No newline at end of file
<?php
use Indicateur\Entity\Db\Snapshot;
use Indicateur\Provider\Privilege\SnapshotPrivileges;
/**
* @see \Indicateur\View\Helper\SnapshotsViewHelper
* @var Snapshot[] $snapshots
* @var array $options
*/
$canAfficher = $this->isAllowed(SnapshotPrivileges::getResourceId(SnapshotPrivileges::SNAPSHOT_AFFICHER));
$canExporter = $this->isAllowed(SnapshotPrivileges::getResourceId(SnapshotPrivileges::SNAPSHOT_AFFICHER));
$canAjouter = $this->isAllowed(SnapshotPrivileges::getResourceId(SnapshotPrivileges::SNAPSHOT_MODIFIER));
$canModifier = $this->isAllowed(SnapshotPrivileges::getResourceId(SnapshotPrivileges::SNAPSHOT_MODIFIER));
$canSupprimer = $this->isAllowed(SnapshotPrivileges::getResourceId(SnapshotPrivileges::SNAPSHOT_MODIFIER));
?>
<table class="table table-condensed datatable" id="snapshots">
<thead>
<tr>
<th class="col-md-10">Snapshot</th>
<th class="col-md-2">Action</th>
</tr>
</thead>
<tbody>
<?php foreach ($snapshots as $snapshot) : ?>
<tr>
<td>
<?php echo $snapshot->getIndicateur()->getCode(); ?> - <?php echo $snapshot->getDate()->format('d/m/Y à H:i:s'); ?>
<br>
<em><?php echo $snapshot->getDescription()??"Aucune description"; ?></em>
</td>
<td class="action">
<?php if ($canAfficher) : ?>
<?php /** @see \Indicateur\Controller\SnapshotController::afficherAction() */ ?>
<a href="<?php echo $this->url('snapshot/afficher', ['snapshot' => $snapshot->getId()], [], true); ?>"
class="action secondary"
>
<span class="icon icon-voir"></span>
Afficher
</a>
<?php endif; ?>
<?php if ($canExporter) : ?>
<br>
<?php /** @see \Indicateur\Controller\SnapshotController::exporterAction() */ ?>
<a href="<?php echo $this->url('snapshot/exporter', ['snapshot' => $snapshot->getId()], [], true); ?>"
class="action secondary"
>
<span class="icon icon-csv"></span>
Exporter
</a>
<?php endif; ?>
<?php if ($canModifier) : ?>
<br>
<?php /** @see \Indicateur\Controller\SnapshotController::modifierAction() */ ?>
<a href="<?php echo $this->url('snapshot/modifier', ['snapshot' => $snapshot->getId()], [], true); ?>"
class="action primary ajax-modal" data-event="modification"
>
<span class="icon icon-editer"></span>
Modifier
</a>
<?php endif; ?>
<?php if ($canSupprimer) : ?>
<br>
<?php /** @see \Indicateur\Controller\SnapshotController::supprimerAction() */ ?>
<a href="<?php echo $this->url('snapshot/supprimer', ['snapshot' => $snapshot->getId()], [], true); ?>"
class="action danger ajax-modal" data-event="modification"
>
<span class="icon icon-unchecked"></span>
Supprimer
</a>
<?php endif; ?>
</td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
<script>
$(function () {
$("body").on("modification", function (event) {
event.div.modal('hide');
window.location.reload();
});
$('#snapshots').DataTable( {
autoWidth: false,
language: {
"url": "/js/datatables_fr.json",
},
columnDefs: [
{ targets: [1], orderable: false }
]
} );
});
</script>
\ No newline at end of file
...@@ -6,11 +6,12 @@ ...@@ -6,11 +6,12 @@
* @var bool $exists * @var bool $exists
* @var array $header * @var array $header
* @var array $data * @var array $data
* @var Snapshot[] $snapshots
*/ */
use Indicateur\Entity\Db\Indicateur; use Indicateur\Entity\Db\Indicateur;
use Indicateur\Entity\Db\Snapshot;
$snapshots = $indicateur->getSnapshots();
?> ?>
<h1 class="page-header"> <h1 class="page-header">
...@@ -103,9 +104,13 @@ $snapshots = $indicateur->getSnapshots(); ...@@ -103,9 +104,13 @@ $snapshots = $indicateur->getSnapshots();
</a> </a>
<?php if (empty($snapshots)) : ?> <?php if (empty($snapshots)) : ?>
<div class="alert alert-info">
<span class="icon icon-info"></span>
Aucun snapshot
</div>
<?php else : ?>
<?php echo $this->snapshots($snapshots, []); ?>
<?php endif; ?> <?php endif; ?>
<span class="TODO">TODO</span>
</div> </div>
</div> </div>
<?php endif; ?> <?php endif; ?>
......
...@@ -10,12 +10,6 @@ use Indicateur\Provider\Privilege\SnapshotPrivileges; ...@@ -10,12 +10,6 @@ use Indicateur\Provider\Privilege\SnapshotPrivileges;
$this->headTitle("Liste des snapshots"); $this->headTitle("Liste des snapshots");
$canAfficher = $this->isAllowed(SnapshotPrivileges::getResourceId(SnapshotPrivileges::SNAPSHOT_AFFICHER));
$canExporter = $this->isAllowed(SnapshotPrivileges::getResourceId(SnapshotPrivileges::SNAPSHOT_AFFICHER));
$canAjouter = $this->isAllowed(SnapshotPrivileges::getResourceId(SnapshotPrivileges::SNAPSHOT_MODIFIER));
$canModifier = $this->isAllowed(SnapshotPrivileges::getResourceId(SnapshotPrivileges::SNAPSHOT_MODIFIER));
$canSupprimer = $this->isAllowed(SnapshotPrivileges::getResourceId(SnapshotPrivileges::SNAPSHOT_MODIFIER));
?> ?>
<h1 class="page-header"> <h1 class="page-header">
...@@ -27,66 +21,7 @@ $canSupprimer = $this->isAllowed(SnapshotPrivileges::getResourceId(SnapshotPrivi ...@@ -27,66 +21,7 @@ $canSupprimer = $this->isAllowed(SnapshotPrivileges::getResourceId(SnapshotPrivi
Pour ajouter un snapshot, rendez-vous sur l'indicateur sur lequel vous voulez ajouter un snapshot. Pour ajouter un snapshot, rendez-vous sur l'indicateur sur lequel vous voulez ajouter un snapshot.
</div> </div>
<table class="table table-condensed datatable" id="snapshots"> <?php echo $this->snapshots($snapshots); ?>
<thead>
<tr>
<th class="col-md-10">Snapshot</th>
<th class="col-md-2">Action</th>
</tr>
</thead>
<tbody>
<?php foreach ($snapshots as $snapshot) : ?>
<tr>
<td>
<?php echo $snapshot->getIndicateur()->getCode(); ?> - <?php echo $snapshot->getDate()->format('d/m/Y à H:i:s'); ?>
<br>
<em><?php echo $snapshot->getDescription()??"Aucune description"; ?></em>
</td>
<td class="action">
<?php if ($canAfficher) : ?>
<?php /** @see \Indicateur\Controller\SnapshotController::afficherAction() */ ?>
<a href="<?php echo $this->url('snapshot/afficher', ['snapshot' => $snapshot->getId()], [], true); ?>"
class="action secondary"
>
<span class="icon icon-voir"></span>
Afficher
</a>
<?php endif; ?>
<?php if ($canExporter) : ?>
<br>
<?php /** @see \Indicateur\Controller\SnapshotController::exporterAction() */ ?>
<a href="<?php echo $this->url('snapshot/exporter', ['snapshot' => $snapshot->getId()], [], true); ?>"
class="action secondary"
>
<span class="icon icon-csv"></span>
Exporter
</a>
<?php endif; ?>
<?php if ($canModifier) : ?>
<br>
<?php /** @see \Indicateur\Controller\SnapshotController::modifierAction() */ ?>
<a href="<?php echo $this->url('snapshot/modifier', ['snapshot' => $snapshot->getId()], [], true); ?>"
class="action primary ajax-modal" data-event="modification"
>
<span class="icon icon-editer"></span>
Modifier
</a>
<?php endif; ?>
<?php if ($canSupprimer) : ?>
<br>
<?php /** @see \Indicateur\Controller\SnapshotController::supprimerAction() */ ?>
<a href="<?php echo $this->url('snapshot/supprimer', ['snapshot' => $snapshot->getId()], [], true); ?>"
class="action danger ajax-modal" data-event="modification"
>
<span class="icon icon-unchecked"></span>
Supprimer
</a>
<?php endif; ?>
</td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
<script> <script>
$(function () { $(function () {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment