mirror of
https://github.com/librenms/librenms.git
synced 2024-10-07 16:52:45 +00:00
Linkable graph component (#13263)
* Linkable graph component * indentation change
This commit is contained in:
@@ -45,6 +45,10 @@ class Graph extends Component
|
|||||||
* @var int
|
* @var int
|
||||||
*/
|
*/
|
||||||
public $absolute_size;
|
public $absolute_size;
|
||||||
|
/**
|
||||||
|
* @var bool|string
|
||||||
|
*/
|
||||||
|
private $link;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a new component instance.
|
* Create a new component instance.
|
||||||
@@ -61,8 +65,20 @@ class Graph extends Component
|
|||||||
* @param \App\Models\Device|int|null $device
|
* @param \App\Models\Device|int|null $device
|
||||||
* @param \App\Models\Port|int|null $port
|
* @param \App\Models\Port|int|null $port
|
||||||
*/
|
*/
|
||||||
public function __construct(string $type = '', array $vars = [], $from = '-1d', $to = null, string $legend = 'no', string $aspect = 'normal', ?int $width = null, ?int $height = null, int $absolute_size = 0, $device = null, $port = null)
|
public function __construct(
|
||||||
{
|
string $type = '',
|
||||||
|
array $vars = [],
|
||||||
|
$from = '-1d',
|
||||||
|
$to = null,
|
||||||
|
string $legend = 'no',
|
||||||
|
string $aspect = 'normal',
|
||||||
|
?int $width = null,
|
||||||
|
?int $height = null,
|
||||||
|
int $absolute_size = 0,
|
||||||
|
$link = true,
|
||||||
|
$device = null,
|
||||||
|
$port = null
|
||||||
|
) {
|
||||||
$this->type = $type;
|
$this->type = $type;
|
||||||
$this->vars = $vars;
|
$this->vars = $vars;
|
||||||
$this->from = $from;
|
$this->from = $from;
|
||||||
@@ -71,6 +87,7 @@ class Graph extends Component
|
|||||||
$this->absolute_size = $absolute_size;
|
$this->absolute_size = $absolute_size;
|
||||||
$this->width = $width ?: ($aspect == 'wide' ? self::DEFAULT_WIDE_WIDTH : self::DEFAULT_NORMAL_WIDTH);
|
$this->width = $width ?: ($aspect == 'wide' ? self::DEFAULT_WIDE_WIDTH : self::DEFAULT_NORMAL_WIDTH);
|
||||||
$this->height = $height ?: ($aspect == 'wide' ? self::DEFAULT_WIDE_HEIGHT : self::DEFAULT_NORMAL_HEIGHT);
|
$this->height = $height ?: ($aspect == 'wide' ? self::DEFAULT_WIDE_HEIGHT : self::DEFAULT_NORMAL_HEIGHT);
|
||||||
|
$this->link = $link;
|
||||||
|
|
||||||
// handle device and port ids/models for convenience could be set in $vars
|
// handle device and port ids/models for convenience could be set in $vars
|
||||||
if ($device instanceof Device) {
|
if ($device instanceof Device) {
|
||||||
@@ -91,8 +108,21 @@ class Graph extends Component
|
|||||||
*/
|
*/
|
||||||
public function render()
|
public function render()
|
||||||
{
|
{
|
||||||
|
if ($this->link === false) {
|
||||||
return view('components.graph', [
|
return view('components.graph', [
|
||||||
'link' => url('graph.php') . '?' . http_build_query($this->vars + [
|
'src' => $this->getSrc(),
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
return view('components.linked-graph', [
|
||||||
|
'link' => $this->getLink(),
|
||||||
|
'src' => $this->getSrc(),
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
private function getSrc(): string
|
||||||
|
{
|
||||||
|
return url('graph.php') . '?' . http_build_query($this->vars + [
|
||||||
'type' => $this->type,
|
'type' => $this->type,
|
||||||
'legend' => $this->legend,
|
'legend' => $this->legend,
|
||||||
'absolute_size' => $this->absolute_size,
|
'absolute_size' => $this->absolute_size,
|
||||||
@@ -100,7 +130,25 @@ class Graph extends Component
|
|||||||
'height' => $this->height,
|
'height' => $this->height,
|
||||||
'from' => $this->from,
|
'from' => $this->from,
|
||||||
'to' => $this->to,
|
'to' => $this->to,
|
||||||
]),
|
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private function getLink(): string
|
||||||
|
{
|
||||||
|
if ($this->link === true) {
|
||||||
|
$url = url('graphs') . '/' . http_build_query($this->vars + [
|
||||||
|
'type' => $this->type,
|
||||||
|
'from' => $this->from,
|
||||||
|
'to' => $this->to,
|
||||||
|
], '', '/');
|
||||||
|
|
||||||
|
return $url;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($this->link === false) {
|
||||||
|
return '';
|
||||||
|
}
|
||||||
|
|
||||||
|
return $this->link;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@@ -1 +1 @@
|
|||||||
<img width="{{ $width }}" height="{{ $height }}" src="{{ $link }}" alt="{{ $type }}" {{ $attributes->merge(['class' => 'graph-image']) }}>
|
<img width="{{ $width }}" height="{{ $height }}" src="{{ $src }}" alt="{{ $type }}" {{ $attributes->merge(['class' => 'graph-image']) }}>
|
||||||
|
1
resources/views/components/linked-graph.blade.php
Normal file
1
resources/views/components/linked-graph.blade.php
Normal file
@@ -0,0 +1 @@
|
|||||||
|
<a href="{{ $link }}"><img width="{{ $width }}" height="{{ $height }}" src="{{ $src }}" alt="{{ $type }}" {{ $attributes->merge(['class' => 'graph-image']) }}></a>
|
Reference in New Issue
Block a user