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:
SourceDoctor
2021-09-03 15:58:09 +02:00
committed by GitHub
parent 4f50c3c05d
commit ada7bae84c
5 changed files with 39 additions and 13 deletions

View File

@ -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;
}
}

View File

@ -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
*/

View File

@ -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;
}
}

View File

@ -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,

View File

@ -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.',