Commit 2aa045ee authored by François Agneray's avatar François Agneray
Browse files

Mise à jour auto des sessions

parent 6304e03c
......@@ -73,6 +73,10 @@ $container[App\Action\DashboardParticipantParcoursAction::class] = function ($c)
return new App\Action\DashboardParticipantParcoursAction($c->get('view'), $c->get('logger'), $c->get('em'), $c->get('settings'));
};
$container[App\Action\DashboardParticipantSessionsRefreshAction::class] = function ($c) {
return new App\Action\DashboardParticipantSessionsRefreshAction($c->get('logger'), $c->get('em'));
};
$container[App\Action\DashboardParticipantParcoursFormationAction::class] = function ($c) {
return new App\Action\DashboardParticipantParcoursFormationAction($c->get('view'), $c->get('logger'), $c->get('em'));
};
......
......@@ -4,9 +4,9 @@ $container = $app->getContainer();
// Error Handler
$container['errorHandler'] = function ($c) {
return new App\Action\CustomHandler($c->get('view'), $c->get('logger'));
};
// $container['errorHandler'] = function ($c) {
// return new App\Action\CustomHandler($c->get('view'), $c->get('logger'));
// };
// Twig
$container['view'] = function ($c) {
......
......@@ -56,6 +56,10 @@ $app->get('/dashboard-participant-parcours', App\Action\DashboardParticipantParc
->add(App\Middleware\TokenMiddleware::class)
->setName('dashboard_participant_parcours');
$app->get('/dashboard-participant-sessions-refresh', App\Action\DashboardParticipantSessionsRefreshAction::class)
->add(App\Middleware\TokenMiddleware::class)
->setName('dashboard_participant_sessions_refresh');
$app->map(['GET', 'POST'],'/dashboard-participant-parcours-formation', App\Action\DashboardParticipantParcoursFormationAction::class)
->add(App\Middleware\TokenMiddleware::class)
->setName('dashboard_participant_parcours_formation');
......
......@@ -25,11 +25,12 @@ final class DashboardParticipantParcoursFormationAction
$this->logger->info("dashboard page action dispatched");
$params = $request->getQueryParams();
$token = $params['token'];
$token = $params['token'];
$id_agenda = (int) $params['agenda'];
$valid = $params['valid'];
$roleSI = $request->getAttribute('roleSI');
if ( ($roleSI != 'admin') && ($roleSI != 'clo_pgm') ){
if ( ($roleSI == 'admin') || ($roleSI == 'clo_pgm') ){
$id_participant = $params['id'];
$participant = $this->em->find('App\Entity\Participant', $params['id']);
}
......
<?php
namespace App\Action;
use Slim\Views\Twig;
use Psr\Log\LoggerInterface;
use Doctrine\ORM\EntityManagerInterface;
use Psr\Http\Message\ServerRequestInterface as Request;
use Psr\Http\Message\ResponseInterface as Response;
final class DashboardParticipantSessionsRefreshAction
{
private $logger;
private $em;
public function __construct(LoggerInterface $logger, EntityManagerInterface $em)
{
$this->logger = $logger;
$this->em = $em;
}
public function __invoke(Request $request, Response $response, $args)
{
$this->logger->info("dashboard-participant-sessions-refresh page action dispatched");
$params = $request->getQueryParams();
$agendas = $this->getAgendas($params['jour'], $params['debut'], $params['fin']);
$aAgendas = array();
foreach($agendas as $agenda) {
$aAgendas[] = array(
'id' => $agenda['agenda']->getId(),
'nb_inscrits' => $agenda['nb_inscrits'],
'quota' => $agenda['agenda']->getFormation()->getQuota()
);
}
$data = array('agendas' => $aAgendas);
return $response->withJson($data);
}
private function getAgendas($jour, $debut, $fin) {
$date_debut = $jour . " " . $debut;
$date_fin = $jour . " " . $fin;
$dql = "SELECT a as agenda, ";
$dql .= "(select count(pa) from App\Entity\ParticipantAgenda pa where pa.agenda=a.id) as nb_inscrits ";
$dql .= "FROM App\Entity\Agenda a ";
$dql .= "WHERE a.dateDebut between '$date_debut' and '$date_fin' and a.dateFin between '$date_debut' and '$date_fin'";
$query = $this->em->createQuery($dql);
return $query->getResult();
}
}
......@@ -11,7 +11,7 @@
<a href="dashboard-home?token={{ token }}"><i class="fa fa-home"></i> Home</a>
</li>
<!--
<li class="navbar-dashboard-item">
<a href="dashboard-participant-sondage?token={{ token }}"><i class="fa fa-address-card-o"></i> Sondage</a>
</li>
......@@ -19,7 +19,7 @@
<li class="navbar-dashboard-item">
<a href="dashboard-participant-parcours?token={{ token }}"><i class="fa fa-cogs"></i> Parcours</a>
</li>
-->
</ul>
</nav>
......
......@@ -137,7 +137,7 @@
<div class="panel-body">
<div>
{% if agendas %}
<table id="tab_agenda" class="table table-striped table-bordered">
<table id="tab_agenda" class="table table-striped table-bordered" data-token="{{ token }}" data-jour="{{ jour }}" data-debut="{{ debut }}" data-fin="{{ fin }}">
<thead>
<tr>
<th width="10%">Session</th>
......@@ -167,8 +167,11 @@
<td>{{ a.getDateFin() | date("H:i") }}</td>
{% endfor %}
<td>{{ agenda.nb_inscrits }} / {{ quota }}</td>
<td>{{ ((agenda.nb_inscrits / quota) * 100) | round }}</td>
<td><span id="nb_inscrits_{{ id_agenda }}">{{ agenda.nb_inscrits }}</span> / {{ quota }}</td>
<td id="nb_inscrits_prct_{{ id_agenda }}">
{% set prct = ((agenda.nb_inscrits / quota) * 100) | round %}
<span class="badge badge-{% if prct <= 50 %}vert{% elseif prct > 50 and prct <= 75 %}orange{% else %}rouge{% endif %}">{{ prct }}%</span>
</td>
<td class="text-center">
{% if agenda.check == 0 %}
{% if inscription %}
......
......@@ -132,7 +132,7 @@
<div class="panel-body">
<div>
{% if agendas %}
<table id="tab_agenda" class="table table-striped table-bordered">
<table id="tab_agenda" class="table table-striped table-bordered" data-token="{{ token }}" data-jour="{{ jour }}" data-debut="{{ debut }}" data-fin="{{ fin }}">
<thead>
<tr>
<th width="10%">Session</th>
......@@ -162,8 +162,11 @@
<td>{{ a.getDateFin() | date("H:i") }}</td>
{% endfor %}
<td>{{ agenda.nb_inscrits }} / {{ quota }}</td>
<td>{{ ((agenda.nb_inscrits / quota) * 100) | round }}</td>
<td><span id="nb_inscrits_{{ id_agenda }}">{{ agenda.nb_inscrits }}</span> / {{ quota }}</td>
<td id="nb_inscrits_prct_{{ id_agenda }}">
{% set prct = ((agenda.nb_inscrits / quota) * 100) | round %}
<span class="badge badge-{% if prct <= 50 %}vert{% elseif prct > 50 and prct <= 75 %}orange{% else %}rouge{% endif %}">{{ prct }}%</span>
</td>
<td class="text-center">
{% if agenda.check == 0 %}
{% if inscription %}
......@@ -181,8 +184,6 @@
</a>
{% endif %}
</td>
</tr>
{% endfor %}
......
var intervalPointer;
$(document).ready(function(){
// ======================================================================
......@@ -52,6 +54,10 @@ $(document).ready(function(){
// Gestion du parcours
// ======================================================================
var tab_agendas = $('#tab_agenda');
if (tab_agendas) {
intervalPointer = setInterval(refreshSessions, 5000);
}
$('.btn-inscription-formation').on('click', function(e) {
e.preventDefault();
......@@ -105,19 +111,46 @@ $(document).ready(function(){
"render": function (data) {
return "<b><a href=\"http://devlog.cnrs.fr/jdev2017/" + data + "\" target=_blank><i class=\"fa fa-external-link\"></i> " + data.toUpperCase()+"</a></b>";
}
},
{
"targets" : 6,
"render": function (data) {
val=parseInt(data);
console.log(val);
if (val < 25){
return "<span class=\"badge badge-vert\">" + data + "%</span>";
}
}
}
}
],
"ordering": false
} );
});
var refreshSessions = function(token, jour, debut, fin) {
var token = $('#tab_agenda').data('token');
var jour = $('#tab_agenda').data('jour');
var debut = $('#tab_agenda').data('debut');
var fin = $('#tab_agenda').data('fin');
if (!token || !jour || !debut || !fin) {
console.log('Manque des valeurs pour lancer la requete');
clearInterval(intervalPointer);
return ;
}
$.ajax({
url: 'dashboard-participant-sessions-refresh?token=' + token + '&jour=' + jour + '&debut=' + debut + '&fin=' + fin,
type: 'GET',
success: function(data) {
data.agendas.forEach(function(agenda) {
$('#nb_inscrits_' + agenda.id).text(agenda.nb_inscrits);
var prct = Math.round(((agenda.nb_inscrits / agenda.quota) * 100));
var badge = '';
if (prct <= 50) {
badge = 'vert';
} else if (prct > 50 && prct <= 75) {
badge = 'orange';
} else {
badge = 'rouge';
}
$('#nb_inscrits_prct_' + agenda.id).html('<span class="badge badge-' + badge + '">' + prct + '%</span>');
});
},
error: function() {
console.log('PB refresh sessions');
clearInterval(intervalPointer);
}
});
}
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment