mirror of
https://github.com/librenms/librenms.git
synced 2024-10-07 16:52:45 +00:00
Locations UI and editing (#9480)
* Better handling of errors Mapquest seems to return the center of the US on error....... * Editable locations WIP * Change to bootgrid ajax table WIP * Graphs working, using handlebars update js libs add current location button * remove sql query, change icon * Add the map to the device view, only when gps is expanded. Allow edit on device page, share js code * fix chevron rotation, improve click area * extra warning * fix overview layout (remove containers) * fix style * fix html divs, change collapse ui a bit move css, update css/js versions * start zoomed out on new locations * don't double load scripts, zoom to 17 * fix php-md errors, remove unused use statement * improve non-admin experience * Move locations page to Laravel More functions in Url and Html util classes reduce code duplication * translation buttons too * fix whitespace * move formatters to the frontend * small changes * disable traffic for locations with no devices * change down 0 to green from gray * missing " * Fix paginate all * working fix for paginate all * allow sort by counts * fix down sort * a little safety * Don't call the function twice * btn-xs
This commit is contained in:
@@ -0,0 +1,77 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Models\Location;
|
||||
use Illuminate\Http\Request;
|
||||
use LibreNMS\Config;
|
||||
use LibreNMS\Util\Html;
|
||||
|
||||
class LocationController extends Controller
|
||||
{
|
||||
public function index()
|
||||
{
|
||||
$maps_api = Config::get('geoloc.api_key');
|
||||
$data = [
|
||||
'maps_api' => $maps_api,
|
||||
'maps_engine' => $maps_api ? Config::get('geoloc.engine') : '',
|
||||
];
|
||||
|
||||
|
||||
$data['graph_template'] = '';
|
||||
Config::set('enable_lazy_load', false);
|
||||
$graph_array = [
|
||||
'type' => 'location_bits',
|
||||
'height' => '100',
|
||||
'width' => '220',
|
||||
'legend' => 'no',
|
||||
'id' => '{{id}}',
|
||||
];
|
||||
foreach (Html::graphRow($graph_array) as $graph) {
|
||||
$data['graph_template'] .= "<div class='col-md-3'>";
|
||||
$data['graph_template'] .= str_replace('%7B%7Bid%7D%7D', '{{id}}', $graph); // restore handlebars
|
||||
$data['graph_template'] .= "</div>";
|
||||
}
|
||||
|
||||
return view('locations', $data);
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the specified resource in storage.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @param Location $location
|
||||
* @return \Illuminate\Http\Response
|
||||
* @throws \Illuminate\Auth\Access\AuthorizationException
|
||||
*/
|
||||
public function update(Request $request, Location $location)
|
||||
{
|
||||
$this->authorize('admin', $request->user());
|
||||
|
||||
$this->validate($request, [
|
||||
'lat' => 'required|numeric|max:90|min:-90',
|
||||
'lng' => 'required|numeric|max:180|min:-180',
|
||||
]);
|
||||
|
||||
$location->fill($request->only(['lat', 'lng']));
|
||||
$location->save();
|
||||
|
||||
return response()->json(['status' => 'success']);
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove the specified resource from storage.
|
||||
*
|
||||
* @param Location $location
|
||||
* @return \Illuminate\Http\Response
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function destroy(Request $request, Location $location)
|
||||
{
|
||||
$this->authorize('admin', $request->user());
|
||||
|
||||
$location->delete();
|
||||
|
||||
return response()->json(['status' => 'success']);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user