mirror of
https://github.com/librenms/librenms.git
synced 2024-10-07 16:52:45 +00:00
* Custom Maps: geo map and color background tabs blade component geo-map blade component and related script enhancements * Update css/js * style fixes * update db_schema.yaml * fix db_schema hand edit * ignore phpstan being wrong * Handle null * another possible null spot * Use standard file cache for custom map background images * Create map->image as jpeg so we can compress it * whitespace fix * Fix background cancel button when other type is selected than the saved type * Save and restore layer * Map must exist before creating static image * Don't show set as image button for Google and Bing. Bing gives an odd error, but Google won't work.
82 lines
2.3 KiB
PHP
82 lines
2.3 KiB
PHP
<?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()
|
|
{
|
|
$data = [
|
|
'maps_config' => [
|
|
'engine' => Config::get('geoloc.engine'),
|
|
'api_key' => Config::get('geoloc.api_key'),
|
|
'tile_url' => Config::get('leaflet.tile_url', '{s}.tile.openstreetmap.org'),
|
|
],
|
|
'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\JsonResponse
|
|
*
|
|
* @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->fixed_coordinates = true; // user has set coordinates, block automated changes
|
|
$location->save();
|
|
|
|
return response()->json(['status' => 'success']);
|
|
}
|
|
|
|
/**
|
|
* Remove the specified resource from storage.
|
|
*
|
|
* @param Location $location
|
|
* @return \Illuminate\Http\JsonResponse
|
|
*
|
|
* @throws \Exception
|
|
*/
|
|
public function destroy(Request $request, Location $location)
|
|
{
|
|
$this->authorize('admin', $request->user());
|
|
|
|
$location->delete();
|
|
|
|
return response()->json(['status' => 'success']);
|
|
}
|
|
}
|