2010-03-24 Miguel de Dios <miguel.dedios@artica.es>

* include/functions_visual_map.php,
	include/ajax/visual_console_builder.ajax.php,
	godmode/reporting/visual_console_builder.preview.php,
	godmode/reporting/visual_console_builder.php,
	godmode/reporting/visual_console_builder.editor.php,
	godmode/reporting/visual_console_builder.editor.js: worked about the new
	visual console builder editor, now it is developing, don't afray.



git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@2524 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
This commit is contained in:
mdtrooper 2010-03-25 16:18:05 +00:00
parent 2ee5b9ad95
commit 72a8fd1696
7 changed files with 310 additions and 34 deletions

View File

@ -1,3 +1,13 @@
2010-03-24 Miguel de Dios <miguel.dedios@artica.es>
* include/functions_visual_map.php,
include/ajax/visual_console_builder.ajax.php,
godmode/reporting/visual_console_builder.preview.php,
godmode/reporting/visual_console_builder.php,
godmode/reporting/visual_console_builder.editor.php,
godmode/reporting/visual_console_builder.editor.js: worked about the new
visual console builder editor, now it is developing, don't afray.
2010-03-24 Junichi Satoh <junichi@rworks.jp>
* operation/snmpconsole/snmp_view.php: To follow timestamp setting,

View File

@ -2,6 +2,7 @@ var creationItem = null;
var openPropertiesPanel = false;
var idItem = 0;
var selectedItem = null;
var lines = Array();
function showAdvanceOptions(close) {
if ($("#advance_options").css('display') == 'none') {
@ -18,11 +19,79 @@ function showAdvanceOptions(close) {
// Main function, execute in event documentReady
function editorMain2() {
$("#background").resizable();
eventsBackground();
eventsButtonsToolbox();
eventsItems();
eventsTextAgent();
draw_lines(lines, 'background');
// var lines = Array ();
// lines.push (eval ({"id":"116","node_begin":"layout-data-115","node_end":"layout-data-116","color":"#ccc"}));
//$("#background").append($('<div id="pepito"></div>'));
// draw_line({"node_begin":"112","node_end":"110","color":"#000"}, 'background');
//$(".map-line").css('z-index', '0');
$(".item").css('z-index', '1'); //For paint the icons over lines
}
function eventsTextAgent() {
var idText = $("#ip_text").html();
$("#text-agent").autocomplete(
"ajax.php",
{
minChars: 2,
scroll:true,
extraParams: {
page: "operation/agentes/exportdata",
search_agents: 1,
id_group: function() { return $("#group").val(); }
},
formatItem: function (data, i, total) {
if (total == 0)
$("#text-agent").css ('background-color', '#cc0000');
else
$("#text-agent").css ('background-color', '');
if (data == "")
return false;
return data[0]+'<br><span class="ac_extra_field">' + idText + ': '+data[1]+'</span>';
},
delay: 200
}
);
$("#text-agent").result (
function () {
selectAgent = true;
var agent_name = this.value;
$('#module').fadeOut ('normal', function () {
$('#module').empty ();
var inputs = [];
inputs.push ("filter=disabled = 0");
inputs.push ("agent_name=" + agent_name);
inputs.push ("get_agent_modules_json=1");
inputs.push ("page=operation/agentes/ver_agente");
jQuery.ajax ({
data: inputs.join ("&"),
type: 'GET',
url: action="ajax.php",
timeout: 10000,
dataType: 'json',
success: function (data) {
$('#module').append ($('<option></option>').attr ('value', 0).text ("--"));
jQuery.each (data, function (i, val) {
s = js_html_entity_decode (val['nombre']);
$('#module').append ($('<option></option>').attr ('value', val['id_agente_modulo']).text (s));
});
$('#module').fadeIn ('normal');
}
});
});
}
);
}
function updateAction() {
@ -32,7 +101,7 @@ function updateAction() {
// TODO VALIDATE DATA
updateDB(selectedItem, idElement , values);
updateDB(selectedItem, idItem , values);
switch (selectedItem) {
case 'background':
@ -124,7 +193,7 @@ function actionClick() {
$("#button_create_div").css('display', 'none');
$("#button_update_div").css('display', 'block');
cleanFields();
console.log(item);
loadFieldsFromDB(item);
}
@ -150,6 +219,8 @@ function loadFieldsFromDB(item) {
dataType: 'json',
success: function (data)
{
var moduleId = 0;
jQuery.each(data, function(key, val) {
if (key == 'background') $("#background_image").val(val);
if (key == 'width') $("input[name=width]").val(val);
@ -161,16 +232,23 @@ function loadFieldsFromDB(item) {
}
if (key == 'pos_x') $("input[name=left]").val(val);
if (key == 'pos_y') $("input[name=top]").val(val);
if (key == 'agent') {
if (key == 'agent_name') {
$("input[name=agent]").val(val);
//Reload no-sincrone the select of modules
}
if (key == 'module') $("select[name=module]").val(val);
if (key == 'modules_html') {
$("select[name=module]").empty().html(val);
$("select[name=module]").val(moduleId);
}
if (key == 'id_agente_modulo') {
moduleId = val;
$("select[name=module]").val(val);
}
if (key == 'period') $("select[name=period]").val(val);
if (key == 'width') $("input[name=width]").val(val);
if (key == 'height') $("input[name=height]").val(val);
if (key == 'parent') $("select[name=parent]").val(val);
if (key == 'map_linked') $("select[name=map_linked]").val(val);
if (key == 'parent_item') $("select[name=parent]").val(val);
if (key == 'id_layout_linked') $("select[name=map_linked]").val(val);
if (key == 'label_color') $("input[name=label_color]").val(val);
});
}
@ -227,6 +305,8 @@ function cleanFields() {
$("select[name=map_linked]").val('');
$("input[name=label_color]").val('#000000');
$("#preview").empty();
var anyText = $("#any_text").html();
$("#module").empty().append($('<option value="0" selected="selected">' + anyText + '</option></select>'));
}
function getImageElement(id_data) {
@ -249,23 +329,46 @@ function getImageElement(id_data) {
}
});
console.log(img);
return img;
}
function getColorLineStatus(id) {
var parameter = Array();
parameter.push ({name: "page", value: "include/ajax/visual_console_builder.ajax"});
parameter.push ({name: "action", value: "get_color_line"});
parameter.push ({name: "id_element", value: id});
var color = null;
jQuery.ajax({
async: false,
url: "ajax.php",
data: parameter,
type: "POST",
dataType: 'json',
success: function (data)
{
color = data['color_line'];
}
});
return color;
}
function createItem(type, values, id_data) {
if ((values['width'] == 0) && (values['height'] == 0)) {
var sizeStyle = '';
var imageSize = '';
}
else {
var sizeStyle = 'width: ' + values['width'] + 'px; height: ' + values['height'] + 'px;';
var imageSize = 'width="' + values['width'] + '" height="' + values['height'] + '"';
}
switch (type) {
case 'static_graph':
var item = $('<div id="' + id_data + '" class="item static_graph" style="color: ' + values['label_color'] + '; text-align: center; position: absolute; ' + sizeStyle + ' margin-top: ' + values['top'] + 'px; margin-left: ' + values['left'] + 'px;">' +
'<img id="image_' + id_data + '" class="image" src="' + getImageElement(id_data) + '" /><br />' +
'<img id="image_' + id_data + '" class="image" src="' + getImageElement(id_data) + '" ' + imageSize + ' /><br />' +
'<span id="text_' + id_data + '" class="text">' + values['label'] + '</span>' +
'</div>'
);
@ -273,6 +376,21 @@ function createItem(type, values, id_data) {
}
$("#background").append(item);
$(".item").css('z-index', '1');
if (values['parent'] != 0) {
var line = {"id": id_data,
"node_begin": values['parent'],
"node_end": id_data,
"color": getColorLineStatus(id_data) };
lines.push(line);
refresh_lines(lines, 'background');
}
}
function addItemSelectParents(id_data, text) {
$("#parent").append($('<option value="' + id_data + '" selected="selected">' + text + '</option></select>'));
}
function insertDB(type, values) {
@ -295,6 +413,7 @@ function insertDB(type, values) {
{
if (data['correct']) {
createItem(type, values, data['id_data']);
addItemSelectParents(data['id_data'], data['text']);
eventsItems();
}
else {
@ -316,6 +435,18 @@ function updateDB(type, idElement , values) {
parameter.push ({name: key, value: val});
});
if ((typeof(values['mov_left']) != 'undefined') &&
(typeof(values['mov_top']) != 'undefined')) {
var top = parseInt($("#" + idElement).css('margin-top').replace('px', ''));
var left = parseInt($("#" + idElement).css('margin-left').replace('px', ''));
top = top + parseInt(values['mov_top']);
left = left + parseInt(values['mov_left']);
parameter.push ({name: 'top', value: top});
parameter.push ({name: 'left', value: left});
}
jQuery.ajax({
url: "ajax.php",
data: parameter,
@ -323,7 +454,12 @@ function updateDB(type, idElement , values) {
dataType: 'text',
success: function (data)
{
// TODO
if ((typeof(values['mov_left']) != 'undefined') &&
(typeof(values['mov_top']) != 'undefined')) {
$("#" + idElement).css('top', '0px').css('margin-top', top + 'px');
$("#" + idElement).css('left', '0px').css('margin-left', left + 'px');
refresh_lines(lines, 'background');
}
}
});
}
@ -344,6 +480,15 @@ function deleteDB(idElement) {
success: function (data)
{
if (data['correct']) {
$("#parent > option[value=" + idElement + "]").remove();
jQuery.each(lines, function(i, line) {
if (line['id'] == idElement) {
lines.splice(i);
}
});
refresh_lines(lines, 'background');
$('#' + idElement).remove();
activeToolboxButton('delete_item', false);
}
@ -366,7 +511,10 @@ function activeToolboxButton(id, active) {
}
function deleteItem() {
activeToolboxButton('edit_item', false);
deleteDB(idItem);
idItem = 0;
selectedItem = null;
}
function eventsItems() {
@ -375,6 +523,8 @@ function eventsItems() {
$('.item').unbind('dragstart');
$(".item").draggable('destroy');
//$(".item").resizable(); //Disable but run in ff and in ie show ungly borders
$('.item').bind('click', function(event, ui) {
event.stopPropagation();
if (!openPropertiesPanel) {
@ -416,14 +566,16 @@ function eventsItems() {
var values = {};
values['left'] = ui.position.left;
values['top'] = ui.position.top;
values['mov_left'] = ui.position.left;
values['mov_top'] = ui.position.top;
updateDB(selectedItem, idItem, values);
});
}
function eventsBackground() {
$("#background").resizable();
$('#background').bind('resizestart', function(event, ui) {
if (!openPropertiesPanel) {
$("#background").css('border', '2px red solid');
@ -486,6 +638,7 @@ function eventsButtonsToolbox() {
if ($("#" + id).hasClass('disabled') == false) {
$("#" + id).css('background', '#e5e5e5');
}
$("#" + id).css('border', '4px outset black');
});
$('.button_toolbox').mousedown(function(event) {

View File

@ -43,8 +43,6 @@ foreach ($all_images as $image_file) {
$images_list[$image_file] = $image_file;
}
debugPrint($_POST);
echo '<div id="editor">';
echo '<div id="toolbox">';
printButtonEditorVisualConsole('static_graph', __('Static Graph'));
@ -89,7 +87,7 @@ $intervals[4838400] = __('Last month');
$intervals[9676800] = "2 ".__('months');
$intervals[29030400] = "6 ".__('months');
echo '<div id="properties_panel" style="display: none; position: absolute; border: 2px solid #114105; padding: 5px; background: white; z-index: 1;">';
echo '<div id="properties_panel" style="display: none; position: absolute; border: 2px solid #114105; padding: 5px; background: white; z-index: 99;">';
//----------------------------Hiden Form----------------------------------------
echo '<div id="hidden_panel_properties"">';
echo '<div id="basic_options" style="width: 300px">';
@ -166,14 +164,14 @@ echo '<div id="hidden_panel_properties"">';
echo '<div id="parent_div" class="static_graph" style="display: block; margin-bottom: 5px;">';
echo __('Parent') . ':';
print_select (array (), 'parent', '', '', __('None'), 0);
print_select_from_sql('SELECT id, label FROM tlayout_data WHERE id_layout = ' . $visualConsole['id'], 'parent', '', '', __('None'), 0);
echo '<br />';
echo '</div>';
echo '<div id="map_linked_div" class="static_graph" style="display: block; margin-bottom: 5px;">';
echo __('Map linked') . ':';
print_select_from_sql ('SELECT id, name FROM tlayout WHERE id != ' . $idVisualConsole,
'map_linked', '', '', 'None', '');
'map_linked', '', '', 'None', '0');
echo '</div>';
echo '<div id="label_color_div" class="static_graph" style="display: block; margin-bottom: 5px;">';
@ -181,7 +179,9 @@ echo '<div id="hidden_panel_properties"">';
print_input_text_extended ('label_color', '#000000', 'text-'.'label_color',
'', 7, 7, false, '', 'class="label_color"', false);
echo '</div>';
//Trick for it have a traduct "any" text.
echo '<span id="any_text" style="display: none;">' . __('Any') . '</span>';
echo '<span id="ip_text" style="display: none;">' . __('IP') . '</span>';
echo '</div>';
echo "</div>";
//------------------------------------------------------------------------------
@ -203,12 +203,14 @@ echo "</form>";
require_css_file ('color-picker');
require_jquery_file ('ui.core');
require_jquery_file ('ui.resizable');
require_jquery_file ('colorpicker');
require_jquery_file ('ui.draggable');
require_jquery_file('ui.core');
require_jquery_file('ui.resizable');
require_jquery_file('colorpicker');
require_jquery_file('ui.draggable');
require_javascript_file('wz_jsgraphics');
require_javascript_file('pandora_visual_console');
require_javascript_file('visual_console_builder.editor', 'godmode/reporting/');
function printButtonEditorVisualConsole($idDiv, $label, $float = 'left', $disabled = false) {
if (!$disabled) $disableClass = '';
else $disableClass = 'disabled';
@ -249,17 +251,32 @@ function printItemInVisualConsole($layoutData) {
if (($width == 0) && ($height == 0)) {
$sizeStyle = '';
$imageSize = '';
}
else {
$sizeStyle = 'width: ' . $width . 'px; height: ' . $height . 'px;';
$imageSize = 'width="' . $width . '" height="' . $height . '"';
}
echo '<div id="' . $id . '" class="item static_graph" style="text-align: center; color: ' . $color . '; position: absolute; ' . $sizeStyle . ' margin-top: ' . $top . 'px; margin-left: ' . $left . 'px;">';
echo '<img class="image" id="image_' . $id . '" src="' . $img . '" /><br />';
echo '<img class="image" id="image_' . $id . '" src="' . $img . '" ' . $imageSize . ' /><br />';
echo '<span id="text_' . $id . '" class="text">' . $label . '</span>';
echo "</div>";
if ($layoutData['parent_item'] != 0) {
echo '<script type="text/javascript">';
echo '$(document).ready (function() {
lines.push({"id": "' . $id . '" , "node_begin":"' . $layoutData['parent_item'] . '","node_end":"' . $id . '","color":"' . getColorLineStatus($layoutData) . '"});
});';
echo '</script>';
}
}
?>
<style type="text/css">
.ui-resizable-handle {
background: transparent !important;
border: transparent !important;
}
</style>
<script type="text/javascript">
id_visual_console = <?php echo $visualConsole['id']; ?>;
$(document).ready (editorMain2);

View File

@ -28,7 +28,7 @@ if (! give_acl ($config['id_user'], 0, "IW")) {
require_once ('include/functions_visual_map.php');
$action = get_parameterBetweenListValues('action', array('new', 'save', 'edit', 'update'), 'new');
$activeTab = get_parameterBetweenListValues('tab', array('data', 'list_elements', 'wizard', 'editor'), 'data');
$activeTab = get_parameterBetweenListValues('tab', array('data', 'list_elements', 'wizard', 'editor', 'preview'), 'data');
$idVisualConsole = get_parameter('id_visual_console', 0);
//Save/Update data in DB
@ -112,6 +112,10 @@ switch ($activeTab) {
break;
}
break;
case 'preview':
$visualConsole = get_db_row_filter('tlayout', array('id' => $idVisualConsole));
$visualConsoleName = $visualConsole['name'];
break;
}
$buttons = array(
@ -126,7 +130,10 @@ $buttons = array(
print_image ("images/pill.png", true, array ("title" => __('Wizard'))) .'</a>'),
'editor' => array('active' => false,
'text' => '<a href="index.php?sec=gmap&sec2=godmode/reporting/visual_console_builder&tab=editor&action=' . $action . '&id_visual_console=' . $idVisualConsole . '">' .
print_image ("images/config.png", true, array ("title" => __('Editor'))) .'</a>'));
print_image ("images/config.png", true, array ("title" => __('Editor'))) .'</a>'),
'preview' => array('active' => false,
'text' => '<a href="index.php?sec=gmap&sec2=godmode/reporting/visual_console_builder&tab=preview&action=' . $action . '&id_visual_console=' . $idVisualConsole . '">' .
print_image ("images/eye.png", true, array ("title" => __('Preview'))) .'</a>'),);
if ($action == 'new') $buttons = array('data' => $buttons['data']); //Show only the data tab
$buttons[$activeTab]['active'] = true;
@ -147,5 +154,8 @@ switch ($activeTab) {
case 'editor':
require_once('godmode/reporting/visual_console_builder.editor.php');
break;
case 'preview':
require_once('godmode/reporting/visual_console_builder.preview.php');
break;
}
?>

View File

@ -0,0 +1,40 @@
<?php
// Pandora FMS - http://pandorafms.com
// ==================================================
// Copyright (c) 2005-2009 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 General Public License
// as published by the Free Software Foundation for 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.
// Login check
global $config;
check_login ();
if (! give_acl ($config['id_user'], 0, "IW")) {
audit_db ($config['id_user'], $_SERVER['REMOTE_ADDR'], "ACL Violation",
"Trying to access report builder");
require ("general/noaccess.php");
exit;
}
require_once ('include/functions_visual_map.php');
print_pandora_visual_map ($visualConsole['id']);
require_javascript_file ('wz_jsgraphics');
require_javascript_file ('pandora_visual_console');
?>
<script language="javascript" type="text/javascript">
/* <![CDATA[ */
$(document).ready (function () {
draw_lines (lines, 'layout_map');
});
/* ]]> */
</script>

View File

@ -45,6 +45,13 @@ $map_linked = get_parameter('map_linked', null);
$label_color = get_parameter('label_color', null);
switch ($action) {
case 'get_color_line':
$layoutData = get_db_row_filter('tlayout_data', array('id' => $id_element));
$return = array();
$return['color_line'] = getColorLineStatus($layoutData);
echo json_encode($return);
break;
case 'get_image':
$layoutData = get_db_row_filter('tlayout_data', array('id' => $id_element));
@ -78,10 +85,10 @@ switch ($action) {
if ($top !== null) {
$values['pos_y'] = $top;
}
//TODO $agent -> $id_agent
$id_agent = 0;
//TODO
$values['id_agent'] = $id_agent;
if ($agent !== null) {
$id_agent = get_agent_id($agent);
$values['id_agent'] = $id_agent;
}
if ($module !== null) {
$values['id_agente_modulo'] = $module;
}
@ -104,7 +111,7 @@ switch ($action) {
$values['label_color'] = $label_color;
}
process_sql_update('tlayout_data', $values, array('id' => $id_element));
$result = process_sql_update('tlayout_data', $values, array('id' => $id_element));
break;
}
break;
@ -116,6 +123,20 @@ switch ($action) {
break;
case 'static_graph':
$elementFields = get_db_row_filter('tlayout_data', array('id' => $id_element));
$elementFields['agent_name'] = get_agent_name($elementFields['id_agent']);
if ($elementFields['id_agent'] != 0) {
$modules = get_agent_modules ($elementFields['id_agent'], false, array('disabled' => 0, 'id_agente' => $elementFields['id_agent']));
$elementFields['modules_html'] = '<option value="0">--</option>';
foreach ($modules as $id => $name) {
$elementFields['modules_html'] .= '<option value="' . $id . '">' . $name . '</option>';
}
}
else {
$elementFields['modules_html'] = '<option value="0">' . __('Any') . '</option>';
}
echo json_encode($elementFields);
break;
}
@ -135,6 +156,10 @@ switch ($action) {
else
$values['id_agent'] = 0;
$values['id_agente_modulo'] = $module;
$values['width'] = $width;
$values['height'] = $height;
$values['id_layout_linked'] = $map_linked;
$values['parent_item'] = $parent;
$idData = process_sql_insert('tlayout_data', $values);
@ -145,6 +170,7 @@ switch ($action) {
else {
$return['correct'] = 1;
$return['id_data'] = $idData;
$return['text'] = $label;
}
echo json_encode($return);
break;

View File

@ -19,6 +19,26 @@
* @subpackage Reporting
*/
function getColorLineStatus($layoutData) {
switch (getStatusElement($layoutData)) {
case 3:
$color = "#ccc"; // Gray
break;
case 2:
$color = "#20f6f6"; // Yellow
break;
case 0:
$color = "#00ff00"; // Green
break;
case 4:
case 1:
$color = "#ff0000"; // Red
break;
}
return $color;
}
function getImageStatusElement($layoutData) {
$img = "images/console/icons/" . $layoutData["image"];
switch (getStatusElement($layoutData)) {
@ -46,7 +66,7 @@ function getImageStatusElement($layoutData) {
function getStatusElement($layoutData) {
//Linked to other layout ?? - Only if not module defined
if ($layoutData['id_layout_linked'] != 0) {
$status = get_layout_status ($layout_data['id_layout_linked']);
$status = get_layout_status ($layoutData['id_layout_linked']);
}
else if ($layoutData["type"] == 0) { //Single object
//Status for a simple module