diff --git a/app/Http/Controllers/FlightController.php b/app/Http/Controllers/FlightController.php index 4bae7f9..d39c0a1 100644 --- a/app/Http/Controllers/FlightController.php +++ b/app/Http/Controllers/FlightController.php @@ -21,7 +21,7 @@ class FlightController extends Controller return [ 'flight_number' => ['nullable', 'string', 'max:10'], 'departure_date' => ['required', 'date'], - 'arrival_date' => ['required', 'date', 'after:departure_date'], + 'arrival_date' => ['required', 'date'], 'from_id' => ['required', 'integer', 'exists:airports,id'], 'to_id' => ['required', 'integer', 'exists:airports,id'], 'airline_id' => ['nullable', 'integer', 'exists:airlines,id'], diff --git a/app/Http/Controllers/SearchController.php b/app/Http/Controllers/SearchController.php index 07ee160..2d9de4a 100644 --- a/app/Http/Controllers/SearchController.php +++ b/app/Http/Controllers/SearchController.php @@ -30,9 +30,11 @@ class SearchController extends Controller public function aircraft() { $q = request('q', ''); + $replacedQuery = str_replace(['A3', 'A2'], ['A-3', 'A-2'], $q); return Aircraft::where('designator', 'ilike', "%{$q}%") ->orWhereRaw("CONCAT(manufacturer_code, ' ', model_full_name) ilike ?", ["%{$q}%"]) + ->orWhereRaw("CONCAT(manufacturer_code, ' ', model_full_name) ilike ?", ["%{$replacedQuery}%"]) ->limit(200) ->orderBy('id', 'asc') ->get(['id', 'manufacturer_code', 'model_full_name', 'designator']) diff --git a/resources/js/Components/FlightsGoneBy/AircraftSearchBox.vue b/resources/js/Components/FlightsGoneBy/AircraftSearchBox.vue index ce530da..6feed75 100644 --- a/resources/js/Components/FlightsGoneBy/AircraftSearchBox.vue +++ b/resources/js/Components/FlightsGoneBy/AircraftSearchBox.vue @@ -41,6 +41,7 @@ const searchAircraft = async (query: string) => { :error-messages="errorMessages" item-title="title" @update:search="searchAircraft" + :custom-filter="() => true" @focus="onFocus" hint="Showing closest matches to the imported value" placeholder="B738" diff --git a/resources/js/Pages/AddFlight.vue b/resources/js/Pages/AddFlight.vue index feb2ffe..72a85ad 100644 --- a/resources/js/Pages/AddFlight.vue +++ b/resources/js/Pages/AddFlight.vue @@ -6,10 +6,11 @@ import AirlineSearchBox from '@/Components/FlightsGoneBy/AirlineSearchBox.vue' import AircraftSearchBox from '@/Components/FlightsGoneBy/AircraftSearchBox.vue' import AirportSearchBox from '@/Components/FlightsGoneBy/AirportSearchBox.vue' import type { SeatType, FlightReason, FlightClass} from '@/Types/types' -import { ref } from 'vue' +import { ref, watch, computed } from 'vue' defineOptions({ layout: MainLayout }) + const props = defineProps<{ flight?: { 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 toOptionsData = ref<{ value: number; title: string; country_code: string }[]>(props.flight?.to_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())}` +})