92 lines
3.1 KiB
Vue
92 lines
3.1 KiB
Vue
<script setup>
|
|
import BasicInfoBanner from "components/banners/BasicInfoBanner.vue";
|
|
import FlightFromPlanForm from "components/flightPlans/FlightFromPlanForm.vue";
|
|
import {computed} from "vue";
|
|
import {useRouter} from "vue-router";
|
|
import {errorObject, successObject} from "src/composables/dialog";
|
|
import {useFlightsStore} from "stores/Flights";
|
|
import {useFlightPlanUtils} from "src/composables/flightPlan";
|
|
import {useQuasar} from "quasar";
|
|
|
|
const props = defineProps({
|
|
flightPlan: {
|
|
type: Object,
|
|
required: true
|
|
}
|
|
});
|
|
|
|
const {getMarkersFrom} = useFlightPlanUtils();
|
|
|
|
const takeoffAirport = computed(() => {
|
|
const markers = getMarkersFrom(props.flightPlan)
|
|
return markers[0].type === 'airport' ? markers[0] : null;
|
|
})
|
|
|
|
const landingAirport = computed(() => {
|
|
const markers = getMarkersFrom(props.flightPlan);
|
|
const lastMarker = markers[markers.length - 1];
|
|
|
|
return lastMarker.type === 'airport' ? lastMarker : null;
|
|
})
|
|
|
|
const $q = useQuasar();
|
|
const $router = useRouter();
|
|
const createNewFlightFromPlan = (formData) => {
|
|
const markers = getMarkersFrom(formData.flightPlan);
|
|
const takeoff = markers.shift();
|
|
const landing = markers.pop();
|
|
|
|
if ((takeoff.type !== 'airport' || landing.type !== 'airport') && !formData.gpxTrackFile) {
|
|
$q.notify(errorObject("Zkontroluj letiště vzletu a přistání. Aktuálně zvolené hodnoty se jako letiště nezdají. Pro pokračování uprav buď plán, nebo zkus nahrát trasu v GPX."));
|
|
return;
|
|
}
|
|
|
|
const track = [];
|
|
if (formData.copyTrack) {
|
|
|
|
// TODO: po ulozeni mapPoint/geocode??? upravit i trasu v planu - predelat ten mapPoint na POI s IDckem
|
|
|
|
for (const i in markers) {
|
|
const marker = markers[i];
|
|
if (i === 0 || i === markers.length - 1 || marker.type === 'mapPoint') continue;
|
|
|
|
const obj = {
|
|
[marker.type === 'airport' ? 'airport' : 'pointOfInterest']: {
|
|
id: marker.airportId || marker.pointOfInterestId || null,
|
|
name: marker.name,
|
|
},
|
|
gpsLatitude: marker.gpsLatitude,
|
|
gpsLongitude: marker.gpsLongitude
|
|
};
|
|
track.push(obj);
|
|
}
|
|
}
|
|
|
|
useFlightsStore().create({
|
|
name: formData.flightPlan.name,
|
|
aircraft: {id: formData.flightPlan.aircraft.id, name: formData.flightPlan.aircraft.callSign},
|
|
flightPlanId: formData.flightPlan.id,
|
|
takeoffAirport: takeoff ? {id: takeoff.airportId, name: takeoff.name} : null,
|
|
landingAirport: landing ? {id: landing.airportId, name: landing.name} : null,
|
|
gpxTrackFile: formData.gpxTrackFile,
|
|
takeoffDatetime: formData.takeoffDatetime,
|
|
landingDatetime: formData.landingDatetime,
|
|
track
|
|
}).then(res => {
|
|
$q.notify(successObject("Let úspěšně vytvořen. Nyní můžeš nastavit detaily."))
|
|
$router.push({name: 'flightEdit', params: {id: res.id, step: 'copilot'}});
|
|
});
|
|
}
|
|
</script>
|
|
|
|
<template>
|
|
<BasicInfoBanner v-if="!takeoffAirport || !landingAirport" color="error">
|
|
V plánu nemáš žádné letiště vzletu nebo přistání. Pro import letu musíš nahrát trasu.
|
|
</BasicInfoBanner>
|
|
<FlightFromPlanForm
|
|
v-bind="$attrs"
|
|
:flight-plan="flightPlan"
|
|
@save="createNewFlightFromPlan"
|
|
/>
|
|
</template>
|