Merge branch 'feature/ux_modules_hierarchy' into 'develop'

Feature/ux modules hierarchy

See merge request 
This commit is contained in:
artu30 2017-01-25 15:35:09 +01:00
commit 20fcd7ef32
10 changed files with 306 additions and 64 deletions

View File

@ -101,6 +101,7 @@ if (strstr($sec2, "enterprise/godmode/policies/policies") !== false) {
}
$show_creation = false;
$checked = get_parameter("checked");
if (($policy_page) || (isset($agent))) {
if ($policy_page) {
@ -114,6 +115,18 @@ if (($policy_page) || (isset($agent))) {
if ($show_creation) {
// Create module/type combo
echo '<form id="create_module_type" method="post" action="'.$url.'">';
if (!$policy_page) {
echo '<td class="datos" style="font-weight: bold;">';
echo __('Show in hierachy mode');
if ($checked == "true") {
$checked = true;
}
else {
$checked = false;
}
html_print_checkbox ('status_hierachy_mode', "", $checked, false, false, "onChange=change_mod_filter();");
echo '</td>';
}
echo '<td class="datos" style="font-weight: bold;">';
echo __("Type");
html_print_select ($modules, 'moduletype', '', '', '', '', false, false, false, '', false, 'max-width:300px;' );
@ -450,12 +463,23 @@ switch ($config["dbtype"]) {
else {
$limit_sql = '';
}
$sql = sprintf("SELECT %s
FROM tagente_modulo
LEFT JOIN tmodule_group
ON tagente_modulo.id_module_group = tmodule_group.id_mg
WHERE %s %s %s %s %s",
$params, $basic_where, $where, $where_tags, $order_sql, $limit_sql);
if ($checked) {
$sql = sprintf("SELECT *
FROM tagente_modulo
LEFT JOIN tmodule_group
ON tagente_modulo.id_module_group = tmodule_group.id_mg
WHERE %s %s %s %s %s",
$basic_where, $where, $where_tags, $order_sql, $limit_sql);
}
else {
$sql = sprintf("SELECT %s
FROM tagente_modulo
LEFT JOIN tmodule_group
ON tagente_modulo.id_module_group = tmodule_group.id_mg
WHERE %s %s %s %s %s",
$params, $basic_where, $where, $where_tags, $order_sql, $limit_sql);
}
$modules = db_get_all_rows_sql($sql);
break;
@ -465,12 +489,24 @@ switch ($config["dbtype"]) {
$set['limit'] = $limit;
$set['offset'] = $offset;
}
$sql = sprintf("SELECT %s
FROM tagente_modulo
LEFT JOIN tmodule_group
ON tmodule_group.id_mg = tagente_modulo.id_module_group
WHERE %s %s %s %s",
$params, $basic_where, $where, $where_tags, $order_sql);
if ($checked) {
$sql = sprintf("SELECT *
FROM tagente_modulo
LEFT JOIN tmodule_group
ON tmodule_group.id_mg = tagente_modulo.id_module_group
WHERE %s %s %s %s",
$basic_where, $where, $where_tags, $order_sql);
}
else {
$sql = sprintf("SELECT %s
FROM tagente_modulo
LEFT JOIN tmodule_group
ON tmodule_group.id_mg = tagente_modulo.id_module_group
WHERE %s %s %s %s",
$params, $basic_where, $where, $where_tags, $order_sql);
}
$modules = oracle_recode_query ($sql, $set, 'AND', false);
break;
}
@ -555,6 +591,15 @@ foreach($tempRows as $row) {
$numericModules[$row['id_tipo']] = true;
}
if ($checked) {
$modules_hierachy = array();
$modules_hierachy = get_hierachy_modules_tree($modules);
$modules_dt = get_dt_from_modules_tree($modules_hierachy);
$modules = $modules_dt;
}
foreach ($modules as $module) {
if (! check_acl ($config["id_user"], $group, "AW", $id_agente) && ! check_acl ($config["id_user"], $group, "AD", $id_agente)) {
continue;
@ -570,20 +615,29 @@ foreach ($modules as $module) {
$module_group2 = $module["id_module_group"];
$data = array ();
if ($module['id_module_group'] != $last_modulegroup) {
$last_modulegroup = $module['id_module_group'];
$data[0] = '<strong>'.modules_get_modulegroup_name ($last_modulegroup).'</strong>';
$i = array_push ($table->data, $data);
$table->rowstyle[$i - 1] = 'text-align: center';
$table->rowclass[$i - 1] = 'datos3';
if ($isFunctionPolicies !== ENTERPRISE_NOT_HOOK)
$table->colspan[$i - 1][0] = 10;
else
$table->colspan[$i - 1][0] = 8;
$data = array ();
if (!$checked) {
if ($module['id_module_group'] != $last_modulegroup) {
$last_modulegroup = $module['id_module_group'];
$data[0] = '<strong>'.modules_get_modulegroup_name ($last_modulegroup).'</strong>';
$i = array_push ($table->data, $data);
$table->rowstyle[$i - 1] = 'text-align: center';
$table->rowclass[$i - 1] = 'datos3';
if ($isFunctionPolicies !== ENTERPRISE_NOT_HOOK)
$table->colspan[$i - 1][0] = 10;
else
$table->colspan[$i - 1][0] = 8;
$data = array ();
}
}
$data[0] = "";
if (isset($module['deep']) && ($module['deep'] != 0)) {
$data[0] .= str_repeat('&nbsp;&nbsp;&nbsp;&nbsp;', $module['deep']);
$data[0] .= html_print_image("images/icono_escuadra.png", true, array("style" => 'padding-bottom: inherit;')) . "&nbsp;&nbsp;";
}
if ($module['quiet']) {
$data[0] .= html_print_image("images/dot_green.disabled.png",
true, array("border" => '0', "title" => __('Quiet'),
@ -764,3 +818,22 @@ if (check_acl ($config['id_user'], $agent['id_grupo'], "AW")) {
echo '</form>';
}
?>
<script type="text/javascript">
function change_mod_filter() {
var checked = $("#checkbox-status_hierachy_mode").is(":checked");
if (/checked/.test(window.location)) {
var url = window.location.toString();
if (checked) {
window.location = url.replace("checked=false", "checked=true");
}
else {
window.location = url.replace("checked=true", "checked=false");
}
}
else {
window.location = window.location + "&checked=true";
}
}
</script>

View File

@ -764,21 +764,32 @@ if ($list_modules) {
$show_context_help_first_time = false;
$hierachy_mode = get_parameter('hierachy_mode', false);
if ($hierachy_mode == "true") {
$modules_hierachy = array();
$modules_hierachy = get_hierachy_modules_tree($modules);
$modules_dt = get_dt_from_modules_tree($modules_hierachy);
$modules = $modules_dt;
}
foreach ($modules as $module) {
//The code add the row of 1 cell with title of group for to be more organice the list.
if ($hierachy_mode !== "true") {
//The code add the row of 1 cell with title of group for to be more organice the list.
if ($module["id_module_group"] != $last_modulegroup)
{
$table->colspan[$rowIndex][0] = count($table->head);
$table->rowclass[$rowIndex] = 'datos4';
if ($module["id_module_group"] != $last_modulegroup)
{
$table->colspan[$rowIndex][0] = count($table->head);
$table->rowclass[$rowIndex] = 'datos4';
array_push ($table->data, array ('<b>'.$module['name'].'</b>'));
array_push ($table->data, array ('<b>'.$module['name'].'</b>'));
$rowIndex++;
$last_modulegroup = $module["id_module_group"];
$rowIndex++;
$last_modulegroup = $module["id_module_group"];
}
//End of title of group
}
//End of title of group
$data = array ();
if (($module["id_modulo"] != 1) && ($module["id_tipo_modulo"] != 100)) {
@ -855,9 +866,14 @@ if ($list_modules) {
$data[2] .= '<a href="index.php?sec=gagente&amp;sec2=godmode/agentes/configurar_agente&amp;id_agente='.$id_agente.'&amp;tab=module&amp;id_agent_module='.$module["id_agente_modulo"].'&amp;edit_module='.$module["id_modulo"].'">' . html_print_image("images/config.png", true, array("alt" => '0', "border" => "", "title" => __('Edit'))) . '</a>';
$data[3] = "";
if (isset($module['deep']) && ($module['deep'] != 0)) {
$data[3] .= str_repeat('&nbsp;&nbsp;&nbsp;&nbsp;', $module['deep']);
$data[3] .= html_print_image("images/icono_escuadra.png", true, array("style" => 'padding-bottom: inherit;')) . "&nbsp;&nbsp;";
}
if ($module['quiet']) {
$data[3] .= html_print_image("images/dot_green.disabled.png", true,
array("border" => '0', "title" => __('Quiet'), "alt" => ""))
@ -1022,7 +1038,7 @@ if ($list_modules) {
"refresh=" . SECONDS_10MINUTES . "&amp;" .
"draw_events=$draw_events', 'day_".$win_handle."')";
if(!is_snapshot_data($module['datos'])){
if(!is_snapshot_data($module['datos'])){
$data[8] .= '<a href="javascript:'.$link.'">' . html_print_image("images/chart_curve.png", true, array("border" => '0', "alt" => "")) . '</a> &nbsp;&nbsp;';
}
$server_name = '';

View File

@ -454,8 +454,10 @@ class Tree {
break;
// Get the modules of an agent
case 'agent':
$columns = 'tam.id_agente_modulo AS id, tam.nombre AS name,
tam.id_tipo_modulo, tam.id_modulo, tae.estado, tae.datos';
$columns = 'tam.id_agente_modulo AS id,
tam.parent_module_id AS parent,
tam.nombre AS name, tam.id_tipo_modulo,
tam.id_modulo, tae.estado, tae.datos';
$order_fields = 'tam.nombre ASC, tam.id_agente_modulo ASC';
// Set for the common ACL only. The strict ACL case is different (groups and tags divided).
@ -1110,6 +1112,10 @@ class Tree {
if (empty($data))
return array();
if ($this->type == 'agent') {
$data = $this->getProcessedModules($data);
}
return $data;
}
@ -1432,6 +1438,12 @@ class Tree {
protected function processModule (&$module, $server = false) {
global $config;
if (isset($module['children'])) {
foreach ($module['children'] as $i => $children) {
$this->processModule($module['children'][$i], $server);
}
}
$module['type'] = 'module';
$module['id'] = (int) $module['id'];
@ -2573,5 +2585,41 @@ class Tree {
return $all_counters;
}
protected function getProcessedModules($modules_tree) {
$tree_modules = array();
$new_modules_root = array_filter($modules_tree, function ($module) {
return (isset($module['parent']) && ($module['parent'] == 0));
});
$new_modules_child = array_filter($modules_tree, function ($module) {
return (isset($module['parent']) && ($module['parent'] != 0));
});
while (!empty($new_modules_child)) {
foreach ($new_modules_child as $i => $child) {
Tree::recursive_modules_tree_view($new_modules_root, $new_modules_child, $i, $child);
}
}
foreach ($new_modules_root as $m) {
$tree_modules[] = $m;
}
return $tree_modules;
}
static function recursive_modules_tree_view (&$new_modules, &$new_modules_child, $i, $child) {
foreach ($new_modules as $index => $module) {
if ($module['id'] == $child['parent']) {
$new_modules[$index]['children'][] = $child;
unset($new_modules_child[$i]);
break;
}
else if (isset($new_modules[$index]['children'])) {
Tree::recursive_modules_tree_view ($new_modules[$index]['children'], $new_modules_child, $i, $child);
}
}
}
}
?>

View File

@ -1500,11 +1500,11 @@ function html_print_table (&$table, $return = false) {
$table->border = '0';
}
if (empty ($table->tablealign) || $table->tablealign != 'left' || $table->tablealign != 'right') {
$table->tablealign = '';
if (empty ($table->tablealign) || (($table->tablealign != 'left') && ($table->tablealign != 'right'))) {
$table->tablealign = '"';
}
else {
$table->tablealign = 'style="float:'.$table->tablealign.';"'; //Align is deprecated. Use float instead
$table->tablealign = 'float:'.$table->tablealign.';"'; //Align is deprecated. Use float instead
}
if (!isset ($table->cellpadding)) {
@ -1526,10 +1526,10 @@ function html_print_table (&$table, $return = false) {
$tableid = empty ($table->id) ? 'table'.$table_count : $table->id;
if (!empty($table->width)) {
$output .= '<table style="width:' . $table->width . ';' . $styleTable . '"'.$table->tablealign;
$output .= '<table style="width:' . $table->width . '; ' . $styleTable . ' '.$table->tablealign;
}
else {
$output .= '<table style="' . $styleTable . '"'.$table->tablealign;
$output .= '<table style="' . $styleTable . ' ' . $table->tablealign;
}
$output .= ' cellpadding="'.$table->cellpadding.'" cellspacing="'.$table->cellspacing.'"';
$output .= ' border="'.$table->border.'" class="'.$table->class.'" id="'.$tableid.'">';

View File

@ -2511,4 +2511,63 @@ function get_same_modules ($agents, $modules) {
return $modules_to_report;
}
function get_hierachy_modules_tree ($modules) {
$new_modules = array();
$new_modules_root = array_filter($modules, function ($module) {
return (isset($module['parent_module_id']) && ($module['parent_module_id'] == 0));
});
$new_modules_child = array_filter($modules, function ($module) {
return (isset($module['parent_module_id']) && ($module['parent_module_id'] != 0));
});
while (!empty($new_modules_child)) {
foreach ($new_modules_child as $i => $child) {
recursive_modules_tree($new_modules_root, $new_modules_child, $i, $child);
}
}
return $new_modules_root;
}
function recursive_modules_tree (&$new_modules, &$new_modules_child, $i, $child) {
foreach ($new_modules as $index => $module) {
if ($module['id_agente_modulo'] == $child['parent_module_id']) {
$new_modules[$index]['child'][] = $child;
$new_modules[$index]['have_childs'] = true;
unset($new_modules_child[$i]);
break;
}
else if (isset($new_modules[$index]['child'])) {
recursive_modules_tree ($new_modules[$index]['child'], $new_modules_child, $i, $child);
}
}
}
function get_dt_from_modules_tree ($modules) {
$final_modules = array();
foreach ($modules as $i => $module) {
$final_modules[$module['id_agente_modulo']] = $module;
$final_modules[$module['id_agente_modulo']]['deep'] = 0;
if (isset($modules[$i]['child'])) {
recursive_get_dt_from_modules_tree($final_modules, $modules[$i]['child'], $final_modules[$module['id_agente_modulo']]['deep']);
}
unset($modules[$i]);
}
return $final_modules;
}
function recursive_get_dt_from_modules_tree (&$f_modules, $modules, $deep) {
foreach ($modules as $i => $module) {
$f_modules[$module['id_agente_modulo']] = $module;
$f_modules[$module['id_agente_modulo']]['deep'] = $deep + 1;
if (isset($modules[$i]['child'])) {
recursive_get_dt_from_modules_tree($f_modules, $modules[$i]['child'], $f_modules[$module['id_agente_modulo']]['deep']);
}
}
}
?>

View File

@ -168,8 +168,8 @@ function slicesbar_graph($chart_data, $period, $width, $height, $colors,
function vbar_graph($flash_chart, $chart_data, $width, $height,
$color, $legend, $long_index, $no_data_image, $xaxisname = "",
$yaxisname = "", $water_mark = "", $font = '', $font_size = '',
$unit = '', $ttl = 1, $homeurl = '', $backgroundColor = 'white') {
$unit = '', $ttl = 1, $homeurl = '', $backgroundColor = 'white',
$from_ux = false) {
setup_watermark($water_mark, $water_mark_file, $water_mark_url);
if (empty($chart_data)) {
@ -179,7 +179,7 @@ function vbar_graph($flash_chart, $chart_data, $width, $height,
if ($flash_chart) {
return flot_vcolumn_chart ($chart_data, $width, $height, $color,
$legend, $long_index, $homeurl, $unit, $water_mark_url,
$homedir,$font,$font_size);
$homedir,$font,$font_size, $from_ux);
}
else {
$graph = array();

View File

@ -546,13 +546,13 @@ function showTooltip(x, y, color, contents) {
}).appendTo("body").fadeIn(200);
}
function pandoraFlotVBars(graph_id, values, labels, labels_long, legend, colors, water_mark, maxvalue, water_mark, separator, separator2, font, font_size ) {
function pandoraFlotVBars(graph_id, values, labels, labels_long, legend, colors, water_mark, maxvalue, water_mark, separator, separator2, font, font_size , from_ux) {
values = values.split(separator2);
legend = legend.split(separator);
font = font.split("/").pop().split(".").shift();
labels_long = labels_long.length > 0 ? labels_long.split(separator) : 0;
colors = colors.length > 0 ? colors.split(separator) : [];
var colors_data = colors.length > 0
? colors
: ['#FFA631','#FC4444','#FAD403','#5BB6E5','#F2919D','#80BA27'];
@ -561,15 +561,22 @@ function pandoraFlotVBars(graph_id, values, labels, labels_long, legend, colors,
for (i = 0; i < values.length; i++) {
var serie = values[i].split(separator);
var aux = new Array();
for (j = 0; j < serie.length; j++) {
var aux2 = parseFloat(serie[j]);
aux.push([aux2, j]);
datas.push( {
data: [[j, aux2]],
color: colors_data[0]
});
if (from_ux) {
datas.push( {
data: [[j, aux2]],
color: colors_data[j]
});
}
else {
datas.push( {
data: [[j, aux2]],
color: colors_data[0]
});
}
};
}

View File

@ -730,7 +730,7 @@ function flot_hcolumn_chart ($graph_data, $width, $height, $water_mark, $font =
}
// Returns a 3D column chart
function flot_vcolumn_chart ($graph_data, $width, $height, $color, $legend, $long_index, $homeurl, $unit, $water_mark, $homedir, $font, $font_size) {
function flot_vcolumn_chart ($graph_data, $width, $height, $color, $legend, $long_index, $homeurl, $unit, $water_mark, $homedir, $font, $font_size, $from_ux) {
global $config;
include_javascript_dependencies_flot_graph();
@ -792,7 +792,7 @@ function flot_vcolumn_chart ($graph_data, $width, $height, $color, $legend, $lon
// Store serialized data to use it from javascript
$labels = implode($separator,$labels);
$colors = implode($separator, $colors);
// Store data series in javascript format
$jsvars = '';
$jsseries = array();
@ -812,7 +812,12 @@ function flot_vcolumn_chart ($graph_data, $width, $height, $color, $legend, $lon
// Javascript code
$return .= "<script type='text/javascript'>";
$return .= "pandoraFlotVBars('$graph_id', '$values', '$labels', '$labels', '$legend', '$colors', false, $max, '$water_mark', '$separator', '$separator2','$font',$font_size)";
if ($from_ux) {
$return .= "pandoraFlotVBars('$graph_id', '$values', '$labels', '$labels', '$legend', '$colors', false, $max, '$water_mark', '$separator', '$separator2','$font',$font_size, true)";
}
else {
$return .= "pandoraFlotVBars('$graph_id', '$values', '$labels', '$labels', '$legend', '$colors', false, $max, '$water_mark', '$separator', '$separator2','$font',$font_size, false)";
}
$return .= "</script>";

View File

@ -118,6 +118,7 @@ if (!isset ($id_agente)) {
$id_agent = (int)get_parameter('id_agente');
$status_filter_monitor = (int)get_parameter('status_filter_monitor', -1);
$status_text_monitor = get_parameter('status_text_monitor', '');
$status_hierachy_mode = get_parameter('status_hierachy_mode', -1);
$sort_field = get_parameter('sort_field', 'name');
$sort = get_parameter('sort', 'up');
@ -138,7 +139,7 @@ echo "</h4>";
ob_start();
print_form_filter_monitors($id_agente, $status_filter_monitor, $status_text_monitor);
print_form_filter_monitors($id_agente, $status_filter_monitor, $status_text_monitor, $status_hierachy_mode);
echo "<div id='module_list_loading'>" .
html_print_image('images/spinner.gif', true) .
@ -185,6 +186,20 @@ ui_toggle($html_toggle,
*/
});
function change_module_filter () {
hierachy_mode = $("#checkbox-status_hierachy_mode").is(":checked");
if (hierachy_mode) {
$("#status_module_group").disable();
$("#status_filter_monitor").disable();
$("#status_module_group").val(-1);
$("#status_filter_monitor").val(-1);
}
else {
$("#status_module_group").enable();
$("#status_filter_monitor").enable();
}
}
function order_module_list(sort_field_param, sort_rows_param) {
sort_field = sort_field_param;
sort_rows = sort_rows_param;
@ -223,7 +238,8 @@ ui_toggle($html_toggle,
filter_status = $("#status_filter_monitor").val();
filter_group = $("#status_module_group").val();
filter_text = $("input[name='status_text_monitor']").val();
hierachy_mode = $("#checkbox-status_hierachy_mode").is(":checked");
var parameters = {};
parameters["list_modules"] = 1;
@ -233,6 +249,7 @@ ui_toggle($html_toggle,
parameters["status_filter_monitor"] = filter_status;
parameters["status_text_monitor"] = filter_text;
parameters["status_module_group"] = filter_group;
parameters["hierachy_mode"] = hierachy_mode;
parameters["filter_monitors"] = 1;
parameters["monitors_change_filter"] = 1;
parameters["page"] = "include/ajax/module";
@ -260,6 +277,9 @@ ui_toggle($html_toggle,
$("#status_filter_monitor").val(-1);
$("#status_module_group").val(-1);
$("input[name='status_text_monitor']").val("");
$("#checkbox-status_hierachy_mode").prop("checked", false);
$("#status_module_group").enable();
$("#status_filter_monitor").enable();
filter_modules();
}
@ -411,7 +431,7 @@ ui_require_jquery_file("ui.datepicker-" . get_user_language(), "include/javascri
</script>
<?php
function print_form_filter_monitors($id_agent, $status_filter_monitor = -1,
$status_text_monitor = '', $status_module_group=-1) {
$status_text_monitor = '', $status_module_group=-1, $status_hierachy_mode=-1) {
$form_text = '';
$table = new stdClass();
@ -449,8 +469,10 @@ function print_form_filter_monitors($id_agent, $status_filter_monitor = -1,
$rows_select[$module_group['id_mg']] = __($module_group['name']);
}
$table->data[0][5] = html_print_select ($rows_select,'status_module_group', $status_module_group, '', '',0, true);
$table->data[0][6] = html_print_button(__('Filter'), 'filter', false, 'filter_modules();', 'class="sub search"', true);
$table->data[0][7] = '&nbsp;' . html_print_button(__('Reset'), 'filter', false, 'reset_filter_modules();', 'class="sub upd" style="margin-top:0px;"', true);
$table->data[0][6] = __('Show in hierachy mode');
$table->data[0][6] .= html_print_checkbox ('status_hierachy_mode', "", false, true, false, "onChange=change_module_filter();");
$table->data[0][7] = html_print_button(__('Filter'), 'filter', false, 'filter_modules();', 'class="sub search"', true);
$table->data[0][8] = '&nbsp;' . html_print_button(__('Reset'), 'filter', false, 'reset_filter_modules();', 'class="sub upd" style="margin-top:0px;"', true);
$form_text .= html_print_table($table, true);
$filter_hidden = false;

View File

@ -1051,6 +1051,11 @@ $policyTab = enterprise_hook('policy_tab');
if ($policyTab == -1)
$policyTab = "";
/* UX Console */
$ux_console_tab = enterprise_hook('ux_console_tab');
if ($ux_console_tab == -1)
$ux_console_tab = "";
/* GIS tab */
$gistab="";
@ -1181,7 +1186,8 @@ $onheader = array('manage' => $managetab,
'gis' => $gistab,
'custom' => $custom_fields,
'graphs' => $graphs,
'policy' => $policyTab);
'policy' => $policyTab,
'ux_console' => $ux_console_tab);
//Added after it exists
// If the agent has incidents associated
@ -1285,6 +1291,9 @@ switch($tab) {
case "policy":
$header_description = ' - ' . __('Policy');
break;
case "ux_console_tab":
$header_description = ' - ' . __('UX Console');
break;
case "incident":
$header_description = ' - ' . __('Incident');
break;
@ -1334,6 +1343,9 @@ switch ($tab) {
case "policy":
enterprise_include ("operation/agentes/policy_view.php");
break;
case "ux_console_tab":
enterprise_include ("operation/agentes/ux_console_view.php");
break;
case "graphs";
require("operation/agentes/graphs.php");
break;