Add airport overview page and links to it #225

This commit is contained in:
Nabeel Shahzad
2018-03-31 15:57:30 -05:00
parent 46f9b3d9b9
commit 0bed38c78b
29 changed files with 380 additions and 56 deletions

View File

@@ -113,6 +113,15 @@ class CreateSettingsTable extends Migration
'description' => 'The units for fuel for display',
]);
$this->addSetting('units.temperature', [
'name' => 'Temperature Units',
'group' => 'units',
'value' => 'f',
'type' => 'select',
'options' => 'f=Fahrenheit,c=Celsius',
'description' => 'The units for temperature',
]);
/**
* BIDS
*/

32
app/Support/Http.php Normal file
View File

@@ -0,0 +1,32 @@
<?php
namespace App\Support;
use GuzzleHttp\Client;
/**
* Helper for HTTP stuff
* @package App\Support
*/
class Http
{
/**
* Download a URI. If a file is given, it will save the downloaded
* content into that file
* @param $uri
* @param array $opts
* @return string
*/
public static function get($uri, array $opts)
{
$client = new Client();
$response = $client->request('GET', $uri, $opts);
$body = $response->getBody()->getContents();
if ($response->getHeader('content-type') === 'application/json') {
$body = \GuzzleHttp\json_decode($body);
}
return $body;
}
}

52
app/Widgets/CheckWx.php Normal file
View File

@@ -0,0 +1,52 @@
<?php
namespace App\Widgets;
use App\Interfaces\Widget;
use App\Support\Http;
/**
* This is a widget for the 3rd party CheckWX service
* @package App\Widgets
*/
class CheckWx extends Widget
{
protected $config = [
'icao' => null,
];
/**
* Attempt to get the data from the CheckWX API
*/
public function run()
{
if (!config('checkwx.api_key')) {
$data = null;
} else {
$url = config('checkwx.url').'/metar/'.$this->config['icao'].'/decoded';
$data = Http::get($url, [
'headers' => [
'X-API-Key' => config('checkwx.api_key'),
'content-type' => 'application/json',
]
]);
$data = json_decode($data);
#dd($data);
if($data->results === 1) {
$data = $data->data[0];
} else {
$data = null;
}
}
return view('widgets.check_wx', [
'config' => $this->config,
'data' => $data,
'unit_alt' => setting('units.altitude'),
'unit_dist' => setting('units.distance'),
'unit_temp' => setting('units.temperature'),
]);
}
}

View File

@@ -195,3 +195,29 @@ if (!function_exists('show_date')) {
return $date->timezone($timezone)->toFormattedDateString();
}
}
if (!function_exists('_fmt')) {
/**
* Replace strings
* @param $line "Hi, my name is :name"
* @param array $replace ['name' => 'Nabeel']
* @return mixed
*/
function _fmt($line, array $replace)
{
if (empty($replace)) {
return $line;
}
foreach ($replace as $key => $value) {
$key = strtolower($key);
$line = str_replace(
[':'.$key],
[$value],
$line
);
}
return $line;
}
}