User can add/edit flights
This commit is contained in:
@@ -21,7 +21,7 @@ class FlightController extends Controller
|
|||||||
return [
|
return [
|
||||||
'flight_number' => ['nullable', 'string', 'max:10'],
|
'flight_number' => ['nullable', 'string', 'max:10'],
|
||||||
'departure_date' => ['required', 'date'],
|
'departure_date' => ['required', 'date'],
|
||||||
'arrival_date' => ['required', 'date', 'after:departure_date'],
|
'arrival_date' => ['required', 'date'],
|
||||||
'from_id' => ['required', 'integer', 'exists:airports,id'],
|
'from_id' => ['required', 'integer', 'exists:airports,id'],
|
||||||
'to_id' => ['required', 'integer', 'exists:airports,id'],
|
'to_id' => ['required', 'integer', 'exists:airports,id'],
|
||||||
'airline_id' => ['nullable', 'integer', 'exists:airlines,id'],
|
'airline_id' => ['nullable', 'integer', 'exists:airlines,id'],
|
||||||
|
|||||||
@@ -30,9 +30,11 @@ class SearchController extends Controller
|
|||||||
public function aircraft()
|
public function aircraft()
|
||||||
{
|
{
|
||||||
$q = request('q', '');
|
$q = request('q', '');
|
||||||
|
$replacedQuery = str_replace(['A3', 'A2'], ['A-3', 'A-2'], $q);
|
||||||
|
|
||||||
return Aircraft::where('designator', 'ilike', "%{$q}%")
|
return Aircraft::where('designator', 'ilike', "%{$q}%")
|
||||||
->orWhereRaw("CONCAT(manufacturer_code, ' ', model_full_name) ilike ?", ["%{$q}%"])
|
->orWhereRaw("CONCAT(manufacturer_code, ' ', model_full_name) ilike ?", ["%{$q}%"])
|
||||||
|
->orWhereRaw("CONCAT(manufacturer_code, ' ', model_full_name) ilike ?", ["%{$replacedQuery}%"])
|
||||||
->limit(200)
|
->limit(200)
|
||||||
->orderBy('id', 'asc')
|
->orderBy('id', 'asc')
|
||||||
->get(['id', 'manufacturer_code', 'model_full_name', 'designator'])
|
->get(['id', 'manufacturer_code', 'model_full_name', 'designator'])
|
||||||
|
|||||||
@@ -41,6 +41,7 @@ const searchAircraft = async (query: string) => {
|
|||||||
:error-messages="errorMessages"
|
:error-messages="errorMessages"
|
||||||
item-title="title"
|
item-title="title"
|
||||||
@update:search="searchAircraft"
|
@update:search="searchAircraft"
|
||||||
|
:custom-filter="() => true"
|
||||||
@focus="onFocus"
|
@focus="onFocus"
|
||||||
hint="Showing closest matches to the imported value"
|
hint="Showing closest matches to the imported value"
|
||||||
placeholder="B738"
|
placeholder="B738"
|
||||||
|
|||||||
@@ -6,10 +6,11 @@ import AirlineSearchBox from '@/Components/FlightsGoneBy/AirlineSearchBox.vue'
|
|||||||
import AircraftSearchBox from '@/Components/FlightsGoneBy/AircraftSearchBox.vue'
|
import AircraftSearchBox from '@/Components/FlightsGoneBy/AircraftSearchBox.vue'
|
||||||
import AirportSearchBox from '@/Components/FlightsGoneBy/AirportSearchBox.vue'
|
import AirportSearchBox from '@/Components/FlightsGoneBy/AirportSearchBox.vue'
|
||||||
import type { SeatType, FlightReason, FlightClass} from '@/Types/types'
|
import type { SeatType, FlightReason, FlightClass} from '@/Types/types'
|
||||||
import { ref } from 'vue'
|
import { ref, watch, computed } from 'vue'
|
||||||
|
|
||||||
defineOptions({ layout: MainLayout })
|
defineOptions({ layout: MainLayout })
|
||||||
|
|
||||||
|
|
||||||
const props = defineProps<{
|
const props = defineProps<{
|
||||||
flight?: {
|
flight?: {
|
||||||
id: number
|
id: number
|
||||||
@@ -162,6 +163,33 @@ const airlineOptionsData = ref<{ value: number; title: string }[]>(props.flight
|
|||||||
const fromOptionsData = ref<{ value: number; title: string; country_code: string }[]>(props.flight?.from_options ?? [])
|
const fromOptionsData = ref<{ value: number; title: string; country_code: string }[]>(props.flight?.from_options ?? [])
|
||||||
const toOptionsData = ref<{ value: number; title: string; country_code: string }[]>(props.flight?.to_options ?? [])
|
const toOptionsData = ref<{ value: number; title: string; country_code: string }[]>(props.flight?.to_options ?? [])
|
||||||
const aircraftOptionsData = ref<{ value: number; title: string }[]>(props.flight?.aircraft_options ?? [])
|
const aircraftOptionsData = ref<{ value: number; title: string }[]>(props.flight?.aircraft_options ?? [])
|
||||||
|
|
||||||
|
|
||||||
|
watch(() => form.departure_date, (newVal) => {
|
||||||
|
if (!newVal) return
|
||||||
|
const dep = new Date(newVal)
|
||||||
|
const arr = new Date(dep.getTime() + 60 * 60 * 1000)
|
||||||
|
|
||||||
|
// Format in local time, not UTC
|
||||||
|
const pad = (n: number) => String(n).padStart(2, '0')
|
||||||
|
form.arrival_date = `${arr.getFullYear()}-${pad(arr.getMonth() + 1)}-${pad(arr.getDate())}T${pad(arr.getHours())}:${pad(arr.getMinutes())}`
|
||||||
|
})
|
||||||
|
|
||||||
|
const arrivalMin = computed(() => {
|
||||||
|
if (!form.departure_date) return undefined
|
||||||
|
const pad = (n: number) => String(n).padStart(2, '0')
|
||||||
|
const d = new Date(form.departure_date)
|
||||||
|
d.setDate(d.getDate() - 2)
|
||||||
|
return `${d.getFullYear()}-${pad(d.getMonth() + 1)}-${pad(d.getDate())}T${pad(d.getHours())}:${pad(d.getMinutes())}`
|
||||||
|
})
|
||||||
|
|
||||||
|
const arrivalMax = computed(() => {
|
||||||
|
if (!form.departure_date) return undefined
|
||||||
|
const pad = (n: number) => String(n).padStart(2, '0')
|
||||||
|
const d = new Date(form.departure_date)
|
||||||
|
d.setDate(d.getDate() + 3)
|
||||||
|
return `${d.getFullYear()}-${pad(d.getMonth() + 1)}-${pad(d.getDate())}T${pad(d.getHours())}:${pad(d.getMinutes())}`
|
||||||
|
})
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
@@ -221,6 +249,8 @@ const aircraftOptionsData = ref<{ value: number; title: string }[]>(props.flight
|
|||||||
type="datetime-local"
|
type="datetime-local"
|
||||||
:disabled="!lookupComplete"
|
:disabled="!lookupComplete"
|
||||||
:error-messages="submitForm.errors.arrival_date"
|
:error-messages="submitForm.errors.arrival_date"
|
||||||
|
:min="arrivalMin"
|
||||||
|
:max="arrivalMax"
|
||||||
/>
|
/>
|
||||||
</v-col>
|
</v-col>
|
||||||
</v-row>
|
</v-row>
|
||||||
|
|||||||
Reference in New Issue
Block a user