diff --git a/src/components/flights/FlightForm.vue b/src/components/flights/FlightForm.vue deleted file mode 100644 index 64a97a2..0000000 --- a/src/components/flights/FlightForm.vue +++ /dev/null @@ -1,213 +0,0 @@ - - - - - - - - {{ formData }} - - - - - - - - - - - - - - - - - - - - - - - - - - Vzlet - - - - - - - - - Přistání - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/src/components/flights/__FlightForm.vue b/src/components/flights/__FlightForm.vue new file mode 100644 index 0000000..1897504 --- /dev/null +++ b/src/components/flights/__FlightForm.vue @@ -0,0 +1,88 @@ + + + + + + + + {{ formData }} + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/components/flights/form/FlightFormBasic.vue b/src/components/flights/form/FlightFormBasic.vue new file mode 100644 index 0000000..edecb52 --- /dev/null +++ b/src/components/flights/form/FlightFormBasic.vue @@ -0,0 +1,148 @@ + + + + + + {{ formData }} + + {{ flight }} + + + + + + + + + + + + + + + + Vzlet + + + + + + + + + + + + + + Přistání + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/components/flights/form/FlightFormCopilot.vue b/src/components/flights/form/FlightFormCopilot.vue new file mode 100644 index 0000000..b5e5851 --- /dev/null +++ b/src/components/flights/form/FlightFormCopilot.vue @@ -0,0 +1,35 @@ + + + + + + + + + + + + + + + diff --git a/src/components/flights/form/FlightFormNotes.vue b/src/components/flights/form/FlightFormNotes.vue new file mode 100644 index 0000000..d65f940 --- /dev/null +++ b/src/components/flights/form/FlightFormNotes.vue @@ -0,0 +1,34 @@ + + + + + + + + diff --git a/src/components/flights/form/FlightFormPhotos.vue b/src/components/flights/form/FlightFormPhotos.vue new file mode 100644 index 0000000..52dc99e --- /dev/null +++ b/src/components/flights/form/FlightFormPhotos.vue @@ -0,0 +1,26 @@ + + + + + + + Test date: {{testDate}} => {{ parseDate(testDate) }} + + + + diff --git a/src/components/flights/form/FlightFormSteps.vue b/src/components/flights/form/FlightFormSteps.vue new file mode 100644 index 0000000..1c42ad8 --- /dev/null +++ b/src/components/flights/form/FlightFormSteps.vue @@ -0,0 +1,66 @@ + + + + + + + + + + + + diff --git a/src/components/inputs/DatetimePicker.vue b/src/components/inputs/DatetimePicker.vue index e76258e..9aa600b 100644 --- a/src/components/inputs/DatetimePicker.vue +++ b/src/components/inputs/DatetimePicker.vue @@ -1,17 +1,18 @@ + + + + diff --git a/src/composables/datetimeUtils.js b/src/composables/datetimeUtils.js index 444a3bb..e6e64b1 100644 --- a/src/composables/datetimeUtils.js +++ b/src/composables/datetimeUtils.js @@ -4,9 +4,35 @@ export const minutesToHumanReadable = (totalMinutes) => { return `${hours}h ${minutes}min` } -export const formatDate = (date) => { +export const formatDate = (date, format = "DD. MM. YYYY") => { if (typeof date === 'string') { - date = new Date(date); + date = parseDate(date); } - return date.getDate()+". "+date.getMonth()+". "+date.getFullYear(); + + return format + .replace("DD", date.getDate().toString()) + .replace("MM", (date.getMonth() + 1).toString()) + .replace("YYYY", date.getFullYear().toString()); +} + + +export const parseDate = (datetime) => { + // const [date, time] = datetime.split("T"); + // const [year, month, day] = date.split("-"); + // const [hour, minute] = time.split(":"); + // + // const dateObject = new Date(year, month, day, hour, minute, 0); + // ^ tohle funguje ok + + + const timestamp = Date.parse(datetime); + const now = new Date(); + const dateObject = new Date(timestamp); + // dateObject.setHours(dateObject.getHours() + now.getTimezoneOffset()); + // console.log("date", date); + // console.log("time", time); + // console.log("month", month, dateObject.getMonth(), dateObject.getUTCMonth()); + // console.log("day", day, dateObject.getDate(), dateObject.getUTCDate()); + + return dateObject; } diff --git a/src/composables/flight.js b/src/composables/flight.js new file mode 100644 index 0000000..717e15b --- /dev/null +++ b/src/composables/flight.js @@ -0,0 +1,8 @@ +export const flightName = (flight) => { + const date = flight.takeoffDatetime;//.getDay() + ". " + flight.takeoffDatetime.getMonth() + ". " + flight.takeoffDatetime.getFullYear(); + if (flight.name !== '') { + return `${flight.name} (${date}})` + } else { + return `${flight.takeoffAirport.icaoCode} - ${flight.takeoffAirport.icaoCode} (${date})`; + } +} diff --git a/src/composables/form/formHandling.js b/src/composables/form/formHandling.js index d0914ce..d674963 100644 --- a/src/composables/form/formHandling.js +++ b/src/composables/form/formHandling.js @@ -1,15 +1,12 @@ export const setDefaultData = (formData, defaultData) => { - console.log("setting default data ", formData, defaultData); - const ignoredFields = ['__typename']; - for (const key in defaultData) { + for (const key in formData) { if (ignoredFields.includes(key)) continue; - if (typeof formData[key] === 'undefined') { - console.error(`Key ${key} not in formData, skipping!`) + if (typeof defaultData[key] === 'undefined') { + console.error(`Key ${key} not in defaultData, skipping!`) continue; } formData[key] = defaultData[key]; } } - diff --git a/src/graphql/fragments/flight.js b/src/graphql/fragments/flight.js index f4d23c6..f81ee78 100644 --- a/src/graphql/fragments/flight.js +++ b/src/graphql/fragments/flight.js @@ -8,20 +8,18 @@ fragment flightFullInfo on Flight { takeoffDatetime landingDatetime durationMinCalculated - - + solo takeoffAirport { - id name + icaoCode } landingAirport { - id name + icaoCode } - aircraft { id name @@ -30,6 +28,14 @@ fragment flightFullInfo on Flight { } `; +export const FRAGMENT_FLIGHT_EDIT_IDS = gql` +fragment flightEditIds on Flight { + landingAirportId + takeoffAirportId + aircraftId + copilotId +} +`; // export const FRAGMENT_LOCATION = gql` // fragment airportInfo on Airport { diff --git a/src/graphql/mutations/flight.js b/src/graphql/mutations/flight.js index f94d3b2..aa6b33d 100644 --- a/src/graphql/mutations/flight.js +++ b/src/graphql/mutations/flight.js @@ -10,3 +10,13 @@ mutation createFlight($input: CreateFlightInput!) { ${FRAGMENT_FLIGHT_FULL_INFO} ` + +export const EDIT_FLIGHT = gql` +mutation editFlight($id: Int!, $input: EditFlightInput!) { + editFlight(id: $id, input: $input) { + ...flightFullInfo + } + } + + ${FRAGMENT_FLIGHT_FULL_INFO} +`; diff --git a/src/graphql/queries/flights.js b/src/graphql/queries/flights.js index 1205824..aa4908d 100644 --- a/src/graphql/queries/flights.js +++ b/src/graphql/queries/flights.js @@ -1,5 +1,5 @@ import gql from "graphql-tag"; -import {FRAGMENT_FLIGHT_FULL_INFO} from "src/graphql/fragments/flight"; +import {FRAGMENT_FLIGHT_EDIT_IDS, FRAGMENT_FLIGHT_FULL_INFO} from "src/graphql/fragments/flight"; export const FLIGHTS_LIST = gql` query FlightsList { @@ -14,9 +14,11 @@ export const FLIGHT_DETAIL = gql` query FlightDetail($id: Int!) { flight(id: $id) { ...flightFullInfo + ...flightEditIds } } ${FRAGMENT_FLIGHT_FULL_INFO} +${FRAGMENT_FLIGHT_EDIT_IDS} `; diff --git a/src/pages/profile/forms/FlightEditPage.vue b/src/pages/profile/forms/FlightEditPage.vue index 8d71de1..12069ef 100644 --- a/src/pages/profile/forms/FlightEditPage.vue +++ b/src/pages/profile/forms/FlightEditPage.vue @@ -1,7 +1,104 @@ - flight edit + loading + + + + Moje lety + {{ flightName(flight) }} + Editace + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/pages/profile/forms/FlightLogPage.vue b/src/pages/profile/forms/FlightLogPage.vue index 9ac05f3..0508130 100644 --- a/src/pages/profile/forms/FlightLogPage.vue +++ b/src/pages/profile/forms/FlightLogPage.vue @@ -6,8 +6,10 @@ import {useRouter} from "vue-router"; import {usePointsOfInterestStore} from "stores/PointsOfInterest"; import {storeToRefs} from "pinia"; import {useMeta} from "quasar"; -import FlightForm from "components/flights/FlightForm.vue"; +import FlightForm from "components/flights/__FlightForm.vue"; import {useAirportsStore} from "stores/Airports"; +import FlightFormSteps from "components/flights/form/FlightFormSteps.vue"; +import FlightFormBasic from "components/flights/form/FlightFormBasic.vue"; const aircraftsStore = useAircraftsStore(); const poiStore = usePointsOfInterestStore(); @@ -27,26 +29,15 @@ const aircrafts = storeToRefs(aircraftsStore).items; const locations = storeToRefs(poiStore).items; const airports = storeToRefs(airportStore).items; -const turnPointsCount = ref(1); - -// watch(() => formData.takeOffLocation, (newVal) => { -// if (!formData.landingLocation) { -// formData.landingLocation = locations.value.find(l => l.id === newVal); -// } -// }) - const router = useRouter(); const handleSave = (formData) => { - flightsStore.create(formData).then(() => { - router.push({name: "myFlights"}); + flightsStore.create(formData).then((flight) => { + router.push({name: "flightEdit", params: {id: flight.id, step: "copilot"}}); }); } +const formStep = ref("basic") -const removeTurnPoint = (idx) => { - formData.turnPoints.splice(idx, 1); - turnPointsCount.value--; -} @@ -58,7 +49,8 @@ const removeTurnPoint = (idx) => { - + + diff --git a/src/router/routes.js b/src/router/routes.js index ba33db1..b23379b 100644 --- a/src/router/routes.js +++ b/src/router/routes.js @@ -20,7 +20,7 @@ const routes = [ {path: 'my-flights', name: "myFlights", component: () => import('pages/profile/lists/FlightsPage.vue')}, {path: 'my-flights/add', name: "addFlight", component: () => import('pages/profile/forms/FlightLogPage.vue')}, {path: 'my-flights/:id', name: "flightDetail", component: () => import('pages/profile/details/FlightDetailPage.vue')}, - {path: 'my-flights/:id/edit', name: "flightEdit", component: () => import('pages/profile/forms/FlightEditPage.vue')}, + {path: 'my-flights/:id/edit/:step?', name: "flightEdit", component: () => import('pages/profile/forms/FlightEditPage.vue')}, {path: 'poi', name: "poi", component: () => import('pages/profile/lists/PointsOfInterestPage.vue')}, {path: 'poi/:id', name: "poiDetail", component: () => import('pages/profile/details/PointOfInterestDetailPage.vue')}, {path: 'pilots', name: "pilots", component: () => import('pages/profile/lists/SecondPilotPage.vue')}, diff --git a/src/stores/Flights.js b/src/stores/Flights.js index 898cb03..e4b2141 100644 --- a/src/stores/Flights.js +++ b/src/stores/Flights.js @@ -1,7 +1,7 @@ import {defineStore} from 'pinia' import {apolloWrapper} from "src/graphql/apollo" import {FLIGHT_DETAIL, FLIGHTS_LIST} from "src/graphql/queries/flights"; -import {CREATE_FLIGHT} from "src/graphql/mutations/flight"; +import {EDIT_FLIGHT, CREATE_FLIGHT} from "src/graphql/mutations/flight"; export const useFlightsStore = defineStore('Flights', { state: () => ({ @@ -23,7 +23,16 @@ export const useFlightsStore = defineStore('Flights', { return data.createFlight; }) }, + update(id, formData) { + return apolloWrapper.mutate(EDIT_FLIGHT, {id: id, input: formData}).then(({data}) => { + console.log("Pridat update ve storu") + return data.editFlight; + }); + }, fetchDetail(id) { + if (typeof id !== "number") { + id = parseInt(id); + } return apolloWrapper.query(FLIGHT_DETAIL, {id}).then(result => result.data.flight); }, fetch() { diff --git a/yarn.lock b/yarn.lock index 1fced6d..decc76c 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2086,6 +2086,11 @@ minimist@^1.2.6: resolved "https://registry.yarnpkg.com/minimist/-/minimist-1.2.8.tgz#c1a464e7693302e082a075cee0c057741ac4772c" integrity sha512-2yyAR8qBkN3YuheJanUpWC5U3bb5osDywNB8RzDVlDwDHbocAJveqqj1u8+SVD7jkWT4yvsHCpWqqWqAxb0zCA== +moment@^2.29.4: + version "2.29.4" + resolved "https://registry.yarnpkg.com/moment/-/moment-2.29.4.tgz#3dbe052889fe7c1b2ed966fcb3a77328964ef108" + integrity sha512-5LC9SOxjSc2HF6vO2CyuTDNivEdoz2IvyJJGj6X8DJ0eFyfszE0QiEd+iXmBvUP3WHxSjFH/vIsA0EN00cgr8w== + ms@2.0.0: version "2.0.0" resolved "https://registry.yarnpkg.com/ms/-/ms-2.0.0.tgz#5608aeadfc00be6c2901df5f9861788de0d597c8"
{{ formData }}