Files
librenms-librenms/app/View/Components/PortLink.php
Tony Murray c5b63bde86 New Blade Components: x-device-link, x-port-link, x-graph-row, x-popup (#13197)
* working popover

* popup component

* cleanup

* finalize device-link component

* attributes WIP

* working graph component

* widgets WIP

* More dynamic configs

* Graph row component

* Build CSS so we can use a dark theme

* graph row set columns

* only one popup visible at a time.

* Just set graph row width statically

* responsive WIP

* rsponsive option for graph-row "working"

* remove @deviceLink and @portLink

* fix non-responsive graph row

* update js/css

* fix style

* bad type?

* types

* types

* types #3

* remove testing code

* full rebel, no closing tags for meta and link

* match previous formatting

* fix vlans display

* restore newline

* remove silly comment

* remove unused line

* style I guess
2021-09-10 08:07:08 -05:00

93 lines
2.1 KiB
PHP

<?php
namespace App\View\Components;
use App\Models\Port;
use Illuminate\Support\Arr;
use Illuminate\View\Component;
use LibreNMS\Util\Rewrite;
use LibreNMS\Util\Url;
class PortLink extends Component
{
/**
* @var \App\Models\Port
*/
public $port;
/**
* @var string
*/
public $link;
/**
* @var array|string|string[]
*/
public $label;
/**
* @var string
*/
public $description;
/**
* @var array|array[]
*/
public $graphs;
/**
* @var string
*/
public $status;
/**
* Create a new component instance.
*
* @return void
*/
public function __construct(Port $port, ?array $graphs = null)
{
$this->port = $port;
$this->link = Url::portUrl($port);
$this->label = Rewrite::normalizeIfName($port->getLabel());
$this->description = $port->getDescription();
$this->status = $this->status();
$this->graphs = $graphs === null ? [
['type' => 'port_bits', 'title' => trans('Traffic'), 'vars' => [['from' => '-1d'], ['from' => '-7d'], ['from' => '-30d'], ['from' => '-1y']]],
] : Arr::wrap($graphs);
if ($this->description == $this->label) {
$this->description = '';
}
}
/**
* Get the view / contents that represent the component.
*
* @return \Illuminate\Contracts\View\View|\Closure|string
*/
public function render()
{
return view('components.port-link');
}
private function status(): string
{
if ($this->port->ifAdminStatus == 'down') {
return 'disabled';
}
return $this->port->ifAdminStatus == 'up' && $this->port->ifOperStatus != 'up'
? 'down'
: 'up';
}
public function fillDefaultVars(array $vars): array
{
return array_map(function ($graph_vars) {
return array_merge([
'from' => '-1d',
'type' => 'port_bits',
'legend' => 'yes',
'text' => '',
], Arr::wrap($graph_vars));
}, $vars);
}
}