Enrichissement \manager\View + vue liste utilisateurs terminée

This commit is contained in:
xdrm-brackets 2016-07-12 10:40:51 +02:00
parent 941863a0f9
commit 469648cdaa
2 changed files with 51 additions and 64 deletions

View File

@ -124,21 +124,15 @@
/* APPLIQUE UN REMPLACEMENT SIMPLE
*
* @template<String> Contenu HTML du templace
* @content<Array> Variables à insérer
* @singles<Array> Variables à insérer
*
* @return result<String> Retourne le templace rempli
*
*/
public static function replace($template, $content){
public static function replaceSingle($template, $singles){
/* [1] On trie le tableau du plus long au plus court
=========================================================*/
// usort($content, ['\manager\View', 'length_sort']);
// $content = array_reverse($content);
/* [2] On applique chaque remplacement
=========================================================*/
foreach($content as $k=>$v){
/* On applique chaque remplacement */
foreach($singles as $k=>$v){
/* Tant qu'il y a, on remplace */
if( strpos($template, '@'.$k) !== false )
@ -151,13 +145,25 @@
private static function length_sort($A, $B){
$lenA = strlen($A);
$lenB = strlen($B);
if( $lenA == $lenB ) return strcmp($A, $B);
/* APPLIQUE UN REMPLACEMENT MULTIPLE
*
* @template<String> Contenu HTML du templace
* @multiples<Array> Tableau de Singles
* @singles<Array> Variables statiques supplémentaires
*
* @return result<String> Retourne le templace rempli
*
*/
public static function replaceMultiple($template, $multiples, $singles=[]){
return ($lenA < $lenB) ? -1 : 1;
$view = '';
/* On applique chaque remplacement */
foreach($multiples as $multiple)
$view .= self::replaceSingle($template, array_merge($multiple, $singles));
return $view;
}

View File

@ -13,38 +13,38 @@
switch($type){
case 'cluster': return "
<span>
@cluster_name
<span class='rem-group' data-group='@cluster_id' data-user='@user_id'></span>
@name
<span class='rem-group' data-group='@id_cluster' data-user='@id_user'></span>
</span>";
break;
case 'user': return "
<article class='inline-box' id='@user_id'>
<article class='inline-box' id='@id_user'>
<span class='title'>@user_firstname @user_lastname <span>#@user_username</span></span>
<span class='link_remove' data-user='@user_id'>@icon_remove</span>
<span class='title'>@firstname @lastname <span>#@username</span></span>
<span class='link_remove' data-user='@id_user'>@icon_remove</span>
<span class='link_edit' data-user='@user_id'>@icon_edit</span>
<span class='link_edit' data-user='@id_user'>@icon_edit</span>
<span class='code'>
@icon_card
<span>@user_code</span>
<span>@code</span>
</span>
<span class='mail'>
@icon_mail
<a href='mailto:@user_mail'>
<span>@user_mail</span>
<a href='mailto:@mail'>
<span>@mail</span>
</a>
</span>
<span class='groups'>
@icon_group
@grouplist
<span class='add-group' data-user='@user_id'>+</span>
<span class='add-group' data-user='@id_user'>+</span>
</span>
</article>";
@ -71,18 +71,10 @@
if( $answer->error != ManagerError::Success )
return "<span class='error'>Une erreur est survenue, veuilez contacter le webmaster si cette erreur persiste.</span>";
$USERLIST = $answer->get('users');
$view_user = '';
foreach($answer->get('users') as $user){
$view_cluster = '';
/* [2] On ajoute les données de ses groupes
=========================================================*/
/* (1) On récupère les groupes de la machine */
foreach($USERLIST as $u=>$user){
$clustersReq = new ModuleRequest('userDefault/getClusters', [ 'id_user' => $user['id_user'] ]);
$clustersRes = $clustersReq->dispatch();
@ -90,40 +82,29 @@
if( $clustersRes->error == ManagerError::Success ) $clusters = $clustersRes->get('clusters');
else $clusters = [];
/* (3) On crée la vue */
foreach($clusters as $cluster){
$view_cluster .= View::replace(self::templateUserlist('cluster'),[
'cluster_id' => $cluster['id_cluster'],
'user_id' => $user['id_user']
]);
$USERLIST[$u]['grouplist'] = View::replaceMultiple(
self::templateUserlist('cluster'),
$clusters,
[ 'id_user' => $user['id_user'] ]
);
}
/* [3] On ajoute les données utilisateurs
=========================================================*/
$view_user .= View::replace(self::templateUserlist('user'), [
'user_id' => $user['id_user'],
'user_username' => $user['username'],
'user_firstname' => $user['firstname'],
'user_lastname' => $user['lastname'],
'user_code' => $user['code'],
'user_mail' => $user['mail'],
$view_user = View::replaceMultiple(
self::templateUserlist('user'),
$USERLIST, [
'icon_remove' => file_get_contents( __ROOT__.'/src/static/sub-menu-side/remove.svg' ),
'icon_edit' => file_get_contents( __ROOT__.'/src/static/sub-menu-side/edit.svg' ),
'icon_card' => file_get_contents( __ROOT__.'/src/static/container/card.svg' ),
'icon_mail' => file_get_contents( __ROOT__.'/src/static/container/mail.svg' ),
'icon_group' => file_get_contents( __ROOT__.'/src/static/container/group.svg' ),
'grouplist' => $view_cluster
]);
$view .= $view_user;
}
return View::replace(self::templateUserlist(), [ 'userlist' => $view_user ]);
return View::replaceSingle(self::templateUserlist(), [ 'userlist' => $view_user ]);
}