Custom graphs in widget in MC

This commit is contained in:
fbsanchez 2021-04-06 14:20:07 +02:00
parent 55e272c360
commit 1c94f619ef
4 changed files with 105 additions and 20 deletions

View File

@ -133,9 +133,14 @@ function custom_graphs_get_user($id_user=0, $only_names=false, $returnAllGroup=t
continue;
}
$all_graph = db_get_all_rows_in_table('tgraph', 'name');
if ($all_graph !== false) {
$all_graphs = array_merge($all_graphs, $all_graph);
$tmp_graphs = db_get_all_rows_in_table('tgraph', 'name');
if ($tmp_graphs !== false) {
foreach ($tmp_graphs as $g) {
$g['id_tgraph'] = $g['id_graph'];
$g['id_graph'] = $connection['id'].'|'.$g['id_graph'];
$g['name'] = $g['name'].' ('.$connection['server_name'].')';
$all_graphs[] = $g;
}
}
metaconsole_restore_db();
@ -168,10 +173,15 @@ function custom_graphs_get_user($id_user=0, $only_names=false, $returnAllGroup=t
$graphs[$graph['id_graph']] = $graph['name'];
} else {
$graphs[$graph['id_graph']] = $graph;
$id_graph = 'id_graph';
if ((bool) is_metaconsole() === true) {
$id_graph = 'id_tgraph';
}
$graphsCount = db_get_value_sql(
'SELECT COUNT(id_gs)
FROM tgraph_source
WHERE id_graph = '.$graph['id_graph']
WHERE id_graph = '.$graph[$id_graph]
);
$graphs[$graph['id_graph']]['graphs_count'] = $graphsCount;
}

View File

@ -21,13 +21,17 @@ function include_javascript_d3($return=false)
if (!$is_include_javascript) {
$is_include_javascript = true;
if (is_metaconsole()) {
$output .= '<script type="text/javascript" src="'.$config['homeurl'].'../../include/javascript/d3.3.5.14.js" charset="utf-8"></script>';
$output .= '<script type="text/javascript" src="'.$config['homeurl'].'../../include/graphs/pandora.d3.js" charset="utf-8"></script>';
} else {
$output .= '<script type="text/javascript" src="'.$config['homeurl'].'include/javascript/d3.3.5.14.js" charset="utf-8"></script>';
$output .= '<script type="text/javascript" src="'.$config['homeurl'].'include/graphs/pandora.d3.js" charset="utf-8"></script>';
}
$output .= '<script type="text/javascript" src="';
$output .= ui_get_full_url('/include/javascript/d3.3.5.14.js');
$output .= '" charset="utf-8"></script>';
$output .= '<script type="text/javascript" src="';
$output .= ui_get_full_url('/include/graphs/bullet.js');
$output .= '" charset="utf-8"></script>';
$output .= '<script type="text/javascript" src="';
$output .= ui_get_full_url('/include/graphs/pandora.d3.js');
$output .= '" charset="utf-8"></script>';
}
if (!$return) {

View File

@ -304,7 +304,7 @@ function initialiceLayout(data) {
},
dataType: "html",
success: function(data) {
console.log(data);
return data;
},
error: function(error) {
console.error(error);

View File

@ -200,6 +200,10 @@ class CustomGraphWidget extends Widget
$values['id_graph'] = $decoder['id_graph'];
}
if (isset($decoder['node']) === true) {
$values['node'] = $decoder['node'];
}
if (isset($decoder['stacked']) === true) {
$values['type'] = $decoder['stacked'];
}
@ -252,21 +256,47 @@ class CustomGraphWidget extends Widget
// Custom graph.
$fields = \custom_graphs_get_user(0, false, $return_all_group);
if ((bool) is_metaconsole() === true) {
$selected = $values['node'].'|'.$values['id_graph'];
} else {
$selected = $values['id_graph'];
}
// If currently selected graph is not included in fields array
// (it belongs to a group over which user has no permissions),
// then add it to fields array.
// This is aimed to avoid overriding this value when a user
// with narrower permissions edits widget configuration.
// then user has no grants over this item.
if ($values['id_graph'] !== null
&& array_key_exists($values['id_graph'], $fields) === false
&& array_key_exists($selected, $fields) === false
) {
$selected_graph = db_get_row(
if ((bool) is_metaconsole() === true) {
$server_name = \db_get_value(
'server_name',
'tmetaconsole_setup',
'id',
$values['node']
);
metaconsole_connect(null, $values['node']);
}
$name = \db_get_value(
'name',
'tgraph',
'id_graph',
$values['id_graph']
);
$fields[$values['id_graph']] = $selected_graph;
if ((bool) is_metaconsole() === true) {
metaconsole_restore_db();
}
if ($name === false) {
$name = \__('This graph has been deleted.');
} else {
$name .= ' ('.$server_name.')';
}
$fields[$selected] = $name;
}
$inputs[] = [
@ -275,7 +305,7 @@ class CustomGraphWidget extends Widget
'type' => 'select',
'fields' => $fields,
'name' => 'id_graph',
'selected' => $values['id_graph'],
'selected' => $selected,
'return' => true,
],
];
@ -340,8 +370,49 @@ class CustomGraphWidget extends Widget
{
// Retrieve global - common inputs.
$values = parent::getPost();
$id_graph = \get_parameter('id_graph', null);
if ($id_graph !== null) {
$values['id_graph'] = $id_graph;
if ((bool) is_metaconsole() === true) {
$mc_stuff = explode('|', $values['id_graph']);
$values['node'] = $mc_stuff[0];
$values['id_graph'] = $mc_stuff[1];
}
// VERIFY ACCESS.
$return_all_group = false;
if (users_can_manage_group_all('RM') === true) {
$return_all_group = true;
}
$availables = \custom_graphs_get_user(0, false, $return_all_group);
if ((bool) is_metaconsole() === true) {
$selected = $values['node'].'|'.$values['id_graph'];
} else {
$selected = $values['id_graph'];
}
// If currently selected graph is not included in fields array
// (it belongs to a group over which user has no permissions),
// then user has no grants over this item.
if ($values['id_graph'] !== null
&& array_key_exists($selected, $availables) === false
) {
// User has no access to this graph.
// Keep previous definition if not grant over desired item.
$values['node'] = $this->values['node'];
$values['id_graph'] = $this->values['id_graph'];
}
} else {
// Keep previous definition if not grant over desired item.
$values['node'] = $this->values['node'];
$values['id_graph'] = $this->values['id_graph'];
}
$values['id_graph'] = \get_parameter('id_graph', 0);
$values['type'] = \get_parameter('type', 0);
$values['period'] = \get_parameter('period', 0);
$values['showLegend'] = \get_parameter_switch('showLegend');