Merge branch '2742-Cambiar_vista_manage_agent_group_tree' into 'develop'

add new tree view edition group

See merge request artica/pandorafms!1773
This commit is contained in:
vgilc 2018-09-18 09:49:24 +02:00
commit 3a15c5844d
5 changed files with 509 additions and 220 deletions

View File

@ -215,20 +215,57 @@ if (! check_acl($config['id_user'], 0, "PM")) {
return; return;
} }
$sec = defined('METACONSOLE') ? 'advanced' : 'gagente';
$url_tree = "index.php?sec=$sec&sec2=godmode/groups/group_list&tab=tree";
$url_groups = "index.php?sec=$sec&sec2=godmode/groups/group_list&tab=groups";
$buttons['tree'] = array(
'active' => false,
'text' => "<a href='$url_tree'>" .
html_print_image(
"images/gm_massive_operations.png",
true,
array (
"title" => __('Tree Group view')
)
) . "</a>"
);
$buttons['groups'] = array(
'active' => false,
'text' => "<a href='$url_groups'>" .
html_print_image(
"images/group.png",
true,
array(
"title" => __('Group view')
)
) . "</a>"
);
$tab = (string)get_parameter('tab', 'groups');
// Marks correct tab
switch ($tab) {
case 'tree':
$buttons['tree']['active'] = true;
break;
case 'groups':
default:
$buttons['groups']['active'] = true;
break;
}
// Header // Header
if (defined('METACONSOLE')) { if (defined('METACONSOLE')) {
agents_meta_print_header(); agents_meta_print_header();
$sec = 'advanced';
echo '<div class="notify">'; echo '<div class="notify">';
echo __("Edit or delete groups can cause problems with synchronization"); echo __("Edit or delete groups can cause problems with synchronization");
echo '</div>'; echo '</div>';
} } else {
else {
ui_print_page_header ( ui_print_page_header (
__("Groups defined in %s", get_product_name()), __("Groups defined in %s", get_product_name()),
"images/group.png", false, "", true, "" "images/group.png", false, "", true, $buttons
); );
$sec = 'gagente';
} }
$create_group = (bool) get_parameter ('create_group'); $create_group = (bool) get_parameter ('create_group');
@ -365,25 +402,33 @@ if (($delete_group) && (check_acl($config['id_user'], 0, "PM"))) {
} }
} }
$acl=''; if($tab == 'tree'){
$search_name = ''; echo html_print_image('images/spinner.gif', true,
$offset = (int)get_parameter('offset', 0); array('class' => "loading_tree",
$search = (string)get_parameter('search', ''); 'style' => 'display: none;'));
$block_size = $config['block_size']; echo "<div id='tree-controller-recipient'></div>";
if(!empty($search)){
$search_name = "AND t.nombre LIKE '%$search%'";
} }
else{
$acl='';
$search_name = '';
$offset = (int)get_parameter('offset', 0);
$search = (string)get_parameter('search', '');
$block_size = $config['block_size'];
if (!users_can_manage_group_all("AR")){ if(!empty($search)){
$search_name = "AND t.nombre LIKE '%$search%'";
}
if (!users_can_manage_group_all("AR")){
$user_groups_acl = users_get_groups(false, "AR"); $user_groups_acl = users_get_groups(false, "AR");
$groups_acl = implode(",", $user_groups_ACL); $groups_acl = implode(",", $user_groups_ACL);
if(empty($groups_acl)) return ui_print_info_message ( array('no_close'=>true, 'message'=> __('There are no defined groups') ) ); if(empty($groups_acl)) return ui_print_info_message ( array('no_close'=>true, 'message'=> __('There are no defined groups') ) );
$acl = "AND t.id_grupo IN ($groups_acl)"; $acl = "AND t.id_grupo IN ($groups_acl)";
} }
$form = "<form method='post' action=''>"; $form = "<form method='post' action=''>";
$form .= "<table class='databox filters' width='100%' style='font-weight: bold;'>"; $form .= "<table class='databox filters' width='100%' style='font-weight: bold;'>";
$form .= "<tr><td>" . __('Search') . '&nbsp;'; $form .= "<tr><td>" . __('Search') . '&nbsp;';
$form .= html_print_input_text ("search", $search, '', 100, 100, true); $form .= html_print_input_text ("search", $search, '', 100, 100, true);
@ -391,11 +436,11 @@ $form = "<form method='post' action=''>";
$form .= "<input name='find' type='submit' class='sub search' value='".__('Search')."'>"; $form .= "<input name='find' type='submit' class='sub search' value='".__('Search')."'>";
$form .= "<td></tr>"; $form .= "<td></tr>";
$form .= "</table>"; $form .= "</table>";
$form .= "</form>"; $form .= "</form>";
echo $form; echo $form;
$groups_sql = $groups_sql =
"SELECT t.*, "SELECT t.*,
p.nombre AS parent_name, p.nombre AS parent_name,
IF(t.parent=p.id_grupo, 1, 0) AS has_child IF(t.parent=p.id_grupo, 1, 0) AS has_child
@ -407,11 +452,11 @@ $groups_sql =
$search_name $search_name
ORDER BY nombre ORDER BY nombre
LIMIT $offset, $block_size LIMIT $offset, $block_size
"; ";
$groups = db_get_all_rows_sql($groups_sql); $groups = db_get_all_rows_sql($groups_sql);
if (!empty($groups)) { if (!empty($groups)) {
//Count all groups for pagination only saw user and filters //Count all groups for pagination only saw user and filters
$groups_sql_count = "SELECT count(*) $groups_sql_count = "SELECT count(*)
FROM tgrupo t FROM tgrupo t
@ -433,11 +478,12 @@ if (!empty($groups)) {
$table->head[5] = __('Description'); $table->head[5] = __('Description');
$table->head[6] = __('Actions'); $table->head[6] = __('Actions');
$table->align = array (); $table->align = array ();
$table->align[0] = 'right'; $table->align[0] = 'left';
$table->align[2] = 'left'; $table->align[2] = 'left';
$table->align[6] = 'left'; $table->align[6] = 'left';
$table->size[0] = '3%';
$table->size[5] = '30%'; $table->size[5] = '30%';
$table->size[6] = '10%'; $table->size[6] = '5%';
$table->data = array (); $table->data = array ();
foreach ($groups as $key => $group) { foreach ($groups as $key => $group) {
@ -504,9 +550,10 @@ if (!empty($groups)) {
$offset, $block_size, $offset, $block_size,
true, 'offset', true true, 'offset', true
); );
} }
else { else {
ui_print_info_message ( array('no_close'=>true, 'message'=> __('There are no defined groups') ) ); ui_print_info_message ( array('no_close'=>true, 'message'=> __('There are no defined groups') ) );
}
} }
if (check_acl($config['id_user'], 0, "PM")) { if (check_acl($config['id_user'], 0, "PM")) {
@ -517,5 +564,101 @@ if (check_acl($config['id_user'], 0, "PM")) {
echo '</form>'; echo '</form>';
} }
ui_require_javascript_file("TreeController", "include/javascript/tree/");
enterprise_hook('close_meta_frame'); enterprise_hook('close_meta_frame');
$tab = "group_edition";
?> ?>
<?php if (!is_metaconsole()){ ?>
<script type="text/javascript" src="include/javascript/fixed-bottom-box.js"></script>
<?php }else{ ?>
<script type="text/javascript" src="../../include/javascript/fixed-bottom-box.js"></script>
<?php } ?>
<script type="text/javascript">
var treeController = TreeController.getController();
if (typeof treeController.recipient != 'undefined' && treeController.recipient.length > 0)
treeController.recipient.empty();
$(".loading_tree").show();
var parameters = {};
parameters['page'] = "include/ajax/tree.ajax";
parameters['getChildren'] = 1;
parameters['type'] = "<?php echo $tab; ?>";
parameters['filter'] = {};
parameters['filter']['searchGroup'] = '';
parameters['filter']['searchAgent'] = '';
parameters['filter']['statusAgent'] = '';
parameters['filter']['searchModule'] = '';
parameters['filter']['statusModule'] = '';
parameters['filter']['groupID'] = '';
parameters['filter']['tagID'] = '';
parameters['filter']['searchHirearchy'] = 1;
parameters['filter']['show_not_init_agents'] = 1;
parameters['filter']['show_not_init_modules'] = 1;
$.ajax({
type: "POST",
url: "<?php echo ui_get_full_url('ajax.php', false, false, false); ?>",
data: parameters,
success: function(data) {
if (data.success) {
$(".loading_tree").hide();
treeController.init({
recipient: $("div#tree-controller-recipient"),
//detailRecipient: $.fixedBottomBox({ width: 400, height: window.innerHeight * 0.9 }),
page: parameters['page'],
emptyMessage: "<?php echo __('No data found'); ?>",
foundMessage: "<?php echo __('Found groups'); ?>",
tree: data.tree,
baseURL: "<?php echo ui_get_full_url(false, false, false, is_metaconsole()); ?>",
ajaxURL: "<?php echo ui_get_full_url('ajax.php', false, false, false); ?>",
filter: parameters['filter'],
counterTitles: {
total: {
agents: "<?php echo __('Total agents'); ?>",
modules: "<?php echo __('Total modules'); ?>",
none: "<?php echo __('Total'); ?>"
},
alerts: {
agents: "<?php echo __('Fired alerts'); ?>",
modules: "<?php echo __('Fired alerts'); ?>",
none: "<?php echo __('Fired alerts'); ?>"
},
critical: {
agents: "<?php echo __('Critical agents'); ?>",
modules: "<?php echo __('Critical modules'); ?>",
none: "<?php echo __('Critical'); ?>"
},
warning: {
agents: "<?php echo __('Warning agents'); ?>",
modules: "<?php echo __('Warning modules'); ?>",
none: "<?php echo __('Warning'); ?>"
},
unknown: {
agents: "<?php echo __('Unknown agents'); ?>",
modules: "<?php echo __('Unknown modules'); ?>",
none: "<?php echo __('Unknown'); ?>"
},
not_init: {
agents: "<?php echo __('Not init agents'); ?>",
modules: "<?php echo __('Not init modules'); ?>",
none: "<?php echo __('Not init'); ?>"
},
ok: {
agents: "<?php echo __('Normal agents'); ?>",
modules: "<?php echo __('Normal modules'); ?>",
none: "<?php echo __('Normal'); ?>"
}
}
});
}
},
dataType: "json"
});
</script>

View File

@ -43,6 +43,7 @@ if (is_ajax ()) {
require_once($config['homedir'] . "/include/class/TreeModule.class.php"); require_once($config['homedir'] . "/include/class/TreeModule.class.php");
require_once($config['homedir'] . "/include/class/TreeTag.class.php"); require_once($config['homedir'] . "/include/class/TreeTag.class.php");
require_once($config['homedir'] . "/include/class/TreeGroup.class.php"); require_once($config['homedir'] . "/include/class/TreeGroup.class.php");
require_once($config['homedir'] . "/include/class/TreeGroupEdition.class.php");
enterprise_include_once("include/class/TreePolicies.class.php"); enterprise_include_once("include/class/TreePolicies.class.php");
enterprise_include_once("include/class/TreeGroupMeta.class.php"); enterprise_include_once("include/class/TreeGroupMeta.class.php");
require_once($config['homedir'] . "/include/functions_reporting.php"); require_once($config['homedir'] . "/include/functions_reporting.php");
@ -104,6 +105,9 @@ if (is_ajax ()) {
if (!class_exists('TreePolicies')) break; if (!class_exists('TreePolicies')) break;
$tree = new TreePolicies($type, $rootType, $id, $rootID, $serverID, $childrenMethod, $access); $tree = new TreePolicies($type, $rootType, $id, $rootID, $serverID, $childrenMethod, $access);
break; break;
case 'group_edition':
$tree = new TreeGroupEdition($type, $rootType, $id, $rootID, $serverID, $childrenMethod, $access);
break;
default: default:
// FIXME. No error handler // FIXME. No error handler
return; return;

View File

@ -0,0 +1,108 @@
<?php
//Pandora FMS- http://pandorafms.com
// ==================================================
// Copyright (c) 2005-2018 Artica Soluciones Tecnologicas
// Please see http://pandorafms.org for full contribution list
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU Lesser General Public License
// as published by the Free Software Foundation; version 2
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
global $config;
require_once($config['homedir']."/include/class/Tree.class.php");
class TreeGroupEdition extends TreeGroup {
public function __construct($type, $rootType = '', $id = -1, $rootID = -1, $serverID = false, $childrenMethod = "on_demand", $access = 'AR') {
global $config;
parent::__construct($type, $rootType, $id, $rootID, $serverID, $childrenMethod, $access);
}
protected function getData() {
if ($this->id == -1) {
$this->getFirstLevel();
}
}
protected function getProcessedGroups () {
$processed_groups = array();
// Index and process the groups
$groups = $this->getGroupCounters();
// If user have not permissions in parent, set parent node to 0 (all)
// Avoid to do foreach for admins
if (!users_can_manage_group_all("AR")) {
foreach ($groups as $id => $group) {
if (!isset($this->userGroups[$groups[$id]['parent']])) {
$groups[$id]['parent'] = 0;
}
}
}
// Build the group hierarchy
foreach ($groups as $id => $group) {
if (isset($groups[$id]['parent']) && ($groups[$id]['parent'] != 0)) {
$parent = $groups[$id]['parent'];
// Parent exists
if (!isset($groups[$parent]['children'])) {
$groups[$parent]['children'] = array();
}
// Store a reference to the group into the parent
$groups[$parent]['children'][] = &$groups[$id];
// This group was introduced into a parent
$groups[$id]['have_parent'] = true;
}
}
// Sort the children groups
foreach ($groups as $id => $group) {
if (isset($groups[$id]['children'])) {
usort($groups[$id]['children'], array("Tree", "cmpSortNames"));
}
}
//Filter groups and eliminates the reference to children groups out of her parent
$groups = array_filter($groups, function ($group) {
return !$group['have_parent'];
});
usort($groups, array("Tree", "cmpSortNames"));
return $groups;
}
protected function getGroupCounters() {
$messages = array(
'confirm' => __('Confirm'),
'cancel' => __('Cancel'),
'messg' => __('Are you sure?')
);
$sql = "SELECT id_grupo AS gid,
nombre as name, parent, icon
FROM tgrupo
";
$stats = db_get_all_rows_sql($sql);
$group_stats = array();
foreach ($stats as $group) {
$group_stats[$group['gid']]['name'] = $group['name'];
$group_stats[$group['gid']]['parent'] = $group['parent'];
$group_stats[$group['gid']]['icon'] = $group['icon'];
$group_stats[$group['gid']]['id'] = $group['gid'];
$group_stats[$group['gid']]['type'] = 'group';
$group_stats[$group['gid']] = $this->getProcessedItem($group_stats[$group['gid']]);
$group_stats[$group['gid']]['delete']['messages'] = $messages;
$group_stats[$group['gid']]['edit'] = 1;
$group_stats[$group['gid']]['alerts'] = '';
}
return $group_stats;
}
}
?>

View File

@ -1585,6 +1585,10 @@ function display_confirm_dialog (message, ok_text, cancel_text, ok_function) {
clean_function(); clean_function();
} }
var buttons_obj = {};
buttons_obj[cancel_text] = clean_function;
buttons_obj[ok_text] = ok_function_clean;
// Display the dialog // Display the dialog
$("body").append('<div id="pandora_confirm_dialog_text"><h3>' + message + '</h3></div>'); $("body").append('<div id="pandora_confirm_dialog_text"><h3>' + message + '</h3></div>');
$("#pandora_confirm_dialog_text").dialog({ $("#pandora_confirm_dialog_text").dialog({
@ -1598,10 +1602,7 @@ function display_confirm_dialog (message, ok_text, cancel_text, ok_function) {
}, },
closeOnEscape: true, closeOnEscape: true,
modal: true, modal: true,
buttons: { buttons: buttons_obj
Cancel: clean_function,
"Confirm": ok_function_clean
}
}); });
} }

View File

@ -279,7 +279,6 @@ var TreeController = {
// Load leaf // Load leaf
function _processNode (container, element) { function _processNode (container, element) {
// type, [id], [serverID], callback // type, [id], [serverID], callback
function _getTreeDetailData (type, id, serverID, callback) { function _getTreeDetailData (type, id, serverID, callback) {
var lastParam = arguments[arguments.length - 1]; var lastParam = arguments[arguments.length - 1];
@ -346,6 +345,36 @@ var TreeController = {
$content.append(element.iconHTML + " "); $content.append(element.iconHTML + " ");
} }
$content.append(element.name); $content.append(element.name);
if(typeof element.edit != 'undefined'){
var url_edit = controller.baseURL + "index.php?sec=gagente&sec2=godmode/groups/configure_group&tab=tree&id_group=" + element.id;
var $updateicon = $('<img src="' + (controller.baseURL.length > 0 ? controller.baseURL : '')+ 'images/config.png" style="width:18px; vertical-align: middle;"/>')
var $updatebtn = $('<a href = "' + url_edit + '"></a>')
.append($updateicon);
$content.append($updatebtn);
}
if(typeof element.delete != 'undefined'){
var url_delete = controller.baseURL + "index.php?sec=gagente&sec2=godmode/groups/group_list&tab=tree&delete_group=1&id_group=" + element.id;
var $deleteBtn = $('<a><img src="' + (controller.baseURL.length > 0 ? controller.baseURL : '') +'images/cross.png" style="width:18px; vertical-align: middle; cursor: pointer;"/></a>');
$deleteBtn.click(function (event){
var ok_function = function(){
window.location.replace(url_delete);
};
display_confirm_dialog(
element.delete.messages.messg,
element.delete.messages.confirm,
element.delete.messages.cancel,
ok_function
)
});
$content.append($deleteBtn);
}
if(typeof element.alerts != 'undefined'){
$content.append(element.alerts);
}
break; break;
case 'agent': case 'agent':
// Is quiet // Is quiet
@ -583,10 +612,14 @@ var TreeController = {
if (typeof(public_user) === 'undefined') public_user = 0; if (typeof(public_user) === 'undefined') public_user = 0;
if (typeof element.searchChildren != 'undefined' && element.searchChildren) { if (typeof element.searchChildren != 'undefined' && element.searchChildren) {
if(element.rootType == "group_edition"
&& typeof element.children == 'undefined'){
$node.addClass("leaf-empty");
}
else{
$node $node
.removeClass("leaf-empty") .removeClass("leaf-empty")
.addClass("leaf-closed"); .addClass("leaf-closed");
$leafIcon.click(function (e) { $leafIcon.click(function (e) {
e.preventDefault(); e.preventDefault();
@ -619,7 +652,6 @@ var TreeController = {
success: function(data, textStatus, xhr) { success: function(data, textStatus, xhr) {
if (data.success) { if (data.success) {
var $group = $node.children("ul.tree-group"); var $group = $node.children("ul.tree-group");
if ((typeof data.tree != 'undefined' && data.tree.length > 0) || $group.length > 0) { if ((typeof data.tree != 'undefined' && data.tree.length > 0) || $group.length > 0) {
$node.addClass("leaf-open"); $node.addClass("leaf-open");
@ -673,6 +705,7 @@ var TreeController = {
} }
}); });
} }
}
return $node; return $node;
} }