Merge branch 'ent-8206-busqueda-de-modulos-en-graficas-personalizadas' into 'develop'

Added select filtered modulo to custom graphs conf menu

See merge request artica/pandorafms!4647
This commit is contained in:
Daniel Rodriguez 2022-02-01 09:38:12 +00:00
commit d21d65a7ac
6 changed files with 157 additions and 104 deletions

View File

@ -327,59 +327,17 @@ echo '<br>';
// Configuration form.
echo '<span id ="none_text" class="invisible">'.__('None').'</span>';
echo "<form method='post' action='index.php?sec=reporting&sec2=godmode/reporting/graph_builder&tab=graph_editor&add_module=1&edit_graph=1&id=".$id_graph."'>";
echo "<form id='agentmodules' method='post' action='index.php?sec=reporting&sec2=godmode/reporting/graph_builder&tab=graph_editor&add_module=1&edit_graph=1&id=".$id_graph."'>";
echo "<table width='100%' cellpadding='4' cellpadding='4' class='databox filters'>";
echo '<tr>';
echo "<td colspan='1'>".__('Filter group').'</td>';
echo '</tr><tr>';
echo "<td colspan='1'>".html_print_select_groups(
$config['id_user'],
($report_w == true) ? 'RW' : (($report_m == true) ? 'RM' : 'RW'),
true,
'group',
'',
'filterByGroup($(\'#group\').val());',
'',
0,
true
).'</td>';
echo '</tr><tr>';
echo "<td class='top'>".__('Agents').ui_print_help_tip(
__('If you select several agents, only the common modules will be displayed'),
true
).'</td>';
echo '<td></td>';
echo "<td class='top'>".__('Modules').'</td>';
echo '</tr><tr>';
echo '<td class="w50p">'.html_print_select(
agents_get_group_agents(),
'id_agents[]',
0,
false,
'',
'',
true,
true,
true,
'w100p',
false,
''
).'</td>';
echo '<td class="select_module_graph"></td>';
echo '<td class="w50p">'.html_print_select(
[],
'module[]',
0,
false,
'',
0,
true,
true,
true,
'w100p',
false,
''
echo '<td class="w50p pdd_50px" id="select_multiple_modules_filtered">'.html_print_input(
[
'type' => 'select_multiple_modules_filtered',
'uniqId' => 'modules',
'class' => 'flex flex-row',
'searchBar' => true,
]
).'</td>';
echo '</tr><tr>';
echo "<td colspan='3'>";
@ -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("<?php echo __('Please, select a module'); ?>");
return false;
}
var modules_selected = $(
"#filtered-module-modules-modules"
).val();
var agents_selected = $(
"#filtered-module-agents-modules"
).val();
$("#agentmodules").submit( function(eventObj) {
$("<input />").attr("type", "hidden")
.attr("value", agents_selected)
.attr("name", "id_agents")
.appendTo("#agentmodules");
$("<input />").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 ($("<option></option>").attr ("value", 0).html ('<?php echo __('None'); ?>'));
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 ($("<option></option>").attr ("value", id).html (value));
});
if (i == 0) {
$("#id_agents").append ($("<option></option>").attr ("value", 0).html ('<?php echo __('None'); ?>'));
}
},
"json"
);
}
function added_ids_sorted_items_to_hidden_input() {
var ids = '';
var first = true;

View File

@ -222,17 +222,14 @@ 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_modules = explode(',', get_parameter('id_modules'));
$id_agents = explode(',', get_parameter('id_agents'));
$weight = get_parameter('weight');
// Id modules has double entities conversion.
// 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)."')"

View File

@ -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 .= '</div>';
if (empty($data['searchBar']) === false && $data['searchBar'] === true) {
$output .= '<div>';
$output .= '<div>';
$output .= html_print_input(
[
'type' => 'text',
'name' => 'agent-searchBar-'.$uniqId,
'onKeyUp' => 'searchAgent(\''.$uniqId.'\')',
'placeholder' => __('Type to search agents'),
'return' => true,
]
);
$output .= '</div>';
$output .= '<div>';
$output .= html_print_input(
[
'type' => 'text',
'name' => 'module-searchBar-'.$uniqId,
'onKeyUp' => 'searchModule(\''.$uniqId.'\')',
'return' => true,
'placeholder' => __('Type to search modules'),
]
);
$output .= '</div>';
$output .= '</div>';
}
$output .= '<div>';
// 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().')',
]
);

View File

@ -231,7 +231,7 @@ function fmModuleChange(uniqId, isMeta) {
if (data) {
jQuery.each(data, function(id, value) {
var option = $("<option></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();
}
});
}

View File

@ -8469,3 +8469,40 @@ div#err_msg_centralised {
display: flex;
flex-direction: row;
}
#select_multiple_modules_filtered > div {
display: flex;
flex-direction: row;
justify-content: space-between;
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;
}
#select_multiple_modules_filtered > div > div > input {
max-width: 250px;
width: 95%;
height: 95%;
}

View File

@ -556,13 +556,13 @@ $table_ichanges = '<div class="autorefresh_select">
</div>
<div class="autorefresh_select_arrows" style="display:grid">
<a href="javascript:">'.html_print_image(
'images/darrowright_green.png',
true,
[
'id' => 'right_autorefreshlist',
'alt' => __('Push selected pages into autorefresh list'),
'title' => __('Push selected pages into autorefresh list'),
]
'images/darrowright_green.png',
true,
[
'id' => 'right_autorefreshlist',
'alt' => __('Push selected pages into autorefresh list'),
'title' => __('Push selected pages into autorefresh list'),
]
).'</a>
<a href="javascript:">'.html_print_image(
'images/darrowleft_green.png',