From 05d1ef50e02c8412a080b0beea09271e7962f249 Mon Sep 17 00:00:00 2001 From: xdrm-brackets Date: Mon, 25 Sep 2017 15:29:15 +0200 Subject: [PATCH] Update *module_merge* to link `id_etree` instead of `id_module` (impacts 5. 6. 8.) --- build/api/module/clusterDefault.php | 44 +++++- build/database/repo/chip.php | 2 +- build/database/repo/etree.php | 202 ++++++++++++++++++++++++++ build/database/repo/module.php | 19 ++- build/database/repo/warehouse.php | 2 +- build/viewer/view/group/view.php | 7 +- build/viewer/view/group/view.twig | 2 +- build/viewer/view/machine/groups.php | 7 +- build/viewer/view/machine/groups.twig | 2 +- config/modules.json | 13 +- config/repositories.json | 8 +- public_html/css/container.scss | 1 + public_html/css/min/container.css | 1 + 13 files changed, 288 insertions(+), 22 deletions(-) create mode 100644 build/database/repo/etree.php diff --git a/build/api/module/clusterDefault.php b/build/api/module/clusterDefault.php index 3d1a200..39f0f11 100755 --- a/build/api/module/clusterDefault.php +++ b/build/api/module/clusterDefault.php @@ -426,7 +426,7 @@ /* RETOURNE LA LISTE DES MODULE D'UN GROUPE DE MACHINES * - * @id_cluster UID du groupe de machine + * @id_machine_cluster UID du groupe de machine * * @return modules Liste des modules autorisés pour le groupe de machines * @@ -438,9 +438,9 @@ /* [1] On récupère les modules =========================================================*/ /* (1) Récupération */ - $mod_req = new Repo('module/getByMachineCluster', [ + $mod_req = new Repo('module/getForMachineCluster', [ $_SESSION['WAREHOUSE']['id'], - $id_cluster + $id_machine_cluster ]); $answer = $mod_req->answer(); @@ -457,6 +457,44 @@ + + + + + + /* RETOURNE L'E-TREE D'UN GROUPE DE MACHINES + * + * @id_machine_cluster UID du groupe de machine + * + * @return e-tree E-tree du groupe de machines + * + */ + public static function getEtree($params){ + extract($params); + + + /* [1] On récupère les modules + =========================================================*/ + /* (1) Récupération */ + $mod_req = new Repo('etree/getForMachineCluster', [ + $_SESSION['WAREHOUSE']['id'], + $id_machine_cluster + ]); + + $answer = $mod_req->answer(); + + /* (2) Gestion erreur */ + if( $answer === false ) + return ['error' => new Error(Err::NoMatchFound)]; // no error + + + /* [3] On retourne la liste + =========================================================*/ + return [ 'etree' => $answer ]; + } + + + } diff --git a/build/database/repo/chip.php b/build/database/repo/chip.php index 30e35c6..228ab18 100755 --- a/build/database/repo/chip.php +++ b/build/database/repo/chip.php @@ -37,7 +37,7 @@ foreach($clusters as $cluster){ - $get_mods = new Repo('module/getByMachineCluster', [$id_warehouse, $cluster['id_machine_cluster']]); + $get_mods = new Repo('module/getForMachineCluster', [$id_warehouse, $cluster['id_machine_cluster']]); $mods = $get_mods->answer(); diff --git a/build/database/repo/etree.php b/build/database/repo/etree.php new file mode 100644 index 0000000..459843c --- /dev/null +++ b/build/database/repo/etree.php @@ -0,0 +1,202 @@ + UID of the given warehouse + * @id_machine_cluster UID of the given machine_cluster + * + * @return etrees The list of etrees + * FALSE on error + * + =========================================================*/ + public static function getForMachineCluster($id_warehouse, $id_machine_cluster){ + + /* (1) On récupère le ETREE de la machine + ---------------------------------------------------------*/ + $module = Table::get('module') + ->select('id_module') + ->select('name'); + + $etree = Table::get('etree') + ->select('id_etree') + ->select('daemon') + ->join('id_module', $module); + + $merge = Table::get('module_merge') + ->join('id_etree', $etree) + ->whereIdWarehouse($id_warehouse) + ->whereIdMachineCluster($id_machine_cluster); + + return $merge->fetch(); + + } + + + + + + + + + + + + /* [4] Adds a module to machine cluster of a warehouse + * + * @id_warehouse UID of the given warehouse + * @id_machine_cluster UID of the given machine_cluster + * @id_module UID of the given module + * + * @return status TRUE on success + * + =========================================================*/ + public static function link($id_warehouse, $id_machine_cluster, $id_module){ + + /* (1) Check module + ---------------------------------------------------------*/ + /* (1) Check if module exists (by its id) */ + $module = Table::get('module') + ->select('*') + ->unique() + ->whereId($id_module); + + if( !$module->fetch() ) + return false; + + /* (2) Check if the module is allowed in the warehouse */ + $module_m = Table::get('module_availability') + ->select('*') + ->unique() + ->whereIdWarehouse($id_warehouse) + ->whereIdModule($id_module); + + // if not allowed in the warehouse -> error + if( !$module->fetch() ) + return false; + + + /* (2) Check machine_cluster + ---------------------------------------------------------*/ + /* (1) Check if machine_cluster exists (by its id) */ + $machine_cluster = Table::get('machine_cluster') + ->select('*') + ->unique() + ->whereIdWarehouse($id_warehouse) + ->whereId($id_machine_cluster); + + if( !$machine_cluster->fetch() ) + return false; + + /* (2) Check link does not already exists */ + $exists = Table::get('module_merge') + ->select('*') + ->unique() + ->whereIdWarehouse($id_warehouse) + ->whereIdMachineCluster($id_machine_cluster) + ->whereIdModule($id_module); + + if( !!$exists->fetch() ) + return true; // returns all right (even if nothing done) + + + + /* (3) Create link + ---------------------------------------------------------*/ + $inserted = Table::get('module_merge')->insert([ + 'id_warehouse' => $id_warehouse, + 'id_module' => $id_module, + 'id_machine_cluster' => $id_machine_cluster + ]); + + // return TRUE only if PDO insert successful + return $inserted; + + } + + + + + + + + /* [5] Removes a module from machine cluster of a warehouse + * + * @id_warehouse UID of the given warehouse + * @id_machine_cluster UID of the given machine_cluster + * @id_module UID of the given module + * + * @return status TRUE on success + * + =========================================================*/ + public static function unlink($id_warehouse, $id_machine_cluster, $id_module){ + + /* (1) Check module + ---------------------------------------------------------*/ + /* (1) Check if module exists (by its id) */ + $module = Table::get('module') + ->select('*') + ->unique() + ->whereId($id_module); + + if( !$module->fetch() ) + return false; + + + + /* (2) Check machine_cluster + ---------------------------------------------------------*/ + /* (1) Check if machine_cluster exists (by its id) */ + $machine_cluster = Table::get('machine_cluster') + ->select('*') + ->unique() + ->whereIdWarehouse($id_warehouse) + ->whereId($id_machine_cluster); + + if( !$machine_cluster->fetch() ) + return false; + + /* (2) Check if link already exists */ + $exists = Table::get('module_merge') + ->select('*') + ->unique() + ->whereIdWarehouse($id_warehouse) + ->whereIdMachineCluster($id_machine_cluster) + ->whereIdModule($id_module); + + if( !$exists->fetch() ) + return false; // returns all right (even if nothing done) + + + + /* (3) Remove link + ---------------------------------------------------------*/ + $deleted = Table::get('module_merge') + ->whereIdWarehouse($id_warehouse) + ->whereIdModule($id_module) + ->whereIdMachineCluster($id_machine_cluster) + ->delete(); + + // return TRUE only if PDO delete successful + return $deleted; + + } + + + + + + } + + +?> diff --git a/build/database/repo/module.php b/build/database/repo/module.php index 79d2f0b..1fb697e 100644 --- a/build/database/repo/module.php +++ b/build/database/repo/module.php @@ -37,7 +37,7 @@ * FALSE on error * =========================================================*/ - public static function getByWarehouse($id_warehouse){ + public static function getForWarehouse($id_warehouse){ /* (1) Build request */ $modules = Table::get('module')->select('*'); @@ -63,14 +63,21 @@ * FALSE on error * =========================================================*/ - public static function getByMachineCluster($id_warehouse, $id_machine_cluster){ + public static function getForMachineCluster($id_warehouse, $id_machine_cluster){ - /* (1) Build request */ - $modules = Table::get('module')->select('*'); - $merge = Table::get('module_merge') + /* (1) On récupère le ETREE de la machine + ---------------------------------------------------------*/ + $module = Table::get('module') + ->select('id_module') + ->select('name'); + + $etree = Table::get('etree') + ->join('id_module', $module); + + $merge = Table::get('module_merge') + ->join('id_etree', $etree) ->whereIdWarehouse($id_warehouse) ->whereIdMachineCluster($id_machine_cluster); - $merge->join('id_module', $modules); return $merge->fetch(); diff --git a/build/database/repo/warehouse.php b/build/database/repo/warehouse.php index e0d640f..2c84a08 100755 --- a/build/database/repo/warehouse.php +++ b/build/database/repo/warehouse.php @@ -99,7 +99,7 @@ /* [1] On récupère les modules =========================================================*/ /* (1) Récupération */ - $mod_req = new Repo('module/getByWarehouse', [$id_warehouse]); + $mod_req = new Repo('module/getForWarehouse', [$id_warehouse]); $answer = $mod_req->answer(); diff --git a/build/viewer/view/group/view.php b/build/viewer/view/group/view.php index 304c6cf..66958c7 100755 --- a/build/viewer/view/group/view.php +++ b/build/viewer/view/group/view.php @@ -61,16 +61,17 @@ })); $twig->addFunction(new \Twig_Function('f_options', function($id_cluster){ - $modReq = new Request('clusterDefault/getModules', [ - 'id_cluster' => (int) $id_cluster + $modReq = new Request('clusterDefault/getEtree', [ + '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('modules'); + return $modRes->get('etree'); })); diff --git a/build/viewer/view/group/view.twig b/build/viewer/view/group/view.twig index 5ec3c28..4a84a3d 100755 --- a/build/viewer/view/group/view.twig +++ b/build/viewer/view/group/view.twig @@ -64,7 +64,7 @@ {{ p_icon.option | raw }} {% for option in f_options(machine_cluster.id_machine_cluster) %} - {{ option.name }} + {{ option.name }}:{{ option.daemon }} {% else %} Aucune option diff --git a/build/viewer/view/machine/groups.php b/build/viewer/view/machine/groups.php index 99fd598..0c79c3d 100755 --- a/build/viewer/view/machine/groups.php +++ b/build/viewer/view/machine/groups.php @@ -62,16 +62,17 @@ })); $twig->addFunction(new \Twig_Function('f_options', function($id_cluster){ - $modReq = new Request('clusterDefault/getModules', [ - 'id_cluster' => (int) $id_cluster + $modReq = new Request('clusterDefault/getEtree', [ + '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('modules'); + return $modRes->get('etree'); })); diff --git a/build/viewer/view/machine/groups.twig b/build/viewer/view/machine/groups.twig index 28011d1..1fc09e8 100755 --- a/build/viewer/view/machine/groups.twig +++ b/build/viewer/view/machine/groups.twig @@ -20,7 +20,7 @@ {{ p_icon.option | raw }} {% for option in f_options(cluster.id_machine_cluster) %} - {{ option.name }} + {{ option.name }}:{{ option.daemon }} {% else %} Aucune option diff --git a/config/modules.json b/config/modules.json index e168521..2b7e89c 100755 --- a/config/modules.json +++ b/config/modules.json @@ -509,11 +509,22 @@ "description": "Retourne les modules d'un groupe de machines", "permissions": [["admin"]], "parameters": { - "id_cluster": { "description": "UID du groupe de machines", "type": "id" } + "id_machine_cluster": { "description": "UID du groupe de machines", "type": "id" } }, "output": { "modules": { "description": "Modules du groupe", "type": "array" } } + }, + + "POST::getEtree": { + "description": "Retourne l'e-tree d'un groupe de machines", + "permissions": [["admin"]], + "parameters": { + "id_machine_cluster": { "description": "UID du groupe de machines", "type": "id" } + }, + "output": { + "modules": { "description": "E-tree du groupe", "type": "array" } + } } }, diff --git a/config/repositories.json b/config/repositories.json index efcaf47..c7f483d 100755 --- a/config/repositories.json +++ b/config/repositories.json @@ -2,12 +2,16 @@ "module": [ "getAll", - "getByWarehouse", - "getByMachineCluster", + "getForWarehouse", + "getForMachineCluster", "link", "unlink" ], + "etree": [ + "getForMachineCluster" + ], + "history": [ "create", "delete", diff --git a/public_html/css/container.scss b/public_html/css/container.scss index 4938ed6..a415cab 100755 --- a/public_html/css/container.scss +++ b/public_html/css/container.scss @@ -337,6 +337,7 @@ .option > span.ignore > span{ border-radius: 3px; + margin-right: .4em; } /* (5) Lien vers la modification */ diff --git a/public_html/css/min/container.css b/public_html/css/min/container.css index 85eb9fc..a1da2cf 100644 --- a/public_html/css/min/container.css +++ b/public_html/css/min/container.css @@ -539,6 +539,7 @@ #WRAPPER > #CONTAINER > section > .inline-box .option > span.ignore > span, #WRAPPER > #CONTAINER > section > .inline-row .option > span.ignore > span { border-radius: 3px; + margin-right: .4em; } #WRAPPER > #CONTAINER > section > .inline-box .link_edit,