mirror of
https://github.com/librenms/librenms.git
synced 2024-10-07 16:52:45 +00:00
New Map Menu (#15969)
* Map Menu New top level Map menu. Ability to group custom maps. Ajax Select controller improvements * Fix style
This commit is contained in:
@@ -47,6 +47,7 @@ class CustomMapController extends Controller
|
||||
return view('map.custom-manage', [
|
||||
'maps' => CustomMap::orderBy('name')->get(['custom_map_id', 'name']),
|
||||
'name' => 'New Map',
|
||||
'menu_group' => null,
|
||||
'node_align' => 10,
|
||||
'edge_separation' => 10,
|
||||
'reverse_arrows' => 0,
|
||||
@@ -101,6 +102,7 @@ class CustomMapController extends Controller
|
||||
'edit' => false,
|
||||
'map_id' => $map->custom_map_id,
|
||||
'name' => $map->name,
|
||||
'menu_group' => $map->menu_group,
|
||||
'reverse_arrows' => $map->reverse_arrows,
|
||||
'legend' => $this->legendConfig($map),
|
||||
'background' => (bool) $map->background_suffix,
|
||||
@@ -123,6 +125,7 @@ class CustomMapController extends Controller
|
||||
$data = [
|
||||
'map_id' => $map->custom_map_id,
|
||||
'name' => $map->name,
|
||||
'menu_group' => $map->menu_group,
|
||||
'node_align' => $map->node_align,
|
||||
'edge_separation' => $map->edge_separation,
|
||||
'reverse_arrows' => $map->reverse_arrows,
|
||||
@@ -163,6 +166,7 @@ class CustomMapController extends Controller
|
||||
return response()->json([
|
||||
'id' => $map->custom_map_id,
|
||||
'name' => $map->name,
|
||||
'menu_group' => $map->menu_group,
|
||||
'width' => $map->width,
|
||||
'height' => $map->height,
|
||||
'reverse_arrows' => $map->reverse_arrows,
|
||||
|
44
app/Http/Controllers/Select/CustomMapMenuGroupController.php
Normal file
44
app/Http/Controllers/Select/CustomMapMenuGroupController.php
Normal file
@@ -0,0 +1,44 @@
|
||||
<?php
|
||||
/*
|
||||
* CustomMapMenuGroupController.php
|
||||
*
|
||||
* -Description-
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* @package LibreNMS
|
||||
* @link http://librenms.org
|
||||
* @copyright 2024 Tony Murray
|
||||
* @author Tony Murray <murraytony@gmail.com>
|
||||
*/
|
||||
|
||||
namespace App\Http\Controllers\Select;
|
||||
|
||||
use App\Models\CustomMap;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class CustomMapMenuGroupController extends SelectController
|
||||
{
|
||||
protected function searchFields($request): array
|
||||
{
|
||||
return ['menu_group'];
|
||||
}
|
||||
|
||||
protected function baseQuery(Request $request): Builder
|
||||
{
|
||||
return CustomMap::query()->hasAccess($request->user())
|
||||
->whereNotNull('menu_group')->select('menu_group')->groupBy('menu_group');
|
||||
}
|
||||
}
|
@@ -62,19 +62,18 @@ class DashboardController extends SelectController
|
||||
];
|
||||
}
|
||||
|
||||
public function formatResponse($paginator)
|
||||
protected function prependItem(): array
|
||||
{
|
||||
if (! request()->has('term')) {
|
||||
$paginator->prepend((object) ['dashboard_id' => 0]);
|
||||
}
|
||||
|
||||
return parent::formatResponse($paginator);
|
||||
return [
|
||||
'id' => 0,
|
||||
'text' => __('No Default Dashboard'),
|
||||
];
|
||||
}
|
||||
|
||||
private function describe($dashboard): string
|
||||
{
|
||||
if ($dashboard->dashboard_id == 0) {
|
||||
return 'No Default Dashboard';
|
||||
return $this->prependItem()['text'];
|
||||
}
|
||||
|
||||
return "{$dashboard->username}: {$dashboard->dashboard_name} ("
|
||||
|
@@ -39,16 +39,11 @@ class PollerGroupController extends SelectController
|
||||
return PollerGroup::query()->select(['id', 'group_name']);
|
||||
}
|
||||
|
||||
protected function formatResponse($paginator)
|
||||
protected function prependItem(): array
|
||||
{
|
||||
// prepend the default group, unless filtered out
|
||||
if ($this->includeGeneral()) {
|
||||
$general = new PollerGroup;
|
||||
$general->id = 0;
|
||||
$general->group_name = 'General';
|
||||
$paginator->prepend($general);
|
||||
}
|
||||
|
||||
return parent::formatResponse($paginator);
|
||||
return [
|
||||
'id' => 0,
|
||||
'text' => __('General'),
|
||||
];
|
||||
}
|
||||
}
|
||||
|
@@ -32,7 +32,6 @@ use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Query\Builder;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Collection;
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
abstract class SelectController extends PaginatedAjaxController
|
||||
{
|
||||
@@ -78,8 +77,15 @@ abstract class SelectController extends PaginatedAjaxController
|
||||
*/
|
||||
protected function formatResponse($paginator)
|
||||
{
|
||||
$results = collect($paginator->items())->map([$this, 'formatItem']);
|
||||
|
||||
// prepend the initial item, unless filtered out
|
||||
if ($this->canPrependFirstItem(request())) {
|
||||
$results->prepend($this->prependItem());
|
||||
}
|
||||
|
||||
return response()->json([
|
||||
'results' => collect($paginator->items())->map([$this, 'formatItem']),
|
||||
'results' => $results,
|
||||
'pagination' => ['more' => $paginator->hasMorePages()],
|
||||
]);
|
||||
}
|
||||
@@ -111,11 +117,28 @@ abstract class SelectController extends PaginatedAjaxController
|
||||
];
|
||||
}
|
||||
|
||||
protected function includeGeneral(): bool
|
||||
protected function prependItem(): ?array
|
||||
{
|
||||
if (request()->has('id') && request('id') !== 0) {
|
||||
return null;
|
||||
}
|
||||
|
||||
protected function canPrependFirstItem(Request $request): bool
|
||||
{
|
||||
$item = $this->prependItem();
|
||||
|
||||
if (empty($item)) {
|
||||
return false;
|
||||
} elseif (request()->has('term') && ! Str::contains('general', strtolower(request('term')))) {
|
||||
}
|
||||
|
||||
if ($request->page > 1) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if ($request->has('id') && $request->id != $item['id']) { // purposely loose comparison
|
||||
return false;
|
||||
}
|
||||
|
||||
if ($request->has('term') && ! str_contains(strtolower($item['text']), strtolower($request->term))) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@@ -23,7 +23,8 @@ class CustomMapSettingsRequest extends FormRequest
|
||||
public function rules(): array
|
||||
{
|
||||
return [
|
||||
'name' => 'required|string',
|
||||
'name' => 'required|string|max:100',
|
||||
'menu_group' => 'nullable|string|max:100',
|
||||
'node_align' => 'integer',
|
||||
'reverse_arrows' => 'boolean',
|
||||
'edge_separation' => 'integer',
|
||||
|
@@ -78,12 +78,6 @@ class MenuComposer
|
||||
//Dashboards
|
||||
$vars['dashboards'] = Dashboard::select('dashboard_id', 'dashboard_name')->allAvailable($user)->orderBy('dashboard_name')->get();
|
||||
|
||||
//Maps
|
||||
$vars['links'] = Link::exists();
|
||||
$vars['device_dependencies'] = \DB::table('device_relationships')->exists();
|
||||
$vars['device_group_dependencies'] = \DB::table('device_group_device')->exists();
|
||||
$vars['custommaps'] = CustomMap::select('custom_map_id', 'name')->hasAccess($user)->orderBy('name')->get();
|
||||
|
||||
// Device menu
|
||||
$vars['device_groups'] = DeviceGroup::hasAccess($user)->orderBy('name')->get(['device_groups.id', 'name', 'desc']);
|
||||
$vars['package_count'] = Package::hasAccess($user)->count();
|
||||
@@ -95,6 +89,12 @@ class MenuComposer
|
||||
new Collection();
|
||||
$vars['show_vmwinfo'] = Vminfo::hasAccess($user)->exists();
|
||||
|
||||
//Maps
|
||||
$vars['links'] = Link::exists();
|
||||
$vars['device_dependencies'] = \DB::table('device_relationships')->exists();
|
||||
$vars['device_group_dependencies'] = $vars['device_groups']->isNotEmpty() && \DB::table('device_group_device')->exists();
|
||||
$vars['custommaps'] = CustomMap::select(['custom_map_id', 'name', 'menu_group'])->hasAccess($user)->orderBy('name')->get()->groupBy('menu_group')->sortKeys();
|
||||
|
||||
// Service menu
|
||||
if (Config::get('show_services')) {
|
||||
$vars['service_counts'] = ObjectCache::serviceCounts(['warning', 'critical']);
|
||||
|
@@ -41,6 +41,7 @@ class CustomMap extends BaseModel
|
||||
];
|
||||
protected $fillable = [
|
||||
'name',
|
||||
'menu_group',
|
||||
'width',
|
||||
'height',
|
||||
'node_align',
|
||||
|
Reference in New Issue
Block a user