From 2f9dcc8fbd24e3d5b8c3c7c34773e4700fc59294 Mon Sep 17 00:00:00 2001 From: laf Date: Tue, 21 Jul 2015 23:01:57 +0100 Subject: [PATCH] Initial dashboard, code formatting is bad + lots needs tidying up --- Makefile | 3 + html/ajax_dash.php | 54 +++++ html/css/jquery.gridster.min.css | 1 + html/css/styles.css | 62 ++++++ html/forms/update-dashboard-config.inc.php | 45 ++++ html/includes/common/alerts.inc.php | 89 ++++++++ html/includes/common/availability-map.inc.php | 45 ++++ .../common/device-summary-horiz.inc.php | 52 +++++ html/index.php | 1 + html/js/jquery.gridster.min.js | 1 + html/pages/front/tiles.php | 202 ++++++++++++++++++ 11 files changed, 555 insertions(+) create mode 100644 html/ajax_dash.php create mode 120000 html/css/jquery.gridster.min.css create mode 100644 html/forms/update-dashboard-config.inc.php create mode 100644 html/includes/common/alerts.inc.php create mode 100644 html/includes/common/availability-map.inc.php create mode 100644 html/includes/common/device-summary-horiz.inc.php create mode 120000 html/js/jquery.gridster.min.js create mode 100644 html/pages/front/tiles.php diff --git a/Makefile b/Makefile index 43d50197c0..58cd633c31 100644 --- a/Makefile +++ b/Makefile @@ -46,3 +46,6 @@ 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 diff --git a/html/ajax_dash.php b/html/ajax_dash.php new file mode 100644 index 0000000000..5336cef769 --- /dev/null +++ b/html/ajax_dash.php @@ -0,0 +1,54 @@ + + * + * 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. + */ + +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'; +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); diff --git a/html/css/jquery.gridster.min.css b/html/css/jquery.gridster.min.css new file mode 120000 index 0000000000..8529b9ed9e --- /dev/null +++ b/html/css/jquery.gridster.min.css @@ -0,0 +1 @@ +../../lib/gridster/dist/jquery.gridster.min.css \ No newline at end of file diff --git a/html/css/styles.css b/html/css/styles.css index 69ae991a8f..13662682f5 100644 --- a/html/css/styles.css +++ b/html/css/styles.css @@ -1654,3 +1654,65 @@ 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; +} + +.tile_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; +} + +.tile_body { + padding: 0.8em; +} diff --git a/html/forms/update-dashboard-config.inc.php b/html/forms/update-dashboard-config.inc.php new file mode 100644 index 0000000000..ea44f11d39 --- /dev/null +++ b/html/forms/update-dashboard-config.inc.php @@ -0,0 +1,45 @@ +$_SESSION['user_id'],'widget_id'=>$tile_id,'title'=>$tile['tile_title'],'content'=>$tile['tile'],'size_x'=>$x,'size_y'=>$y),'dashboard_items'); + if (is_numeric($item_id)) { + $extra = array('item_id'=>$item_id,'title'=>$tile['tile_title'],'content'=>$tile['tile'],'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, 'dashboard_items', '`dashboard_item_id`=?', array($line['id'])); + } + } +} + +$response = array( + 'status' => $status, + 'message' => $message, + 'extra' => $extra, +); +echo _json_encode($response); diff --git a/html/includes/common/alerts.inc.php b/html/includes/common/alerts.inc.php new file mode 100644 index 0000000000..7f347f9168 --- /dev/null +++ b/html/includes/common/alerts.inc.php @@ -0,0 +1,89 @@ + +
+ +
+ +
+ + + + + + + + + + + + +
StatusRule HostnameTimestampSeverityAcknowledge
+
+'; + + diff --git a/html/includes/common/availability-map.inc.php b/html/includes/common/availability-map.inc.php new file mode 100644 index 0000000000..d8c68becb8 --- /dev/null +++ b/html/includes/common/availability-map.inc.php @@ -0,0 +1,45 @@ + +* 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. +*/ + +$sql = "SELECT `D`.`hostname`,`D`.`device_id`,`D`.`status`,`D`.`uptime` FROM `devices` AS `D`"; + +if (is_admin() === false && is_read() === false) { + $sql .= " , `devices_perms` AS P WHERE D.`device_id` = P.`device_id` AND P.`user_id` = ? AND"; + $param = array($_SESSION['user_id']); +} +else { + $sql .= " WHERE"; +} + +$sql .= " `D`.`ignore` = '0' AND `D`.`disabled` = '0' ORDER BY `hostname`"; + +$temp_output = array(); + +foreach(dbFetchRows($sql,$param) as $device) { + if ($device['status'] == '1') { + $btn_type = 'btn-success'; + if ($device['uptime'] < $config['uptime_warning']) { + $btn_type = 'btn-warning'; + } + } + else { + $btn_type = 'btn-danger'; + } + $temp_output[] = " 'device', 'device' => $device['device_id'])). "' role='button' class='btn " . $btn_type . " btn-xs' title='" . $device['hostname'] . "' style='min-height:25px; min-width:25px; border-radius:0px; border:0px; margin:0; padding:0;'>"; +} + +$temp_rows = count($temp_output); + +$temp_output[] = ""; +$temp_header = array("

All Devices(" . $temp_rows . ")

"); +$common_output = array_merge($temp_header,$temp_output); + diff --git a/html/includes/common/device-summary-horiz.inc.php b/html/includes/common/device-summary-horiz.inc.php new file mode 100644 index 0000000000..6a33213cdb --- /dev/null +++ b/html/includes/common/device-summary-horiz.inc.php @@ -0,0 +1,52 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + '; +if ($config['show_services']) { + +$temp_output .= ' + + + + + + + + '; +} +$temp_output .= ' + +
 TotalUpDownIgnoredDisabled
Devices'.$devices['count'].' '.$devices['up'].' up '.$devices['down'].' down '.$devices['ignored'].' ignored '.$devices['disabled'].' disabled
Ports'.$ports['count'].' '.$ports['up'].' up '.$ports['down'].' down '.$ports['ignored'].' ignored '.$ports['shutdown'].' shutdown
Services'.$services['count'].''.$services['up'].' up '.$services['down'].' down '.$services['ignored'].' ignored '.$services['disabled'].' disabled
+
+'; + +$common_output[] = $temp_output; diff --git a/html/index.php b/html/index.php index 9dc7a454ad..98c3d8fee1 100644 --- a/html/index.php +++ b/html/index.php @@ -138,6 +138,7 @@ else { + diff --git a/html/js/jquery.gridster.min.js b/html/js/jquery.gridster.min.js new file mode 120000 index 0000000000..0209b9c12f --- /dev/null +++ b/html/js/jquery.gridster.min.js @@ -0,0 +1 @@ +../../lib/gridster/dist/jquery.gridster.min.js \ No newline at end of file diff --git a/html/pages/front/tiles.php b/html/pages/front/tiles.php new file mode 100644 index 0000000000..0150af456d --- /dev/null +++ b/html/pages/front/tiles.php @@ -0,0 +1,202 @@ +'0','widget_id'=>1,'title'=>'Add a widget','content'=>'placeholder','col'=>1,'row'=>1,'size_x'=>1,'size_y'=>1,'refresh'=>60); +} + +$data = serialize(_json_encode($data)); +$dash_config = unserialize(stripslashes($data)); + +$new_tile = ' + +'; + +?> + + + + + +
+
+
+
    +
+
+
+ +