Compare commits
9
Commits
1.4
...
91a6873b64
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
91a6873b64 | ||
|
|
4a9b1ad56a | ||
|
|
ad61508b3c | ||
|
|
95ed0e339f | ||
|
|
4102dd29ef | ||
|
|
28fd782a40 | ||
|
|
3c66a3945c | ||
|
|
a68e31dad7 | ||
|
|
023ce6f964 |
@@ -17,7 +17,10 @@ class PopulateAirportTimezones extends Command
|
|||||||
*/
|
*/
|
||||||
public function handle()
|
public function handle()
|
||||||
{
|
{
|
||||||
Airport::whereNull('timezone')->chunkById(100, function ($airports) {
|
Airport::where(function ($query) {
|
||||||
|
$query->whereNull('timezone')
|
||||||
|
->orWhere('timezone', 'Undefined');
|
||||||
|
})->chunkById(100, function ($airports) {
|
||||||
foreach ($airports as $airport) {
|
foreach ($airports as $airport) {
|
||||||
$zoneName = null;
|
$zoneName = null;
|
||||||
$attempts = 0;
|
$attempts = 0;
|
||||||
|
|||||||
@@ -58,28 +58,38 @@ class SearchController extends Controller
|
|||||||
{
|
{
|
||||||
$q = request('q', '');
|
$q = request('q', '');
|
||||||
$len = strlen($q);
|
$len = strlen($q);
|
||||||
|
$includeInactive = request()->boolean('include_inactive');
|
||||||
|
|
||||||
if ($len < 3) return [];
|
if ($len < 3) return [];
|
||||||
|
|
||||||
return Airport::with('region.country')
|
return Airport::with('region.country')
|
||||||
|
->when(!$includeInactive, fn($query) => $query->where('active', true))
|
||||||
->when($len === 3, fn($query) => $query->where('iata_code', 'ilike', $q))
|
->when($len === 3, fn($query) => $query->where('iata_code', 'ilike', $q))
|
||||||
->when($len >= 4, fn($query) => $query->where(function ($sub) use ($q, $len) {
|
->when($len >= 4, fn($query) => $query->where(function ($sub) use ($q, $len) {
|
||||||
$sub->when($len === 4, fn($s) => $s->where('icao_code', 'ilike', $q))
|
$sub->when($len === 4, fn($s) => $s->where('icao_code', 'ilike', $q))
|
||||||
->orWhere('name', 'ilike', "%{$q}%")
|
->orWhere('name', 'ilike', "%{$q}%")
|
||||||
->orWhere('municipality', 'ilike', "%{$q}%");
|
->orWhere('municipality', 'ilike', "%{$q}%");
|
||||||
})->orderByRaw("
|
}))
|
||||||
|
->orderByRaw("
|
||||||
|
CASE
|
||||||
|
WHEN active THEN 0
|
||||||
|
ELSE 1
|
||||||
|
END
|
||||||
|
")
|
||||||
|
->orderByRaw("
|
||||||
CASE
|
CASE
|
||||||
WHEN icao_code = ? THEN 0
|
WHEN icao_code = ? THEN 0
|
||||||
WHEN iata_code = ? THEN 1
|
WHEN iata_code = ? THEN 1
|
||||||
ELSE 2
|
ELSE 2
|
||||||
END
|
END
|
||||||
", [$q, $q]))
|
", [$q, $q])
|
||||||
->limit(15)
|
->limit(15)
|
||||||
->get(['id', 'name', 'municipality', 'iata_code', 'icao_code', 'region_id'])
|
->get(['id', 'name', 'municipality', 'iata_code', 'icao_code', 'region_id', 'active'])
|
||||||
->map(fn($airport) => [
|
->map(fn(Airport $airport) => [
|
||||||
'value' => $airport->id,
|
'value' => $airport->id,
|
||||||
'title' => $airport->display_name,
|
'title' => $airport->display_name,
|
||||||
'country_code' => strtolower($airport->region->country->code),
|
'country_code' => strtolower($airport->region->country->code),
|
||||||
|
'active' => $airport->active,
|
||||||
])
|
])
|
||||||
->values();
|
->values();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,6 +3,7 @@
|
|||||||
namespace App\Http\Controllers;
|
namespace App\Http\Controllers;
|
||||||
|
|
||||||
use App\Models\Achievement;
|
use App\Models\Achievement;
|
||||||
|
use App\Models\AchievementCategory;
|
||||||
use App\Models\Aircraft;
|
use App\Models\Aircraft;
|
||||||
use App\Models\Airport;
|
use App\Models\Airport;
|
||||||
use App\Models\Alliance;
|
use App\Models\Alliance;
|
||||||
@@ -105,8 +106,14 @@ class UserProfileController extends Controller
|
|||||||
$achievements = Achievement::with(['category', 'difficulty'])
|
$achievements = Achievement::with(['category', 'difficulty'])
|
||||||
->orderBy('id', 'asc')
|
->orderBy('id', 'asc')
|
||||||
->get()
|
->get()
|
||||||
->groupBy(fn(Achievement $a) => $a->category->name)
|
->groupBy(fn(Achievement $a) => $a->category->internal_name)
|
||||||
->map(fn($group) => $group->sortBy('sort_order')->values());
|
->sortBy(function ($group, $internalName) {
|
||||||
|
$index = array_search($internalName, AchievementCategory::ORDER);
|
||||||
|
return $index === false ? PHP_INT_MAX : $index;
|
||||||
|
})
|
||||||
|
->mapWithKeys(fn($group) => [
|
||||||
|
$group->first()->category->name => $group->sortBy('sort_order')->values(),
|
||||||
|
]);
|
||||||
|
|
||||||
$userAchievements = $user->achievements()
|
$userAchievements = $user->achievements()
|
||||||
->with('achievement')
|
->with('achievement')
|
||||||
|
|||||||
@@ -16,6 +16,16 @@ use Illuminate\Database\Eloquent\Relations\HasMany;
|
|||||||
*/
|
*/
|
||||||
class AchievementCategory extends Model
|
class AchievementCategory extends Model
|
||||||
{
|
{
|
||||||
|
const array ORDER = [
|
||||||
|
'number_of_flights',
|
||||||
|
'distance',
|
||||||
|
'general_flying',
|
||||||
|
'countries_and_continents',
|
||||||
|
'aircraft',
|
||||||
|
'airlines_and_alliances',
|
||||||
|
'fun_challenges',
|
||||||
|
];
|
||||||
|
|
||||||
protected $fillable = [
|
protected $fillable = [
|
||||||
'internal_name',
|
'internal_name',
|
||||||
'name',
|
'name',
|
||||||
|
|||||||
@@ -20,12 +20,14 @@ class Airport extends Model
|
|||||||
'icao_code',
|
'icao_code',
|
||||||
'iata_code',
|
'iata_code',
|
||||||
'local_code',
|
'local_code',
|
||||||
|
'active',
|
||||||
];
|
];
|
||||||
|
|
||||||
protected $casts = [
|
protected $casts = [
|
||||||
'latitude_deg' => 'float',
|
'latitude_deg' => 'float',
|
||||||
'longitude_deg' => 'float',
|
'longitude_deg' => 'float',
|
||||||
'elevation_ft' => 'integer',
|
'elevation_ft' => 'integer',
|
||||||
|
'active' => 'boolean',
|
||||||
];
|
];
|
||||||
|
|
||||||
protected $appends = [
|
protected $appends = [
|
||||||
@@ -37,6 +39,8 @@ class Airport extends Model
|
|||||||
'LHR', 'LGW', 'STN', 'LTN', 'LCY', 'SEN',
|
'LHR', 'LGW', 'STN', 'LTN', 'LCY', 'SEN',
|
||||||
];
|
];
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
protected function displayName() : Attribute{
|
protected function displayName() : Attribute{
|
||||||
return Attribute::make(
|
return Attribute::make(
|
||||||
get: function () {
|
get: function () {
|
||||||
@@ -53,6 +57,11 @@ class Airport extends Model
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function scopeActive($query)
|
||||||
|
{
|
||||||
|
return $query->where('active', true);
|
||||||
|
}
|
||||||
|
|
||||||
public function region(): BelongsTo
|
public function region(): BelongsTo
|
||||||
{
|
{
|
||||||
return $this->belongsTo(Region::class);
|
return $this->belongsTo(Region::class);
|
||||||
|
|||||||
@@ -0,0 +1,57 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
use App\Models\Achievement;
|
||||||
|
use App\Models\AchievementCategory;
|
||||||
|
use Illuminate\Database\Migrations\Migration;
|
||||||
|
|
||||||
|
return new class extends Migration
|
||||||
|
{
|
||||||
|
public function up(): void
|
||||||
|
{
|
||||||
|
$newCategory = AchievementCategory::create([
|
||||||
|
'internal_name' => 'number_of_flights',
|
||||||
|
'name' => 'Number of Flights',
|
||||||
|
'description' => 'Achievements for reaching flight count milestones.',
|
||||||
|
]);
|
||||||
|
|
||||||
|
$achievementsToUpdate = [
|
||||||
|
'general_flying.first_flight',
|
||||||
|
'general_flying.10_flights',
|
||||||
|
'general_flying.500_flights',
|
||||||
|
'general_flying.50_flights',
|
||||||
|
'general_flying.100_flights',
|
||||||
|
'general_flying.1000_flights',
|
||||||
|
];
|
||||||
|
|
||||||
|
foreach ($achievementsToUpdate as $internalName) {
|
||||||
|
$achievement = Achievement::where('internal_name', $internalName)->first();
|
||||||
|
|
||||||
|
if (!$achievement) {
|
||||||
|
continue; // or throw, depending how strict you want this
|
||||||
|
}
|
||||||
|
|
||||||
|
$achievement->update([
|
||||||
|
'achievement_category_id' => $newCategory->id,
|
||||||
|
'internal_name' => str_replace('general_flying.', 'number_of_flights.', $internalName),
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function down(): void
|
||||||
|
{
|
||||||
|
$oldCategory = AchievementCategory::where('internal_name', 'general_flying')->first();
|
||||||
|
|
||||||
|
if ($oldCategory) {
|
||||||
|
Achievement::where('internal_name', 'like', 'number_of_flights.%')
|
||||||
|
->get()
|
||||||
|
->each(function (Achievement $achievement) use ($oldCategory) {
|
||||||
|
$achievement->update([
|
||||||
|
'achievement_category_id' => $oldCategory->id,
|
||||||
|
'internal_name' => str_replace('number_of_flights.', 'general_flying.', $achievement->internal_name),
|
||||||
|
]);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
AchievementCategory::where('internal_name', 'number_of_flights')->delete();
|
||||||
|
}
|
||||||
|
};
|
||||||
@@ -0,0 +1,133 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
use App\Models\Airport;
|
||||||
|
use Illuminate\Database\Migrations\Migration;
|
||||||
|
use Illuminate\Database\Schema\Blueprint;
|
||||||
|
use Illuminate\Support\Facades\Schema;
|
||||||
|
|
||||||
|
return new class extends Migration
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Run the migrations.
|
||||||
|
*/
|
||||||
|
public function up(): void
|
||||||
|
{
|
||||||
|
Schema::table('airports', function (Blueprint $table) {
|
||||||
|
$table->boolean('active')->default(true);
|
||||||
|
});
|
||||||
|
|
||||||
|
Airport::whereIataCode('TXL')->update(['active' => false]);
|
||||||
|
$this->importCsv();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reverse the migrations.
|
||||||
|
*/
|
||||||
|
public function down(): void
|
||||||
|
{
|
||||||
|
Schema::table('airports', function (Blueprint $table) {
|
||||||
|
$table->dropColumn('active');
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
private function importCsv(): void
|
||||||
|
{
|
||||||
|
$path = storage_path('app/private/seed_data/airports.csv');
|
||||||
|
|
||||||
|
if (! file_exists($path)) {
|
||||||
|
throw new \RuntimeException("Airports CSV not found at: {$path}");
|
||||||
|
}
|
||||||
|
|
||||||
|
$handle = fopen($path, 'rb');
|
||||||
|
|
||||||
|
if ($handle === false) {
|
||||||
|
throw new \RuntimeException("Failed to open airports CSV at: {$path}");
|
||||||
|
}
|
||||||
|
|
||||||
|
// Skip header row
|
||||||
|
fgetcsv($handle);
|
||||||
|
|
||||||
|
$regionMap = DB::table('regions')->pluck('id', 'code')->all();
|
||||||
|
|
||||||
|
$batch = [];
|
||||||
|
$batchSize = 500;
|
||||||
|
$now = now()->toDateTimeString();
|
||||||
|
|
||||||
|
while (($row = fgetcsv($handle)) !== false) {
|
||||||
|
if (count($row) < 19) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
// id, ident, type, name, latitude_deg, longitude_deg, elevation_ft,
|
||||||
|
// continent, iso_country, iso_region, municipality, scheduled_service,
|
||||||
|
// icao_code, iata_code, gps_code, local_code, home_link, wikipedia_link, keywords
|
||||||
|
[
|
||||||
|
,
|
||||||
|
,
|
||||||
|
$type,
|
||||||
|
$name,
|
||||||
|
$latitudeDeg,
|
||||||
|
$longitudeDeg,
|
||||||
|
$elevationFt,
|
||||||
|
,
|
||||||
|
,
|
||||||
|
$isoRegion,
|
||||||
|
$municipality,
|
||||||
|
,
|
||||||
|
$icaoCode,
|
||||||
|
$iataCode,
|
||||||
|
,
|
||||||
|
$localCode,
|
||||||
|
] = $row;
|
||||||
|
|
||||||
|
$icaoCode = trim(str_replace(["\r", "\n"], '', $icaoCode));
|
||||||
|
$iataCode = trim(str_replace(["\r", "\n"], '', $iataCode));
|
||||||
|
|
||||||
|
// Only importing airports with no IATA/ICAO code — coded airports are already in the DB
|
||||||
|
if ($icaoCode !== '' || $iataCode !== '') {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
$type = trim($type);
|
||||||
|
$name = trim($name);
|
||||||
|
$localCode = trim($localCode);
|
||||||
|
$isoRegion = trim($isoRegion);
|
||||||
|
|
||||||
|
if (! isset($regionMap[$isoRegion])) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
$elevationFt = trim($elevationFt);
|
||||||
|
|
||||||
|
$batch[] = [
|
||||||
|
'type' => $type,
|
||||||
|
'name' => $name,
|
||||||
|
'latitude_deg' => (float) trim($latitudeDeg),
|
||||||
|
'longitude_deg' => (float) trim($longitudeDeg),
|
||||||
|
'elevation_ft' => $elevationFt !== '' ? (int) $elevationFt : null,
|
||||||
|
'region_id' => $regionMap[$isoRegion],
|
||||||
|
'municipality' => trim($municipality) !== '' ? trim($municipality) : null,
|
||||||
|
'icao_code' => null,
|
||||||
|
'iata_code' => null,
|
||||||
|
'local_code' => $localCode !== '' ? $localCode : null,
|
||||||
|
'timezone' => 'Undefined',
|
||||||
|
'active' => $type !== 'closed',
|
||||||
|
'created_at' => $now,
|
||||||
|
'updated_at' => $now,
|
||||||
|
];
|
||||||
|
|
||||||
|
echo "Added: {$name}\n";
|
||||||
|
|
||||||
|
if (count($batch) >= $batchSize) {
|
||||||
|
DB::table('airports')->insert($batch);
|
||||||
|
$batch = [];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fclose($handle);
|
||||||
|
|
||||||
|
if (! empty($batch)) {
|
||||||
|
DB::table('airports')->insert($batch);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import { ref, nextTick } from 'vue'
|
import { ref, nextTick, watch } from 'vue'
|
||||||
import axios from 'axios'
|
import axios from 'axios'
|
||||||
|
|
||||||
const props = defineProps<{
|
const props = defineProps<{
|
||||||
@@ -12,6 +12,8 @@ const model = defineModel<{ value: number, title: string, country_code: string }
|
|||||||
|
|
||||||
const airportOptions = ref(props.prefilledOptions ?? [])
|
const airportOptions = ref(props.prefilledOptions ?? [])
|
||||||
const autocompleteRef = ref<any>(null)
|
const autocompleteRef = ref<any>(null)
|
||||||
|
const includeInactive = ref(true)
|
||||||
|
const lastQuery = ref('')
|
||||||
|
|
||||||
const onFocus = () => {
|
const onFocus = () => {
|
||||||
nextTick(() => {
|
nextTick(() => {
|
||||||
@@ -21,6 +23,8 @@ const onFocus = () => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const searchAirports = async (query: string) => {
|
const searchAirports = async (query: string) => {
|
||||||
|
lastQuery.value = query
|
||||||
|
|
||||||
if (!query || query.length < 2) {
|
if (!query || query.length < 2) {
|
||||||
airportOptions.value = props.prefilledOptions ?? []
|
airportOptions.value = props.prefilledOptions ?? []
|
||||||
return
|
return
|
||||||
@@ -28,9 +32,19 @@ const searchAirports = async (query: string) => {
|
|||||||
|
|
||||||
if (query === model.value?.title) return
|
if (query === model.value?.title) return
|
||||||
|
|
||||||
const { data } = await axios.get('/search/airports', { params: { q: query } })
|
const { data } = await axios.get('/search/airports', {
|
||||||
|
params: {
|
||||||
|
q: query,
|
||||||
|
include_inactive: includeInactive.value ? 1 : undefined,
|
||||||
|
},
|
||||||
|
})
|
||||||
airportOptions.value = data
|
airportOptions.value = data
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Re-run the last search when the checkbox is toggled, so results update immediately
|
||||||
|
watch(includeInactive, () => {
|
||||||
|
if (lastQuery.value) searchAirports(lastQuery.value)
|
||||||
|
})
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
@@ -62,7 +76,6 @@ const searchAirports = async (query: string) => {
|
|||||||
<span :class="`fi fi-${item.country_code}`"></span>
|
<span :class="`fi fi-${item.country_code}`"></span>
|
||||||
</span>
|
</span>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
</v-list-item>
|
</v-list-item>
|
||||||
</template>
|
</template>
|
||||||
</v-autocomplete>
|
</v-autocomplete>
|
||||||
|
|||||||
@@ -370,10 +370,34 @@ export default defineComponent({
|
|||||||
link.click()
|
link.click()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function loopPoints(origin: LngLat, radiusDeg = 0.2, steps = 48): LngLat[] {
|
||||||
|
const [lng, lat] = origin
|
||||||
|
|
||||||
|
// Widen the longitude radius to compensate for mercator distortion at this latitude
|
||||||
|
const lngRadius = radiusDeg / Math.max(Math.cos(lat * Math.PI / 180), 0.15)
|
||||||
|
|
||||||
|
// Center the loop above the origin so the airport point sits at the bottom of the loop
|
||||||
|
const centerLat = lat + radiusDeg
|
||||||
|
|
||||||
|
const points: LngLat[] = []
|
||||||
|
for (let i = 0; i <= steps; i++) {
|
||||||
|
const theta = (i / steps) * Math.PI * 2
|
||||||
|
points.push([
|
||||||
|
lng + Math.sin(theta) * lngRadius,
|
||||||
|
centerLat - radiusDeg * Math.cos(theta),
|
||||||
|
])
|
||||||
|
}
|
||||||
|
return points // first and last point === origin, at the bottom of the loop
|
||||||
|
}
|
||||||
|
|
||||||
const getArc = (flight: Flight): LngLat[] => {
|
const getArc = (flight: Flight): LngLat[] => {
|
||||||
const key = routeKey(flight.departure_airport, flight.arrival_airport)
|
const key = routeKey(flight.departure_airport, flight.arrival_airport)
|
||||||
if (!arcCache.has(key)) {
|
if (!arcCache.has(key)) {
|
||||||
arcCache.set(key, greatCirclePoints(
|
const isSameAirport = flight.departure_airport.id === flight.arrival_airport.id
|
||||||
|
|
||||||
|
arcCache.set(key, isSameAirport
|
||||||
|
? loopPoints([flight.departure_airport.longitude_deg, flight.departure_airport.latitude_deg])
|
||||||
|
: greatCirclePoints(
|
||||||
[flight.departure_airport.longitude_deg, flight.departure_airport.latitude_deg],
|
[flight.departure_airport.longitude_deg, flight.departure_airport.latitude_deg],
|
||||||
[flight.arrival_airport.longitude_deg, flight.arrival_airport.latitude_deg],
|
[flight.arrival_airport.longitude_deg, flight.arrival_airport.latitude_deg],
|
||||||
))
|
))
|
||||||
@@ -666,8 +690,10 @@ export default defineComponent({
|
|||||||
? { top: 20, bottom: 20, left: 55, right: 55 }
|
? { top: 20, bottom: 20, left: 55, right: 55 }
|
||||||
: { top: 60, bottom: 60, left: 60, right: 60 }
|
: { top: 60, bottom: 60, left: 60, right: 60 }
|
||||||
|
|
||||||
const lngs = props.flights.flatMap(f => [f.departure_airport.longitude_deg, f.arrival_airport.longitude_deg])
|
// Use full arc/loop geometry, not just endpoints, so loops aren't clipped
|
||||||
const lats = props.flights.flatMap(f => [f.departure_airport.latitude_deg, f.arrival_airport.latitude_deg])
|
const allPoints = props.flights.flatMap(getArc)
|
||||||
|
const lngs = allPoints.map(p => p[0])
|
||||||
|
const lats = allPoints.map(p => p[1])
|
||||||
|
|
||||||
const minLat = Math.min(...lats)
|
const minLat = Math.min(...lats)
|
||||||
const maxLat = Math.max(...lats)
|
const maxLat = Math.max(...lats)
|
||||||
@@ -689,7 +715,6 @@ export default defineComponent({
|
|||||||
}
|
}
|
||||||
map!.fitBounds([[minLng, minLat], [maxLng, maxLat]], { padding, duration: 0 })
|
map!.fitBounds([[minLng, minLat], [maxLng, maxLat]], { padding, duration: 0 })
|
||||||
}
|
}
|
||||||
|
|
||||||
// ── Map init ──────────────────────────────────────────────────────────
|
// ── Map init ──────────────────────────────────────────────────────────
|
||||||
|
|
||||||
const initMap = (): void => {
|
const initMap = (): void => {
|
||||||
|
|||||||
Reference in New Issue
Block a user