diff --git a/app/Http/Controllers/Select/PollerGroupController.php b/app/Http/Controllers/Select/PollerGroupController.php index 327360bbb4..337b9739bf 100644 --- a/app/Http/Controllers/Select/PollerGroupController.php +++ b/app/Http/Controllers/Select/PollerGroupController.php @@ -26,7 +26,6 @@ namespace App\Http\Controllers\Select; use App\Models\PollerGroup; -use Illuminate\Support\Str; class PollerGroupController extends SelectController { @@ -52,15 +51,4 @@ class PollerGroupController extends SelectController 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; - } } diff --git a/app/Http/Controllers/Select/PortGroupController.php b/app/Http/Controllers/Select/PortGroupController.php index 744859f83a..dbe458eabb 100644 --- a/app/Http/Controllers/Select/PortGroupController.php +++ b/app/Http/Controllers/Select/PortGroupController.php @@ -38,6 +38,19 @@ class PortGroupController extends SelectController 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 */ diff --git a/app/Http/Controllers/Select/SelectController.php b/app/Http/Controllers/Select/SelectController.php index 857cdb93fe..6851ecb92b 100644 --- a/app/Http/Controllers/Select/SelectController.php +++ b/app/Http/Controllers/Select/SelectController.php @@ -28,6 +28,7 @@ use App\Http\Controllers\PaginatedAjaxController; use Illuminate\Contracts\Pagination\Paginator; use Illuminate\Database\Eloquent\Model; use Illuminate\Http\Request; +use Illuminate\Support\Str; abstract class SelectController extends PaginatedAjaxController { @@ -91,4 +92,15 @@ abstract class SelectController extends PaginatedAjaxController '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; + } } diff --git a/misc/config_definitions.json b/misc/config_definitions.json index 2715bf45e2..deb69c0a48 100644 --- a/misc/config_definitions.json +++ b/misc/config_definitions.json @@ -864,7 +864,16 @@ }, "default_port_group": { "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": { "order": 2, diff --git a/resources/lang/en/settings.php b/resources/lang/en/settings.php index 018ab12cd6..611cad5483 100644 --- a/resources/lang/en/settings.php +++ b/resources/lang/en/settings.php @@ -1185,6 +1185,10 @@ return [ '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', ], + 'default_port_group' => [ + 'description' => 'Default Port Group', + 'help' => 'New discovered Ports will be assigned to this port Group.', + ], 'nets' => [ 'description' => 'Autodiscovery Networks', 'help' => 'Networks from which devices will be discovered automatically.',