Merge pull request #2884 from QuxLabs/issue-2877

Added custom titles to graph widget
This commit is contained in:
Neil Lathwood
2016-01-29 09:54:00 +00:00
+18 -5
View File
@@ -1,5 +1,5 @@
<?php <?php
/* Copyright (C) 2015 Daniel Preussker, QuxLabs UG <preussker@quxlabs.com> /* Copyright (C) 2015-2016 Daniel Preussker, QuxLabs UG <preussker@quxlabs.com>
* This program is free software: you can redistribute it and/or modify * 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 * it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or * the Free Software Foundation, either version 3 of the License, or
@@ -16,7 +16,7 @@
/** /**
* Generic Graph Widget * Generic Graph Widget
* @author Daniel Preussker * @author Daniel Preussker
* @copyright 2015 Daniel Preussker, QuxLabs UG * @copyright 2015-2016 Daniel Preussker, QuxLabs UG
* @license GPL * @license GPL
* @package LibreNMS * @package LibreNMS
* @subpackage Widgets * @subpackage Widgets
@@ -25,6 +25,14 @@
if( defined('show_settings') || empty($widget_settings) ) { if( defined('show_settings') || empty($widget_settings) ) {
$common_output[] = ' $common_output[] = '
<form class="form" onsubmit="widget_settings(this); return false;"> <form class="form" onsubmit="widget_settings(this); return false;">
<div class="form-group">
<div class="col-sm-2">
<label for="title" class="control-label">Title: </label>
</div>
<div class="col-sm-10">
<input type="text" class="form-control" name="title" placeholder="Automatic Title" value="'.htmlspecialchars($widget_settings['title']).'">
</div>
</div>
<div class="form-group"> <div class="form-group">
<div class="col-sm-2"> <div class="col-sm-2">
<label for="graph_type" class="control-label">Graph: </label> <label for="graph_type" class="control-label">Graph: </label>
@@ -365,12 +373,13 @@ $(function() {
</script>'; </script>';
} }
else { else {
$widget_settings['title'] = "";
$type = explode('_',$widget_settings['graph_type'],2); $type = explode('_',$widget_settings['graph_type'],2);
$type = array_shift($type); $type = array_shift($type);
$widget_settings['graph_'.$type] = json_decode($widget_settings['graph_'.$type],true)?:$widget_settings['graph_'.$type]; $widget_settings['graph_'.$type] = json_decode($widget_settings['graph_'.$type],true)?:$widget_settings['graph_'.$type];
if ($type == 'device') { if ($type == 'device') {
if (empty($widget_settings['title'])) {
$widget_settings['title'] = $widget_settings['graph_device']['name']." / ".$widget_settings['graph_type']; $widget_settings['title'] = $widget_settings['graph_device']['name']." / ".$widget_settings['graph_type'];
}
$param = 'device='.$widget_settings['graph_device']['device_id']; $param = 'device='.$widget_settings['graph_device']['device_id'];
} }
elseif ($type == 'application') { elseif ($type == 'application') {
@@ -399,17 +408,21 @@ else {
$tmp[] = $port['port_id']; $tmp[] = $port['port_id'];
} }
$param = 'id='.implode(',',$tmp); $param = 'id='.implode(',',$tmp);
$widget_settings['graph_type']= 'multiport_bits_separate'; $widget_settings['graph_type'] = 'multiport_bits_separate';
if (empty($widget_settings['title'])) {
$widget_settings['title'] = 'Overall '.ucfirst($type).' Bits ('.$widget_settings['graph_range'].')'; $widget_settings['title'] = 'Overall '.ucfirst($type).' Bits ('.$widget_settings['graph_range'].')';
} }
}
elseif ($type == 'custom') { elseif ($type == 'custom') {
foreach (dbFetchRows("SELECT port_id FROM `ports` WHERE `port_descr_type` = ? ORDER BY ifAlias", array($widget_settings['graph_custom'])) as $port) { foreach (dbFetchRows("SELECT port_id FROM `ports` WHERE `port_descr_type` = ? ORDER BY ifAlias", array($widget_settings['graph_custom'])) as $port) {
$tmp[] = $port['port_id']; $tmp[] = $port['port_id'];
} }
$param = 'id='.implode(',',$tmp); $param = 'id='.implode(',',$tmp);
$widget_settings['graph_type']= 'multiport_bits_separate'; $widget_settings['graph_type'] = 'multiport_bits_separate';
if (empty($widget_settings['title'])) {
$widget_settings['title'] = 'Overall '.ucfirst(htmlspecialchars($widget_settings['graph_custom'])).' Bits ('.$widget_settings['graph_range'].')'; $widget_settings['title'] = 'Overall '.ucfirst(htmlspecialchars($widget_settings['graph_custom'])).' Bits ('.$widget_settings['graph_range'].')';
} }
}
else { else {
$param = 'id='.$widget_settings['graph_'.$type][$type.'_id']; $param = 'id='.$widget_settings['graph_'.$type][$type.'_id'];
} }