Add more airlines and fix edit bugs
This commit is contained in:
@@ -42,17 +42,18 @@ class FlightController extends Controller
|
|||||||
|
|
||||||
// Extract the airline code prefix — letters at the start e.g. "QF" from "QF1"
|
// Extract the airline code prefix — letters at the start e.g. "QF" from "QF1"
|
||||||
preg_match('/^([A-Z]{2,3})/', $number, $matches);
|
preg_match('/^([A-Z]{2,3})/', $number, $matches);
|
||||||
$iataCode = $matches[1] ?? null;
|
$code = $matches[1] ?? null;
|
||||||
|
$isIata = strlen($code) === 2;
|
||||||
|
$codeColumn = $isIata ? 'IATA_code' : 'ICAO_code';
|
||||||
|
|
||||||
$airlines = $iataCode
|
$airlines = $code
|
||||||
? Airline::where('IATA_code', $iataCode)
|
? Airline::where($codeColumn, $code)
|
||||||
->get()
|
->get()
|
||||||
->map(fn ($a) => ['value' => $a->id, 'title' => $a->name])
|
->map(fn ($airline) => ['value' => $airline->id, 'title' => $airline->display_name])
|
||||||
: collect();
|
: collect()->toArray();
|
||||||
|
|
||||||
return response()->json([
|
return response()->json([
|
||||||
'airline_options' => $airlines,
|
'airline_options' => $airlines,
|
||||||
'from_options' => [], // populate from a flight schedule API if you have one
|
'from_options' => [],
|
||||||
'to_options' => [],
|
'to_options' => [],
|
||||||
'aircraft_options' => [],
|
'aircraft_options' => [],
|
||||||
]);
|
]);
|
||||||
@@ -137,12 +138,12 @@ class FlightController extends Controller
|
|||||||
'flight_class' => $flight->flightClass->toArray(),
|
'flight_class' => $flight->flightClass->toArray(),
|
||||||
'flight_reason' => $flight->flightReason->toArray(),
|
'flight_reason' => $flight->flightReason->toArray(),
|
||||||
'airline_options' => $flight->airline
|
'airline_options' => $flight->airline
|
||||||
? [['value' => $flight->airline->id, 'title' => $flight->airline->displayName()]]
|
? [['value' => $flight->airline->id, 'title' => $flight->airline->display_name]]
|
||||||
: [],
|
: [],
|
||||||
'from_options' => [['value' => $flight->departureAirport->id, 'title' => $flight->departureAirport->displayName(), 'country_code' => strtolower($flight->departureAirport->region->country->code)]],
|
'from_options' => [['value' => $flight->departureAirport->id, 'title' => $flight->departureAirport->display_name, 'country_code' => strtolower($flight->departureAirport->region->country->code)]],
|
||||||
'to_options' => [['value' => $flight->arrivalAirport->id, 'title' => $flight->arrivalAirport->displayName(), 'country_code' => strtolower($flight->arrivalAirport->region->country->code)]],
|
'to_options' => [['value' => $flight->arrivalAirport->id, 'title' => $flight->arrivalAirport->display_name, 'country_code' => strtolower($flight->arrivalAirport->region->country->code)]],
|
||||||
'aircraft_options' => $flight->aircraft
|
'aircraft_options' => $flight->aircraft
|
||||||
? [['value' => $flight->aircraft->id, 'title' => $flight->aircraft->displayName()]]
|
? [['value' => $flight->aircraft->id, 'title' => $flight->aircraft->display_name]]
|
||||||
: [],
|
: [],
|
||||||
];
|
];
|
||||||
return Inertia::render('AddFlight', [
|
return Inertia::render('AddFlight', [
|
||||||
|
|||||||
@@ -57,7 +57,7 @@ class FlightImportController extends Controller
|
|||||||
->get(['id', 'manufacturer_code', 'model_full_name', 'designator'])
|
->get(['id', 'manufacturer_code', 'model_full_name', 'designator'])
|
||||||
->map(fn($aircraft) => [
|
->map(fn($aircraft) => [
|
||||||
'value' => $aircraft->id,
|
'value' => $aircraft->id,
|
||||||
'title' => $aircraft->displayName(),
|
'title' => $aircraft->display_name,
|
||||||
])
|
])
|
||||||
->values()
|
->values()
|
||||||
->toArray();
|
->toArray();
|
||||||
@@ -92,9 +92,9 @@ class FlightImportController extends Controller
|
|||||||
->limit(10)
|
->limit(10)
|
||||||
->orderBy('id')
|
->orderBy('id')
|
||||||
->get(['id', 'name', 'municipality', 'iata_code', 'icao_code', 'region_id'])
|
->get(['id', 'name', 'municipality', 'iata_code', 'icao_code', 'region_id'])
|
||||||
->map(fn($airport) => [
|
->map(fn(Airport $airport) => [
|
||||||
'value' => $airport->id,
|
'value' => $airport->id,
|
||||||
'title' => $airport->displayName(),
|
'title' => $airport->display_name,
|
||||||
'country_code' => strtolower($airport?->region->country->code ?? ''),
|
'country_code' => strtolower($airport?->region->country->code ?? ''),
|
||||||
])
|
])
|
||||||
->values()
|
->values()
|
||||||
@@ -131,7 +131,7 @@ class FlightImportController extends Controller
|
|||||||
->get(['id', 'name', 'IATA_code', 'ICAO_code'])
|
->get(['id', 'name', 'IATA_code', 'ICAO_code'])
|
||||||
->map(fn($airline) => [
|
->map(fn($airline) => [
|
||||||
'value' => $airline->id,
|
'value' => $airline->id,
|
||||||
'title' => $airline->displayName(),
|
'title' => $airline->display_name,
|
||||||
])
|
])
|
||||||
->values()
|
->values()
|
||||||
->toArray();
|
->toArray();
|
||||||
|
|||||||
@@ -29,7 +29,7 @@ class SearchController extends Controller
|
|||||||
->get(['id', 'name', 'IATA_code', 'ICAO_code', 'logo'])
|
->get(['id', 'name', 'IATA_code', 'ICAO_code', 'logo'])
|
||||||
->map(fn($airline) => [
|
->map(fn($airline) => [
|
||||||
'value' => $airline->id,
|
'value' => $airline->id,
|
||||||
'title' => $airline->displayName(),
|
'title' => $airline->display_name,
|
||||||
])
|
])
|
||||||
->values();
|
->values();
|
||||||
}
|
}
|
||||||
@@ -47,7 +47,7 @@ class SearchController extends Controller
|
|||||||
->get(['id', 'manufacturer_code', 'model_full_name', 'designator'])
|
->get(['id', 'manufacturer_code', 'model_full_name', 'designator'])
|
||||||
->map(fn($aircraft) => [
|
->map(fn($aircraft) => [
|
||||||
'value' => $aircraft->id,
|
'value' => $aircraft->id,
|
||||||
'title' => $aircraft->displayName(),
|
'title' => $aircraft->display_name,
|
||||||
])
|
])
|
||||||
->values();
|
->values();
|
||||||
}
|
}
|
||||||
@@ -76,7 +76,7 @@ class SearchController extends Controller
|
|||||||
->get(['id', 'name', 'municipality', 'iata_code', 'icao_code', 'region_id'])
|
->get(['id', 'name', 'municipality', 'iata_code', 'icao_code', 'region_id'])
|
||||||
->map(fn($airport) => [
|
->map(fn($airport) => [
|
||||||
'value' => $airport->id,
|
'value' => $airport->id,
|
||||||
'title' => $airport->displayName(),
|
'title' => $airport->display_name,
|
||||||
'country_code' => strtolower($airport->region->country->code),
|
'country_code' => strtolower($airport->region->country->code),
|
||||||
])
|
])
|
||||||
->values();
|
->values();
|
||||||
|
|||||||
+11
-2
@@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
namespace App\Models;
|
namespace App\Models;
|
||||||
|
|
||||||
|
use Illuminate\Database\Eloquent\Casts\Attribute;
|
||||||
use Illuminate\Database\Eloquent\Model;
|
use Illuminate\Database\Eloquent\Model;
|
||||||
|
|
||||||
class Aircraft extends Model
|
class Aircraft extends Model
|
||||||
@@ -20,7 +21,15 @@ class Aircraft extends Model
|
|||||||
'engine_count' => 'integer',
|
'engine_count' => 'integer',
|
||||||
];
|
];
|
||||||
|
|
||||||
public function displayName() : string{
|
protected $appends = [
|
||||||
return "{$this->manufacturer_code} {$this->model_full_name} ({$this->designator})";
|
'display_name',
|
||||||
|
];
|
||||||
|
|
||||||
|
protected function displayName() : Attribute{
|
||||||
|
return Attribute::make(
|
||||||
|
get: function () {
|
||||||
|
return "{$this->manufacturer_code} {$this->model_full_name} ({$this->designator})";
|
||||||
|
}
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+12
-2
@@ -3,6 +3,7 @@
|
|||||||
namespace App\Models;
|
namespace App\Models;
|
||||||
|
|
||||||
use Illuminate\Database\Eloquent\Builder;
|
use Illuminate\Database\Eloquent\Builder;
|
||||||
|
use Illuminate\Database\Eloquent\Casts\Attribute;
|
||||||
use Illuminate\Database\Eloquent\Model;
|
use Illuminate\Database\Eloquent\Model;
|
||||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||||
|
|
||||||
@@ -26,9 +27,18 @@ class Airline extends Model
|
|||||||
|
|
||||||
|
|
||||||
public $timestamps = false;
|
public $timestamps = false;
|
||||||
|
protected $appends = [
|
||||||
|
'display_name',
|
||||||
|
];
|
||||||
|
|
||||||
public function displayName() : string {
|
protected function displayName() : Attribute{
|
||||||
return "{$this->name} ({$this->IATA_code}/{$this->ICAO_code})";
|
return Attribute::make(
|
||||||
|
get: function () {
|
||||||
|
$codes = array_filter([$this->IATA_code, $this->ICAO_code]);
|
||||||
|
$codeString = count($codes) ? ' (' . implode('/', $codes) . ')' : '';
|
||||||
|
return "{$this->name}{$codeString}";
|
||||||
|
}
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function country(): BelongsTo
|
public function country(): BelongsTo
|
||||||
|
|||||||
+20
-2
@@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
namespace App\Models;
|
namespace App\Models;
|
||||||
|
|
||||||
|
use Illuminate\Database\Eloquent\Casts\Attribute;
|
||||||
use Illuminate\Database\Eloquent\Model;
|
use Illuminate\Database\Eloquent\Model;
|
||||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||||
|
|
||||||
@@ -27,8 +28,25 @@ class Airport extends Model
|
|||||||
'elevation_ft' => 'integer',
|
'elevation_ft' => 'integer',
|
||||||
];
|
];
|
||||||
|
|
||||||
public function displayName() : string{
|
protected $appends = [
|
||||||
return "{$this->municipality} / {$this->name} ({$this->iata_code}/{$this->icao_code})";
|
'display_code',
|
||||||
|
'display_name',
|
||||||
|
];
|
||||||
|
|
||||||
|
protected function displayName() : Attribute{
|
||||||
|
return Attribute::make(
|
||||||
|
get: function () {
|
||||||
|
$codes = array_filter([$this->iata_code, $this->icao_code]);
|
||||||
|
$codeString = count($codes) ? ' (' . implode('/', $codes) . ')' : '';
|
||||||
|
return "{$this->municipality} / {$this->name}{$codeString}";
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
protected function displayCode(): Attribute
|
||||||
|
{
|
||||||
|
return Attribute::make(
|
||||||
|
get: fn () => $this->iata_code ?? $this->icao_code ?? $this->local_code ?? '---'
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function region(): BelongsTo
|
public function region(): BelongsTo
|
||||||
|
|||||||
@@ -6,5 +6,8 @@ use Illuminate\Database\Eloquent\Model;
|
|||||||
|
|
||||||
class SeatType extends Model
|
class SeatType extends Model
|
||||||
{
|
{
|
||||||
|
protected $fillable = [
|
||||||
|
'name',
|
||||||
|
];
|
||||||
public $timestamps = false;
|
public $timestamps = false;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
use App\Models\Airline;
|
use App\Models\Airline;
|
||||||
use App\Models\Country;
|
use App\Models\Country;
|
||||||
|
use App\Models\SeatType;
|
||||||
use App\Models\UserFlight;
|
use App\Models\UserFlight;
|
||||||
use Illuminate\Database\Migrations\Migration;
|
use Illuminate\Database\Migrations\Migration;
|
||||||
use Illuminate\Database\Schema\Blueprint;
|
use Illuminate\Database\Schema\Blueprint;
|
||||||
@@ -77,6 +78,8 @@ return new class extends Migration
|
|||||||
UserFlight::where('flight_reason_id', null)->update(['flight_reason_id' => 0]);
|
UserFlight::where('flight_reason_id', null)->update(['flight_reason_id' => 0]);
|
||||||
UserFlight::where('flight_class_id', null)->update(['flight_class_id' => 0]);
|
UserFlight::where('flight_class_id', null)->update(['flight_class_id' => 0]);
|
||||||
|
|
||||||
|
UserFlight::where('flight_reason_id', 0)->update(['flight_reason_id' => 1]);
|
||||||
|
SeatType::where('id', 0)->update(['name' => 'Unassigned']);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -0,0 +1,36 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
use App\Models\Airport;
|
||||||
|
use App\Models\Country;
|
||||||
|
use App\Models\Region;
|
||||||
|
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
|
||||||
|
{
|
||||||
|
Airport::create([
|
||||||
|
'name' => 'Horizontal Falls Pontoon',
|
||||||
|
'region_id' => Region::whereCode('AU-WA')->first()->id,
|
||||||
|
'municipality' => 'Horizontal Falls',
|
||||||
|
'latitude_deg' => -16.373295,
|
||||||
|
'longitude_deg' => 123.964757,
|
||||||
|
'elevation_ft' => 0,
|
||||||
|
'type' => 'seaplane_base',
|
||||||
|
'timezone' => 'Australia/Perth',
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reverse the migrations.
|
||||||
|
*/
|
||||||
|
public function down(): void
|
||||||
|
{
|
||||||
|
//
|
||||||
|
}
|
||||||
|
};
|
||||||
@@ -30,7 +30,7 @@ function classKey(flight: Flight): string {
|
|||||||
<div class="pass-route">
|
<div class="pass-route">
|
||||||
<div class="pass-endpoint">
|
<div class="pass-endpoint">
|
||||||
<AirportToolTip :airport="flight.departure_airport">
|
<AirportToolTip :airport="flight.departure_airport">
|
||||||
<div class="pass-iata">{{ flight.departure_airport.iata_code }}</div>
|
<div class="pass-iata">{{ flight.departure_airport.display_code}}</div>
|
||||||
</AirportToolTip>
|
</AirportToolTip>
|
||||||
<div class="pass-endpoint-city">{{ flight.departure_airport.municipality }}</div>
|
<div class="pass-endpoint-city">{{ flight.departure_airport.municipality }}</div>
|
||||||
<div class="pass-endpoint-date">{{ flight.departure_date_display }}</div>
|
<div class="pass-endpoint-date">{{ flight.departure_date_display }}</div>
|
||||||
@@ -50,7 +50,7 @@ function classKey(flight: Flight): string {
|
|||||||
|
|
||||||
<div class="pass-endpoint pass-endpoint--right">
|
<div class="pass-endpoint pass-endpoint--right">
|
||||||
<AirportToolTip :airport="flight.arrival_airport">
|
<AirportToolTip :airport="flight.arrival_airport">
|
||||||
<div class="pass-iata">{{ flight.arrival_airport.iata_code }}</div>
|
<div class="pass-iata">{{ flight.arrival_airport.display_code}}</div>
|
||||||
</AirportToolTip>
|
</AirportToolTip>
|
||||||
<div class="pass-endpoint-city">{{ flight.arrival_airport.municipality }}</div>
|
<div class="pass-endpoint-city">{{ flight.arrival_airport.municipality }}</div>
|
||||||
<div class="pass-endpoint-date">{{ flight.arrival_date_display ?? flight.departure_date_display }}</div>
|
<div class="pass-endpoint-date">{{ flight.arrival_date_display ?? flight.departure_date_display }}</div>
|
||||||
@@ -213,6 +213,7 @@ function classKey(flight: Flight): string {
|
|||||||
font-size: 0.8rem;
|
font-size: 0.8rem;
|
||||||
color: #778899;
|
color: #778899;
|
||||||
font-weight: 500;
|
font-weight: 500;
|
||||||
|
white-space: nowrap;
|
||||||
}
|
}
|
||||||
|
|
||||||
.pass-endpoint-date {
|
.pass-endpoint-date {
|
||||||
@@ -258,7 +259,6 @@ function classKey(flight: Flight): string {
|
|||||||
font-size: 0.72rem;
|
font-size: 0.72rem;
|
||||||
color: #778899;
|
color: #778899;
|
||||||
text-align: center;
|
text-align: center;
|
||||||
white-space: nowrap;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
.pass-aircraft {
|
.pass-aircraft {
|
||||||
|
|||||||
@@ -204,7 +204,7 @@ const tableItems = computed(() =>
|
|||||||
<span class="class-cell">
|
<span class="class-cell">
|
||||||
<FlightClassBadge :flight="(item as Flight)" />
|
<FlightClassBadge :flight="(item as Flight)" />
|
||||||
<InlineBadge v-if="(item as Flight).seat_number" variant="economy">{{(item as Flight).seat_number}}</InlineBadge>
|
<InlineBadge v-if="(item as Flight).seat_number" variant="economy">{{(item as Flight).seat_number}}</InlineBadge>
|
||||||
<InlineBadge v-if="(item as Flight).seat_type?.name && (item as Flight).seat_type?.name !== 'Unspecified'" variant="economy">{{(item as Flight).seat_type?.name}}</InlineBadge>
|
<InlineBadge v-if="(item as Flight).seat_type?.name && (item as Flight).seat_type?.name !== 'Unassigned'" variant="economy">{{(item as Flight).seat_type?.name}}</InlineBadge>
|
||||||
</span>
|
</span>
|
||||||
</td>
|
</td>
|
||||||
|
|
||||||
|
|||||||
Vendored
+3
@@ -52,6 +52,7 @@ export interface Airport {
|
|||||||
created_at: string | null
|
created_at: string | null
|
||||||
updated_at: string | null
|
updated_at: string | null
|
||||||
timezone: string
|
timezone: string
|
||||||
|
display_code: string
|
||||||
}
|
}
|
||||||
|
|
||||||
export type Continent = {
|
export type Continent = {
|
||||||
@@ -81,6 +82,7 @@ export interface Airline {
|
|||||||
logo: string | null
|
logo: string | null
|
||||||
country_id: number
|
country_id: number
|
||||||
country?: Country
|
country?: Country
|
||||||
|
display_name: string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -96,6 +98,7 @@ export interface Aircraft {
|
|||||||
wtc: string
|
wtc: string
|
||||||
created_at: string | null
|
created_at: string | null
|
||||||
updated_at: string | null
|
updated_at: string | null
|
||||||
|
display_name: string
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface SeatType {
|
export interface SeatType {
|
||||||
|
|||||||
Reference in New Issue
Block a user