mirror of
https://github.com/librenms/librenms.git
synced 2024-10-07 16:52:45 +00:00
* Handle missing device when linking Sometimes a device is gone, but data still points to it. Prevent error when that happens (even though it should not) * Handle more gracefully * Remove original work around * Allow unsaved devices, we just need device_id really
71 lines
1.6 KiB
PHP
71 lines
1.6 KiB
PHP
<?php
|
|
|
|
namespace App\View\Components;
|
|
|
|
use App\Facades\DeviceCache;
|
|
use App\Models\Device;
|
|
use Illuminate\View\Component;
|
|
use LibreNMS\Util\Graph;
|
|
|
|
class DeviceLink extends Component
|
|
{
|
|
/**
|
|
* @var \App\Models\Device
|
|
*/
|
|
public $device;
|
|
/**
|
|
* @var string|null
|
|
*/
|
|
public $tab;
|
|
/**
|
|
* @var string|null
|
|
*/
|
|
public $section;
|
|
/**
|
|
* @var string
|
|
*/
|
|
public $status;
|
|
|
|
/**
|
|
* Create a new component instance.
|
|
*
|
|
* @param int|\App\Models\Device $device
|
|
*/
|
|
public function __construct($device, ?string $tab = null, ?string $section = null)
|
|
{
|
|
$this->device = $device instanceof Device ? $device : DeviceCache::get($device);
|
|
$this->tab = $tab;
|
|
$this->section = $section;
|
|
$this->status = $this->status();
|
|
}
|
|
|
|
/**
|
|
* Get the view / contents that represent the component.
|
|
*
|
|
* @return \Illuminate\Contracts\View\View|\Closure|string
|
|
*/
|
|
public function render()
|
|
{
|
|
if (empty($this->device->device_id)) {
|
|
return view('components.device-link-missing');
|
|
}
|
|
|
|
if (! $this->device->canAccess(auth()->user())) {
|
|
return view('components.device-link-no-access');
|
|
}
|
|
|
|
return view('components.device-link', [
|
|
'graphs' => Graph::getOverviewGraphsForDevice($this->device),
|
|
]);
|
|
}
|
|
|
|
public function status(): string
|
|
{
|
|
if ($this->device->disabled) {
|
|
return 'disabled';
|
|
}
|
|
|
|
return $this->device->status ? 'up' : ($this->device->ignore ? 'disabled' : 'down');
|
|
}
|
|
}
|