Files
librenms-librenms/app/View/Components/PortLink.php
T
075ba4c932 Ports UI update (#16115)
* WIP Device Ports porting to Laravel

* WIP port links

* Port Links WIP

* Port Links

* in_array -> isset

* Add request to DeviceTab data

* Add initial Pagination

* Missing select component

* Collapsed and expandable port neighbors
New expandable component

* Port sorting

* Fix port transfer

* Use menu entries to filter ports

* Add translatable strings

* style fixes and cleanup

* update css

* graph views and tidy controller
basic port link view

* cleanup

* port row blade to reuse in legacy port view

* Legacy tab url handling
work properly in subdirectory
remove includes from sub tab directory to prevent oddity

* fallback to detail list when the view doesn't exist

* Use named variable to simplify

* Fix issue from file that was a symlink

* Submenu handle sub items and query string urls

* extract pageLinks to improve readability

* fix typo

* Apply fixes from StyleCI

* phpstan was not happy using the relationship HasMany query

* Don't allow *bps etc to be on a second line

* Improve table on small screens

* Fix sort

---------

Co-authored-by: Tony Murray <[email protected]>
2024-06-16 11:29:06 -05:00

97 lines
2.3 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;
public bool $basic;
/**
* Create a new component instance.
*
* @return void
*/
public function __construct(Port $port, ?array $graphs = null, bool $basic = false)
{
$this->basic = $basic;
$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 $this->basic
? view('components.port-link_basic')
: 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);
}
}