Merge branch '807-module-massive-operations-with-tag-filter-dev' into 'develop'

807 module massive operations with tag filter dev

See merge request !476
This commit is contained in:
vgilc 2017-05-31 17:42:09 +02:00
commit 1d6747c353
5 changed files with 150 additions and 27 deletions

View File

@ -130,6 +130,11 @@ foreach ($agent_alerts as $alert) {
$alerts[$alert['id']] = $name;
}
$tags = tags_get_user_tags();
$table->data['tags'][0] = __('Tags');
$table->data['tags'][1] = html_print_select ($tags, 'tags[]',
$tags_name, false, __('Any'), -1, true, true, true);
$table->data['operations'][0] = __('Operations');
$table->data['operations'][1] = '<span class="with_modules'.(empty ($modules) ? ' invisible': '').'">';
$table->data['operations'][1] .= html_print_checkbox ('copy_modules', 1, true, true);
@ -282,12 +287,16 @@ $(document).ready (function () {
}
});
$("#tags").change(function() {
$("#source_id_agent").trigger("change");
});
$("#status_agents_destiny").change(function() {
$("#destiny_id_group").trigger("change");
});
$("#source_id_agent").change (function () {
var id_agent = this.value;
var id_agent = $("#source_id_agent").val();
if (id_agent == 0) {
$("#submit-go").attr("disabled", "disabled");
@ -302,6 +311,21 @@ $(document).ready (function () {
return;
}
var params = {
"page" : "operation/agentes/ver_agente",
"get_agent_modules_json" : 1,
"get_id_and_name" : 1,
"disabled" : 0,
"id_agent" : id_agent
};
var tags_to_search = $('#tags').val();
if (tags_to_search != null) {
if (tags_to_search[0] != -1) {
params['tags'] = tags_to_search;
}
}
$("#submit-go").attr("disabled", false);
$("#modules_loading").show ();
@ -313,12 +337,7 @@ $(document).ready (function () {
var no_alerts;
/* Get modules */
jQuery.post ("ajax.php",
{"page" : "operation/agentes/ver_agente",
"get_agent_modules_json" : 1,
"id_agent" : this.value,
"disabled" : 0,
"get_id_and_name" : 1
},
params,
function (data, status) {
if (data.length == 0) {
no_modules = true;

View File

@ -444,7 +444,12 @@ $table->data['form_agents_1'][3] = __('Select all modules of this group') . ' '
html_print_checkbox_extended ("force_group", 'group', '', '', false,
'', 'style="margin-right: 40px;"', true);
$tags = tags_get_user_tags();
$table->rowstyle['form_modules_4'] = 'vertical-align: top;';
$table->rowclass['form_modules_4'] = 'select_modules_row select_modules_row_2';
$table->data['form_modules_4'][0] = __('Tags');
$table->data['form_modules_4'][1] = html_print_select ($tags, 'tags[]',
$tags_name, false, __('Any'), -1, true, true, true);
$table->rowclass['form_agents_2'] = 'select_agents_row';
$table->data['form_agents_2'][0] = __('Status');
@ -489,7 +494,12 @@ $table->data['form_modules_2'][2] .= html_print_select(
$table->data['form_modules_2'][3] = html_print_select (array(), 'agents[]',
$agents_select, false, __('None'), 0, true, true, false, '', false, 'width:100%');
$tags = tags_get_user_tags();
$table->rowstyle['form_agents_4'] = 'vertical-align: top;';
$table->rowclass['form_agents_4'] = 'select_agents_row select_agents_row_2';
$table->data['form_agents_4'][0] = __('Tags');
$table->data['form_agents_4'][1] = html_print_select ($tags, 'tags[]',
$tags_name, false, __('Any'), -1, true, true, true);
$table->rowstyle['form_agents_3'] = 'vertical-align: top;';
$table->rowclass['form_agents_3'] = 'select_agents_row select_agents_row_2';
@ -544,6 +554,7 @@ $(document).ready (function () {
.css('display', '<?php echo $modules_row?>');
$(".select_agents_row")
.css('display', '<?php echo $agents_row?>');
$(".select_modules_row_2").css('display', 'none');
// Trigger change to refresh selection when change selection mode
$("#agents_selection_mode").change (function() {
@ -573,7 +584,7 @@ $(document).ready (function () {
var params = {
"page" : "operation/agentes/ver_agente",
"get_agent_modules_json" : 1,
"get_distinct_name" : 1,
"get_id_and_name" : 1,
"indexed" : 0,
"privilege" : "AW"
};
@ -584,6 +595,13 @@ $(document).ready (function () {
var status_module = $('#status_module').val();
if (status_module != '-1')
params['status_module'] = status_module;
var tags_to_search = $('#tags').val();
if (tags_to_search != null) {
if (tags_to_search[0] != -1) {
params['tags'] = tags_to_search;
}
}
$("#module_loading").show ();
$("tr#delete_table-edit1, tr#delete_table-edit2").hide ();
@ -656,6 +674,7 @@ $(document).ready (function () {
else if (selector == 'modules') {
$(".select_agents_row").hide();
$(".select_modules_row").show();
$("#module_type").trigger("change");
}
});
@ -714,6 +733,15 @@ $(document).ready (function () {
$("#status_agents").change(function() {
$("#groups_select").trigger("change");
});
$("#tags").change(function() {
selector = $("#form_edit input[name=selection_mode]:checked").val();
$("#module_type").trigger("change");
});
$("#tags1").change(function() {
selector = $("#form_edit input[name=selection_mode]:checked").val();
$("#id_agents").trigger("change");
});
$("#form_modules").submit(function() {
var get_parameters_count = window.location.href.slice(

View File

@ -312,6 +312,13 @@ $table->data['form_modules_3'][1] = html_print_select($status_list,
'status_module', 'selected', '', __('All'), AGENT_MODULE_STATUS_ALL, true);
$table->data['form_modules_3'][3] = '';
$tags = tags_get_user_tags();
$table->rowstyle['form_modules_4'] = 'vertical-align: top;';
$table->rowclass['form_modules_4'] = 'select_modules_row select_modules_row_2';
$table->data['form_modules_4'][0] = __('Tags');
$table->data['form_modules_4'][1] = html_print_select ($tags, 'tags[]',
$tags_name, false, __('Any'), -1, true, true, true);
$table->rowstyle['form_modules_2'] = 'vertical-align: top;';
$table->rowclass['form_modules_2'] = 'select_modules_row select_modules_row_2';
$table->data['form_modules_2'][0] = __('Modules');
@ -343,8 +350,12 @@ $table->data['form_agents_2'][1] = html_print_select($status_list,
'status_agents', 'selected', '', __('All'), AGENT_STATUS_ALL, true);
$table->data['form_agents_2'][3] = '';
$tags = tags_get_user_tags();
$table->rowstyle['form_agents_4'] = 'vertical-align: top;';
$table->rowclass['form_agents_4'] = 'select_agents_row select_agents_row_2';
$table->data['form_agents_4'][0] = __('Tags');
$table->data['form_agents_4'][1] = html_print_select ($tags, 'tags[]',
$tags_name, false, __('Any'), -1, true, true, true);
$table->rowstyle['form_agents_3'] = 'vertical-align: top;';
$table->rowclass['form_agents_3'] = 'select_agents_row select_agents_row_2';
@ -679,8 +690,10 @@ $(document).ready (function () {
clean_lists();
$(".select_modules_row").css('display', '<?php echo $modules_row?>');
$(".select_agents_row").css('display', '<?php echo $agents_row?>');
$(".select_modules_row_2").css('display', 'none');
// Trigger change to refresh selection when change selection mode
$("#agents_selection_mode").change (function() {
@ -727,7 +740,7 @@ $(document).ready (function () {
var params = {
"page" : "operation/agentes/ver_agente",
"get_agent_modules_json" : 1,
"get_distinct_name" : 1,
"get_id_and_name" : 1,
"indexed" : 0
};
@ -737,6 +750,13 @@ $(document).ready (function () {
var status_module = $('#status_module').val();
if (status_module != '-1')
params['status_module'] = status_module;
var tags_to_search = $('#tags').val();
if (tags_to_search != null) {
if (tags_to_search[0] != -1) {
params['tags'] = tags_to_search;
}
}
$("#module_loading").show ();
$("tr#delete_table-edit1, tr#delete_table-edit0, tr#delete_table-edit2").hide ();
@ -943,6 +963,7 @@ $(document).ready (function () {
else if(selector == 'modules') {
$(".select_agents_row").hide();
$(".select_modules_row").show();
$("#module_type").trigger("change");
}
});
@ -974,7 +995,6 @@ $(document).ready (function () {
$("#groups_select").change (
function () {
if (this.value < 0) {
clean_lists();
$(".select_agents_row_2").css('display', 'none');
@ -1058,6 +1078,14 @@ $(document).ready (function () {
}
});
$("#tags").change(function() {
selector = $("#form_edit input[name=selection_mode]:checked").val();
$("#module_type").trigger("change");
});
$("#tags1").change(function() {
selector = $("#form_edit input[name=selection_mode]:checked").val();
$("#id_agents").trigger("change");
});
});
function disabled_status () {

View File

@ -175,7 +175,9 @@ function agent_changed_by_multiple_agents (event, id_agent, selected) {
//val() because the var is same <option val="NNN"></option>
idAgents.push($(val).val());
});
var tags_to_search = $('#tags1').val();
//Hack to find only enabled modules
//Pass a flag as global var
find_modules = 'all';
@ -226,6 +228,7 @@ function agent_changed_by_multiple_agents (event, id_agent, selected) {
"page": "operation/agentes/ver_agente",
"get_agent_modules_json_for_multiple_agents": 1,
"id_agent[]": idAgents,
"tags[]": tags_to_search,
"all": find_modules,
"module_types_excluded[]": module_types_excluded,
"name": module_name,
@ -401,8 +404,6 @@ function alert_templates_changed_by_multiple_agents_with_alerts (event, id_agent
templates.push($(val).val());
});
console.log(templates);
$('#module').attr ('disabled', 1);
$('#module').empty ();
$('#module').append ($('<option></option>').html ("Loading...").attr ("value", 0));
@ -1092,7 +1093,7 @@ function openURLTagWindow(url) {
window.open(url, '','width=300, height=300, toolbar=no, location=no, directories=no, status=no, menubar=no');
}
function removeTinyMCE(elementID) {console.log(elementID);
function removeTinyMCE(elementID) {
if (elementID.length > 0 && !isEmptyObject(tinyMCE))
tinyMCE.EditorManager.execCommand('mceRemoveControl', true, elementID);
}

View File

@ -301,6 +301,7 @@ if (is_ajax ()) {
if ($get_agent_modules_json_for_multiple_agents) {
$idAgents = get_parameter('id_agent');
$tags = get_parameter('tags', null);
$module_types_excluded = get_parameter('module_types_excluded', array());
$module_name = (string) get_parameter('name');
$selection_mode = get_parameter('selection_mode', 'common');
@ -491,7 +492,7 @@ if (is_ajax ()) {
}
else {
if(implode(',', $idAgents) < 0) {
$sql = 'SELECT DISTINCT(nombre) FROM tagente_modulo
$sql = 'SELECT DISTINCT nombre, id_agente_modulo FROM tagente_modulo
WHERE nombre IN (
SELECT nombre
FROM tagente_modulo
@ -499,7 +500,7 @@ if (is_ajax ()) {
HAVING count(nombre) = (SELECT count(nombre) FROM tagente_modulo))';
}
else {
$sql = 'SELECT DISTINCT(nombre)
$sql = 'SELECT DISTINCT nombre, id_agente_modulo
FROM tagente_modulo t1
WHERE ' . $filter . '
AND t1.delete_pending = 0
@ -521,6 +522,31 @@ if (is_ajax ()) {
$nameModules = db_get_all_rows_sql($sql);
if ($tags != null) {
if ((count($tags) >= 1) && ($tags[0] != "") && ($tags[0] != -1)) {
$implode_tags = implode(",", $tags);
$tag_modules = db_get_all_rows_sql("SELECT DISTINCT id_agente_modulo FROM ttag_module WHERE id_tag IN (" . $implode_tags . ")");
if ($tag_modules) {
$final_modules = array();
foreach ($nameModules as $key => $module) {
$in_array = false;
foreach ($tag_modules as $t_module) {
if ($module['id_agente_modulo'] == $t_module['id_agente_modulo']) {
$in_array = true;
}
}
if ($in_array) {
$final_modules[] = $module;
}
}
$nameModules = $final_modules;
}
else {
$nameModules = array();
}
}
}
if ($nameModules == false) {
$nameModules = array();
}
@ -549,7 +575,9 @@ if (is_ajax ()) {
// Use 0 as not received
$id_tipo_modulo = (int) get_parameter ('id_tipo_modulo', 0);
$status_modulo = (int) get_parameter ('status_module', -1);
$tags = (array) get_parameter ('tags', array());
// Filter
$filter = array();
if ($disabled !== -1)
@ -629,7 +657,7 @@ if (is_ajax ()) {
agents_get_group_agents(
array_keys (users_get_groups ()), $search, "none"));
$agent_modules = agents_get_modules ($id_agent, $fields, $filter, $indexed);
$agent_modules = agents_get_modules ($id_agent, $fields, $filter, $indexed, true, false, $tags);
}
// Restore db connection
metaconsole_restore_db();
@ -642,20 +670,39 @@ if (is_ajax ()) {
agents_get_group_agents(
array_keys(users_get_groups ()), $search, "none"));
$agent_modules = agents_get_modules ($id_agent, $fields, $filter, $indexed);
$agent_modules = agents_get_modules ($id_agent, $fields, $filter, $indexed, true, false, $tags);
}
if (empty($agent_modules))
$agent_modules = array();
if (!empty($tags)) {
$implode_tags = implode(",", $tags);
$tag_modules = db_get_all_rows_sql("SELECT DISTINCT id_agente_modulo FROM ttag_module WHERE id_tag IN (" . $implode_tags . ")");
if ($tag_modules) {
$final_modules = array();
foreach ($agent_modules as $key => $module) {
$in_array = false;
foreach ($tag_modules as $t_module) {
if ($module['id_agente_modulo'] == $t_module['id_agente_modulo']) {
$in_array = true;
}
}
if ($in_array) {
$final_modules[] = $module;
}
}
$agent_modules = $final_modules;
}
else {
$agent_modules = array();
}
}
foreach ($agent_modules as $key => $module) {
$agent_modules[$key]['nombre'] = io_safe_output($module['nombre']);
}
//Hack to translate text "any" in PHP to javascript
//$agent_modules['any_text'] = __('Any');
echo json_encode ($agent_modules);
return;