diff --git a/manager/module/clusterDefault.php b/manager/module/clusterDefault.php index ca80faa..f7c9384 100644 --- a/manager/module/clusterDefault.php +++ b/manager/module/clusterDefault.php @@ -52,7 +52,6 @@ /* RENVOIE UN GROUPE EN FONCTION D'UN MOT CLE * * @keywords Element de recherche - * @class Type de groupe * * @return clusters Retourne la liste des groupes trouves * @@ -60,15 +59,22 @@ public static function search($params){ extract($params); - $repoMethod = ($class==0) ? 'user_cluster/search' : 'machine_cluster/search'; - // On recupere les donnees des groupes utilisateurs - $cluster = new Repo($repoMethod, [ + $userClusters = new Repo('user_cluster/search', [ $_SESSION['WAREHOUSE']['id'], $keywords ]); - return [ 'clusters' => $cluster->answer() ]; + + // On recupere les donnees des groupes machines + $machineClusters = new Repo('machine_cluster/search', [ + $_SESSION['WAREHOUSE']['id'], + $keywords + ]); + + $merged = array_merge($userClusters->answer(), $machineClusters->answer()); + + return [ 'clusters' => $merged ]; } diff --git a/manager/view/group/membersChoice.php b/manager/view/group/membersChoice.php index 12e2087..02a4e76 100644 --- a/manager/view/group/membersChoice.php +++ b/manager/view/group/membersChoice.php @@ -63,7 +63,7 @@ /* [0] Initialisation =========================================================*/ /* (1) On vérifie les paramètres */ - if( !isset($params['id_cluster']) && !is_number($params['id_cluster']) ) + if( !isset($params['id_cluster']) || !is_numeric($params['id_cluster']) || !isset($params['class']) || !is_numeric($params['class']) ) return View::$htmlError; /* (2) On initialise les vues */ @@ -76,7 +76,8 @@ =========================================================*/ /* (1) On récupère le groupe */ $checktypeRequest = new ModuleRequest('clusterDefault/getById', [ - 'id_cluster' => $params['id_cluster'] + 'id_cluster' => $params['id_cluster'], + 'class' => $params['class'] ]); $checktypeResponse = $checktypeRequest->dispatch(); @@ -93,7 +94,8 @@ =========================================================*/ /* (1) On exécute la requête */ $getmembersRequest = new ModuleRequest('clusterDefault/getMembers', [ - 'id_cluster' => $params['id_cluster'] + 'id_cluster' => $params['id_cluster'], + 'class' => $params['class'] ]); $getmembersResponse = $getmembersRequest->dispatch(); @@ -104,13 +106,13 @@ /* (3) On récupère la liste des UID uniquement */ $members_id = []; foreach($getmembersResponse->get('members') as $member) - $members_id[] = $member['id_member']; + $members_id[] = ($params['class']==0) ? $member['id_user'] : $member['id_machine']; /* [3] SI GROUPE D'UTILISATEURS -> On récupère les utilisateurs =========================================================*/ - if( $currentCluster['class'] == clusterRepo::USER_CLASS ){ + if( $params['class'] == 0 ){ /* (1) On récupère les utilisateurs ---------------------------------------------------------*/ @@ -160,8 +162,8 @@ /* (2) On gère l'affichage des machines ---------------------------------------------------------*/ /* (1) On gère l'état 'membre' ou non */ - foreach($MACHINELIST as $u=>$user) - $MACHINELIST[$u]['already_in'] = in_array($user['id_machine'], $members_id) ? 'checked' : ''; + foreach($MACHINELIST as $m=>$machine) + $MACHINELIST[$m]['already_in'] = in_array($machine['id_machine'], $members_id) ? 'checked' : ''; /* (2) On génère la vue */ $members_view = View::replaceMultiple( @@ -171,16 +173,14 @@ } - $class = ($currentCluster['class'] == clusterRepo::USER_CLASS) ? 0 : 1; - return View::replaceSingle( self::template(), [ - 'id_cluster' => $currentCluster['id_cluster'], - 'class' => $class, + 'id_cluster' => $params['id_cluster'], + 'class' => $params['class'], 'name' => $currentCluster['name'], - 'clustertype' => ($class==0) ? 'utilisateurs' : 'machines', + 'clustertype' => ($params['class']==0) ? 'utilisateurs' : 'machines', 'members' => $members_view ] ); diff --git a/view/groups.php b/view/groups.php index b0955db..d2890e7 100755 --- a/view/groups.php +++ b/view/groups.php @@ -123,7 +123,8 @@ echo "




"; // Suppression de groupe - echo "
"; + echo "
"; + echo "
"; echo ""; echo ""; @@ -154,6 +155,7 @@ echo "




"; echo "
"; + echo "
"; echo ""; echo ""; @@ -176,10 +178,11 @@ /* (1) Si on a un ID_CLUSTER, on affiche la composition ---------------------------------------------------------*/ - if( isset($post[1]) && is_numeric($post[1]) ){ + if( isset($post[1]) && preg_match('/^(u|m)(\d+)$/', $post[1], $m) ){ $membersChoice = new View('group.membersChoice', [ - 'id_cluster' => $post[1] + 'id_cluster' => $m[2], + 'class' => ($m[1]=='u') ? 0 : 1 ]); $membersChoice->view(); diff --git a/view/js/groups-min.js b/view/js/groups-min.js index e21f055..f10d5a2 100644 --- a/view/js/groups-min.js +++ b/view/js/groups-min.js @@ -3,16 +3,16 @@ edit:{text:'#CONTAINER > section[data-sublink="edit"] ',element:document.querySe element:document.querySelector('#CONTAINER > section[data-sublink="permissions"]')}}; if(null!=section.view.element){1 article.inline-box[id]");for(c=0;c= 2 && !isNaN(pageManager.vars[1]) ){ + if( pageManager.vars.length >= 2 && /^[um]\d+$/.test(pageManager.vars[1]) ){ + var prefix = pageManager.vars[1][0]; + var cluster = pageManager.vars[1].slice(1); + + var request = { + path: 'clusterDefault/getById', + id_cluster: cluster, + class: (prefix=='u') ? 0 : 1 + }; // On récupère la user d'uid donné dans l'URL - api.send({path:'clusterDefault/getById', id_cluster:pageManager.vars[1]}, function(response){ + api.send(request, function(response){ // Si aucune erreur et un résultat if( response.ModuleError == 0 ){ found_remove = [ response.cluster ]; // On récupère le résultat @@ -352,7 +377,7 @@ if( section.remove.element != null ){ /* (4) Redaction de la requete */ var getClusters = { path: 'clusterDefault/search', - keywords: section.remove.input.search.keyword.value + keywords: section.remove.input.search.keyword.value }; /* (5) On envoie la requête */ @@ -363,8 +388,8 @@ if( section.remove.element != null ){ section.remove.input.search.submit.anim('active', 1000); /* (6) On met à jour les données des users, et le compteur */ - searchindex_remove = 0; - found_remove = getClustersResponse.clusters; + searchindex_remove = 0; + found_remove = getClustersResponse.clusters; section.remove.input.search.sum.innerHTML = found_remove.length; // On met à jour l'auto-remplissage