mirror of
https://github.com/pandorafms/pandorafms.git
synced 2025-07-29 16:55:05 +02:00
Custom graphs in widget in MC
This commit is contained in:
parent
55e272c360
commit
1c94f619ef
@ -133,9 +133,14 @@ function custom_graphs_get_user($id_user=0, $only_names=false, $returnAllGroup=t
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
$all_graph = db_get_all_rows_in_table('tgraph', 'name');
|
$tmp_graphs = db_get_all_rows_in_table('tgraph', 'name');
|
||||||
if ($all_graph !== false) {
|
if ($tmp_graphs !== false) {
|
||||||
$all_graphs = array_merge($all_graphs, $all_graph);
|
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();
|
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'];
|
$graphs[$graph['id_graph']] = $graph['name'];
|
||||||
} else {
|
} else {
|
||||||
$graphs[$graph['id_graph']] = $graph;
|
$graphs[$graph['id_graph']] = $graph;
|
||||||
|
$id_graph = 'id_graph';
|
||||||
|
if ((bool) is_metaconsole() === true) {
|
||||||
|
$id_graph = 'id_tgraph';
|
||||||
|
}
|
||||||
|
|
||||||
$graphsCount = db_get_value_sql(
|
$graphsCount = db_get_value_sql(
|
||||||
'SELECT COUNT(id_gs)
|
'SELECT COUNT(id_gs)
|
||||||
FROM tgraph_source
|
FROM tgraph_source
|
||||||
WHERE id_graph = '.$graph['id_graph']
|
WHERE id_graph = '.$graph[$id_graph]
|
||||||
);
|
);
|
||||||
$graphs[$graph['id_graph']]['graphs_count'] = $graphsCount;
|
$graphs[$graph['id_graph']]['graphs_count'] = $graphsCount;
|
||||||
}
|
}
|
||||||
|
@ -21,13 +21,17 @@ function include_javascript_d3($return=false)
|
|||||||
if (!$is_include_javascript) {
|
if (!$is_include_javascript) {
|
||||||
$is_include_javascript = true;
|
$is_include_javascript = true;
|
||||||
|
|
||||||
if (is_metaconsole()) {
|
$output .= '<script type="text/javascript" src="';
|
||||||
$output .= '<script type="text/javascript" src="'.$config['homeurl'].'../../include/javascript/d3.3.5.14.js" charset="utf-8"></script>';
|
$output .= ui_get_full_url('/include/javascript/d3.3.5.14.js');
|
||||||
$output .= '<script type="text/javascript" src="'.$config['homeurl'].'../../include/graphs/pandora.d3.js" charset="utf-8"></script>';
|
$output .= '" 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="';
|
||||||
$output .= '<script type="text/javascript" src="'.$config['homeurl'].'include/graphs/pandora.d3.js" charset="utf-8"></script>';
|
$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) {
|
if (!$return) {
|
||||||
|
@ -304,7 +304,7 @@ function initialiceLayout(data) {
|
|||||||
},
|
},
|
||||||
dataType: "html",
|
dataType: "html",
|
||||||
success: function(data) {
|
success: function(data) {
|
||||||
console.log(data);
|
return data;
|
||||||
},
|
},
|
||||||
error: function(error) {
|
error: function(error) {
|
||||||
console.error(error);
|
console.error(error);
|
||||||
|
@ -200,6 +200,10 @@ class CustomGraphWidget extends Widget
|
|||||||
$values['id_graph'] = $decoder['id_graph'];
|
$values['id_graph'] = $decoder['id_graph'];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (isset($decoder['node']) === true) {
|
||||||
|
$values['node'] = $decoder['node'];
|
||||||
|
}
|
||||||
|
|
||||||
if (isset($decoder['stacked']) === true) {
|
if (isset($decoder['stacked']) === true) {
|
||||||
$values['type'] = $decoder['stacked'];
|
$values['type'] = $decoder['stacked'];
|
||||||
}
|
}
|
||||||
@ -252,21 +256,47 @@ class CustomGraphWidget extends Widget
|
|||||||
// Custom graph.
|
// Custom graph.
|
||||||
$fields = \custom_graphs_get_user(0, false, $return_all_group);
|
$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
|
// If currently selected graph is not included in fields array
|
||||||
// (it belongs to a group over which user has no permissions),
|
// (it belongs to a group over which user has no permissions),
|
||||||
// then add it to fields array.
|
// then user has no grants over this item.
|
||||||
// This is aimed to avoid overriding this value when a user
|
|
||||||
// with narrower permissions edits widget configuration.
|
|
||||||
if ($values['id_graph'] !== null
|
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',
|
'tgraph',
|
||||||
'id_graph',
|
'id_graph',
|
||||||
$values['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[] = [
|
$inputs[] = [
|
||||||
@ -275,7 +305,7 @@ class CustomGraphWidget extends Widget
|
|||||||
'type' => 'select',
|
'type' => 'select',
|
||||||
'fields' => $fields,
|
'fields' => $fields,
|
||||||
'name' => 'id_graph',
|
'name' => 'id_graph',
|
||||||
'selected' => $values['id_graph'],
|
'selected' => $selected,
|
||||||
'return' => true,
|
'return' => true,
|
||||||
],
|
],
|
||||||
];
|
];
|
||||||
@ -340,8 +370,49 @@ class CustomGraphWidget extends Widget
|
|||||||
{
|
{
|
||||||
// Retrieve global - common inputs.
|
// Retrieve global - common inputs.
|
||||||
$values = parent::getPost();
|
$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['type'] = \get_parameter('type', 0);
|
||||||
$values['period'] = \get_parameter('period', 0);
|
$values['period'] = \get_parameter('period', 0);
|
||||||
$values['showLegend'] = \get_parameter_switch('showLegend');
|
$values['showLegend'] = \get_parameter_switch('showLegend');
|
||||||
|
Loading…
x
Reference in New Issue
Block a user