* #355 Calculate distance button in add/edit Flight page * Styling * Move add/edit flight logic out of controller and into service layer * Styling * Formatting * Run styleci against modules dir * Styleci config * Style fixes in /modules
This commit is contained in:
18
resources/js/admin/airport_lookup.js
Normal file
18
resources/js/admin/airport_lookup.js
Normal file
@@ -0,0 +1,18 @@
|
||||
/**
|
||||
* Lookup an airport from the server
|
||||
* @param icao
|
||||
* @param callback
|
||||
*/
|
||||
export default (icao, callback) => {
|
||||
let params = {
|
||||
method: 'GET',
|
||||
url: '/api/airports/' + icao + '/lookup',
|
||||
};
|
||||
|
||||
console.log('Looking airport up');
|
||||
axios(params)
|
||||
.then(response => {
|
||||
console.log(response);
|
||||
callback(response.data);
|
||||
});
|
||||
};
|
||||
@@ -2,7 +2,14 @@
|
||||
* Admin stuff needed
|
||||
*/
|
||||
|
||||
|
||||
require('./../bootstrap');
|
||||
|
||||
import airport_lookup from "./airport_lookup";
|
||||
import calculate_distance from "./calculate_distance";
|
||||
|
||||
window.phpvms.airport_lookup = airport_lookup;
|
||||
window.phpvms.calculate_distance = calculate_distance;
|
||||
|
||||
// Import the mapping function
|
||||
window.phpvms.map = require('../maps/index');
|
||||
|
||||
19
resources/js/admin/calculate_distance.js
Normal file
19
resources/js/admin/calculate_distance.js
Normal file
@@ -0,0 +1,19 @@
|
||||
/**
|
||||
* Lookup an airport from the server
|
||||
* @param fromICAO
|
||||
* @param toICAO
|
||||
* @param callback
|
||||
*/
|
||||
export default (fromICAO, toICAO, callback) => {
|
||||
let params = {
|
||||
method: 'GET',
|
||||
url: '/api/airports/' + fromICAO + '/distance/' + toICAO,
|
||||
};
|
||||
|
||||
console.log('Calcuating airport distance');
|
||||
axios(params)
|
||||
.then(response => {
|
||||
console.log(response);
|
||||
callback(response.data);
|
||||
});
|
||||
};
|
||||
@@ -51,19 +51,6 @@ function setEditable() {
|
||||
@endif
|
||||
}
|
||||
|
||||
function phpvms_vacentral_airport_lookup(icao, callback) {
|
||||
let params = {
|
||||
method: 'GET',
|
||||
url: '{{ url('/api/airports/') }}/' + icao + '/lookup',
|
||||
};
|
||||
|
||||
axios(params)
|
||||
.then(response => {
|
||||
console.log(response);
|
||||
callback(response.data);
|
||||
});
|
||||
}
|
||||
|
||||
$(document).ready(function() {
|
||||
|
||||
const api_key = $('meta[name="api-key"]').attr('content');
|
||||
@@ -101,7 +88,7 @@ $(document).ready(function() {
|
||||
return;
|
||||
}
|
||||
|
||||
phpvms_vacentral_airport_lookup(icao, function(response) {
|
||||
phpvms.airport_lookup(icao, function(response) {
|
||||
_.forEach(response.data, function(value, key) {
|
||||
if(key === 'city') {
|
||||
key = 'location';
|
||||
|
||||
@@ -69,7 +69,10 @@
|
||||
<div class="form-group col-sm-4">
|
||||
{{ Form::label('dpt_airport_id', 'Departure Airport:') }} <span
|
||||
class="required">*</span>
|
||||
{{ Form::select('dpt_airport_id', $airports, null , ['class' => 'form-control select2']) }}
|
||||
{{ Form::select('dpt_airport_id', $airports, null , [
|
||||
'id' => 'dpt_airport_id',
|
||||
'class' => 'form-control select2'
|
||||
]) }}
|
||||
<p class="text-danger">{{ $errors->first('dpt_airport_id') }}</p>
|
||||
</div>
|
||||
|
||||
@@ -77,7 +80,10 @@
|
||||
<div class="form-group col-sm-4">
|
||||
{{ Form::label('arr_airport_id', 'Arrival Airport:') }} <span
|
||||
class="required">*</span>
|
||||
{{ Form::select('arr_airport_id', $airports, null , ['class' => 'form-control select2']) }}
|
||||
{{ Form::select('arr_airport_id', $airports, null , [
|
||||
'id' => 'arr_airport_id',
|
||||
'class' => 'form-control select2'
|
||||
]) }}
|
||||
<p class="text-danger">{{ $errors->first('arr_airport_id') }}</p>
|
||||
</div>
|
||||
|
||||
@@ -113,7 +119,8 @@
|
||||
|
||||
<div class="form-group col-sm-3">
|
||||
{{ Form::label('distance', 'Distance:') }} <span class="description small">in nautical miles</span>
|
||||
{{ Form::text('distance', null, ['class' => 'form-control']) }}
|
||||
<a href="#" class="airport_distance_lookup">Calculate</a>
|
||||
{{ Form::text('distance', null, ['id' => 'distance', 'class' => 'form-control']) }}
|
||||
<p class="text-danger">{{ $errors->first('distance') }}</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -95,6 +95,21 @@ $(document).ready(function () {
|
||||
setEditable();
|
||||
setFieldsEditable();
|
||||
});
|
||||
|
||||
$('a.airport_distance_lookup').click(function (e) {
|
||||
e.preventDefault();
|
||||
const fromIcao = $("select#dpt_airport_id option:selected").val();
|
||||
const toIcao = $("select#arr_airport_id option:selected").val();
|
||||
if (fromIcao === '' || toIcao === '') {
|
||||
return;
|
||||
}
|
||||
|
||||
console.log(`Calculating from ${fromIcao} to ${toIcao}`);
|
||||
phpvms.calculate_distance(fromIcao, toIcao, function (response) {
|
||||
console.log('Calculate distance:', response);
|
||||
$("#distance").val(response.data.distance.nmi);
|
||||
});
|
||||
});
|
||||
});
|
||||
</script>
|
||||
@endsection
|
||||
|
||||
Reference in New Issue
Block a user