Removed build/viewer + migrated forms of machine/*

This commit is contained in:
xdrm-brackets 2017-11-07 11:21:27 +01:00
parent 77e3fc6f98
commit 550b1bd849
27 changed files with 74 additions and 1516 deletions

View File

@ -0,0 +1,12 @@
<?php
namespace view\machine\form\create;
use \generic\core\i_view;
class main extends i_view{
public function __construct(){}
}

View File

@ -0,0 +1,5 @@
<form class='valid'>
<input id='create_name' type='text' placeholder='Name'><br>
<span class='error-msg create_name'></span><br>
<button id='create_submit'>Créer</button>
</form>

View File

@ -0,0 +1,12 @@
<?php
namespace view\machine\form\edit;
use \generic\core\i_view;
class main extends i_view{
public function __construct(){}
}

View File

@ -0,0 +1,14 @@
<form class='neutral'>
<input id='edit_search_keyword' type='text' class='search' placeholder='Recherche...'><br>
<input id='edit_search_id' type='hidden' value=''>
<!-- Indice du resultat -->
<span class='edit_search_view'>machine <span class='edit_search_num'>0</span> sur <span class='edit_search_sum'>0</span></span><br><br>
<button id='edit_search_submit' class='search'>Trouver/Suivant</button><br>
<br><br><hr class='OR' data-label='PUIS' /><br><br>
<input id='edit_name' type='text' placeholder='Name'><br>
<span class='error-msg edit_name'></span><br>
<button id='edit_submit' disabled>Modifier</button>
</form>

View File

@ -0,0 +1,12 @@
<?php
namespace view\machine\form\remove;
use \generic\core\i_view;
class main extends i_view{
public function __construct(){}
}

View File

@ -0,0 +1,13 @@
<form class='invalid'>
<input id='remove_search_keyword' type='text' class='search' placeholder='Recherche...'><br>
<input id='remove_search_id' type='hidden' value=''>
<!-- Indice du resultat -->
<span class='remove_search_view'>machine <span class='remove_search_num'>0</span> sur <span class='remove_search_sum'>0</span></span><br><br>
<button id='remove_search_submit' class='search'>Trouver/Suivant</button><br>
<br><br><hr class='OR' data-label='PUIS' /><br><br>
<input id='remove_name' type='text' placeholder='Name'><br>
<button id='remove_submit' disabled>Supprimer</button>
</form>

View File

@ -1,146 +0,0 @@
<?php
namespace viewer\core;
use \error\core\Error;
use \error\core\Err;
class Viewer{
public $error;
private $template;
private $args;
private $view;
public static $htmlError = "<span class='error'>Une erreur est survenue, veuilez contacter le webmaster si cette erreur persiste.</span>";
/* INITIALISATION DE LA VUE VUE
*
* @template<String> Nom du modèle de la vue à utiliser
* @args<Array> Données pour construire la vue à partir du modèle
*
*/
public function __construct($template, $args){
$this->error = new Error(Err::Success);
// Si pas parametre manquant, on quitte
if( $template == null ){
$this->error = new Error(Err::MissingPath);
return false;
}
/* [1] On vérifie que le template existe
=========================================================*/
$templatePath = $this->checkPath($template);
if( $templatePath === false )
return false;
/* [2] On récupère le chemin du template et on l'enregistre
=========================================================*/
$this->template = $templatePath;
/* [3] On enregistre les paramètres
=========================================================*/
$this->args = $args;
/* [4] On process la vue
=========================================================*/
$this->view = call_user_func(
$this->template,
$this->args
);
}
/* AFFICHE LA VUE CALCULEE
*
*/
public function view(){
echo $this->view;
}
/* RETOURNE LA VUE CALCULEE
*
*/
public function getView(){
return $this->view;
}
/* VERIFICATION DE L'EXISTENCE D'UN MODELE
*
* @template<String> Chemin du modèle
*
* @return status<Boolean> TRUE si le modèle existe, sinon FALSE
*
*/
private function checkPath($template){
/* [1] On vérifie le format
=========================================================*/
if( !preg_match('/^(\w+)\.(\w+)$/i', $template, $match) ){
$this->error = new Error(Err::ParamError);
return false;
}
/* [2] On vérifie que le template existe
=========================================================*/
$class = '\\viewer\\view\\'.$match[1].'\\'.$match[2];
$method = 'render';
/* (1) On vérifie que la classe existe */
if( !class_exists($class) ){
$this->error = new Error(Err::UnknownTemplate);
return false;
}
/* (2) On vérifie que la méthode existe */
if( !method_exists($class, $method) ){
$this->error = new Error(Err::UnknownTemplate);
return false;
}
/* [3] Si tout est bon, on renvoie les données
=========================================================*/
return [ $class, $method ];
}
}
// USE case
//
// $myView = new Viewer('templateParent.templateModel', [
// 'myVar' => 1,
// 'helloMsg' => 'Hello',
// ]);
//
// $myView->view();
//
?>

View File

@ -1,52 +0,0 @@
<?php
namespace viewer\view\group;
use \api\core\Request;
use \error\core\Error;
use \error\core\Err;
use \api\core\Authentification;
class group_choice{
public static function render(){
/* [1] Init Twig
=========================================================*/
$loader = new \Twig_Loader_Filesystem(__BUILD__.'/viewer/view');
$twig = new \Twig_Environment($loader, []);
/* [2] Store variables
=========================================================*/
$variables = [
'p_theme' => $_SESSION['WAREHOUSE']['theme']
];
/* [3] Store functions
=========================================================*/
$twig->addFunction(new \Twig_Function('f_clusters', function($class){
/* (1) On récupère les groupes */
$getClustersReq = new Request('clusterDefault/getAll', ['class' => $class]);
$getClusters = $getClustersReq->dispatch();
/* (2) si erreur, on retourne rien par défaut */
if( $getClusters->error->get() != Err::Success )
return [];
/* (3) On enregistre le résultat */
return $getClusters->get('clusters');
}));
/* [4] Build the whole stuff
=========================================================*/
return $twig->render('group/group_choice.twig', [
'p_icon' => $variables['p_icon'],
'p_theme' => $variables['p_theme']
]);
}
}
?>

View File

@ -1,16 +0,0 @@
<form class='neutral' action='' method='POST' id='choose-cluster'>
<select data-name='cluster'>
<option value='.' selected disabled>Groupe à modifier</option>
{% for user_cluster in f_clusters(0) %}
<option value='u{{ user_cluster.id_user_cluster }}'>{{ user_cluster.name }} (utilisateur)</option>
{% endfor %}
{% for machine_cluster in f_clusters(1) %}
<option value='m{{ machine_cluster.id_machine_cluster }}'>{{ machine_cluster.name }} (machine)</option>
{% endfor %}
</select>
<button id='choose-cluster'>Modifier la composition</button>
</form>

View File

@ -1,138 +0,0 @@
<?php
namespace viewer\view\group;
use \viewer\core\Viewer;
use \api\core\Request;
use \error\core\Err;
use \error\core\Error;
use \api\core\Authentification;
class members_choice{
public static function render($params){
/* [1] On vérifie le type de groupe (user/machine)
=========================================================*/
/* (1) On vérifie les paramètres */
if( !isset($params['id_cluster']) || !is_numeric($params['id_cluster']) || !isset($params['class']) || !is_numeric($params['class']) )
return Viewer::$htmlError;
/* (2) On récupère le groupe */
$checktypeRequest = new Request('clusterDefault/getById', [
'id_cluster' => $params['id_cluster'],
'class' => $params['class']
]);
$checktypeResponse = $checktypeRequest->dispatch();
/* (3) Si on ne le trouve pas, on retourne une erreur */
if( $checktypeResponse->error->get() != Err::Success )
return Viewer::$htmlError;
/* (4) On récupère les données du groupe */
$currentCluster = $checktypeResponse->get('cluster');
/* [2] Init Twig
=========================================================*/
$loader = new \Twig_Loader_Filesystem(__BUILD__.'/viewer/view');
$twig = new \Twig_Environment($loader, []);
/* [3] Store variables
=========================================================*/
$variables = [
'p_id_cluster' => $params['id_cluster'],
'p_class' => $params['class'],
'p_name' => $currentCluster['name'],
'p_theme' => $_SESSION['WAREHOUSE']['theme']
];
/* [4] Store functions
=========================================================*/
$twig->addFunction(new \Twig_Function('f_members', function($id_cluster, $class){
/* [1] On récupère les membres
=========================================================*/
/* (1) On exécute la requête */
$getmembersRequest = new Request('clusterDefault/getMembers', [
'id_cluster' => $id_cluster,
'class' => $class
]);
$getmembersResponse = $getmembersRequest->dispatch();
/* (2) Si erreur, on retourne rien par défaut */
if( $getmembersResponse->error->get() != Err::Success )
return [];
/* (3) On récupère la liste des UID uniquement */
$members_ids = [];
foreach($getmembersResponse->get('members') as $member)
$members_ids[] = ($class==0) ? $member['id_user'] : $member['id_machine'];
/* [2] On récupère les utilisateurs non membres
=========================================================*/
/* (1) On récupère les utilisateurs */
if( $class == 0 ){
/* (2) On exécute la requête */
$getusersRequest = new Request('userDefault/getAll');
// On recupere la reponse
$getusersResponse = $getusersRequest->dispatch();
/* (3) si erreur, on affiche l'explicitation */
if( $getusersResponse->error->get() != Err::Success )
return [];
/* (4) On récupère la liste des utilisateurs */
$users = $getusersResponse->get('users');
/* (5) On ajoute s'ils sont dans le groupe ou non */
foreach($users as $u=>$user)
$users[$u]['already'] = in_array($user['id_user'], $members_ids);
return $users;
/* [3] On récupère les machines non membres
=========================================================*/
/* (1) On récupère les machines */
}else{
/* (2) On exécute la requête */
$getmachinesRequest = new Request('machineDefault/getAll');
// On recupere la reponse
$getmachinesResponse = $getmachinesRequest->dispatch();
/* (3) si erreur, on affiche l'explicitation */
if( $getmachinesResponse->error->get() != Err::Success )
return [];
/* (4) On récupère la liste des machines */
$machines = $getmachinesResponse->get('machines');
/* (5) On ajoute s'ils sont dans le groupe ou non */
foreach($machines as $u=>$machine)
$machines[$u]['already'] = in_array($machine['id_machine'], $members_ids);
return $machines;
}
}));
/* [5] Build the whole stuff
=========================================================*/
return $twig->render('group/members_choice.twig', [
'p_class' => $variables['p_class'],
'p_name' => $variables['p_name'],
'p_id_cluster' => $variables['p_id_cluster'],
'p_theme' => $variables['p_theme']
]);
}
}
?>

View File

@ -1,50 +0,0 @@
<span style='text-align:center; color: #666; text-decoration: underline; cursor: pointer;' id='members-change-group'>Modifier un autre groupe</span>
<p></p>
<article class='check-table'>
<input type='hidden' id='members-member-idcluster' value='{{ p_id_cluster }}'>
<input type='hidden' id='members-member-class' value='{{ p_class }}'>
<div>
{# USER HEADER #}
{% if p_class == 0 %}
<span><strong>Identifiant</strong></span>
<span><strong>Nom</strong></span>
<span><strong>Code RFID</strong></span>
{# MACHINE HEADER #}
{% else %}
<span><strong>Nom</strong></span>
{% endif %}
<span><strong>Membre de <u>{{ p_name }}</u></strong></span>
</div>
{% for member in f_members(p_id_cluster, p_class) %}
{# USER ENTRIES #}
{% if p_class == 0 %}
<div>
<span>{{ member.username }}</span>
<span>{{ member.firstname }} {{ member.lastname }}</span>
<span>{{ member.code }}</span>
<span>
<input type='checkbox' value='{{ member.id_user }}' data-name='members' id='checkbox_{{ member.id_user }}' {% if member.already %}checked{% endif %}>
<label for='checkbox_{{ member.id_user }}'></label>
</span>
</div>
{# MACHINE ENTRIES #}
{% else %}
<div>
<span>{{ member.name }}</span>
<span>
<input type='checkbox' value='{{ member.id_machine }}' data-name='members' id='checkbox_{{ member.id_machine }}' {% if member.already %}checked{% endif %}>
<label for='checkbox_{{ member.id_machine }}'></label>
</span>
</div>
{% endif %}
{% endfor %}
</article>

View File

@ -1,126 +0,0 @@
<?php
namespace viewer\view\group;
use \viewer\core\Viewer;
use \api\core\Request;
use \api\core\Authentification;
use \error\core\Err;
use \error\core\Error;
class permission{
public static function render(){
debug();
/* [1] Init Twig
=========================================================*/
$loader = new \Twig_Loader_Filesystem(__BUILD__.'/viewer/view');
$twig = new \Twig_Environment($loader, []);
/* [2] Store variables
=========================================================*/
$variables = [
'p_icon' => [
'remove' => file_get_contents( __PUBLIC__.'/src/static/sub-menu-side/remove.svg' ),
'edit' => file_get_contents( __PUBLIC__.'/src/static/sub-menu-side/edit.svg' ),
'device' => file_get_contents( __PUBLIC__.'/src/static/menu-side/device.svg' ),
'permission' => file_get_contents( __PUBLIC__.'/src/static/sub-menu-side/permission.svg')
],
'p_theme' => $_SESSION['WAREHOUSE']['theme']
];
/* [3] Store functions
=========================================================*/
$twig->addFunction(new \Twig_Function('f_clusters', function(){
$request = new Request('clusterDefault/getAll', [
'class' => 1
]);
$answer = $request->dispatch();
// si erreur, on affiche rien par défaut
if( $answer->error->get() != Err::Success )
return [];
return $answer->get('clusters');
}));
$twig->addFunction(new \Twig_Function('f_nbmachines', function($id_cluster){
$machineReq = new Request('clusterDefault/getMembers', [
'id_cluster' => (int) $id_cluster,
'class' => 1
]);
$machineRes = $machineReq->dispatch();
// si erreur, on affiche rien par défaut
if( $machineRes->error->get() != Err::Success )
return [];
return count($machineRes->get('members'));
}));
$twig->addFunction(new \Twig_Function('f_permissions', function(){
$permReq = new Request('clusterDefault/getPermissions', []);
$permRes = $permReq->dispatch();
// si erreur, on affiche rien par défaut
if( $permRes->error->get() != Err::Success )
return [];
return $permRes->get('permissions');
}));
$twig->addFunction(new \Twig_Function('f_userclusters', function($id_cluster, $id_permission){
$ucReq = new Request('clusterDefault/getAuthenticatedClusters', [
'id_target' => $id_cluster,
'id_action' => $id_permission
]);
$ucRes = $ucReq->dispatch();
// si erreur, on affiche rien par défaut
if( $ucRes->error->get() != Err::Success )
return [];
return $ucRes->get('clusters');
}));
$twig->addFilter(new \Twig_Filter('translate', function($word, $lang){
$word = strtolower($word);
if( $lang === 'fr' ){
switch($word){
case 'start': return 'démarrer'; break;
case 'stop': return 'arrêter'; break;
case 'signal': return 'signaler'; break;
case 'lock': return 'bloquer'; break;
case 'unlock': return 'débloquer'; break;
case 'unsignal': return 'désignaler'; break;
default: return 'inconnu'; break;
}
}else
return $word;
}));
/* [4] Build the whole stuff
=========================================================*/
return $twig->render('group/permission.twig', [
'p_icon' => $variables['p_icon'],
'p_theme' => $variables['p_theme']
]);
}
}
?>

View File

@ -1,50 +0,0 @@
<input type='text' class='searchbar' placeholder='Recherche'>
{% for machine_cluster in f_clusters() %}
<article class='inline-box' id='{{ machine_cluster.id_machine_cluster }}'>
{% set nbmachines = f_nbmachines(machine_cluster.id_machine_cluster) %}
<span class='title' style='color: {{ p_theme }}'>{{ machine_cluster.name }}</span>
{# <span class='link_remove' data-cluster='{{ machine_cluster.id_machine_cluster }}'>{{ p_icon.remove | raw }}</span>
<span class='link_edit' data-cluster='{{ machine_cluster.id_machine_cluster }}'>{{ p_icon.edit | raw }}</span> #}
<span class='code'>
{{ p_icon.device | raw }}
<span>{{ nbmachines }} machines</span>
</span>
{% for permission in f_permissions() %}
<span class='groups'>
<span style='border-color: #ddd; background-color: #eee;'>
{{ permission.name | translate('fr') }}
<span class='icon-permission'></span>
</span>
<span class='ignore'>
{% for user_cluster in f_userclusters(machine_cluster.id_machine_cluster,permission.id_permission) %}
<span>
{{ user_cluster.name }}
<span class='rem-permission' data-permission='{{ permission.id_permission }}' data-source='{{ user_cluster.id_user_cluster }}' data-target='{{ machine_cluster.id_machine_cluster }}'></span>
</span>
{% endfor %}
</span>
<span class='add-permission' data-target='{{ machine_cluster.id_machine_cluster }}' data-permission='{{ permission.id_permission }}'>+</span>
</span>
{% endfor %}
</article>
{# if no result #}
{% else %}
<article class='inline-box'>
<span>Aucun groupe trouvé.</span>
</article>
{% endfor %}

View File

@ -1,90 +0,0 @@
<?php
namespace viewer\view\group;
use \api\core\Request;
use \api\core\Authentification;
use \error\core\Err;
use \error\core\Error;
class view{
public static function render(){
/* [1] Init Twig
=========================================================*/
$loader = new \Twig_Loader_Filesystem(__BUILD__.'/viewer/view');
$twig = new \Twig_Environment($loader, []);
/* [2] Store variables
=========================================================*/
$variables = [
'p_icon' => [
'remove' => file_get_contents( __PUBLIC__.'/src/static/sub-menu-side/remove.svg' ),
'edit' => file_get_contents( __PUBLIC__.'/src/static/sub-menu-side/edit.svg' ),
'device' => file_get_contents( __PUBLIC__.'/src/static/menu-side/device.svg' ),
'user' => file_get_contents( __PUBLIC__.'/src/static/menu-side/users.svg' ),
'group' => file_get_contents( __PUBLIC__.'/src/static/container/group.svg' ),
'option' => file_get_contents( __PUBLIC__.'/src/static/container/option.svg' )
],
'p_theme' => $_SESSION['WAREHOUSE']['theme']
];
/* [3] Store functions
=========================================================*/
$twig->addFunction(new \Twig_Function('f_clusters', function($class){
/* (1) On récupère les groupes */
$getClustersReq = new Request('clusterDefault/getAll', ['class' => $class]);
$getClusters = $getClustersReq->dispatch();
/* (2) si erreur, on retourne rien par défaut */
if( $getClusters->error->get() != Err::Success )
return [];
/* (3) On enregistre le résultat */
return $getClusters->get('clusters');
}));
$twig->addFunction(new \Twig_Function('f_members', function($id_cluster, $class){
$membersReq = new Request('clusterDefault/getMembers', [
'id_cluster' => (int) $id_cluster,
'class' => $class
]);
$membersRes = $membersReq->dispatch();
//
// si erreur, on affiche rien par défaut
if( $membersRes->error->get() != Err::Success )
return [];
return $membersRes->get('members');
}));
$twig->addFunction(new \Twig_Function('f_options', function($id_cluster){
$modReq = new Request('clusterDefault/getEtrees', [
'id_machine_cluster' => (int) $id_cluster
]);
$modRes = $modReq->dispatch();
// si erreur, on affiche rien par défaut
if( $modRes->error->get() != Err::Success )
return [];
return $modRes->get('etrees');
}));
/* [4] Build the whole stuff
=========================================================*/
return $twig->render('group/view.twig', [
'p_icon' => $variables['p_icon'],
'p_theme' => $variables['p_theme']
]);
}
}
?>

View File

@ -1,101 +0,0 @@
<input type='text' class='searchbar' placeholder='Recherche'>
{% set noresult = true %}
{% for user_cluster in f_clusters(0) %}
{% set noresult = false %}
{% set id_user_cluster = 'u' ~ user_cluster.id_user_cluster %}
{% set memlen = f_members(user_cluster.id_user_cluster,0) | length %}
<article class='inline-box' id='{{ id_user_cluster }}'>
<span class='title' style='color: {{ p_theme }}'>{{ user_cluster.name }}</span>
<span class='link_remove' data-cluster='{{ id_user_cluster }}'>{{ p_icon.remove | raw }}</span>
<span class='link_edit' data-cluster='{{ id_user_cluster }}'>{{ p_icon.edit | raw }}</span>
<span class='code'>
{{ p_icon.user | raw }}
<span>{{ memlen }} utilisateur{% if memlen > 1 %}s{% endif %}</span>
</span>
<span class='groups'>
{{ p_icon.group | raw }}
<span class='ignore'>
{% for user in f_members(user_cluster.id_user_cluster, 0) %}
<span>
{{ user.username }}
<span class='rem-member' data-member='{{ user.id_user }}' data-cluster='{{ id_user_cluster }}'></span>
</span>
{% endfor %}
</span>
<span class='add-member' data-cluster='{{ id_user_cluster }}'>+</span>
</span>
</article>
{% endfor %}
{% for machine_cluster in f_clusters(1) %}
{% set noresult = false %}
{% set id_machine_cluster = 'm' ~ machine_cluster.id_machine_cluster %}
{% set memlen = f_members(machine_cluster.id_machine_cluster,1) | length %}
<article class='inline-box' id='{{ id_machine_cluster }}'>
<span class='title' style='color: {{ p_theme }}'>{{ machine_cluster.name }}</span>
<span class='link_remove' data-cluster='{{ id_machine_cluster }}'>{{ p_icon.remove | raw }}</span>
<span class='link_edit' data-cluster='{{ id_machine_cluster }}'>{{ p_icon.edit | raw }}</span>
<span class='code'>
{{ p_icon.device | raw }}
<span>{{ memlen }} machine{% if memlen > 1 %}s{% endif %}</span>
</span>
<span class='option'>
{{ p_icon.option | raw }}
{% for option in f_options(machine_cluster.id_machine_cluster) %}
<span class='ignore'>
<span>{{ option.name }}:{{ option.daemon }}</span>
</span>
{% else %}
<span class='ignore'>Aucune option</span>
{% endfor %}
</span>
<span class='groups'>
{{ p_icon.group | raw }}
<span class='ignore'>
{% for machine in f_members(machine_cluster.id_machine_cluster,1) %}
<span>
{{ machine.name }}
<span class='rem-member' data-member='{{ machine.id_machine }}' data-cluster='{{ id_machine_cluster }}'></span>
</span>
{% endfor %}
</span>
<span class='add-member' data-cluster='{{ id_machine_cluster }}'>+</span>
</span>
</article>
{% endfor %}
{# if no result #}
{% if noresult %}
<article class='inline-box'>
<span>Aucun groupe trouvé</span>
</article>
{% endif %}

View File

@ -1,129 +0,0 @@
<?php
namespace viewer\view\history;
use \api\core\Request;
use \error\core\Error;
use \error\core\Err;
class view{
public static function render(){
/* [1] Init Twig
=========================================================*/
$loader = new \Twig_Loader_Filesystem(__BUILD__.'/viewer/view');
$twig = new \Twig_Environment($loader, []);
/* [2] Store variables
=========================================================*/
$variables = [
'p_theme' => $_SESSION['WAREHOUSE']['theme']
];
/* [3] Store functions
=========================================================*/
$twig->addFunction(new \Twig_Function('f_history', function(){
$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');
}));
$twig->addFilter(new \Twig_Filter('f_tsformat', function($ts){
date_default_timezone_set('Europe/Paris');
return date('d/m/Y H:i:s', $ts);
}));
$twig->addFilter(new \Twig_Filter('f_tsrelative', function($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;
}
}));
/* [4] Build the whole stuff
=========================================================*/
return $twig->render('history/view.twig', [
'p_theme' => $variables['p_theme']
]);
}
/* RETURNS A RELATIVE HUMAN-READABLE TIME
*
* @ts<int> Timestamp to process
*
* @return relative<Array> human-readable relative time [value, unit]
*
*/
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, '.'];
}
}

View File

@ -1,44 +0,0 @@
<input type='text' class='searchbar' placeholder='Recherche'>
{% for entry in f_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>{{ entry.timestamp | f_tsformat }}</span>
<span style='color:#aaa;'>Il y a {{ entry.timestamp | f_tsrelative }}</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 %}

View File

@ -1,91 +0,0 @@
<?php
namespace viewer\view\machine;
use \viewer\core\Viewer;
use \api\core\Request;
use \api\core\Authentification;
use \error\core\Error;
use \error\core\Err;
class groups{
public static function render(){
/* [1] Init Twig
=========================================================*/
$loader = new \Twig_Loader_Filesystem(__BUILD__.'/viewer/view');
$twig = new \Twig_Environment($loader, []);
/* [2] Store variables
=========================================================*/
$variables = [
'p_icon' => [
'remove' => file_get_contents( __PUBLIC__.'/src/static/sub-menu-side/remove.svg' ),
'edit' => file_get_contents( __PUBLIC__.'/src/static/sub-menu-side/edit.svg' ),
'device' => file_get_contents( __PUBLIC__.'/src/static/menu-side/device.svg' ),
'group' => file_get_contents( __PUBLIC__.'/src/static/container/group.svg' ),
'option' => file_get_contents( __PUBLIC__.'/src/static/container/option.svg' )
],
'p_theme' => $_SESSION['WAREHOUSE']['theme']
];
/* [3] Store functions
=========================================================*/
$twig->addFunction(new \Twig_Function('f_clusters', function(){
$request = new Request('clusterDefault/getAll', [
'class' => 1
]);
$answer = $request->dispatch();
// si erreur, on affiche rien par défaut
if( $answer->error->get() != Err::Success )
return [];
return $answer->get('clusters');
}));
$twig->addFunction(new \Twig_Function('f_machines', function($id_cluster){
$usersReq = new Request('clusterDefault/getMembers', [
'id_cluster' => (int) $id_cluster,
'class' => 1
]);
$usersRes = $usersReq->dispatch();
// si erreur, on affiche rien par défaut
if( $usersRes->error->get() != Err::Success )
return [];
return $usersRes->get('members');
}));
$twig->addFunction(new \Twig_Function('f_options', function($id_cluster){
$modReq = new Request('clusterDefault/getEtrees', [
'id_machine_cluster' => (int) $id_cluster
]);
$modRes = $modReq->dispatch();
// si erreur, on affiche rien par défaut
if( $modRes->error->get() != Err::Success )
return [];
return $modRes->get('etrees');
}));
/* [4] Build the whole stuff
=========================================================*/
return $twig->render('machine/groups.twig', [
'p_icon' => $variables['p_icon'],
'p_theme' => $variables['p_theme']
]);
}
}
?>

View File

@ -1,54 +0,0 @@
<input type='text' class='searchbar' placeholder='Recherche'>
{% for cluster in f_clusters() %}
<article class='inline-box' id='{{ cluster.id_machine_cluster }}'>
{% set machinelist = f_machines(cluster.id_machine_cluster) %}
<span class='title' style='color: {{ p_theme }}'>{{ cluster.name }}</span>
<span class='link_remove' data-cluster='{{ cluster.id_machine_cluster }}'>{{ p_icon.remove | raw }}</span>
<span class='link_edit' data-cluster='{{ cluster.id_machine_cluster }}'>{{ p_icon.edit | raw }}</span>
<span class='code'>
{{ p_icon.device | raw }}
<span>{{ machinelist | length }} machines</span>
</span>
<span class='option'>
{{ p_icon.option | raw }}
{% for option in f_options(cluster.id_machine_cluster) %}
<span class='ignore'>
<span>{{ option.name }}:{{ option.daemon }}</span>
</span>
{% else %}
<span class='ignore'>Aucune option</span>
{% endfor %}
</span>
<span class='groups'>
{{ p_icon.group | raw }}
<span class='ignore'>
{% for machine in machinelist %}
<span>
{{ machine.name }}
<span class='rem-member' data-member='{{ machine.id_machine }}' data-cluster='{{ cluster.id_machine_cluster }}'></span>
</span>
{% endfor %}
</span>
<span class='add-member' data-cluster='{{ cluster.id_machine_cluster }}'>+</span>
</span>
</article>
{# if no result #}
{% else %}
<article class='inline-box'>
<span>Aucun groupe trouvé.</span>
</article>
{% endfor %}

View File

@ -1,102 +0,0 @@
<?php
namespace viewer\view\machine;
use \viewer\core\Viewer;
use \api\core\Request;
use \error\core\Error;
use \error\core\Err;
class view{
public static function render(){
/* [1] Init Twig
=========================================================*/
$loader = new \Twig_Loader_Filesystem(__BUILD__.'/viewer/view');
$twig = new \Twig_Environment($loader, []);
/* [2] Store variables
=========================================================*/
$variables = [
'p_icon' => [
'remove' => file_get_contents( __PUBLIC__.'/src/static/sub-menu-side/remove.svg' ),
'edit' => file_get_contents( __PUBLIC__.'/src/static/sub-menu-side/edit.svg' ),
'group' => file_get_contents( __PUBLIC__.'/src/static/container/group.svg' ),
'motor' => file_get_contents( __PUBLIC__.'/src/static/container/motor.svg' )
],
'p_theme' => $_SESSION['WAREHOUSE']['theme']
];
/* [3] Store functions
=========================================================*/
$twig->addFunction(new \Twig_Function('f_machines', function(){
$request = new Request('machineDefault/getAll'); // On utilise la methode 'getAll' du module 'machineDefault'
$answer = $request->dispatch(); // On recupere la reponse
// si erreur, on affiche rien par défaut
if( $answer->error->get() != Err::Success )
return [];
return $answer->get('machines');
}));
$twig->addFunction(new \Twig_Function('f_getstate', function($id_machine){
/* (1) Write / Execute request */
$req = new Request('machineDefault/getState', ['id_machine' => $id_machine]);
$res = $req->dispatch();
/* (2) Manage error */
if( $res->error->get() != Err::Success )
return 'detached';
return $res->get('state');
}));
$twig->addFunction(new \Twig_Function('f_clusters', function($id_machine){
$request = new Request('machineDefault/getClusters', [
'id_machine' => (int) $id_machine
]);
$answer = $request->dispatch();
// si erreur, on affiche rien par défaut
if( $answer->error->get() != Err::Success )
return [];
return $answer->get('clusters');
}));
$twig->addFunction(new \Twig_Function('f_motheure', function($id_machine){
/* (1) Get its machine_clusters
---------------------------------------------------------*/
/* (1) Create request */
$motheureReq = new Request('motheure/getCount', ['id_machine' => $id_machine]);
/* (2) Execute */
$motheureRes = $motheureReq->dispatch();
/* (3) Manage error */
if( $motheureRes->error->get() != Err::Success )
return null;
return $motheureRes->get('count');
}));
/* [4] Build the whole stuff
=========================================================*/
return $twig->render('machine/view.twig', [
'p_icon' => $variables['p_icon'],
'p_theme' => $variables['p_theme']
]);
}
}
?>

View File

@ -1,45 +0,0 @@
<input type='text' class='searchbar' placeholder='Recherche'>
{% for machine in f_machines() %}
<article class='inline-box' id='{{ machine.id_machine }}'>
<span class='state' data-state='{{ f_getstate(machine.id_machine) }}'></span>
<span class='title' style='color: {{ p_theme }}' title='{{ machine.ap | default('?') }} ({{ machine.ip | default('?') }})'>{{ machine.name }} <span>#{{ machine.name }}</span></span>
<span class='link_remove' data-machine='{{ machine.id_machine }}'>{{ p_icon.remove | raw }}</span>
<span class='link_edit' data-machine='{{ machine.id_machine }}'>{{ p_icon.edit | raw }}</span>
{# List etrees #}
{% set motheure = f_motheure(machine.id_machine) %}
{% if motheure %}
<span class='motheure'>
{{ p_icon.motor | raw }}
<span>{{ motheure }}</span>ms
</span>
{% endif %}
<span class='groups'>
{{ p_icon.group | raw }}
<span class='ignore'>
{% for cluster in f_clusters(machine.id_machine) %}
<span>
{{ cluster.name }}
<span class='rem-group' data-group='{{ cluster.id_machine_cluster }}' data-machine='{{ machine.id_machine }}'></span>
</span>
{% endfor %}
</span>
<span class='add-group' data-machine='{{ machine.id_machine }}'>+</span>
</span>
</article>
{# if no result #}
{% else %}
<article class='inline-box'>
<span>Aucune machine trouvée</span>
</article>
{% endfor %}

View File

@ -1,84 +0,0 @@
<?php
namespace viewer\view\user;
use \viewer\core\Viewer;
use \api\core\Request;
use \api\core\Authentification;
use \error\core\Error;
use \error\core\Err;
class groups{
public static function render(){
/* [1] Init Twig
=========================================================*/
$loader = new \Twig_Loader_Filesystem(__BUILD__.'/viewer/view');
$twig = new \Twig_Environment($loader, []);
/* [2] Store variables
=========================================================*/
$variables = [
'p_icon' => [
'remove' => file_get_contents( __PUBLIC__.'/src/static/sub-menu-side/remove.svg' ),
'edit' => file_get_contents( __PUBLIC__.'/src/static/sub-menu-side/edit.svg' ),
'type' => file_get_contents( __PUBLIC__.'/src/static/container/type.svg' ),
'group' => file_get_contents( __PUBLIC__.'/src/static/container/group.svg' )
],
'p_theme' => $_SESSION['WAREHOUSE']['theme']
];
/* [3] Store functions
=========================================================*/
$twig->addFunction(new \Twig_Function('f_clusters', function(){
$request = new Request('clusterDefault/getAll', [
'class' => 0
]);
$answer = $request->dispatch();
// si erreur, on affiche rien par défaut
if( $answer->error->get() != Err::Success )
return [];
return $answer->get('clusters');
}));
$twig->addFunction(new \Twig_Function('f_users', function($id_cluster){
$usersReq = new Request('clusterDefault/getMembers', [
'id_cluster' => (int) $id_cluster,
'class' => 0
]);
$usersRes = $usersReq->dispatch();
// si erreur, on affiche rien par défaut
if( $usersRes->error->get() != Err::Success )
return [];
return $usersRes->get('members');
}));
/* [4] Build the whole stuff
=========================================================*/
return $twig->render('user/groups.twig', [
'p_icon' => $variables['p_icon'],
'p_theme' => $variables['p_theme']
]);
}
}
?>

View File

@ -1,44 +0,0 @@
<input type='text' class='searchbar' placeholder='Recherche'>
{% for cluster in f_clusters() %}
<article class='inline-box' id='{{ cluster.id_user_cluster }}'>
{% set userlist = f_users(cluster.id_user_cluster) %}
<span class='title' style='color: {{ p_theme }}'>{{ cluster.name }}</span>
<span class='link_remove' data-cluster='{{ cluster.id_user_cluster }}'>{{ p_icon.remove | raw }}</span>
<span class='link_edit' data-cluster='{{ cluster.id_user_cluster }}'>{{ p_icon.edit | raw }}</span>
<span class='code'>
{{ p_icon.type | raw }}
<span>{{ userlist | length }} utilisateurs</span>
</span>
<span class='groups'>
{{ p_icon.group | raw }}
<span class='ignore'>
{% for user in userlist %}
<span>
{{ user.username }}
<span class='rem-member' data-member='{{ user.id_user }}' data-cluster='{{ cluster.id_user_cluster }}'></span>
</span>
{% endfor %}
</span>
<span class='add-member' data-cluster='{{ cluster.id_user_cluster }}'>+</span>
</span>
</article>
{# if no result #}
{% else %}
<article class='inline-box'>
<span>Aucun groupe trouvé.</span>
</article>
{% endfor %}

View File

@ -1,70 +0,0 @@
<?php
namespace viewer\view\user;
use \api\core\Request;
use \api\core\Authentification;
use \error\core\Error;
use \error\core\Err;
class view{
public static function render(){
/* [1] Init Twig
=========================================================*/
$loader = new \Twig_Loader_Filesystem(__BUILD__.'/viewer/view');
$twig = new \Twig_Environment($loader, []);
/* [2] Store variables
=========================================================*/
$variables = [
'p_icon' => [
'remove' => file_get_contents( __PUBLIC__.'/src/static/sub-menu-side/remove.svg' ),
'edit' => file_get_contents( __PUBLIC__.'/src/static/sub-menu-side/edit.svg' ),
'card' => file_get_contents( __PUBLIC__.'/src/static/container/card.svg' ),
'mail' => file_get_contents( __PUBLIC__.'/src/static/container/mail.svg' ),
'group' => file_get_contents( __PUBLIC__.'/src/static/container/group.svg' )
],
'p_theme' => $_SESSION['WAREHOUSE']['theme']
];
/* [3] Store functions
=========================================================*/
$twig->addFunction(new \Twig_Function('f_users', function(){
$request = new Request('userDefault/getAll'); // On utilise la methode 'getAll' du module 'userDefault'
$answer = $request->dispatch(); // On recupere la reponse
// si erreur, on affiche rien
if( $answer->error->get() != Err::Success )
return [];
return $answer->get('users');
}));
$twig->addFunction(new \Twig_Function('f_clusters', function($id_user){
$clustersReq = new Request('userDefault/getClusters', [ 'id_user' => $id_user ]);
$clustersRes = $clustersReq->dispatch();
/* (2) Gestion si erreur */
if( $clustersRes->error->get() != Err::Success )
return [];
return $clustersRes->get('clusters');
}));
/* [4] Build the whole stuff
=========================================================*/
return $twig->render('user/view.twig', [
'p_icon' => $variables['p_icon'],
'p_theme' => $variables['p_theme']
]);
}
}
?>

View File

@ -1,53 +0,0 @@
<input type='text' class='searchbar' placeholder='Recherche'>
{% for user in f_users() %}
<article class='inline-box' id='{{ user.id_user }}'>
<span class='title' style='color: {{ p_theme }}'>{{ user.firstname }} {{ user.lastname }} <span>#{{ user.username }}</span></span>
<span class='link_remove' data-user='{{ user.id_user }}'>{{ p_icon.remove | raw }}</span>
<span class='link_edit' data-user='{{ user.id_user }}'>{{ p_icon.edit | raw }}</span>
<span class='code'>
{{ p_icon.card | raw }}
<span>{{ user.code }}</span>
</span>
<span class='mail'>
{{ p_icon.mail | raw }}
<a href='mailto:{{ user.mail }}'>
<span>{{ user.mail }}</span>
</a>
</span>
<span class='groups'>
{{ p_icon.group | raw }}
<span class='ignore'>
{% for cluster in f_clusters(user.id_user) %}
<span>
{{ cluster.name }}
<span class='rem-group' data-group='{{ cluster.id_user_cluster }}' data-user='{{ user.id_user }}'></span>
</span>
{% endfor %}
</span>
<span class='add-group' data-user='{{ user.id_user }}'>+</span>
</span>
</article>
{# if no result #}
{% else %}
<article class='inline-box'>
<span>Aucun utilisateur trouvé</span>
</article>
{% endfor %}

View File

@ -22,7 +22,6 @@
"http\\": "build/http", "http\\": "build/http",
"orm\\": "build/orm", "orm\\": "build/orm",
"router\\": "build/router", "router\\": "build/router",
"viewer\\": "build/viewer",
"log\\": "build/log", "log\\": "build/log",
"generic\\": "build/generic", "generic\\": "build/generic",
"view\\": "build/generic/view", "view\\": "build/generic/view",

View File

@ -69,11 +69,8 @@
=========================================================*/ =========================================================*/
echo "<section data-sublink='create'>"; echo "<section data-sublink='create'>";
echo "<form class='valid'>"; $view = View::load('machine.form.create');
echo "<input id='create_name' type='text' placeholder='Name'><br>"; echo $view->render();
echo "<span class='error-msg create_name'></span><br>";
echo "<button id='create_submit'>Créer</button>";
echo "</form>";
echo '</section>'; echo '</section>';
@ -92,18 +89,8 @@
=========================================================*/ =========================================================*/
echo "<section data-sublink='remove'>"; echo "<section data-sublink='remove'>";
echo "<form class='invalid'>"; $view = View::load('machine.form.remove');
echo "<input id='remove_search_keyword' type='text' class='search' placeholder='Recherche...'><br>"; echo $view->render();
echo "<input id='remove_search_id' type='hidden' value=''>";
// Indice du resultat
echo "<span class='remove_search_view'>machine <span class='remove_search_num'>0</span> sur <span class='remove_search_sum'>0</span></span><br><br>";
echo "<button id='remove_search_submit' class='search'>Trouver/Suivant</button><br>";
echo "<br><br><hr class='OR' data-label='PUIS' /><br><br>";
echo "<input id='remove_name' type='text' placeholder='Name'><br>";
echo "<button id='remove_submit' disabled>Supprimer</button>";
echo "</form>";
echo '</section>'; echo '</section>';
@ -122,19 +109,8 @@
=========================================================*/ =========================================================*/
echo "<section data-sublink='edit'>"; echo "<section data-sublink='edit'>";
echo "<form class='neutral'>"; $view = View::load('machine.form.edit');
echo "<input id='edit_search_keyword' type='text' class='search' placeholder='Recherche...'><br>"; echo $view->render();
echo "<input id='edit_search_id' type='hidden' value=''>";
// Indice du resultat
echo "<span class='edit_search_view'>machine <span class='edit_search_num'>0</span> sur <span class='edit_search_sum'>0</span></span><br><br>";
echo "<button id='edit_search_submit' class='search'>Trouver/Suivant</button><br>";
echo "<br><br><hr class='OR' data-label='PUIS' /><br><br>";
echo "<input id='edit_name' type='text' placeholder='Name'><br>";
echo "<span class='error-msg edit_name'></span><br>";
echo "<button id='edit_submit' disabled>Modifier</button>";
echo "</form>";
echo '</section>'; echo '</section>';