Skip to content

Commit

Permalink
Revert "Device settings: attempt to open related tab (librenms#14250)"
Browse files Browse the repository at this point in the history
This reverts commit 673ad55.
  • Loading branch information
Martin22 committed Sep 5, 2022
1 parent 6fda23b commit 7680bb3
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 27 deletions.
31 changes: 4 additions & 27 deletions app/Http/Controllers/DeviceController.php
Expand Up @@ -90,7 +90,7 @@ public function index(Request $request, $device, $current_tab = 'overview', $var
$data = $tabs[$current_tab]->data($device);

// Device Link Menu, select the primary link
$device_links = $this->deviceLinkMenu($device, $current_tab);
$device_links = $this->deviceLinkMenu($device);
$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);
Expand Down Expand Up @@ -150,33 +150,15 @@ private function buildDeviceGraphArrays($device)
return $graphs;
}

private function deviceLinkMenu(Device $device, string $current_tab): array
private function deviceLinkMenu(Device $device)
{
$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, $suffix]),
'title' => $title,
'url' => route('device', [$device->device_id, 'edit']),
'title' => __('Edit'),
'external' => false,
];
}
Expand Down Expand Up @@ -230,9 +212,4 @@ private function deviceLinkMenu(Device $device, string $current_tab): array

return $device_links;
}

private function editTabExists(string $tab): bool
{
return is_file(base_path("includes/html/pages/device/edit/$tab.inc.php"));
}
}
5 changes: 5 additions & 0 deletions phpstan-baseline.neon
Expand Up @@ -7115,6 +7115,11 @@ 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
Expand Down

0 comments on commit 7680bb3

Please sign in to comment.