New maps in progress... (get node data)

This commit is contained in:
Arturo Gonzalez 2016-02-24 13:04:38 +01:00
parent bd736ea598
commit cccce11f79
3 changed files with 94 additions and 43 deletions

View File

@ -30,9 +30,55 @@ if (is_ajax ()) {
$id_map = (int)get_parameter('id_map');
$data_graph_id = (int)get_parameter('data_graph_id');
$return_data = '<span>GOD SAVE FERMIN!!</span>';
$return_data = '';
sleep(2);
switch ($type) {
case ITEM_TYPE_AGENT_NETWORKMAP:
$node_data = db_get_all_rows_sql("SELECT *
FROM tagente
WHERE id_agente = " . $id_node_data);
$node_data = $node_data[0];
if (!empty($node_data)) {
$return_data .= '<div id="agent_data_to_show_"' . $node_data['id_agente'] .'>';
$return_data .= '<span><strong>Agent: </strong>' . $node_data['nombre'] . '</span></br>';
$return_data .= '<span><strong>IP Addres: </strong>' . $node_data['direccion'] . '</span></br>';
$agent_os = db_get_row_sql("SELECT name FROM tconfig_os WHERE id_os = " . $node_data['id_os']);
$agent_os = $agent_os['name'];
$return_data .= '<span><strong>OS: </strong>' . $agent_os . ' ' . $node_data['os_version'] .'</span></br>';
$return_data .= '<span><strong>Description: </strong>' . $node_data['comentarios'] . '</span></br>';
$agent_group = db_get_row_sql("SELECT nombre FROM tgrupo WHERE id_grupo = " . $node_data['id_grupo']);
$agent_group = $agent_group['nombre'];
$return_data .= '<span><strong>Group: </strong>' . $agent_group . '</span></br>';
$return_data .= '<span><strong>Agent Version: </strong>' . $node_data['agent_version'] . '</span></br>';
$return_data .= '<span><strong>Last Contact: </strong>' . $node_data['ultimo_contacto'] . '</span></br>';
$return_data .= '<span><strong>Remote: </strong>' . $node_data['ultimo_contacto_remoto'] . '</span>';
$return_data .= '</div>';
}
else {
$return_data = '<span>No data to show</span>';
}
break;
case ITEM_TYPE_MODULE_NETWORKMAP:
$node_data = db_get_all_rows_sql("SELECT *
FROM tagente_modulo
WHERE id_agente_modulo = " . $id_node_data);
$node_data = $node_data[0];
if (!empty($node_data)) {
$return_data .= '<div id="module_data_to_show_"' . $node_data['id_agente'] .'>';
$return_data .= '<span><strong>Module: </strong>' . $node_data['nombre'] . '</span></br>';
$agent_module = db_get_row_sql("SELECT nombre FROM tagente WHERE id_agente = " . $node_data['id_agnte']);
$agent_module = $agent_module['nombre'];
$return_data .= '<span><strong>Agent: </strong>' . $agent_module . '</span></br>';
$return_data .= '<span><strong>Description: </strong>' . $node_data['descripcion'] . '</span>';
$return_data .= '</div>';
}
else {
$return_data = '<span>No data to show</span>';
}
break;
}
sleep(1);
echo json_encode($return_data);
return;
}

View File

@ -23,22 +23,22 @@
abstract class Map {
protected $status = STATUS_OK;
protected $id = null;
protected $type = null;
protected $subtype = null;
protected $id_group = null;
protected $generation_method = null;
protected $width = null;
protected $height = null;
protected $nodes = array();
protected $edges = array();
protected $requires_js = null;
public static function getName($id = null) {
if (empty($id)) {
return null;
@ -47,39 +47,39 @@ abstract class Map {
return db_get_value('name', 'tmap', 'id', $id);
}
}
public function __construct($id) {
$this->id = $id;
$this->requires_js = array();
$this->requires_js[] = "include/javascript/d3.3.5.14.js";
$this->requires_js[] = "include/javascript/map/MapController.js";
$this->requires_js[] = "include/javascript/jquery.tooltipster.js";
$this->requires_js[] = "include/javascript/jquery.svg.js";
$this->requires_js[] = "include/javascript/jquery.svgdom.js";
if (!$this->loadDB()) {
$this->status = STATUS_ERROR;
}
}
protected function processDBValues($dbValues) {
$this->type = (int)$dbValues['type'];
$this->subtype = (int)$dbValues['subtype'];
$this->id_group = (int)$dbValues['id_group'];
$this->generation_method = (int)$dbValues['generation_method'];
$this->width = (int)$dbValues['width'];
$this->height = (int)$dbValues['height'];
}
private function loadDB() {
$row = db_get_row_filter('tmap', array('id' => $this->id));
if (empty($row))
return false;
switch (get_class($this)) {
case 'Networkmap':
Networkmap::processDBValues($row);
@ -92,9 +92,9 @@ abstract class Map {
break;
}
}
abstract function printJSInit();
public function writeJSGraph() {
?>
<script type="text/javascript">
@ -105,14 +105,14 @@ abstract class Map {
var temp = [];
for (var i in nodes) { temp[parseInt(i)] = nodes[i];}
nodes = temp;
temp = [];
for (var i in edges) { temp[parseInt(i)] = edges[i];}
edges = temp;
</script>
<?php
}
public function show() {
// Tooltip css
echo "<link rel=\"stylesheet\" type=\"text/css\" href=\"include/styles/tooltipster.css\"/>" . "\n";
@ -120,15 +120,19 @@ abstract class Map {
echo "<link rel=\"stylesheet\" type=\"text/css\" href=\"include/styles/tooltipster-shadow.css\"/>" . "\n";
echo "<link rel=\"stylesheet\" type=\"text/css\" href=\"include/styles/tooltipster-noir.css\"/>" . "\n";
echo "<link rel=\"stylesheet\" type=\"text/css\" href=\"include/styles/tooltipster-light.css\"/>" . "\n";
//Tooltips spinner
echo "<div id='spinner_tooltip' style='display:none;'>";
html_print_image('images/spinner.gif');
echo "</div>";
foreach ($this->requires_js as $js) {
echo "<script type='text/javascript' src='$js'></script>" . "\n";
}
$this->writeJSContants();
$this->writeJSGraph();
?>
<div id="map" data-id="<?php echo $this->id;?>" style="border: 1px red solid;">
<div class="zoom_box" style="">
<style type="text/css">
@ -137,14 +141,14 @@ abstract class Map {
height: 210px;
background: blue;
border-radius: 15px;
top: 100px;
left: 10px;
position: absolute;
}
.vertical_range {
padding: 0;
-webkit-transform: rotate(270deg);
@ -156,26 +160,26 @@ abstract class Map {
background: transparent !important;
border: 0px !important;
}
.vertical_range {
left: -92px;
top: 93px;
}
@media screen and (-webkit-min-device-pixel-ratio:0)
{
/* Only for chrome */
.vertical_range {
left: -87px;
top: 93px;
}
}
.home_zoom {
top: 360px;
left: 10px;
display: table-cell;
position: absolute;
font-weight: bolder;
@ -189,11 +193,11 @@ abstract class Map {
text-align: center;
vertical-align: middle;
}
.zoom_in {
top: 10px;
left: 10px;
display: table-cell;
position: relative;
font-weight: bolder;
@ -207,11 +211,11 @@ abstract class Map {
text-align: center;
vertical-align: middle;
}
.zoom_out {
top: 320px;
left: 10px;
display: table-cell;
position: absolute;
font-weight: bolder;
@ -250,11 +254,11 @@ abstract class Map {
<svg xmlns="http://www.w3.org/2000/svg" pointer-events="all" width="<?php echo $width;?>" height="<?php echo $height;?>">
</svg>
</div>
<?php
$this->printJSInit();
}
public function writeJSContants() {
$contants = array();
$contants["ITEM_TYPE_AGENT_NETWORKMAP"] = ITEM_TYPE_AGENT_NETWORKMAP;
@ -270,7 +274,7 @@ abstract class Map {
</script>
<?php
}
public function getType() {
return $this->type;
}

View File

@ -170,7 +170,7 @@ MapController.prototype.init_map = function() {
self.paint_nodes();
this.init_events();
};
@ -239,6 +239,7 @@ This function manages nodes tooltips
*/
MapController.prototype.tooltip_map_create = function(self, event) {
var nodeTarget = $(event.currentTarget).parent();
var spinner = $('#spinner_tooltip').html();
var nodeR = parseInt($(event.currentTarget).attr("r"));
nodeR = nodeR * self._zoomManager.scale(); // Apply zoom
@ -249,7 +250,7 @@ MapController.prototype.tooltip_map_create = function(self, event) {
var data_graph_id = parseInt(nodeTarget.data("graph_id"));
if (this.containsTooltipId(node_id)) {
nodeTarget.tooltipster('content', 'Loading...');
nodeTarget.tooltipster('content', spinner);
self.nodeData(data_id, type, self._id, data_graph_id, nodeTarget);
nodeTarget.tooltipster("option", "offsetX", nodeR);
nodeTarget.tooltipster("show");
@ -263,7 +264,7 @@ MapController.prototype.tooltip_map_create = function(self, event) {
offsetX: nodeR,
theme: 'tooltipster-noir',
multiple: true,
content: 'Loading...',
content: spinner,
functionBefore: function(origin, continueTooltip) {
continueTooltip();
self.nodeData(data_id, type, self._id, data_graph_id, origin);