Add ACARS live time/coords/default zoom into admin settings

This commit is contained in:
Nabeel Shahzad
2018-05-16 10:54:01 -05:00
parent a63a784dec
commit da0a7cbe81
9 changed files with 83 additions and 35 deletions

View File

@@ -122,6 +122,35 @@ class CreateSettingsTable extends Migration
'description' => 'The units for temperature',
]);
/**
* ACARS Settings
*/
$this->addSetting('acars.live_time', [
'name' => 'Live Time',
'group' => 'acars',
'value' => 12,
'type' => 'int',
'description' => 'Age of flights to show on the map in hours. '
.'Set to 0 to show only all in-progress flights',
]);
$this->addSetting('acars.center_coords', [
'name' => 'Center Coords',
'group' => 'acars',
'value' => '30.1945,-97.6699',
'type' => 'text',
'description' => 'Where to center the map; enter as LAT,LON',
]);
$this->addSetting('acars.default_zoom', [
'name' => 'Default Zoom',
'group' => 'acars',
'value' => 5,
'type' => 'int',
'description' => 'Initial zoom level on the map',
]);
/**
* BIDS
*/

View File

@@ -7,6 +7,7 @@ use App\Models\Acars;
use App\Models\Enums\AcarsType;
use App\Models\Enums\PirepState;
use App\Models\Pirep;
use Carbon\Carbon;
/**
* Class AcarsRepository
@@ -51,14 +52,21 @@ class AcarsRepository extends Repository
/**
* Get all of the PIREPS that are in-progress, and then
* get the latest update for those flights
* @param int $live_time Age in hours of the oldest flights to show
* @return Pirep
*/
public function getPositions()
public function getPositions($live_time = 0)
{
return Pirep::with(['airline', 'position', 'aircraft'])
->where(['state' => PirepState::IN_PROGRESS])
->orderBy('created_at', 'desc')
->get();
$q = Pirep::with(['airline', 'position', 'aircraft'])
->where(['state' => PirepState::IN_PROGRESS]);
if($live_time !== null && $live_time > 0) {
$st = Carbon::now('UTC')->subHours($live_time);
$q = $q->whereDate('created_at', '>=', $st);
}
$q = $q->orderBy('created_at', 'desc');
return $q->get();
}
/**

View File

@@ -25,13 +25,20 @@ class LiveMap extends Widget
$geoSvc = app(GeoService::class);
$acarsRepo = app(AcarsRepository::class);
$pireps = $acarsRepo->getPositions();
$pireps = $acarsRepo->getPositions(setting('acars.live_time', 0));
$positions = $geoSvc->getFeatureForLiveFlights($pireps);
$center_coords = setting('acars.center_coords', '0,0');
$center_coords = array_map(function($c) {
return (float) trim($c);
}, explode(',', $center_coords));
return view('widgets.live_map', [
'config' => $this->config,
'pireps' => $pireps,
'positions' => $positions,
'config' => $this->config,
'pireps' => $pireps,
'positions' => $positions,
'center' => $center_coords,
'zoom' => setting('acars.default_zoom', 5),
]);
}
}