Added views history/*
This commit is contained in:
parent
3a730ccfbd
commit
77e3fc6f98
|
@ -0,0 +1,20 @@
|
|||
<?php
|
||||
|
||||
namespace view\history\details;
|
||||
|
||||
use \generic\core\i_view;
|
||||
use \api\core\Request;
|
||||
use \error\core\Err;
|
||||
|
||||
|
||||
class main extends i_view{
|
||||
|
||||
public $id_history;
|
||||
|
||||
|
||||
|
||||
public function __construct($id_history){
|
||||
$this->id_history = $id_history;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1 @@
|
|||
details
|
|
@ -0,0 +1,110 @@
|
|||
<?php
|
||||
|
||||
namespace view\history\view;
|
||||
|
||||
use \generic\core\i_view;
|
||||
use \api\core\Request;
|
||||
use \error\core\Err;
|
||||
|
||||
|
||||
class main extends i_view{
|
||||
|
||||
|
||||
|
||||
public function __construct(){}
|
||||
|
||||
|
||||
|
||||
|
||||
public function get_history(){
|
||||
$req = new Request('historyDefault/getAll', []);
|
||||
|
||||
$res = $req->dispatch();
|
||||
|
||||
// si erreur, on retourne rien par défaut
|
||||
if( $res->error->get() != Err::Success )
|
||||
return [];
|
||||
|
||||
return $res->get('history');
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
public function ts_format($ts){
|
||||
date_default_timezone_set('Europe/Paris');
|
||||
return date('d/m/Y H:i:s', $ts);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
public function ts_relative($ts){
|
||||
$r = self::relativetime($ts);
|
||||
|
||||
// if only one
|
||||
$o = $r[0] <= 1;
|
||||
|
||||
switch($r[1]){
|
||||
|
||||
case 'Y': return $r[0].' an'.($o?'':'s'); break;
|
||||
case 'm': return $r[0].' mois'; break;
|
||||
case 'd': return $r[0].' jour'.($o?'':'s'); break;
|
||||
|
||||
case 'H': return $r[0].' heure'.($o?'':'s'); break;
|
||||
case 'i': return $r[0].' minute'.($o?'':'s'); break;
|
||||
case 's': return $r[0].' seconde'.($o?'':'s'); break;
|
||||
|
||||
default: return 'peu de temps'; break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private static function relativetime($ts){
|
||||
|
||||
/* [1] Explode time into human-readable time units
|
||||
=========================================================*/
|
||||
$units = [];
|
||||
|
||||
/* (1) Date units */
|
||||
$units['year'] = (int) date('Y', $ts);
|
||||
$units['month'] = (int) date('m', $ts);
|
||||
$units['day'] = (int) date('d', $ts);
|
||||
|
||||
/* (2) Time units */
|
||||
$units['hour'] = (int) date('H', $ts);
|
||||
$units['minute'] = (int) date('i', $ts);
|
||||
$units['second'] = (int) date('s', $ts);
|
||||
|
||||
|
||||
/* [2] Calculate relative time for each unit
|
||||
=========================================================*/
|
||||
/* (1) Date units */
|
||||
$units['year'] = intval(date('Y')) - $units['year'];
|
||||
$units['month'] = intval(date('m')) - $units['month'];
|
||||
$units['day'] = intval(date('d')) - $units['day'];
|
||||
|
||||
/* (2) Time units */
|
||||
$units['hour'] = intval(date('H')) - $units['hour'];
|
||||
$units['minute'] = intval(date('i')) - $units['minute'];
|
||||
$units['second'] = intval(date('s')) - $units['second'];
|
||||
|
||||
|
||||
/* [3] Return significative relative time
|
||||
=========================================================*/
|
||||
/* (1) Date units */
|
||||
if( $units['year'] > 0 ) return [ $units['year'], 'Y' ];
|
||||
if( $units['month'] > 0 ) return [ $units['month'], 'm' ];
|
||||
if( $units['day'] > 0 ) return [ $units['day'], 'd' ];
|
||||
|
||||
/* (2) Time units */
|
||||
if( $units['hour'] > 0 ) return [ $units['hour'], 'H' ];
|
||||
if( $units['minute'] > 0 ) return [ $units['minute'], 'i' ];
|
||||
if( $units['second'] > 0 ) return [ $units['second'], 's' ];
|
||||
|
||||
/* (3) Default value */
|
||||
return [0, '.'];
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -0,0 +1,44 @@
|
|||
<input type='text' class='searchbar' placeholder='Recherche'>
|
||||
|
||||
|
||||
|
||||
{% for entry in core.get_history() %}
|
||||
|
||||
|
||||
{% if loop.index == 1 %}
|
||||
|
||||
<article class='inline-row' style='border: 0; box-shadow: none;background: transparent;'>
|
||||
<span>Machine</span>
|
||||
<span>Dernière utilisation</span>
|
||||
<span>Utilisateur</span>
|
||||
<span>Action</span>
|
||||
<span>Historique détaillé</span>
|
||||
</article>
|
||||
|
||||
{% endif %}
|
||||
|
||||
<article class='inline-row' id='{{ entry.id_history }}'>
|
||||
|
||||
<span data-machine='{{ entry.id_machine }}' class='title'><span>#{{ entry.machine_name }}</span></span>
|
||||
|
||||
<span>
|
||||
<span>{{ core.ts_format(entry.timestamp) }}</span>
|
||||
<span style='color:#aaa;'>Il y a {{ core.ts_relative(entry.timestamp) }}</span>
|
||||
</span>
|
||||
|
||||
|
||||
<span data-user='{{ entry.id_user }}'>
|
||||
<span>{{ entry.user_name }}</span>
|
||||
<span style='color:#aaa;'>{{ entry.user_firstname }} {{ entry.user_lastname }}</span>
|
||||
</span>
|
||||
|
||||
<span>
|
||||
<span>{{ entry.action_name }}</span>
|
||||
</span>
|
||||
|
||||
<span>
|
||||
<button class='search' data-details='{{ entry.id_history }}'>Détails</button>
|
||||
</span>
|
||||
|
||||
</article>
|
||||
{% endfor %}
|
|
@ -1,11 +1,7 @@
|
|||
<?php define('__ROOT__', dirname(dirname(dirname(__FILE__))) );
|
||||
require_once __ROOT__.'/vendor/autoload.php';
|
||||
use \api\core\Request;
|
||||
use \database\core\DatabaseDriver;
|
||||
use \database\core\Repo;
|
||||
use \viewer\core\Viewer;
|
||||
|
||||
use \orm\core\Table; use \orm\core\Rows;
|
||||
use \generic\core\View;
|
||||
?>
|
||||
|
||||
<!-- [1] Gestion du sous-menu de gauche -->
|
||||
|
@ -45,8 +41,8 @@
|
|||
=========================================================*/
|
||||
echo "<section data-sublink='view' class='list fstart'>";
|
||||
|
||||
$view = new Viewer('history.view', []);
|
||||
$view->view();
|
||||
$view = View::load('history.view');
|
||||
echo $view->render();
|
||||
|
||||
echo '</section>';
|
||||
|
||||
|
@ -60,9 +56,10 @@
|
|||
|
||||
echo "<section data-sublink='details' class='list fstart'>";
|
||||
|
||||
echo "details";
|
||||
$view = new Viewer('history.details', []);
|
||||
$view->view();
|
||||
$view = View::load('history.details');
|
||||
echo $view->render([
|
||||
$post[1] // id_history
|
||||
]);
|
||||
|
||||
echo '</section>';
|
||||
|
||||
|
|
Loading…
Reference in New Issue