mirror of
https://github.com/librenms/librenms.git
synced 2024-10-07 16:52:45 +00:00
Device settings: attempt to open related tab (#14250)
* Device settings: attempt to open related tab * remove baseline
This commit is contained in:
@@ -90,7 +90,7 @@ class DeviceController extends Controller
|
||||
$data = $tabs[$current_tab]->data($device);
|
||||
|
||||
// Device Link Menu, select the primary link
|
||||
$device_links = $this->deviceLinkMenu($device);
|
||||
$device_links = $this->deviceLinkMenu($device, $current_tab);
|
||||
$primary_device_link_name = Config::get('html.device.primary_link', 'edit');
|
||||
if (! isset($device_links[$primary_device_link_name])) {
|
||||
$primary_device_link_name = array_key_first($device_links);
|
||||
@@ -149,15 +149,33 @@ class DeviceController extends Controller
|
||||
return $graphs;
|
||||
}
|
||||
|
||||
private function deviceLinkMenu(Device $device)
|
||||
private function deviceLinkMenu(Device $device, string $current_tab): array
|
||||
{
|
||||
$device_links = [];
|
||||
|
||||
if (Gate::allows('update', $device)) {
|
||||
$suffix = 'edit';
|
||||
$title = __('Edit');
|
||||
|
||||
// check if metric has more specific edit page
|
||||
if (preg_match('#health/metric=(\w+)#', \Request::path(), $matches)) {
|
||||
if ($this->editTabExists($matches[1])) {
|
||||
$current_tab = $matches[1];
|
||||
} elseif ($this->editTabExists($matches[1] . 's')) {
|
||||
$current_tab = $matches[1] . 's';
|
||||
}
|
||||
}
|
||||
|
||||
// check if edit page exists
|
||||
if ($this->editTabExists($current_tab)) {
|
||||
$suffix .= "/section=$current_tab";
|
||||
$title .= ' ' . ucfirst($current_tab);
|
||||
}
|
||||
|
||||
$device_links['edit'] = [
|
||||
'icon' => 'fa-gear',
|
||||
'url' => route('device', [$device->device_id, 'edit']),
|
||||
'title' => __('Edit'),
|
||||
'url' => route('device', [$device->device_id, $suffix]),
|
||||
'title' => $title,
|
||||
'external' => false,
|
||||
];
|
||||
}
|
||||
@@ -211,4 +229,9 @@ class DeviceController extends Controller
|
||||
|
||||
return $device_links;
|
||||
}
|
||||
|
||||
private function editTabExists(string $tab): bool
|
||||
{
|
||||
return is_file(base_path("includes/html/pages/device/edit/$tab.inc.php"));
|
||||
}
|
||||
}
|
||||
|
@@ -7115,11 +7115,6 @@ parameters:
|
||||
count: 1
|
||||
path: app/Http/Controllers/DeviceController.php
|
||||
|
||||
-
|
||||
message: "#^Method App\\\\Http\\\\Controllers\\\\DeviceController\\:\\:deviceLinkMenu\\(\\) has no return type specified\\.$#"
|
||||
count: 1
|
||||
path: app/Http/Controllers/DeviceController.php
|
||||
|
||||
-
|
||||
message: "#^Method App\\\\Http\\\\Controllers\\\\DeviceController\\:\\:index\\(\\) has no return type specified\\.$#"
|
||||
count: 1
|
||||
|
Reference in New Issue
Block a user