Created /generic/core/i_view and the 'View' builder + migrated views : user/*, machine/*, group/*

This commit is contained in:
xdrm-brackets 2017-11-06 15:15:24 +01:00
parent 5d3beefb30
commit 3a730ccfbd
24 changed files with 1234 additions and 27 deletions

View File

@ -0,0 +1,79 @@
<?php
namespace generic\core;
class View{
/* (1) Attributes
---------------------------------------------------------*/
private $view_class;
private $arguments;
public static $html_error = "<span class='error'>Une erreur est survenue, veuilez contacter le webmaster si cette erreur persiste.</span>";
/* (2) Instance constructor
*
* @view_class<String> The target view class
*
---------------------------------------------------------*/
private function __construct(String $view_class){
$this->view_class = $view_class;
}
/* (3) Renders a view with injected data
*
* @injected_data<Array> Data to inject
*
* @return render<String> Rendered view
*
---------------------------------------------------------*/
public function render($injected_data=[]){
/* (1) Create instance with data */
$view = new $this->view_class(...$injected_data);
/* (2) Dispatch rendering */
return $view->render();
}
/* (4) Loads a view from its path (builder)
*
* @view_path<String> View path
*
* @return view<View> View instance
* NULL on error
*
---------------------------------------------------------*/
public static function load(String $view_path){
/* (1) Check arguments
---------------------------------------------------------*/
/* (1) Check path format */
if( !preg_match('@^[\w+\.]+$@', $view_path) )
return null;
/* (2) Extract class */
$view_class = '\\view\\'.str_replace('.', '\\', $view_path).'\\main';
/* (3) Check if class exists */
if( !class_exists($view_class) )
return null;
/* (2) Return View instance
---------------------------------------------------------*/
return new self($view_class);
}
}

View File

@ -0,0 +1,43 @@
<?php
namespace generic\core;
abstract class i_view{
/* (1) Renders the view
*
---------------------------------------------------------*/
public function render(){
/* (1) Get path information (child class)
---------------------------------------------------------*/
/* (1) Get child class */
$child_class = str_replace('\\', '/', get_class(debug_backtrace()[0]['object']));
/* (2) Extract root DIR */
$root_path = __BUILD__.'/generic/'.dirname($child_class);
/* (3) Extract file name */
$base_path = basename($child_class).'.twig';
/* (2) Setup
---------------------------------------------------------*/
/* (1) Initialize twig */
$loader = new \Twig_Loader_Filesystem($root_path);
$twig = new \Twig_Environment($loader, [
'debug' => true,
'cache' => false,
'auto_reload' => true
]);
/* (3) Build the view and return it back
---------------------------------------------------------*/
/* (1) Render and return the view */
return $twig->render($base_path, [ 'core' => $this ]);
}
}

View File

@ -0,0 +1,127 @@
<?php
namespace view\group\member\choice;
use \generic\core\i_view;
use \api\core\Request;
use \error\core\Err;
use \generic\core\View;
class main extends i_view{
public $class;
public $name;
public $id_cluster;
public function __construct(String $id_cluster, int $class){
/* (1) On vérifie le type de groupe (user/machine)
---------------------------------------------------------*/ {
/* (1) On vérifie les paramètres */
if( !isset($id_cluster) || !is_numeric($id_cluster) || !isset($class) || !is_numeric($class) )
return View::$html_error;
/* (2) On récupère le groupe */
$checktypeRequest = new Request('clusterDefault/getById', [
'id_cluster' => $id_cluster,
'class' => $class
]);
$checktypeResponse = $checktypeRequest->dispatch();
/* (3) Si on ne le trouve pas, on retourne une erreur */
if( $checktypeResponse->error->get() != Err::Success )
return View::$html_error;
/* (4) On récupère les données du groupe */
$currentCluster = $checktypeResponse->get('cluster');
}
/* (2) Fill attributes
---------------------------------------------------------*/
$this->id_cluster = $id_cluster;
$this->class = $class;
$this->name = $currentCluster['name'];
}
public function get_members($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;
}
}
}

View File

@ -0,0 +1,50 @@
<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='{{ core.id_cluster }}'>
<input type='hidden' id='members-member-class' value='{{ core.class }}'>
<div>
{# USER HEADER #}
{% if core.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>{{ core.name }}</u></strong></span>
</div>
{% for member in core.get_members(core.id_cluster, core.class) %}
{# USER ENTRIES #}
{% if core.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

@ -0,0 +1,32 @@
<?php
namespace view\group\member\group;
use \generic\core\i_view;
use \api\core\Request;
use \error\core\Err;
class main extends i_view{
public function __construct(){
}
public function get_clusters($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');
}
}

View File

@ -0,0 +1,16 @@
<form class='neutral' action='' method='POST' id='choose-cluster'>
<select data-name='cluster'>
<option value='.' selected disabled>Groupe à modifier</option>
{% for user_cluster in core.get_clusters(0) %}
<option value='u{{ user_cluster.id_user_cluster }}'>{{ user_cluster.name }} (utilisateur)</option>
{% endfor %}
{% for machine_cluster in core.get_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

@ -0,0 +1,113 @@
<?php
namespace view\group\permission;
use \generic\core\i_view;
use \api\core\Request;
use \error\core\Err;
use \generic\core\View;
class main extends i_view{
public function __construct(){
/* (1) Setup attributes
---------------------------------------------------------*/
/* (1) Fill attributes */
$this->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')
];
$this->theme = $_SESSION['WAREHOUSE']['theme'];
}
public function get_clusters(){
$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');
}
public function get_nb_machines($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'));
}
public function get_permissions(){
$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');
}
public function get_authed_user_clusters($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');
}
public function permission_translate($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;
}
}

View File

@ -0,0 +1,50 @@
<input type='text' class='searchbar' placeholder='Recherche'>
{% for machine_cluster in core.get_clusters() %}
<article class='inline-box' id='{{ machine_cluster.id_machine_cluster }}'>
{% set nb_machines = core.get_nb_machines(machine_cluster.id_machine_cluster) %}
<span class='title' style='color: {{ core.theme }}'>{{ machine_cluster.name }}</span>
{# <span class='link_remove' data-cluster='{{ machine_cluster.id_machine_cluster }}'>{{ core.icon.remove | raw }}</span>
<span class='link_edit' data-cluster='{{ machine_cluster.id_machine_cluster }}'>{{ core.icon.edit | raw }}</span> #}
<span class='code'>
{{ core.icon.device | raw }}
<span>{{ nb_machines }} machines</span>
</span>
{% for permission in core.get_permissions() %}
<span class='groups'>
<span style='border-color: #ddd; background-color: #eee;'>
{{ core.permission_translate(permission.name, 'fr') }}
<span class='icon-permission'></span>
</span>
<span class='ignore'>
{% for user_cluster in core.get_authed_user_clusters(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

@ -0,0 +1,79 @@
<?php
namespace view\group\view;
use \generic\core\i_view;
use \api\core\Request;
use \error\core\Err;
use \generic\core\View;
class main extends i_view{
public function __construct(){
/* (1) Setup attributes
---------------------------------------------------------*/
/* (1) Fill attributes */
$this->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' )
];
$this->theme = $_SESSION['WAREHOUSE']['theme'];
}
public function get_clusters($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');
}
public function get_members($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');
}
public function get_options($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');
}
}

View File

@ -0,0 +1,101 @@
<input type='text' class='searchbar' placeholder='Recherche'>
{% set noresult = true %}
{% for user_cluster in core.get_clusters(0) %}
{% set noresult = false %}
{% set id_user_cluster = 'u' ~ user_cluster.id_user_cluster %}
{% set memlen = core.get_members(user_cluster.id_user_cluster,0) | length %}
<article class='inline-box' id='{{ id_user_cluster }}'>
<span class='title' style='color: {{ core.theme }}'>{{ user_cluster.name }}</span>
<span class='link_remove' data-cluster='{{ id_user_cluster }}'>{{ core.icon.remove | raw }}</span>
<span class='link_edit' data-cluster='{{ id_user_cluster }}'>{{ core.icon.edit | raw }}</span>
<span class='code'>
{{ core.icon.user | raw }}
<span>{{ memlen }} utilisateur{% if memlen > 1 %}s{% endif %}</span>
</span>
<span class='groups'>
{{ core.icon.group | raw }}
<span class='ignore'>
{% for user in core.get_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 core.get_clusters(1) %}
{% set noresult = false %}
{% set id_machine_cluster = 'm' ~ machine_cluster.id_machine_cluster %}
{% set memlen = core.get_members(machine_cluster.id_machine_cluster,1) | length %}
<article class='inline-box' id='{{ id_machine_cluster }}'>
<span class='title' style='color: {{ core.theme }}'>{{ machine_cluster.name }}</span>
<span class='link_remove' data-cluster='{{ id_machine_cluster }}'>{{ core.icon.remove | raw }}</span>
<span class='link_edit' data-cluster='{{ id_machine_cluster }}'>{{ core.icon.edit | raw }}</span>
<span class='code'>
{{ core.icon.device | raw }}
<span>{{ memlen }} machine{% if memlen > 1 %}s{% endif %}</span>
</span>
<span class='option'>
{{ core.icon.option | raw }}
{% for option in core.get_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'>
{{ core.icon.group | raw }}
<span class='ignore'>
{% for machine in core.get_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

@ -0,0 +1,87 @@
<?php
namespace view\machine\group;
use \generic\core\i_view;
use \api\core\Request;
use \error\core\Err;
class main extends i_view{
/* (1) Attributes
---------------------------------------------------------*/
public $icon;
public $theme;
public function __construct(){
/* (1) Setup attributes
---------------------------------------------------------*/
/* (1) Fill attributes */
$this->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' )
];
$this->theme = $_SESSION['WAREHOUSE']['theme'];
}
public function get_clusters(){
$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');
}
public function get_members($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');
}
public function get_options($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');
}
}

View File

@ -0,0 +1,54 @@
<input type='text' class='searchbar' placeholder='Recherche'>
{% for cluster in core.get_clusters() %}
<article class='inline-box' id='{{ cluster.id_machine_cluster }}'>
{% set machinelist = core.get_members(cluster.id_machine_cluster) %}
<span class='title' style='color: {{ core.theme }}'>{{ cluster.name }}</span>
<span class='link_remove' data-cluster='{{ cluster.id_machine_cluster }}'>{{ core.icon.remove | raw }}</span>
<span class='link_edit' data-cluster='{{ cluster.id_machine_cluster }}'>{{ core.icon.edit | raw }}</span>
<span class='code'>
{{ core.icon.device | raw }}
<span>{{ machinelist | length }} machines</span>
</span>
<span class='option'>
{{ core.icon.option | raw }}
{% for option in core.get_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'>
{{ core.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

@ -0,0 +1,102 @@
<?php
namespace view\machine\view;
use \generic\core\i_view;
use \api\core\Request;
use \error\core\Err;
class main extends i_view{
/* (1) Attributes
---------------------------------------------------------*/
public $icon;
public $theme;
public function __construct(){
/* (1) Setup attributes
---------------------------------------------------------*/
/* (1) Fill attributes */
$this->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' )
];
$this->theme = $_SESSION['WAREHOUSE']['theme'];
}
public function get_machines(){
$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');
}
public function get_state($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');
}
public function get_clusters($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');
}
public function get_motheure($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');
}
}

View File

@ -0,0 +1,45 @@
<input type='text' class='searchbar' placeholder='Recherche'>
{% for machine in core.get_machines() %}
<article class='inline-box' id='{{ machine.id_machine }}'>
<span class='state' data-state='{{ core.get_state(machine.id_machine) }}'></span>
<span class='title' style='color: {{ core.theme }}' title='{{ machine.ap | default('?') }} ({{ machine.ip | default('?') }})'>{{ machine.name }} <span>#{{ machine.name }}</span></span>
<span class='link_remove' data-machine='{{ machine.id_machine }}'>{{ core.icon.remove | raw }}</span>
<span class='link_edit' data-machine='{{ machine.id_machine }}'>{{ core.icon.edit | raw }}</span>
{# List etrees #}
{% set motheure = core.get_motheure(machine.id_machine) %}
{% if motheure %}
<span class='motheure'>
{{ core.icon.motor | raw }}
<span>{{ motheure }}</span>ms
</span>
{% endif %}
<span class='groups'>
{{ core.icon.group | raw }}
<span class='ignore'>
{% for cluster in core.get_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

@ -0,0 +1,68 @@
<?php
namespace view\user\group;
use \generic\core\i_view;
use \api\core\Request;
use \error\core\Err;
class main extends i_view{
/* (1) Attributes
---------------------------------------------------------*/
public $icon;
public $theme;
public function __construct(){
/* (1) Setup attributes
---------------------------------------------------------*/
/* (1) Fill attributes */
$this->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' )
];
$this->theme = $_SESSION['WAREHOUSE']['theme'];
}
public function get_clusters(){
$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');
}
public function get_members($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');
}
}

View File

@ -0,0 +1,44 @@
<input type='text' class='searchbar' placeholder='Recherche'>
{% for cluster in core.get_clusters() %}
<article class='inline-box' id='{{ cluster.id_user_cluster }}'>
{% set userlist = core.get_members(cluster.id_user_cluster) %}
<span class='title' style='color: {{ core.theme }}'>{{ cluster.name }}</span>
<span class='link_remove' data-cluster='{{ cluster.id_user_cluster }}'>{{ core.icon.remove | raw }}</span>
<span class='link_edit' data-cluster='{{ cluster.id_user_cluster }}'>{{ core.icon.edit | raw }}</span>
<span class='code'>
{{ core.icon.type | raw }}
<span>{{ userlist | length }} utilisateurs</span>
</span>
<span class='groups'>
{{ core.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

@ -0,0 +1,63 @@
<?php
namespace view\user\view;
use \generic\core\i_view;
use \api\core\Request;
use \error\core\Err;
class main extends i_view{
/* (1) Attributes
---------------------------------------------------------*/
public $icon;
public $theme;
public function __construct(){
/* (1) Setup attributes
---------------------------------------------------------*/
/* (1) Fill attributes */
$this->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' )
];
$this->theme = $_SESSION['WAREHOUSE']['theme'];
}
public function get_users(){
$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');
}
public function get_clusters($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');
}
}

View File

@ -0,0 +1,53 @@
<input type='text' class='searchbar' placeholder='Recherche'>
{% for user in core.get_users() %}
<article class='inline-box' id='{{ user.id_user }}'>
<span class='title' style='color: {{ core.theme }}'>{{ user.firstname }} {{ user.lastname }} <span>#{{ user.username }}</span></span>
<span class='link_remove' data-user='{{ user.id_user }}'>{{ core.icon.remove | raw }}</span>
<span class='link_edit' data-user='{{ user.id_user }}'>{{ core.icon.edit | raw }}</span>
<span class='code'>
{{ core.icon.card | raw }}
<span>{{ user.code }}</span>
</span>
<span class='mail'>
{{ core.icon.mail | raw }}
<a href='mailto:{{ user.mail }}'>
<span>{{ user.mail }}</span>
</a>
</span>
<span class='groups'>
{{ core.icon.group | raw }}
<span class='ignore'>
{% for cluster in core.get_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

@ -13,7 +13,7 @@
=========================================================*/
$loader = new \Twig_Loader_Filesystem(__BUILD__.'/viewer/view');
$twig = new \Twig_Environment($loader, []);
/* [2] Store variables
=========================================================*/

View File

@ -24,7 +24,9 @@
"router\\": "build/router",
"viewer\\": "build/viewer",
"log\\": "build/log",
"token\\": "build/token"
"generic\\": "build/generic",
"view\\": "build/generic/view",
"token\\": "build/token"
},
"files": ["autoloader.php", "lib/vendor/autoload.php"]
}

View File

@ -1,9 +1,9 @@
<?php define('__ROOT__', dirname(dirname(dirname(__FILE__))) );
require_once __ROOT__.'/vendor/autoload.php';
use \viewer\core\Viewer;
use \api\core\Request;
use \database\core\Repo;
?>
use \generic\core\View;
?>
<!-- [1] Gestion du sous-menu de gauche -->
@ -60,8 +60,8 @@
echo "<section data-sublink='view' class='list'>";
$clusterView = new Viewer('group.view', []);
$clusterView->view();
$view = View::load('group.view');
echo $view->render();
echo '</section>';
@ -179,20 +179,20 @@
=========================================================*/
echo "<section data-sublink='members' class='contain-check-table'>";
/* (1) Si on a un ID_CLUSTER, on affiche la composition
---------------------------------------------------------*/
/* (1) Si on a un ID_CLUSTER, on affiche la composition
---------------------------------------------------------*/
if( isset($post[1]) && preg_match('/^(u|m)(\d+)$/', $post[1], $m) ){
$membersChoice = new Viewer('group.members_choice', [
'id_cluster' => (int) $m[2],
'class' => (int) ($m[1]=='u') ? 0 : 1
$view = View::load('group.member.choice');
echo $view->render([
(int) $m[2], // id_cluster
(int) ($m[1]=='u') ? 0 : 1 // class
]);
$membersChoice->view();
}else{
$groupChoice = new Viewer('group.group_choice', []);
$groupChoice->view();
$view = View::load('group.member.group');
echo $view->render();
}
@ -207,7 +207,7 @@
=========================================================*/
echo "<section data-sublink='permissions'>";
$groupChoice = new Viewer('group.permission', []);
$groupChoice->view();
$view = View::load('group.permission');
echo $view->render();
echo '</section>';

View File

@ -1,6 +1,6 @@
<?php define('__ROOT__', dirname(dirname(dirname(__FILE__))) );
require_once __ROOT__.'/vendor/autoload.php';
use \viewer\core\Viewer;
use \generic\core\View;
?>
<!-- [1] Gestion du sous-menu de gauche -->
@ -49,8 +49,8 @@
debug();
echo "<section data-sublink='view' class='list'>";
$machineView = new Viewer('machine.view', []);
$machineView->view();
$view = View::load('machine.view');
echo $view->render();
echo '</section>';
@ -145,7 +145,7 @@
=========================================================*/
echo "<section data-sublink='groups' class='list'>";
$grouplist = new Viewer('machine.groups', []);
$grouplist->view();
$view = View::load('machine.group');
echo $view->render();
echo '</section>';

View File

@ -51,7 +51,6 @@
echo "<section data-sublink='view' class='list'>";
echo '</section>';

View File

@ -1,8 +1,8 @@
<?php define('__ROOT__', dirname(dirname(dirname(__FILE__))) );
require_once __ROOT__.'/vendor/autoload.php';
use \api\core\Request;
use \viewer\core\Viewer;
use \database\core\Repo;
use \generic\core\View;
?>
<!-- [1] Gestion du sous-menu de gauche -->
@ -51,8 +51,8 @@
=========================================================*/
echo "<section data-sublink='view' class='list'>";
$userlist = new Viewer('user.view', []);
$userlist->view();
$view = View::load('user.view');
echo $view->render();
echo '</section>';
@ -177,7 +177,7 @@
=========================================================*/
echo "<section data-sublink='groups' class='list'>";
$grouplist = new Viewer('user.groups', []);
$grouplist->view();
$view = View::load('user.group');
echo $view->render();
echo '</section>';