Skip to content

Commit

Permalink
Merge pull request #1523 from laf/issue-685
Browse files Browse the repository at this point in the history
Dynamic dashboard
  • Loading branch information
f0o committed Aug 1, 2015
2 parents 3227156 + f091ba3 commit b01fa8a
Show file tree
Hide file tree
Showing 50 changed files with 14,078 additions and 206 deletions.
3 changes: 3 additions & 0 deletions Makefile
Expand Up @@ -47,6 +47,9 @@ vis:
typeahead:
$(GIT_SUBTREE) --prefix=lib/typeahead https://github.com/twitter/typeahead.js.git master

gridster:
$(GIT_SUBTREE) --prefix=lib/gridster https://github.com/ducksboard/gridster.js.git master

jquery-mapael:
$(GIT_SUBTREE) --prefix=lib/jQuery-Mapael https://github.com/neveldo/jQuery-Mapael.git master

Expand Down
1 change: 1 addition & 0 deletions doc/General/Acknowledgement.md
Expand Up @@ -22,6 +22,7 @@ LibreNMS 3rd party acknowledgements
- Moment (http://momentjs.com/): MIT
- Tag Manager (http://soliantconsulting.github.io/tagmanager/): MIT
- TW Sack (https://code.google.com/p/tw-sack/): GPLv3
- Gridster (http://gridster.net/): MIT

#### 3rd Party GPLv3 Non-compliant

Expand Down
47 changes: 47 additions & 0 deletions html/ajax_dash.php
@@ -0,0 +1,47 @@
<?php

/*
* LibreNMS
*
* Copyright (c) 2014 Neil Lathwood <https://github.com/laf/ http://www.lathwood.co.uk/fa>
*
* 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, either version 3 of the License, or (at your
* option) any later version. Please see LICENSE.txt at the top level of
* the source code distribution for details.
*/

require_once '../includes/defaults.inc.php';
set_debug($_REQUEST['debug']);
require_once '../config.php';
require_once '../includes/definitions.inc.php';
require_once 'includes/functions.inc.php';
require_once '../includes/functions.php';
require_once 'includes/authenticate.inc.php';

if (!$_SESSION['authenticated']) {
echo 'unauthenticated';
exit;
}

$type = mres($_POST['type']);

if ($type == 'placeholder') {
$output = 'Please add a Widget to get started';
$status = 'ok';
}
elseif (is_file('includes/common/'.$type.'.inc.php')) {

include 'includes/common/'.$type.'.inc.php';
$output = implode('', $common_output);
$status = 'ok';

}

$response = array(
'status' => $status,
'html' => $output,
);

echo _json_encode($response);
8 changes: 1 addition & 7 deletions html/ajax_form.php
Expand Up @@ -13,15 +13,9 @@
*/

// FUA
if (isset($_REQUEST['debug'])) {
ini_set('display_errors', 1);
ini_set('display_startup_errors', 0);
ini_set('log_errors', 0);
ini_set('allow_url_fopen', 0);
ini_set('error_reporting', E_ALL);
}

require_once '../includes/defaults.inc.php';
set_debug($_REQUEST['debug']);
require_once '../config.php';
require_once '../includes/definitions.inc.php';
require_once 'includes/functions.inc.php';
Expand Down
9 changes: 1 addition & 8 deletions html/ajax_listports.php
Expand Up @@ -11,15 +11,8 @@
* @copyright (C) 2006 - 2012 Adam Armstrong
*/

if (isset($_GET['debug'])) {
ini_set('display_errors', 1);
ini_set('display_startup_errors', 0);
ini_set('log_errors', 0);
ini_set('allow_url_fopen', 0);
ini_set('error_reporting', E_ALL);
}

require_once '../includes/defaults.inc.php';
set_debug($_REQUEST['debug']);
require_once '../config.php';
require_once '../includes/definitions.inc.php';
require_once 'includes/functions.inc.php';
Expand Down
1 change: 1 addition & 0 deletions html/ajax_rulesuggest.php
Expand Up @@ -29,6 +29,7 @@
}

require_once '../includes/defaults.inc.php';
set_debug($_REQUEST['debug']);
require_once '../config.php';
require_once '../includes/definitions.inc.php';
require_once '../includes/functions.php';
Expand Down
9 changes: 1 addition & 8 deletions html/ajax_search.php
@@ -1,14 +1,7 @@
<?php

if (isset($_REQUEST['debug'])) {
ini_set('display_errors', 1);
ini_set('display_startup_errors', 0);
ini_set('log_errors', 0);
ini_set('allow_url_fopen', 0);
ini_set('error_reporting', E_ALL);
}

require_once '../includes/defaults.inc.php';
set_debug($_REQUEST['debug']);
require_once '../config.php';
require_once '../includes/definitions.inc.php';
require_once 'includes/functions.inc.php';
Expand Down
9 changes: 1 addition & 8 deletions html/ajax_table.php
Expand Up @@ -12,15 +12,8 @@
* the source code distribution for details.
*/

if (isset($_REQUEST['debug'])) {
ini_set('display_errors', 1);
ini_set('display_startup_errors', 0);
ini_set('log_errors', 0);
ini_set('allow_url_fopen', 0);
ini_set('error_reporting', E_ALL);
}

require_once '../includes/defaults.inc.php';
set_debug($_REQUEST['debug']);
require_once '../config.php';
require_once '../includes/definitions.inc.php';
require_once 'includes/functions.inc.php';
Expand Down
1 change: 1 addition & 0 deletions html/css/jquery.gridster.min.css
63 changes: 63 additions & 0 deletions html/css/styles.css
Expand Up @@ -1654,6 +1654,69 @@ tr.search:nth-child(odd) {
color: #FFFFFF;
}

.gridster * {
margin:0;
}

.grid ul {
list-style-type: none;
}

.gridster li {
font-size: 1em;
font-weight: bold;
text-align: center;
line-height: 100%;
}


.gridster {
margin: 0 auto;

opacity: .8;

-webkit-transition: opacity .6s;
-moz-transition: opacity .6s;
-o-transition: opacity .6s;
-ms-transition: opacity .6s;
transition: opacity .6s;
}

.gridster .gs-w {
background: #ffffff;
box-shadow: inset 0 0 2px #000;
color: 000000
cursor: pointer;
-webkit-border-radius: 4px;
-moz-border-radius: 4px;
border-radius: 4px;

}

.gridster .player {
background: #BBB;
}


.gridster .preview-holder {
border: none!important;
background: red!important;
}

.widget_header {
padding: 0.8em;
background-color: #000000;
color: #ffffff;
-webkit-border-top-left-radius: 4px;
-moz-border-top-right-radius: 4px;
border-top-left-radius: 4px;
border-top-right-radius: 4px;
}

.widget_body {
padding: 0.8em;
}

.mapTooltip {
position : fixed;
background-color : #B2B3B1;
Expand Down
59 changes: 59 additions & 0 deletions html/forms/update-dashboard-config.inc.php
@@ -0,0 +1,59 @@
<?php

$status = 'error';
$message = 'Error updating user dashboard config';

$data = json_decode($_POST['data'],true);
$sub_type = mres($_POST['sub_type']);
$widget_id = mres($_POST['widget_id']);

if ($sub_type == 'remove' && is_numeric($widget_id)) {
if ($widget_id == 0 || dbDelete('users_widgets','`user_id`=? AND `user_widget_id`=?', array($_SESSION['user_id'],$widget_id))) {
$status = 'ok';
$message = '';
}
}
elseif ($sub_type == 'remove-all') {
if (dbDelete('users_widgets','`user_id`=?', array($_SESSION['user_id']))) {
$status = 'ok';
$message = '';
}
}
elseif ($sub_type == 'add' && is_numeric($widget_id)) {
$dupe_check = dbFetchCEll('SELECT `user_widget_id` FROM `users_widgets` WHERE `user_id`=? AND `widget_id`=?',array($_SESSION['user_id'],$widget_id));

if (is_numeric($dupe_check)) {
$message = 'This widget has already been added';
}
else {

$widget = dbFetchRow('SELECT * FROM `widgets` WHERE `widget_id`=?', array($widget_id));
if (is_array($widget)) {
list($x,$y) = explode(',',$widget['base_dimensions']);
$item_id = dbInsert(array('user_id'=>$_SESSION['user_id'],'widget_id'=>$widget_id,'title'=>$widget['widget_title'],'size_x'=>$x,'size_y'=>$y),'users_widgets');
if (is_numeric($item_id)) {
$extra = array('widget_id'=>$widget_id,'title'=>$widget['widget_title'],'widget'=>$widget['widget'],'size_x'=>$x,'size_y'=>$y);
$status = 'ok';
$message = '';
}
}
}
}
else {
$status = 'ok';
$message = '';

foreach ($data as $line) {
if (is_array($line)) {
$update = array('col'=>$line['col'],'row'=>$line['row'],'size_x'=>$line['size_x'],'size_y'=>$line['size_y']);
dbUpdate($update, 'users_widgets', '`user_widget_id`=?', array($line['id']));
}
}
}

$response = array(
'status' => $status,
'message' => $message,
'extra' => $extra,
);
echo _json_encode($response);
@@ -1,3 +1,6 @@
<?php

$common_output[] = '
<div class="row">
<div class="col-sm-12">
<span id="message"></span>
Expand Down Expand Up @@ -25,39 +28,39 @@
{
return {
id: "alerts",
device_id: '<?php echo $device['device_id']; ?>'
device_id: \'' . $device['device_id'] .'\'
};
},
url: "/ajax_table.php",
formatters: {
"status": function(column,row) {
return "<h4><span class='label label-"+row.extra+" threeqtr-width'>" + row.msg + "</span></h4>";
return "<h4><span class=\'label label-"+row.extra+" threeqtr-width\'>" + row.msg + "</span></h4>";
},
"ack": function(column,row) {
return "<button type='button' class='btn btn-"+row.ack_col+" btn-sm command-ack-alert' data-target='#ack-alert' data-state='"+row.state+"' data-alert_id='"+row.alert_id+"' name='ack-alert' id='ack-alert' data-extra='"+row.extra+"'><span class='glyphicon glyphicon-"+row.ack_ico+"'aria-hidden='true'></span></button>";
return "<button type=\'button\' class=\'btn btn-"+row.ack_col+" btn-sm command-ack-alert\' data-target=\'#ack-alert\' data-state=\'"+row.state+"\' data-alert_id=\'"+row.alert_id+"\' name=\'ack-alert\' id=\'ack-alert\' data-extra=\'"+row.extra+"\'><span class=\'glyphicon glyphicon-"+row.ack_ico+"\'aria-hidden=\'true\'></span></button>";
}
},
templates: {
}
}).on("loaded.rs.jquery.bootgrid", function() {
grid.find(".incident-toggle").each( function() {
$(this).parent().addClass('incident-toggle-td');
$(this).parent().addClass(\'incident-toggle-td\');
}).on("click", function(e) {
var target = $(this).data("target");
$(target).collapse('toggle');
$(this).toggleClass('glyphicon-plus glyphicon-minus');
$(target).collapse(\'toggle\');
$(this).toggleClass(\'glyphicon-plus glyphicon-minus\');
});
grid.find(".incident").each( function() {
$(this).parent().addClass('col-lg-4 col-md-4 col-sm-4 col-xs-4');
$(this).parent().addClass(\'col-lg-4 col-md-4 col-sm-4 col-xs-4\');
$(this).parent().parent().on("mouseenter", function() {
$(this).find(".incident-toggle").fadeIn(200);
}).on("mouseleave", function() {
$(this).find(".incident-toggle").fadeOut(200);
}).on("click", "td:not(.incident-toggle-td)", function() {
var target = $(this).parent().find(".incident-toggle").data("target");
if( $(this).parent().find(".incident-toggle").hasClass('glyphicon-plus') ) {
$(this).parent().find(".incident-toggle").toggleClass('glyphicon-plus glyphicon-minus');
$(target).collapse('toggle');
if( $(this).parent().find(".incident-toggle").hasClass(\'glyphicon-plus\') ) {
$(this).parent().find(".incident-toggle").toggleClass(\'glyphicon-plus glyphicon-minus\');
$(target).collapse(\'toggle\');
}
});
});
Expand All @@ -70,15 +73,17 @@
url: "/ajax_form.php",
data: { type: "ack-alert", alert_id: alert_id, state: state },
success: function(msg){
$("#message").html('<div class="alert alert-info">'+msg+'</div>');
$("#message").html(\'<div class="alert alert-info">\'+msg+\'</div>\');
if(msg.indexOf("ERROR:") <= -1) {
location.reload();
}
},
error: function(){
$("#message").html('<div class="alert alert-info">An error occurred acking this alert.</div>');
$("#message").html(\'<div class="alert alert-info">An error occurred acking this alert.</div>\');
}
});
});
});
</script>
</script>';


0 comments on commit b01fa8a

Please sign in to comment.