Widget Eventlog Sensors Link and Mouseover functionality (#11380)

* Global Settings - Alert Default Settings

* Revert "Global Settings - Alert Default Settings"

This reverts commit a1af62b146.

* Widget Eventlog - Sensors link and overlib Image

* travis fix

* handling via AppServiceProvider

* collect function

* Travis ...

* static list of Sensor Types

* adding all sensor graph_types

* remove collect

* correct getTypes - remove change to lower case

* class sensor_descr switch

* class sensor_descr switch - revert

* Use standard sensor type names

* move types to attribute list

* going back to changes from 9eee7fad58

Co-authored-by: Tony Murray <murraytony@gmail.com>
This commit is contained in:
SourceDoctor
2020-04-19 19:57:49 +02:00
committed by GitHub
parent bb9ebb4e45
commit cc2894c0df
7 changed files with 167 additions and 32 deletions

View File

@@ -171,6 +171,53 @@ class Url
return Rewrite::normalizeIfName($text);
}
/**
* @param Sensor $sensor
* @param string $text
* @param string $type
* @param boolean $overlib
* @param boolean $single_graph
* @return mixed|string
*/
public static function sensorLink($sensor, $text = null, $type = null, $overlib = true, $single_graph = false)
{
$label = $sensor->sensor_descr;
if (!$text) {
$text = $label;
}
$content = '<div class=list-large>' . addslashes(htmlentities($sensor->device->displayName() . ' - ' . $label)) . '</div>';
$content .= "<div style=\'width: 850px\'>";
$graph_array = [
'type' => $type ?: 'sensor_' . $sensor->sensor_class,
'legend' => 'yes',
'height' => 100,
'width' => 340,
'to' => Carbon::now()->timestamp,
'from' => Carbon::now()->subDay()->timestamp,
'id' => $sensor->sensor_id,
];
$content .= self::graphTag($graph_array);
if (!$single_graph) {
$graph_array['from'] = Carbon::now()->subWeek()->timestamp;
$content .= self::graphTag($graph_array);
$graph_array['from'] = Carbon::now()->subMonth()->timestamp;
$content .= self::graphTag($graph_array);
$graph_array['from'] = Carbon::now()->subYear()->timestamp;
$content .= self::graphTag($graph_array);
}
$content .= '</div>';
if (!$overlib) {
return $content;
}
return self::overlibLink(self::sensorUrl($sensor), $text, $content, self::sensorLinkDisplayClass($sensor));
}
public static function deviceUrl($device, $vars = [])
{
return self::generate(['page' => 'device', 'device' => $device->device_id], $vars);
@@ -181,6 +228,11 @@ class Url
return self::generate(['page' => 'device', 'device' => $port->device_id, 'tab' => 'port', 'port' => $port->port_id], $vars);
}
public static function sensorUrl($sensor, $vars = [])
{
return self::generate(['page' => 'device', 'device' => $sensor->device_id, 'tab' => 'health' , 'metric' => $sensor->sensor_class], $vars);
}
/**
* @param Port $port
* @return string
@@ -369,6 +421,25 @@ class Url
return "interface-upup";
}
/**
* Get html class for a sensor
*
* @param Sensor $sensor
* @return string
*/
public static function sensorLinkDisplayClass($sensor)
{
if ($sensor->sensor_current >> $sensor->sensor_limit) {
return "sensor-high";
}
if ($sensor->sensor_current << $sensor->sensor_limit_low) {
return "sensor-low";
}
return 'sensor-ok';
}
/**
* @param string $os
* @param string $feature