From 328a9db1fb70fd75f35f47cd7d72034df2b75f54 Mon Sep 17 00:00:00 2001 From: Calvo Date: Fri, 21 Jan 2022 12:56:14 +0100 Subject: [PATCH 1/3] Added select filtered modulo to custom graphs conf menu --- .../reporting/graph_builder.graph_editor.php | 116 +++++------------- .../godmode/reporting/graph_builder.php | 10 +- .../javascript/multiselect_filtered.js | 9 +- pandora_console/include/styles/pandora.css | 31 +++++ 4 files changed, 65 insertions(+), 101 deletions(-) diff --git a/pandora_console/godmode/reporting/graph_builder.graph_editor.php b/pandora_console/godmode/reporting/graph_builder.graph_editor.php index 54ced4e030..fdf11c8425 100644 --- a/pandora_console/godmode/reporting/graph_builder.graph_editor.php +++ b/pandora_console/godmode/reporting/graph_builder.graph_editor.php @@ -327,59 +327,17 @@ echo '
'; // Configuration form. echo ''; -echo "
"; +echo ""; echo ""; echo ''; -echo "'; -echo ''; -echo "'; -echo ''; -echo "'; -echo ''; -echo "'; -echo ''; -echo ''; -echo ''; -echo ''; echo ''; echo "
".__('Filter group').'
".html_print_select_groups( - $config['id_user'], - ($report_w == true) ? 'RW' : (($report_m == true) ? 'RM' : 'RW'), - true, - 'group', - '', - 'filterByGroup($(\'#group\').val());', - '', - 0, - true -).'
".__('Agents').ui_print_help_tip( - __('If you select several agents, only the common modules will be displayed'), - true -).'".__('Modules').'
'.html_print_select( - agents_get_group_agents(), - 'id_agents[]', - 0, - false, - '', - '', - true, - true, - true, - 'w100p', - false, - '' -).''.html_print_select( - [], - 'module[]', - 0, - false, - '', - 0, - true, - true, - true, - 'w100p', - false, - '' +echo ''.html_print_input( + [ + 'type' => 'select_multiple_modules_filtered', + 'uniqId' => 'modules', + 'class' => 'flex flex-row', + + ] ).'
"; @@ -403,52 +361,34 @@ ui_require_jquery_file('autocomplete'); $(document).ready (function () { $(document).data('text_for_module', $("#none_text").html()); - $("#id_agents").change(agent_changed_by_multiple_agents); - $("#submit-add").click(function() { - $('#module').map(function(){ - if ($(this).val() != "0" ) - $(this).prop('selected', true); - }); - - if($('#module')[0].childElementCount == 1 && ($('#module')[0].value == "" || $('#module')[0].value == "0")) { + if($('#filtered-module-modules-modules')[0].value == "" || $('#filtered-module-modules-modules')[0].value == "0") { alert(""); return false; } + + var modules_selected = $( + "#filtered-module-modules-modules" + ).val(); + var agents_selected = $( + "#filtered-module-agents-modules" + ).val(); + + $("#agentmodules").submit( function(eventObj) { + $("").attr("type", "hidden") + .attr("value", agents_selected) + .attr("name", "id_agents") + .appendTo("#agentmodules"); + $("").attr("type", "hidden") + .attr("value", modules_selected) + .attr("name", "id_modules") + .appendTo("#agentmodules"); + return true; + }); }); }); -function filterByGroup(idGroup) { - $('#id_agents').empty (); - $('#module').empty(); - $("#module").append ($("").attr ("value", 0).html ('')); - - jQuery.post ("ajax.php", - {"page" : "godmode/groups/group_list", - "get_group_agents" : 1, - "id_group" : idGroup, - // Add a key prefix to avoid auto sorting in js object conversion - "keys_prefix" : "_" - }, - function (data, status) { - i = 0 - jQuery.each (data, function (id, value) { - // Remove keys_prefix from the index - id = id.substring(1); - - i++; - $("#id_agents").append ($("").attr ("value", id).html (value)); - }); - - if (i == 0) { - $("#id_agents").append ($("").attr ("value", 0).html ('')); - } - }, - "json" - ); -} - function added_ids_sorted_items_to_hidden_input() { var ids = ''; var first = true; diff --git a/pandora_console/godmode/reporting/graph_builder.php b/pandora_console/godmode/reporting/graph_builder.php index 92d117df1b..7993d7e38a 100644 --- a/pandora_console/godmode/reporting/graph_builder.php +++ b/pandora_console/godmode/reporting/graph_builder.php @@ -222,8 +222,8 @@ function add_quotes($item) if ($add_module === true) { $id_graph = get_parameter('id'); - $id_modules = get_parameter('module'); - $id_agents = get_parameter('id_agents'); + $id_agent_modules = explode(',', get_parameter('id_modules')); + $id_agents = explode(',', get_parameter('id_agents')); $weight = get_parameter('weight'); // Id modules has double entities conversion. @@ -234,9 +234,7 @@ if ($add_module === true) { // to browse in db. io_safe_input_array($id_modules); - $id_agent_modules = db_get_all_rows_sql( - 'SELECT id_agente_modulo FROM tagente_modulo WHERE id_agente IN ('.implode(',', $id_agents).") AND nombre IN ('".implode("','", $id_modules)."')" - ); + if (count($id_agent_modules) > 0 && $id_agent_modules != '') { $order = db_get_row_sql("SELECT `field_order` from tgraph_source WHERE id_graph=$id_graph ORDER BY `field_order` DESC"); @@ -244,7 +242,7 @@ if ($add_module === true) { $order = $order['field_order']; foreach ($id_agent_modules as $id_agent_module) { $order++; - $result = db_process_sql_insert('tgraph_source', ['id_graph' => $id_graph, 'id_agent_module' => $id_agent_module['id_agente_modulo'], 'weight' => $weight, 'field_order' => $order]); + $result = db_process_sql_insert('tgraph_source', ['id_graph' => $id_graph, 'id_agent_module' => $id_agent_module, 'weight' => $weight, 'field_order' => $order]); } } else { $result = false; diff --git a/pandora_console/include/javascript/multiselect_filtered.js b/pandora_console/include/javascript/multiselect_filtered.js index c813c8e26a..8baef88586 100644 --- a/pandora_console/include/javascript/multiselect_filtered.js +++ b/pandora_console/include/javascript/multiselect_filtered.js @@ -231,13 +231,8 @@ function fmModuleChange(uniqId) { if (data) { jQuery.each(data, function(id, value) { var option = $("") - .attr( - "value", - value["id_node"] - ? value["id_node"] + "|" + value["id_agente_modulo"] - : value["id_agente_modulo"] - ) - .html(value["nombre"]); + .attr("value", id) + .html(value); $("#filtered-module-modules-" + uniqId).append(option); }); } diff --git a/pandora_console/include/styles/pandora.css b/pandora_console/include/styles/pandora.css index 5ff90674f4..45a4b8c65d 100644 --- a/pandora_console/include/styles/pandora.css +++ b/pandora_console/include/styles/pandora.css @@ -8455,3 +8455,34 @@ div#err_msg_centralised { display: flex; flex-direction: row; } + +#select_multiple_modules_filtered > div { + display: flex; + flex-direction: row; + justify-content: space-around; + align-items: center; + margin: 5px; + flex-wrap: wrap; + flex: 1 1 320px; +} + +#select_multiple_modules_filtered > div > div { + display: flex; + flex-direction: column; + justify-content: center; + align-items: center; + flex-wrap: wrap; + width: 250px; +} + +#select_multiple_modules_filtered > div > div > * { + flex: auto; +} + +#select_multiple_modules_filtered > div > div > select { + min-width: 250px !important; +} + +#select_multiple_modules_filtered > div > div > .select2 { + min-width: 250px !important; +} From f383586dcca3e49247f1929f6de4280d29db71a1 Mon Sep 17 00:00:00 2001 From: Calvo Date: Tue, 25 Jan 2022 20:15:40 +0100 Subject: [PATCH 2/3] WIP:Added searchbar to select multiple modules --- .../reporting/graph_builder.graph_editor.php | 8 +-- pandora_console/include/functions_html.php | 38 ++++++++++++-- .../javascript/multiselect_filtered.js | 49 ++++++++++++++++++- pandora_console/include/styles/pandora.css | 6 ++- 4 files changed, 92 insertions(+), 9 deletions(-) diff --git a/pandora_console/godmode/reporting/graph_builder.graph_editor.php b/pandora_console/godmode/reporting/graph_builder.graph_editor.php index fdf11c8425..1ff88206ea 100644 --- a/pandora_console/godmode/reporting/graph_builder.graph_editor.php +++ b/pandora_console/godmode/reporting/graph_builder.graph_editor.php @@ -333,10 +333,10 @@ echo "'; echo ''; echo ''; diff --git a/pandora_console/include/functions_html.php b/pandora_console/include/functions_html.php index 885b239d2c..b7f21f392d 100644 --- a/pandora_console/include/functions_html.php +++ b/pandora_console/include/functions_html.php @@ -1480,11 +1480,43 @@ function html_print_select_multiple_modules_filtered(array $data):string 'return' => true, 'nothing' => __('All'), 'nothing_value' => 0, - 'script' => 'fmModuleChange(\''.$uniqId.'\', '.is_metaconsole().')', + 'script' => 'fmModuleChange(\''.$uniqId.'\', '.(int) is_metaconsole().')', ] ); $output .= ''; + if (empty($data['searchBar']) === false && $data['searchBar'] === true) { + $output .= '
'; + + $output .= '
'; + $output .= html_print_input( + [ + 'type' => 'text', + 'name' => 'agent-searchBar-'.$uniqId, + 'onKeyUp' => 'searchAgent(\''.$uniqId.'\')', + 'value' => __('Type for search...'), + 'return' => true, + ] + ); + + $output .= '
'; + + $output .= '
'; + $output .= html_print_input( + [ + 'type' => 'text', + 'name' => 'module-searchBar-'.$uniqId, + 'onKeyUp' => 'searchModule(\''.$uniqId.'\')', + 'return' => true, + 'value' => 'test', + ] + ); + + $output .= '
'; + + $output .= '
'; + } + $output .= '
'; // Agent. $agents = agents_get_group_agents( @@ -1533,7 +1565,7 @@ function html_print_select_multiple_modules_filtered(array $data):string 'return' => true, 'multiple' => true, 'style' => 'min-width: 200px;max-width:200px;', - 'script' => 'fmModuleChange(\''.$uniqId.'\', '.is_metaconsole().')', + 'script' => 'fmModuleChange(\''.$uniqId.'\', '.(int) is_metaconsole().')', ] ); @@ -1550,7 +1582,7 @@ function html_print_select_multiple_modules_filtered(array $data):string 'name' => 'filtered-module-show-common-modules-'.$uniqId, 'selected' => $data['mShowCommonModules'], 'return' => true, - 'script' => 'fmModuleChange(\''.$uniqId.'\', '.is_metaconsole().')', + 'script' => 'fmModuleChange(\''.$uniqId.'\', '.(int) is_metaconsole().')', ] ); diff --git a/pandora_console/include/javascript/multiselect_filtered.js b/pandora_console/include/javascript/multiselect_filtered.js index 8de92ffcf3..88a0ad8dde 100644 --- a/pandora_console/include/javascript/multiselect_filtered.js +++ b/pandora_console/include/javascript/multiselect_filtered.js @@ -231,7 +231,7 @@ function fmModuleChange(uniqId, isMeta) { if (data) { jQuery.each(data, function(id, value) { var option = $(""); - if (isMeta === true) { + if (isMeta === 1) { option .attr( "value", @@ -251,3 +251,50 @@ function fmModuleChange(uniqId, isMeta) { "json" ); } + +// Function to search in agents select. +function searchAgent(uniqId) { + // Declare variables + var agents = $("#filtered-module-agents-" + uniqId + " option"); + + // Loop through all list items, and hide those who don't match the search query + agents.each(function() { + var filter = $("#text-agent-searchBar-modules") + .val() + .toUpperCase(); + + if ( + $(this) + .text() + .toUpperCase() + .indexOf(filter) > -1 + ) { + $(this).show(); + } else { + $(this).hide(); + } + }); +} + +// Function to search in modules select. +function searchModule(uniqId) { + // Declare variables + var modules = $("#filtered-module-modules-" + uniqId + " option"); + + // Loop through all list items, and hide those who don't match the search query + modules.each(function() { + var filter = $("#text-module-searchBar-modules") + .val() + .toUpperCase(); + if ( + $(this) + .text() + .toUpperCase() + .indexOf(filter) > -1 + ) { + $(this).show(); + } else { + $(this).hide(); + } + }); +} diff --git a/pandora_console/include/styles/pandora.css b/pandora_console/include/styles/pandora.css index c804175618..bec08fdb10 100644 --- a/pandora_console/include/styles/pandora.css +++ b/pandora_console/include/styles/pandora.css @@ -8473,7 +8473,7 @@ div#err_msg_centralised { #select_multiple_modules_filtered > div { display: flex; flex-direction: row; - justify-content: space-around; + justify-content: space-between; align-items: center; margin: 5px; flex-wrap: wrap; @@ -8500,3 +8500,7 @@ div#err_msg_centralised { #select_multiple_modules_filtered > div > div > .select2 { min-width: 250px !important; } + +#select_multiple_modules_filtered > div > div > select { + max-width: 250px !important; +} From 5b624fc3883a7c0d1c02d190d7c22dceae34d39b Mon Sep 17 00:00:00 2001 From: Calvo Date: Wed, 26 Jan 2022 11:52:49 +0100 Subject: [PATCH 3/3] Added searchbar to select multiple modules on custom graph --- .../reporting/graph_builder.graph_editor.php | 2 +- .../godmode/reporting/graph_builder.php | 11 +++++----- pandora_console/include/functions_html.php | 20 +++++++++---------- pandora_console/include/styles/pandora.css | 6 ++++-- 4 files changed, 20 insertions(+), 19 deletions(-) diff --git a/pandora_console/godmode/reporting/graph_builder.graph_editor.php b/pandora_console/godmode/reporting/graph_builder.graph_editor.php index 1ff88206ea..dfe8c1d117 100644 --- a/pandora_console/godmode/reporting/graph_builder.graph_editor.php +++ b/pandora_console/godmode/reporting/graph_builder.graph_editor.php @@ -331,7 +331,7 @@ echo ""; echo '
'; -echo '
'.html_print_input( [ - 'type' => 'select_multiple_modules_filtered', - 'uniqId' => 'modules', - 'class' => 'flex flex-row', - + 'type' => 'select_multiple_modules_filtered', + 'uniqId' => 'modules', + 'class' => 'flex flex-row', + 'searchBar' => true, ] ).'
'.html_print_input( +echo ''.html_print_input( [ 'type' => 'select_multiple_modules_filtered', 'uniqId' => 'modules', diff --git a/pandora_console/godmode/reporting/graph_builder.php b/pandora_console/godmode/reporting/graph_builder.php index 7993d7e38a..bdbee9a14b 100644 --- a/pandora_console/godmode/reporting/graph_builder.php +++ b/pandora_console/godmode/reporting/graph_builder.php @@ -222,7 +222,7 @@ function add_quotes($item) if ($add_module === true) { $id_graph = get_parameter('id'); - $id_agent_modules = explode(',', get_parameter('id_modules')); + $id_modules = explode(',', get_parameter('id_modules')); $id_agents = explode(',', get_parameter('id_agents')); $weight = get_parameter('weight'); @@ -230,11 +230,10 @@ if ($add_module === true) { // Safe output remove all entities. io_safe_output_array($id_modules, ''); - // We need to put the entities again - // to browse in db. - io_safe_input_array($id_modules); - + $id_agent_modules = db_get_all_rows_sql( + 'SELECT id_agente_modulo FROM tagente_modulo WHERE id_agente IN ('.implode(',', $id_agents).") AND nombre IN ('".implode("','", $id_modules)."')" + ); if (count($id_agent_modules) > 0 && $id_agent_modules != '') { $order = db_get_row_sql("SELECT `field_order` from tgraph_source WHERE id_graph=$id_graph ORDER BY `field_order` DESC"); @@ -242,7 +241,7 @@ if ($add_module === true) { $order = $order['field_order']; foreach ($id_agent_modules as $id_agent_module) { $order++; - $result = db_process_sql_insert('tgraph_source', ['id_graph' => $id_graph, 'id_agent_module' => $id_agent_module, 'weight' => $weight, 'field_order' => $order]); + $result = db_process_sql_insert('tgraph_source', ['id_graph' => $id_graph, 'id_agent_module' => $id_agent_module['id_agente_modulo'], 'weight' => $weight, 'field_order' => $order]); } } else { $result = false; diff --git a/pandora_console/include/functions_html.php b/pandora_console/include/functions_html.php index b7f21f392d..81bb15757f 100644 --- a/pandora_console/include/functions_html.php +++ b/pandora_console/include/functions_html.php @@ -1491,11 +1491,11 @@ function html_print_select_multiple_modules_filtered(array $data):string $output .= '
'; $output .= html_print_input( [ - 'type' => 'text', - 'name' => 'agent-searchBar-'.$uniqId, - 'onKeyUp' => 'searchAgent(\''.$uniqId.'\')', - 'value' => __('Type for search...'), - 'return' => true, + 'type' => 'text', + 'name' => 'agent-searchBar-'.$uniqId, + 'onKeyUp' => 'searchAgent(\''.$uniqId.'\')', + 'placeholder' => __('Type to search agents'), + 'return' => true, ] ); @@ -1504,11 +1504,11 @@ function html_print_select_multiple_modules_filtered(array $data):string $output .= '
'; $output .= html_print_input( [ - 'type' => 'text', - 'name' => 'module-searchBar-'.$uniqId, - 'onKeyUp' => 'searchModule(\''.$uniqId.'\')', - 'return' => true, - 'value' => 'test', + 'type' => 'text', + 'name' => 'module-searchBar-'.$uniqId, + 'onKeyUp' => 'searchModule(\''.$uniqId.'\')', + 'return' => true, + 'placeholder' => __('Type to search modules'), ] ); diff --git a/pandora_console/include/styles/pandora.css b/pandora_console/include/styles/pandora.css index bec08fdb10..ba89e2d915 100644 --- a/pandora_console/include/styles/pandora.css +++ b/pandora_console/include/styles/pandora.css @@ -8501,6 +8501,8 @@ div#err_msg_centralised { min-width: 250px !important; } -#select_multiple_modules_filtered > div > div > select { - max-width: 250px !important; +#select_multiple_modules_filtered > div > div > input { + max-width: 250px; + width: 95%; + height: 95%; }