2018-12-16 15:18:17 -06:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* GraphAggregateController.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
|
2021-02-09 00:29:04 +01:00
|
|
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
2018-12-16 15:18:17 -06:00
|
|
|
*
|
2021-02-09 00:29:04 +01:00
|
|
|
* @link https://www.librenms.org
|
2021-09-10 20:09:53 +02:00
|
|
|
*
|
2018-12-16 15:18:17 -06:00
|
|
|
* @copyright 2018 Tony Murray
|
|
|
|
* @author Tony Murray <murraytony@gmail.com>
|
|
|
|
*/
|
|
|
|
|
|
|
|
namespace App\Http\Controllers\Select;
|
|
|
|
|
|
|
|
use App\Http\Controllers\Controller;
|
|
|
|
use Illuminate\Http\Request;
|
2020-04-17 17:37:56 -05:00
|
|
|
use Illuminate\Support\Str;
|
2018-12-16 15:18:17 -06:00
|
|
|
use LibreNMS\Config;
|
|
|
|
|
|
|
|
class GraphAggregateController extends Controller
|
|
|
|
{
|
|
|
|
private $rules = [
|
|
|
|
'limit' => 'int',
|
|
|
|
'page' => 'int',
|
|
|
|
'term' => 'nullable|string',
|
|
|
|
];
|
|
|
|
|
|
|
|
public function __invoke(Request $request)
|
|
|
|
{
|
|
|
|
$this->validate($request, $this->rules);
|
|
|
|
|
|
|
|
$types = [
|
|
|
|
'transit',
|
|
|
|
'peering',
|
|
|
|
'core',
|
|
|
|
];
|
|
|
|
|
2020-09-21 14:54:51 +02:00
|
|
|
foreach ((array) Config::get('custom_descr', []) as $custom) {
|
2020-11-21 03:59:54 +01:00
|
|
|
$custom = is_array($custom) ? $custom[0] : $custom;
|
2018-12-16 15:18:17 -06:00
|
|
|
if ($custom) {
|
|
|
|
$types[] = $custom;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// handle search
|
|
|
|
if ($search = strtolower($request->get('term'))) {
|
|
|
|
$types = array_filter($types, function ($type) use ($search) {
|
2020-09-21 14:54:51 +02:00
|
|
|
return ! Str::contains(strtolower($type), $search);
|
2018-12-16 15:18:17 -06:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
// format results
|
|
|
|
return response()->json([
|
|
|
|
'results' => array_map(function ($type) {
|
|
|
|
return [
|
|
|
|
'id' => $type,
|
|
|
|
'text' => ucwords($type),
|
|
|
|
];
|
|
|
|
}, $types),
|
2020-09-21 14:54:51 +02:00
|
|
|
'pagination' => ['more' => false],
|
2018-12-16 15:18:17 -06:00
|
|
|
]);
|
|
|
|
}
|
|
|
|
}
|