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 /* APPLIQUE UN REMPLACEMENT SIMPLE
* *
* @template<String> Contenu HTML du templace * @template<String> Contenu HTML du templace
* @content<Array> Variables à insérer * @singles<Array> Variables à insérer
* *
* @return result<String> Retourne le templace rempli * @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 /* On applique chaque remplacement */
=========================================================*/ foreach($singles as $k=>$v){
// usort($content, ['\manager\View', 'length_sort']);
// $content = array_reverse($content);
/* [2] On applique chaque remplacement
=========================================================*/
foreach($content as $k=>$v){
/* Tant qu'il y a, on remplace */ /* Tant qu'il y a, on remplace */
if( strpos($template, '@'.$k) !== false ) 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){ switch($type){
case 'cluster': return " case 'cluster': return "
<span> <span>
@cluster_name @name
<span class='rem-group' data-group='@cluster_id' data-user='@user_id'></span> <span class='rem-group' data-group='@id_cluster' data-user='@id_user'></span>
</span>"; </span>";
break; break;
case 'user': return " 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='title'>@firstname @lastname <span>#@username</span></span>
<span class='link_remove' data-user='@user_id'>@icon_remove</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'> <span class='code'>
@icon_card @icon_card
<span>@user_code</span> <span>@code</span>
</span> </span>
<span class='mail'> <span class='mail'>
@icon_mail @icon_mail
<a href='mailto:@user_mail'> <a href='mailto:@mail'>
<span>@user_mail</span> <span>@mail</span>
</a> </a>
</span> </span>
<span class='groups'> <span class='groups'>
@icon_group @icon_group
@grouplist @grouplist
<span class='add-group' data-user='@user_id'>+</span> <span class='add-group' data-user='@id_user'>+</span>
</span> </span>
</article>"; </article>";
@ -71,18 +71,10 @@
if( $answer->error != ManagerError::Success ) if( $answer->error != ManagerError::Success )
return "<span class='error'>Une erreur est survenue, veuilez contacter le webmaster si cette erreur persiste.</span>"; return "<span class='error'>Une erreur est survenue, veuilez contacter le webmaster si cette erreur persiste.</span>";
$USERLIST = $answer->get('users');
$view_user = ''; foreach($USERLIST as $u=>$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 */
$clustersReq = new ModuleRequest('userDefault/getClusters', [ 'id_user' => $user['id_user'] ]); $clustersReq = new ModuleRequest('userDefault/getClusters', [ 'id_user' => $user['id_user'] ]);
$clustersRes = $clustersReq->dispatch(); $clustersRes = $clustersReq->dispatch();
@ -90,40 +82,29 @@
if( $clustersRes->error == ManagerError::Success ) $clusters = $clustersRes->get('clusters'); if( $clustersRes->error == ManagerError::Success ) $clusters = $clustersRes->get('clusters');
else $clusters = []; else $clusters = [];
/* (3) On crée la vue */ $USERLIST[$u]['grouplist'] = View::replaceMultiple(
foreach($clusters as $cluster){ self::templateUserlist('cluster'),
$view_cluster .= View::replace(self::templateUserlist('cluster'),[ $clusters,
'cluster_id' => $cluster['id_cluster'], [ 'id_user' => $user['id_user'] ]
'user_id' => $user['id_user'] );
]);
} }
$view_user = View::replaceMultiple(
/* [3] On ajoute les données utilisateurs self::templateUserlist('user'),
=========================================================*/ $USERLIST, [
$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'],
'icon_remove' => file_get_contents( __ROOT__.'/src/static/sub-menu-side/remove.svg' ), '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_edit' => file_get_contents( __ROOT__.'/src/static/sub-menu-side/edit.svg' ),
'icon_card' => file_get_contents( __ROOT__.'/src/static/container/card.svg' ), 'icon_card' => file_get_contents( __ROOT__.'/src/static/container/card.svg' ),
'icon_mail' => file_get_contents( __ROOT__.'/src/static/container/mail.svg' ), 'icon_mail' => file_get_contents( __ROOT__.'/src/static/container/mail.svg' ),
'icon_group' => file_get_contents( __ROOT__.'/src/static/container/group.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 ]);
} }