Save user flights
This commit is contained in:
@@ -13,6 +13,7 @@ use App\Models\UserFlight;
|
|||||||
use Carbon\Carbon;
|
use Carbon\Carbon;
|
||||||
use Illuminate\Http\Request;
|
use Illuminate\Http\Request;
|
||||||
use Illuminate\Support\Facades\Auth;
|
use Illuminate\Support\Facades\Auth;
|
||||||
|
use Inertia\Inertia;
|
||||||
|
|
||||||
class FlightImportController extends Controller
|
class FlightImportController extends Controller
|
||||||
{
|
{
|
||||||
@@ -168,7 +169,7 @@ class FlightImportController extends Controller
|
|||||||
$validated = $request->validate([
|
$validated = $request->validate([
|
||||||
'date' => 'required|date',
|
'date' => 'required|date',
|
||||||
'imported_flight_id' => 'required|exists:imported_flights,id',
|
'imported_flight_id' => 'required|exists:imported_flights,id',
|
||||||
'flight_number' => 'required|string',
|
'flight_number' => 'nullable|string',
|
||||||
'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',
|
||||||
'dep_time' => 'nullable|date_format:H:i',
|
'dep_time' => 'nullable|date_format:H:i',
|
||||||
@@ -238,15 +239,14 @@ class FlightImportController extends Controller
|
|||||||
'aircraft_id' => $validated['aircraft_id'] ?? null,
|
'aircraft_id' => $validated['aircraft_id'] ?? null,
|
||||||
'aircraft_registration' => $validated['registration'] ?? null,
|
'aircraft_registration' => $validated['registration'] ?? null,
|
||||||
'seat_number' => $validated['seat_number'] ?? null,
|
'seat_number' => $validated['seat_number'] ?? null,
|
||||||
'seat_type_id' => $validated['seat_type_id'] ?? null,
|
'seat_type_id' => $validated['seat_type_id'] ?? 0,
|
||||||
'flight_class_id' => $validated['flight_class_id'] ?? null,
|
'flight_class_id' => $validated['flight_class_id'] ?? 0,
|
||||||
'flight_reason_id' => $validated['flight_reason_id'] ?? null,
|
'flight_reason_id' => $validated['flight_reason_id'] ?? 0,
|
||||||
'note' => $validated['note'] ?? null,
|
'note' => $validated['note'] ?? null,
|
||||||
]);
|
]);
|
||||||
|
|
||||||
ImportedFlight::destroy($validated['imported_flight_id']);
|
ImportedFlight::destroy($validated['imported_flight_id']);
|
||||||
|
return to_route('reconcile');
|
||||||
return redirect()->route('reconcile');
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -18,7 +18,7 @@ class SearchController extends Controller
|
|||||||
->orWhere('IATA_code', 'ilike', "%{$q}%")
|
->orWhere('IATA_code', 'ilike', "%{$q}%")
|
||||||
->orWhere('ICAO_code', 'ilike', "%{$q}%");
|
->orWhere('ICAO_code', 'ilike', "%{$q}%");
|
||||||
})
|
})
|
||||||
->limit(15)
|
->limit(50)
|
||||||
->get(['id', 'name', 'IATA_code', 'ICAO_code', 'logo'])
|
->get(['id', 'name', 'IATA_code', 'ICAO_code', 'logo'])
|
||||||
->map(fn($a) => [
|
->map(fn($a) => [
|
||||||
'value' => $a->id,
|
'value' => $a->id,
|
||||||
@@ -33,7 +33,7 @@ class SearchController extends Controller
|
|||||||
|
|
||||||
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}%"])
|
||||||
->limit(15)
|
->limit(200)
|
||||||
->get(['id', 'manufacturer_code', 'model_full_name', 'designator'])
|
->get(['id', 'manufacturer_code', 'model_full_name', 'designator'])
|
||||||
->map(fn($a) => [
|
->map(fn($a) => [
|
||||||
'value' => $a->id,
|
'value' => $a->id,
|
||||||
|
|||||||
@@ -1,11 +1,16 @@
|
|||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import {Link} from "@inertiajs/vue3";
|
|
||||||
import MainHeader from "@/Components/FlightsGoneBy/MainHeader.vue";
|
import MainHeader from "@/Components/FlightsGoneBy/MainHeader.vue";
|
||||||
import MainFooter from "@/Components/FlightsGoneBy/MainFooter.vue";
|
import MainFooter from "@/Components/FlightsGoneBy/MainFooter.vue";
|
||||||
import Radar from "@/Components/FlightsGoneBy/Radar.vue";
|
import Radar from "@/Components/FlightsGoneBy/Radar.vue";
|
||||||
import { usePage } from "@inertiajs/vue3";
|
import { usePage, router } from "@inertiajs/vue3";
|
||||||
const page = usePage();
|
import { ref } from "vue";
|
||||||
|
|
||||||
|
const page = usePage();
|
||||||
|
const transitionKey = ref(0);
|
||||||
|
|
||||||
|
router.on('success', () => {
|
||||||
|
transitionKey.value++;
|
||||||
|
});
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
@@ -13,7 +18,7 @@ const page = usePage();
|
|||||||
<div class="layoutContainer">
|
<div class="layoutContainer">
|
||||||
<MainHeader />
|
<MainHeader />
|
||||||
<Transition name="fade" mode="out-in">
|
<Transition name="fade" mode="out-in">
|
||||||
<main id="pageContainer" :key="page.url" >
|
<main id="pageContainer" :key="transitionKey">
|
||||||
<slot />
|
<slot />
|
||||||
</main>
|
</main>
|
||||||
</Transition>
|
</Transition>
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ const selectedFile = ref<File | null>(null);
|
|||||||
|
|
||||||
const blurb = computed(() => {
|
const blurb = computed(() => {
|
||||||
if (status.value === 'success') {
|
if (status.value === 'success') {
|
||||||
return `Successfully imported ${importedCount} flight${importedCount.value !== 1 ? 's' : ''}. You will just need to reconcile some mismatched airlines and airports.`;
|
return `Successfully imported ${importedCount.value} flight${importedCount.value !== 1 ? 's' : ''}. You will just need to reconcile some mismatched airlines and airports.`;
|
||||||
}
|
}
|
||||||
return 'Import a CSV export from MyFlightRadar24. You will then be guided to reconcile any data mismatches.';
|
return 'Import a CSV export from MyFlightRadar24. You will then be guided to reconcile any data mismatches.';
|
||||||
});
|
});
|
||||||
@@ -64,45 +64,49 @@ async function onFileChange(e: Event) {
|
|||||||
|
|
||||||
<template>
|
<template>
|
||||||
<Head title="Import" />
|
<Head title="Import" />
|
||||||
<GlassBox title="Import Your Flights">
|
<GlassBox title="Import Your Flights" :blurb="blurb">
|
||||||
<p v-if="status !== 'success'">
|
<v-row no-gutters class="ga-3">
|
||||||
Import a CSV export from MyFlightRadar24. You will then be guided
|
|
||||||
to reconcile any data mismatches.
|
<!-- File input / loading / success -->
|
||||||
</p>
|
<v-col cols="12">
|
||||||
<p v-else-if="status === 'success'" type="success" >
|
|
||||||
Successfully imported {{ importedCount }} flight{{ importedCount !== 1 ? 's' : '' }}. You will just need to reconcile some mismatched airlines and airports.
|
|
||||||
</p>
|
|
||||||
<v-file-input
|
<v-file-input
|
||||||
style="flex:0;width:100%"
|
|
||||||
prepend-icon=""
|
|
||||||
v-if="status !== 'uploading' && status !== 'success'"
|
v-if="status !== 'uploading' && status !== 'success'"
|
||||||
|
prepend-icon=""
|
||||||
label="Select CSV File"
|
label="Select CSV File"
|
||||||
accept=".csv"
|
accept=".csv"
|
||||||
@change="onFileChange"
|
@change="onFileChange"
|
||||||
ref="fileInput"
|
ref="fileInput"
|
||||||
v-model="selectedFile"
|
v-model="selectedFile"
|
||||||
|
hide-details
|
||||||
/>
|
/>
|
||||||
|
|
||||||
<div v-else-if="status === 'uploading'" class="d-flex align-center ga-3 mt-2">
|
<div
|
||||||
|
v-else-if="status === 'uploading'"
|
||||||
|
class="d-flex flex-column align-center justify-center ga-3 py-4"
|
||||||
|
>
|
||||||
<v-progress-circular indeterminate color="primary" />
|
<v-progress-circular indeterminate color="primary" />
|
||||||
<span>Importing your flights…</span>
|
<span>Importing your flights…</span>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<v-alert closable v-if="status === 'error'" type="error">
|
<v-btn
|
||||||
|
v-else-if="status === 'success'"
|
||||||
|
:href="route('reconcile')"
|
||||||
|
size="x-large"
|
||||||
|
block
|
||||||
|
>
|
||||||
|
Reconcile Your Data
|
||||||
|
</v-btn>
|
||||||
|
</v-col>
|
||||||
|
|
||||||
|
<!-- Errors (independent of the above) -->
|
||||||
|
<v-col v-if="status === 'error'" cols="12">
|
||||||
|
<v-alert closable type="error">
|
||||||
<div v-for="(err, i) in errors" :key="i">{{ err }}</div>
|
<div v-for="(err, i) in errors" :key="i">{{ err }}</div>
|
||||||
</v-alert>
|
</v-alert>
|
||||||
|
</v-col>
|
||||||
|
|
||||||
<v-btn :href="route('reconcile')" v-if="status === 'success'" size="x-large" block >Reconcile Your Data</v-btn>
|
</v-row>
|
||||||
</GlassBox>
|
</GlassBox>
|
||||||
</template>
|
</template>
|
||||||
<style scoped>
|
<style scoped>
|
||||||
h2{
|
|
||||||
font-size: 2rem;
|
|
||||||
}
|
|
||||||
|
|
||||||
p{
|
|
||||||
text-align: center;
|
|
||||||
width: 80%;
|
|
||||||
}
|
|
||||||
|
|
||||||
</style>
|
</style>
|
||||||
|
|||||||
@@ -195,11 +195,17 @@ function submit() {
|
|||||||
</v-col>
|
</v-col>
|
||||||
</v-row>
|
</v-row>
|
||||||
|
|
||||||
<!-- Submit -->
|
|
||||||
<v-row>
|
<v-row>
|
||||||
<v-col cols="12" class="d-flex justify-end">
|
<v-col cols="12" class="d-flex justify-end">
|
||||||
<v-btn block size="large" :loading="form.processing" :disabled="form.processing" @click="submit">
|
<v-btn
|
||||||
Save Flight
|
block
|
||||||
|
size="large"
|
||||||
|
:loading="submitForm.processing"
|
||||||
|
:disabled="submitForm.processing"
|
||||||
|
@click="submit"
|
||||||
|
>
|
||||||
|
<v-progress-circular v-if="submitForm.processing" indeterminate size="24" />
|
||||||
|
<span v-else>Save Flight</span>
|
||||||
</v-btn>
|
</v-btn>
|
||||||
</v-col>
|
</v-col>
|
||||||
</v-row>
|
</v-row>
|
||||||
|
|||||||
+1
-4
@@ -34,12 +34,9 @@ Route::domain(config('app.domain'))->group(
|
|||||||
Route::get('/reconcile', function () {
|
Route::get('/reconcile', function () {
|
||||||
$flight = new FlightImportController()->reconcile(request());
|
$flight = new FlightImportController()->reconcile(request());
|
||||||
|
|
||||||
if (!$flight) {
|
|
||||||
return redirect('/import/fr24');
|
|
||||||
}
|
|
||||||
|
|
||||||
return Inertia::render('ReconcileFlight', [
|
return Inertia::render('ReconcileFlight', [
|
||||||
'flight' => $flight,
|
'flight' => $flight,
|
||||||
|
'key' => $flight['imported_flight_id'],
|
||||||
]);
|
]);
|
||||||
})->name('reconcile');
|
})->name('reconcile');
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user