mirror of
https://github.com/librenms/librenms.git
synced 2024-10-07 16:52:45 +00:00
default port group in Settings (#13175)
* default port group in Settings * . * wrap query with try catch * update config schema * change to select2 * . * . * inject no default port group choice * Paginator * .
This commit is contained in:
@ -26,7 +26,6 @@
|
|||||||
namespace App\Http\Controllers\Select;
|
namespace App\Http\Controllers\Select;
|
||||||
|
|
||||||
use App\Models\PollerGroup;
|
use App\Models\PollerGroup;
|
||||||
use Illuminate\Support\Str;
|
|
||||||
|
|
||||||
class PollerGroupController extends SelectController
|
class PollerGroupController extends SelectController
|
||||||
{
|
{
|
||||||
@ -52,15 +51,4 @@ class PollerGroupController extends SelectController
|
|||||||
|
|
||||||
return parent::formatResponse($paginator);
|
return parent::formatResponse($paginator);
|
||||||
}
|
}
|
||||||
|
|
||||||
private function includeGeneral(): bool
|
|
||||||
{
|
|
||||||
if (request()->has('id') && request('id') !== 0) {
|
|
||||||
return false;
|
|
||||||
} elseif (request()->has('term') && ! Str::contains('general', strtolower(request('term')))) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -38,6 +38,19 @@ class PortGroupController extends SelectController
|
|||||||
return PortGroup::hasAccess($request->user())->select(['id', 'name']);
|
return PortGroup::hasAccess($request->user())->select(['id', 'name']);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected function formatResponse($paginator)
|
||||||
|
{
|
||||||
|
// prepend the default group, unless filtered out
|
||||||
|
if ($this->includeGeneral()) {
|
||||||
|
$general = new PortGroup;
|
||||||
|
$general->id = 0;
|
||||||
|
$general->name = 'no default Port Group';
|
||||||
|
$paginator->prepend($general);
|
||||||
|
}
|
||||||
|
|
||||||
|
return parent::formatResponse($paginator);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param PortGroup $port_group
|
* @param PortGroup $port_group
|
||||||
*/
|
*/
|
||||||
|
@ -28,6 +28,7 @@ use App\Http\Controllers\PaginatedAjaxController;
|
|||||||
use Illuminate\Contracts\Pagination\Paginator;
|
use Illuminate\Contracts\Pagination\Paginator;
|
||||||
use Illuminate\Database\Eloquent\Model;
|
use Illuminate\Database\Eloquent\Model;
|
||||||
use Illuminate\Http\Request;
|
use Illuminate\Http\Request;
|
||||||
|
use Illuminate\Support\Str;
|
||||||
|
|
||||||
abstract class SelectController extends PaginatedAjaxController
|
abstract class SelectController extends PaginatedAjaxController
|
||||||
{
|
{
|
||||||
@ -91,4 +92,15 @@ abstract class SelectController extends PaginatedAjaxController
|
|||||||
'text' => $attributes->forget($model->getKeyName())->first(),
|
'text' => $attributes->forget($model->getKeyName())->first(),
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected function includeGeneral(): bool
|
||||||
|
{
|
||||||
|
if (request()->has('id') && request('id') !== 0) {
|
||||||
|
return false;
|
||||||
|
} elseif (request()->has('term') && ! Str::contains('general', strtolower(request('term')))) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -864,7 +864,16 @@
|
|||||||
},
|
},
|
||||||
"default_port_group": {
|
"default_port_group": {
|
||||||
"default": 0,
|
"default": 0,
|
||||||
"type": "integer"
|
"type": "select-dynamic",
|
||||||
|
"group": "discovery",
|
||||||
|
"section": "networks",
|
||||||
|
"order": 0,
|
||||||
|
"options": {
|
||||||
|
"target": "port-group"
|
||||||
|
},
|
||||||
|
"validate": {
|
||||||
|
"value": "integer|zero_or_exists:port_groups,id"
|
||||||
|
}
|
||||||
},
|
},
|
||||||
"device_location_map_open": {
|
"device_location_map_open": {
|
||||||
"order": 2,
|
"order": 2,
|
||||||
|
@ -1185,6 +1185,10 @@ return [
|
|||||||
'description' => 'Max number of routes allowed for discovery',
|
'description' => 'Max number of routes allowed for discovery',
|
||||||
'help' => 'No route will be discovered if the size of the routing table is bigger than this number',
|
'help' => 'No route will be discovered if the size of the routing table is bigger than this number',
|
||||||
],
|
],
|
||||||
|
'default_port_group' => [
|
||||||
|
'description' => 'Default Port Group',
|
||||||
|
'help' => 'New discovered Ports will be assigned to this port Group.',
|
||||||
|
],
|
||||||
'nets' => [
|
'nets' => [
|
||||||
'description' => 'Autodiscovery Networks',
|
'description' => 'Autodiscovery Networks',
|
||||||
'help' => 'Networks from which devices will be discovered automatically.',
|
'help' => 'Networks from which devices will be discovered automatically.',
|
||||||
|
Reference in New Issue
Block a user