From f31f1bc2fcf2a2255a5287bcaffba1fd44a06cfd Mon Sep 17 00:00:00 2001 From: josh Date: Sat, 22 Aug 2026 15:00:55 +1000 Subject: [PATCH] Add airport search filter --- app/Http/Controllers/SearchController.php | 40 ++++++++++++------- .../FlightsGoneBy/AirportSearchBox.vue | 36 +++++++++++++++-- 2 files changed, 58 insertions(+), 18 deletions(-) diff --git a/app/Http/Controllers/SearchController.php b/app/Http/Controllers/SearchController.php index 6d53615..ba1e3c1 100644 --- a/app/Http/Controllers/SearchController.php +++ b/app/Http/Controllers/SearchController.php @@ -58,12 +58,17 @@ class SearchController extends Controller { $q = request('q', ''); $len = strlen($q); - $includeInactive = request()->boolean('include_inactive'); + $showClosed = request()->boolean('show_closed'); + $showNoCode = request()->boolean('show_no_code'); if ($len < 3) return []; return Airport::with('region.country') - ->when(!$includeInactive, fn($query) => $query->where('active', true)) + ->when(!$showClosed, fn($query) => $query->where('active', true)) + ->when(!$showNoCode, fn($query) => $query->where(function ($sub) { + $sub->whereNotNull('iata_code') + ->orWhereNotNull('icao_code'); + })) ->when($len === 3, fn($query) => $query->where('iata_code', 'ilike', $q)) ->when($len >= 4, fn($query) => $query->where(function ($sub) use ($q, $len) { $sub->when($len === 4, fn($s) => $s->where('icao_code', 'ilike', $q)) @@ -71,18 +76,25 @@ class SearchController extends Controller ->orWhere('municipality', 'ilike', "%{$q}%"); })) ->orderByRaw(" - CASE - WHEN active THEN 0 - ELSE 1 - END - ") - ->orderByRaw(" - CASE - WHEN icao_code = ? THEN 0 - WHEN iata_code = ? THEN 1 - ELSE 2 - END - ", [$q, $q]) + CASE + WHEN active THEN 0 + ELSE 1 + END + ") + ->orderByRaw(" + CASE + WHEN iata_code IS NOT NULL AND icao_code IS NOT NULL THEN 0 + WHEN iata_code IS NOT NULL OR icao_code IS NOT NULL THEN 1 + ELSE 2 + END + ") + ->orderByRaw(" + CASE + WHEN icao_code = ? THEN 0 + WHEN iata_code = ? THEN 1 + ELSE 2 + END + ", [$q, $q]) ->limit(15) ->get(['id', 'name', 'municipality', 'iata_code', 'icao_code', 'region_id', 'active']) ->map(fn(Airport $airport) => [ diff --git a/resources/js/Components/FlightsGoneBy/AirportSearchBox.vue b/resources/js/Components/FlightsGoneBy/AirportSearchBox.vue index 502eaff..25033fa 100644 --- a/resources/js/Components/FlightsGoneBy/AirportSearchBox.vue +++ b/resources/js/Components/FlightsGoneBy/AirportSearchBox.vue @@ -12,10 +12,14 @@ const model = defineModel<{ value: number, title: string, country_code: string } const airportOptions = ref(props.prefilledOptions ?? []) const autocompleteRef = ref(null) -const includeInactive = ref(true) +const showClosed = ref(false) +const showNoCode = ref(false) const lastQuery = ref('') +const menuOpen = ref(false) const onFocus = () => { + menuOpen.value = true + nextTick(() => { const input = autocompleteRef.value?.$el?.querySelector('input') input?.select() @@ -35,14 +39,15 @@ const searchAirports = async (query: string) => { const { data } = await axios.get('/search/airports', { params: { q: query, - include_inactive: includeInactive.value ? 1 : undefined, + show_closed: showClosed.value ? 1 : undefined, + show_no_code: showNoCode.value ? 1 : undefined, }, }) airportOptions.value = data } -// Re-run the last search when the checkbox is toggled, so results update immediately -watch(includeInactive, () => { +// Re-run the last search when either checkbox is toggled, so results update immediately +watch([showClosed, showNoCode], () => { if (lastQuery.value) searchAirports(lastQuery.value) }) @@ -51,6 +56,7 @@ watch(includeInactive, () => { { clearable hide-no-data return-object + autocomplete="off" :custom-filter="() => true" > + + +