Added User Settings
This commit is contained in:
@@ -272,7 +272,7 @@ class FlightController extends Controller
|
||||
$updated = $flight->snapshot($flight->id);
|
||||
$this->recordChanges($flight, $dirty, $original, $updated);
|
||||
|
||||
return redirect()->route('profile.departure-board', [Auth::user()->name, $flight->id]);
|
||||
return redirect()->route('profile.departure-board', [$flight->user->name, $flight->id]);
|
||||
}
|
||||
|
||||
public function delete(UserFlight $flight, ?string $referrer = 'departure-board')
|
||||
|
||||
@@ -17,7 +17,7 @@ class FlightProfileController extends Controller
|
||||
public function profileData(User $user, string $view, ?int $selectedFlightId = null) : array {
|
||||
return [
|
||||
'user' => $user,
|
||||
'canEdit' => (auth()->check() && auth()->id() === $user->id) || auth()->user()->hasRole('admin'),
|
||||
'canEdit' => (auth()->check() && auth()->id() === $user->id) || (auth()->check() && auth()->user()->hasRole('admin')),
|
||||
'initialView' => $view,
|
||||
'selectedFlightId' => $selectedFlightId,
|
||||
'flight_api_url' => self::getUserFlightApiURL($user),
|
||||
|
||||
@@ -0,0 +1,29 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Settings\SettingsRegistry;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class SettingsController extends Controller
|
||||
{
|
||||
public function show(Request $request)
|
||||
{
|
||||
$user = $request->user();
|
||||
$current = array_merge(SettingsRegistry::defaults(), $user->settings ?? []);
|
||||
$schema = SettingsRegistry::schema();
|
||||
|
||||
$fields = array_map(fn($field) => array_merge($field, [
|
||||
'value' => $current[$field['key']] ?? $field['default'],
|
||||
]), $schema);
|
||||
|
||||
return response()->json(['fields' => $fields]);
|
||||
}
|
||||
|
||||
public function update(Request $request)
|
||||
{
|
||||
$validated = $request->validate(SettingsRegistry::validationRules());
|
||||
$request->user()->updateSettings($validated['settings']);
|
||||
return response()->json(['message' => 'Settings saved.']);
|
||||
}
|
||||
}
|
||||
@@ -5,9 +5,11 @@ namespace App\Http\Controllers;
|
||||
use App\Models\Followee;
|
||||
use App\Models\Notification;
|
||||
use App\Models\User;
|
||||
use App\Settings\SettingsRegistry;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\RedirectResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Inertia\Inertia;
|
||||
|
||||
class UserController extends Controller
|
||||
{
|
||||
@@ -37,4 +39,17 @@ class UserController extends Controller
|
||||
|
||||
return response()->json(['following' => true]);
|
||||
}
|
||||
|
||||
public function settings(){
|
||||
$user = auth()->user();
|
||||
$current = array_merge(SettingsRegistry::defaults(), $user->settings ?? []);
|
||||
$fields = array_map(fn($field) => array_merge($field, [
|
||||
'value' => $current[$field['key']] ?? $field['default'],
|
||||
]), SettingsRegistry::schema());
|
||||
|
||||
return Inertia::render('UserSettings', [
|
||||
'fields' => $fields,
|
||||
'categories' => SettingsRegistry::categories(),
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -45,7 +45,13 @@ class Airline extends Model
|
||||
protected function logoUrl() : Attribute{
|
||||
return Attribute::make(
|
||||
get: function () {
|
||||
return config('app.logo_api_url') . "/airline/$this->internal_name/logo/tail";
|
||||
$user = auth()->user();
|
||||
$apiUrl = config('app.logo_api_url');
|
||||
if ($user && !$user->getSetting('ai_tail_logos')) {
|
||||
return $apiUrl .'/airline/blank/logo/tail';
|
||||
}
|
||||
|
||||
return $apiUrl . "/airline/$this->internal_name/logo/tail";
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
+26
-10
@@ -3,9 +3,11 @@
|
||||
namespace App\Models;
|
||||
|
||||
use App\Http\Controllers\UserFlightController;
|
||||
use App\Settings\SettingsRegistry;
|
||||
use Database\Factories\UserFactory;
|
||||
use Illuminate\Database\Eloquent\Attributes\Fillable;
|
||||
use Illuminate\Database\Eloquent\Attributes\Hidden;
|
||||
use Illuminate\Database\Eloquent\Casts\Attribute;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||
use Illuminate\Foundation\Auth\User as Authenticatable;
|
||||
@@ -13,7 +15,7 @@ use App\Traits\HasAchievements;
|
||||
use Laravel\Sanctum\HasApiTokens;
|
||||
use Spatie\Permission\Traits\HasRoles;
|
||||
|
||||
#[Fillable(['name', 'email', 'password', 'distance_unit'])]
|
||||
#[Fillable(['name', 'email', 'password', 'distance_unit', 'settings'])]
|
||||
#[Hidden(['password', 'remember_token'])]
|
||||
class User extends Authenticatable
|
||||
{
|
||||
@@ -21,24 +23,38 @@ class User extends Authenticatable
|
||||
/** @use HasFactory<UserFactory> */
|
||||
use HasFactory, HasAchievements, HasApiTokens, HasRoles;
|
||||
|
||||
/**
|
||||
* Get the attributes that should be cast.
|
||||
*
|
||||
* @return array<string, string>
|
||||
*/
|
||||
protected function casts(): array
|
||||
{
|
||||
return [
|
||||
protected $casts = [
|
||||
'email_verified_at' => 'datetime',
|
||||
'password' => 'hashed',
|
||||
'settings' => 'array',
|
||||
];
|
||||
}
|
||||
|
||||
protected $appends = ['resolved_settings'];
|
||||
|
||||
public function achievements(): HasMany
|
||||
{
|
||||
return $this->hasMany(UserAchievement::class);
|
||||
}
|
||||
|
||||
public function getSetting(string $key): mixed
|
||||
{
|
||||
$defaults = SettingsRegistry::defaults();
|
||||
return $this->settings[$key] ?? $defaults[$key] ?? null;
|
||||
}
|
||||
|
||||
public function updateSettings(array $values): void
|
||||
{
|
||||
$current = array_merge(SettingsRegistry::defaults(), $this->settings ?? []);
|
||||
$this->update(['settings' => array_merge($current, $values)]);
|
||||
}
|
||||
|
||||
protected function resolvedSettings(): Attribute
|
||||
{
|
||||
return Attribute::make(
|
||||
get: fn() => array_merge(SettingsRegistry::defaults(), $this->settings ?? [])
|
||||
);
|
||||
}
|
||||
|
||||
public function unlockedAchievements(): HasMany
|
||||
{
|
||||
return $this->achievements()
|
||||
|
||||
@@ -227,6 +227,10 @@ class UserFlight extends Model
|
||||
return Attribute::make(
|
||||
get: function () {
|
||||
|
||||
$user = auth()?->user();
|
||||
|
||||
$useAi = !$user || $user->getSetting('ai_liveries');
|
||||
|
||||
$apiUrl = config('app.logo_api_url');
|
||||
|
||||
if (!$this->aircraft) {
|
||||
@@ -234,7 +238,7 @@ class UserFlight extends Model
|
||||
}
|
||||
|
||||
|
||||
if ($this->airline){
|
||||
if ($this->airline && $useAi){
|
||||
$path = "images/liveries/{$this->airline->internal_name}_{$this->aircraft->designator}.png";
|
||||
if (Storage::disk('local')->exists($path)) {
|
||||
$finalPath = $apiUrl."/airline/{$this->airline->internal_name}/livery/{$this->aircraft->designator}";
|
||||
|
||||
@@ -0,0 +1,131 @@
|
||||
<?php
|
||||
|
||||
namespace App\Settings;
|
||||
|
||||
class SettingsRegistry
|
||||
{
|
||||
|
||||
public static function categories(): array
|
||||
{
|
||||
return [
|
||||
'Units of Measurement' => 'Select either metric or incorrect units.',
|
||||
'FlightsGoneBy Settings' => 'Settings for Site Behaviour',
|
||||
'AI Generated Content' => 'Airline tail logos and liveries are AI generated with human cleanup. If you would rather not see any AI, then our blank aircraft templates are human created.',
|
||||
'Account & Privacy' => 'Everything to do with your account.',
|
||||
];
|
||||
}
|
||||
|
||||
public static function schema(): array
|
||||
{
|
||||
return [
|
||||
[
|
||||
'key' => 'distance_unit',
|
||||
'type' => 'select',
|
||||
'label' => 'Distance Units',
|
||||
'category' => 'Units of Measurement',
|
||||
'default' => 'km',
|
||||
'options' => [
|
||||
['value' => 'km', 'label' => 'Kilometres (km)'],
|
||||
['value' => 'mi', 'label' => 'Miles (mi)'],
|
||||
['value' => 'nm', 'label' => 'Nautical miles (nm)'],
|
||||
],
|
||||
],
|
||||
[
|
||||
'category' => 'Account & Privacy',
|
||||
'key' => 'private_profile',
|
||||
'type' => 'select',
|
||||
'label' => 'Account Privacy',
|
||||
'default' => 'public',
|
||||
'options' => [
|
||||
['value' => 'public', 'label' => 'Public Profile Viewable By Everyone'],
|
||||
['value' => 'private', 'label' => 'Private Profile Viewable Only By You and Your Approved Followers'],
|
||||
]
|
||||
],
|
||||
[
|
||||
'key' => 'default_login_page',
|
||||
'type' => 'select',
|
||||
'label' => 'Default Page After Login',
|
||||
'category' => 'FlightsGoneBy Settings',
|
||||
'default' => 'feed_first',
|
||||
'options' => [
|
||||
['value' => 'feed_first', 'label' => 'Feed if Following People, Profile if Not'],
|
||||
['value' => 'profile', 'label' => 'Your Profile'],
|
||||
['value' => 'feed', 'label' => 'Your Feed'],
|
||||
['value' => 'dashboard', 'label' => 'Your Dashboard'],
|
||||
],
|
||||
],
|
||||
[
|
||||
'key' => 'default_profile_view',
|
||||
'type' => 'select',
|
||||
'label' => 'Default View When Loading a Profile',
|
||||
'category' => 'FlightsGoneBy Settings',
|
||||
'default' => 'departure-board',
|
||||
'options' => [
|
||||
['value' => 'departure-board', 'label' => 'Departure Board'],
|
||||
['value' => 'map', 'label' => 'Map'],
|
||||
['value' => 'boarding-passes', 'label' => 'Boarding Passes'],
|
||||
['value' => 'achievements', 'label' => 'Achievements'],
|
||||
],
|
||||
],
|
||||
[
|
||||
'category' => 'AI Generated Content',
|
||||
'key' => 'ai_liveries',
|
||||
'type' => 'checkbox',
|
||||
'label' => 'Show AI Generated Livery Images',
|
||||
'default' => true,
|
||||
],
|
||||
[
|
||||
'category' => 'AI Generated Content',
|
||||
'key' => 'ai_tail_logos',
|
||||
'type' => 'checkbox',
|
||||
'label' => 'Show AI Generated Tail Logos',
|
||||
'default' => true,
|
||||
],
|
||||
[
|
||||
'key' => 'departure_board_columns',
|
||||
'category' => 'FlightsGoneBy Settings',
|
||||
'type' => 'multiselect',
|
||||
'label' => 'Which columns to show on the Departure Board',
|
||||
'default' => ['airline', 'flight_number', 'from', 'to', 'departure_date', 'departure_time', 'arrival_time', 'duration', 'distance', 'aircraft', 'registration', 'class_seat_combined'],
|
||||
'options' => [
|
||||
['value' => 'airline', 'label' => 'Airline'],
|
||||
['value' => 'flight_number', 'label' => 'Flight Number'],
|
||||
['value' => 'from', 'label' => 'From'],
|
||||
['value' => 'to', 'label' => 'To'],
|
||||
['value' => 'departure_date', 'label' => 'Departure Date'],
|
||||
['value' => 'departure_time', 'label' => 'Departure Time'],
|
||||
['value' => 'arrival_time', 'label' => 'Arrival Time'],
|
||||
['value' => 'duration', 'label' => 'Duration'],
|
||||
['value' => 'distance', 'label' => 'Distance'],
|
||||
['value' => 'aircraft', 'label' => 'Aircraft'],
|
||||
['value' => 'registration', 'label' => 'Aircraft Registration'],
|
||||
['value' => 'class_seat_combined', 'label' => 'Class/Seat Type/Seat Number Combined'],
|
||||
],
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
public static function defaults(): array
|
||||
{
|
||||
return collect(static::schema())
|
||||
->pluck('default', 'key')
|
||||
->toArray();
|
||||
}
|
||||
|
||||
public static function validationRules(): array
|
||||
{
|
||||
$rules = [];
|
||||
foreach (static::schema() as $field) {
|
||||
$key = "settings.{$field['key']}";
|
||||
$rules[$key] = match ($field['type']) {
|
||||
'select' => ['required', 'string', 'in:' . implode(',', array_column($field['options'], 'value'))],
|
||||
'checkbox' => ['boolean'],
|
||||
'text' => ['nullable', 'string', 'max:255'],
|
||||
'multiselect' => ['nullable', 'array'],
|
||||
"settings.{$field['key']}.*" => ['string'],
|
||||
default => ['nullable'],
|
||||
};
|
||||
}
|
||||
return $rules;
|
||||
}
|
||||
}
|
||||
@@ -9,11 +9,13 @@ return new class extends Migration
|
||||
/**
|
||||
* Run the migrations.
|
||||
*/
|
||||
// database/migrations/xxxx_add_settings_to_users_table.php
|
||||
public function up(): void
|
||||
{
|
||||
//
|
||||
Schema::table('users', function (Blueprint $table) {
|
||||
$table->json('settings')->nullable()->after('password');
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*/
|
||||
|
||||
@@ -53,6 +53,13 @@ function formatEngineType(type: string): string {
|
||||
<div class="tooltip-rows" v-if="flight?.livery_url">
|
||||
<LiveryImage :flight="flight" />
|
||||
</div>
|
||||
<div class="tooltip-divider" v-if="flight?.aircraft_registration" />
|
||||
<div class="tooltip-rows" v-if="flight?.aircraft_registration">
|
||||
<div class="tooltip-row">
|
||||
<span class="tooltip-label">Registration</span>
|
||||
<span class="tooltip-value">{{ flight.aircraft_registration}}</span>
|
||||
</div>
|
||||
</div>
|
||||
</GlassTooltip>
|
||||
</template>
|
||||
|
||||
|
||||
@@ -1,9 +1,10 @@
|
||||
<script setup lang="ts">
|
||||
import {Flight, User} from "@/Types/types";
|
||||
import {Flight, SharedProps, User} from "@/Types/types";
|
||||
import { computed, ref, watch, nextTick } from "vue";
|
||||
import type { DataTableSortItem } from 'vuetify';
|
||||
import {FlightStats} from "@/Composables/useFlightStats";
|
||||
import DepartureBoardTableRow from "@/Components/FlightsGoneBy/DepartureBoardTableRow.vue";
|
||||
import {usePage} from "@inertiajs/vue3";
|
||||
|
||||
const props = defineProps<{
|
||||
flightStats: FlightStats
|
||||
@@ -12,24 +13,34 @@ const props = defineProps<{
|
||||
flightId?: number | null
|
||||
}>()
|
||||
|
||||
|
||||
const page = usePage<SharedProps>().props
|
||||
const ITEMS_PER_PAGE = 25
|
||||
|
||||
const headers = [
|
||||
const defaultColumns = ['airline', 'flight_number', 'from', 'to', 'departure_date', 'departure_time', 'arrival_time', 'duration', 'distance', 'aircraft', 'registration', 'class_seat_combined']
|
||||
const columnsToShow = computed(() => page.auth.user?.resolved_settings?.departure_board_columns ?? defaultColumns)
|
||||
const showColumn = (column: string) => columnsToShow.value.includes(column)
|
||||
|
||||
const allHeaders = [
|
||||
{ title: '', key: 'airline', sortable: true },
|
||||
{ title: 'FLIGHT', key: 'flight_number', sortable: true },
|
||||
{ title: 'FROM', key: 'departure_airport', sortable: true },
|
||||
{ title: 'TO', key: 'arrival_airport', sortable: true },
|
||||
{ title: 'FROM', key: 'from', sortable: true },
|
||||
{ title: 'TO', key: 'to', sortable: true },
|
||||
{ title: 'DATE', key: 'departure_date', sortable: true },
|
||||
{ title: 'DEPART', key: 'departure_time_display', sortable: false },
|
||||
{ title: 'ARRIVE', key: 'arrival_time_display', sortable: false },
|
||||
{ title: 'DEPART', key: 'departure_time', sortable: false },
|
||||
{ title: 'ARRIVE', key: 'arrival_time', sortable: false },
|
||||
{ title: 'DURATION', key: 'duration', sortable: true },
|
||||
{ title: 'DISTANCE', key: 'distance', sortable: true },
|
||||
{ title: 'AIRCRAFT', key: 'aircraft.designator', sortable: true },
|
||||
{ title: 'REG', key: 'aircraft_registration', sortable: true },
|
||||
{ title: 'CLASS', key: 'flight_class', sortable: true },
|
||||
{ title: 'AIRCRAFT', key: 'aircraft', sortable: true },
|
||||
{ title: 'REG', key: 'registration', sortable: true },
|
||||
{ title: 'CLASS', key: 'class_seat_combined', sortable: true },
|
||||
{ title: '', key: 'actions', sortable: false },
|
||||
]
|
||||
|
||||
const headers = computed(() =>
|
||||
allHeaders.filter(h => h.key === 'actions' || showColumn(h.key))
|
||||
)
|
||||
|
||||
const CLASS_ORDER: Record<string, number> = {
|
||||
'Unspecified': 0,
|
||||
'Economy': 1,
|
||||
@@ -40,7 +51,7 @@ const CLASS_ORDER: Record<string, number> = {
|
||||
}
|
||||
|
||||
const customKeySort = {
|
||||
flight_class: (a: Flight['flight_class'], b: Flight['flight_class']) => {
|
||||
class_seat_combined: (a: Flight['flight_class'], b: Flight['flight_class']) => {
|
||||
return (CLASS_ORDER[a?.name ?? ''] ?? -1) - (CLASS_ORDER[b?.name ?? ''] ?? -1)
|
||||
},
|
||||
airline: (a: Flight['airline'], b: Flight['airline']) => {
|
||||
@@ -123,6 +134,7 @@ watch(
|
||||
},
|
||||
{ immediate: true }
|
||||
)
|
||||
|
||||
</script>
|
||||
|
||||
<template>
|
||||
@@ -160,6 +172,7 @@ watch(
|
||||
|
||||
<template v-else-if="!(item as any)._groupHeader">
|
||||
<DepartureBoardTableRow
|
||||
:columnsToShow="columnsToShow"
|
||||
:flight="(item as Flight)"
|
||||
:user="user"
|
||||
:can-edit="canEdit"
|
||||
|
||||
@@ -20,9 +20,12 @@ const props = defineProps<{
|
||||
highlighted?: boolean
|
||||
group?: 'upcoming' | 'departed'
|
||||
isSorting?: boolean
|
||||
columnsToShow: string[]
|
||||
}>()
|
||||
|
||||
const page = usePage<SharedProps>()
|
||||
const showColumn = (column: string) => props.columnsToShow.includes(column)
|
||||
|
||||
</script>
|
||||
|
||||
<template>
|
||||
@@ -34,11 +37,11 @@ const page = usePage<SharedProps>()
|
||||
]"
|
||||
:data-flight-id="flight.id"
|
||||
>
|
||||
<td class="v-data-table__td airline-logo-cell">
|
||||
<td v-if="showColumn('airline')" class="v-data-table__td airline-logo-cell">
|
||||
<AirlineLogo size="32" :airline="flight.airline" class="airline-logo-img" />
|
||||
</td>
|
||||
|
||||
<td class="v-data-table__td flight-number-cell">
|
||||
<td v-if="showColumn('flight_number')" class="v-data-table__td flight-number-cell">
|
||||
<div class="flight-cell">
|
||||
<Mono class="flight-number">
|
||||
{{ flight.flight_number }}
|
||||
@@ -46,56 +49,56 @@ const page = usePage<SharedProps>()
|
||||
</div>
|
||||
</td>
|
||||
|
||||
<td class="v-data-table__td">
|
||||
<td v-if="showColumn('from')" class="v-data-table__td">
|
||||
<AirportToolTip :airport="flight.departure_airport">
|
||||
<Mono class="iata">{{ flight.departure_airport.display_code }}</Mono><br/>
|
||||
</AirportToolTip>
|
||||
<span class="city-name">{{ flight.departure_airport.municipality }}</span>
|
||||
</td>
|
||||
|
||||
<td class="v-data-table__td">
|
||||
<td v-if="showColumn('to')" class="v-data-table__td">
|
||||
<AirportToolTip :airport="flight.arrival_airport">
|
||||
<span class="iata"><Mono>{{ flight.arrival_airport.display_code }}</Mono></span><br/>
|
||||
</AirportToolTip>
|
||||
<span class="city-name" >{{ flight.arrival_airport.municipality }}</span>
|
||||
</td>
|
||||
|
||||
<td class="v-data-table__td">
|
||||
<td v-if="showColumn('departure_date')" class="v-data-table__td">
|
||||
<span class="date-cell"><Mono muted smaller>{{ flight.departure_date_display }}</Mono></span>
|
||||
</td>
|
||||
|
||||
<td class="v-data-table__td">
|
||||
<td v-if="showColumn('departure_time')" class="v-data-table__td">
|
||||
<span class="time-cell">
|
||||
<Mono small>{{ flight.departure_time_display }}</Mono>
|
||||
</span>
|
||||
</td>
|
||||
|
||||
<td class="v-data-table__td arrival-time-cell">
|
||||
<td v-if="showColumn('arrival_time')" class="v-data-table__td arrival-time-cell">
|
||||
<Mono small>{{ flight.arrival_time_display }}</Mono>
|
||||
<DayDifference :value="flight.arrival_day_difference" />
|
||||
</td>
|
||||
|
||||
<td class="v-data-table__td duration-cell">
|
||||
<td v-if="showColumn('duration')" class="v-data-table__td duration-cell">
|
||||
<Mono muted small>{{ flight.duration_display ?? '—' }}</Mono>
|
||||
</td>
|
||||
|
||||
<td class="v-data-table__td distance-cell">
|
||||
<td v-if="showColumn('distance')" class="v-data-table__td distance-cell">
|
||||
<Mono muted small>
|
||||
<Distance :unit="page.props.auth.user?.distance_unit" :value="Math.round(flight.distance)" />
|
||||
<Distance :unit="page.props.auth.user?.resolved_settings?.distance_unit" :value="Math.round(flight.distance)" />
|
||||
</Mono>
|
||||
</td>
|
||||
|
||||
<td class="v-data-table__td aircraft-cell">
|
||||
<td v-if="showColumn('aircraft')" class="v-data-table__td aircraft-cell">
|
||||
<AircraftToolTip v-if="flight.aircraft" :aircraft="flight.aircraft" :flight="flight">
|
||||
<Mono muted small>{{ flight.aircraft?.designator }}</Mono>
|
||||
</AircraftToolTip>
|
||||
</td>
|
||||
|
||||
<td class="v-data-table__td registration-cell">
|
||||
<td v-if="showColumn('registration')" class="v-data-table__td registration-cell">
|
||||
<Mono muted smaller v-if="flight.aircraft_registration">{{ flight.aircraft_registration }}</Mono>
|
||||
</td>
|
||||
|
||||
<td class="v-data-table__td class-badges-cell">
|
||||
<td v-if="showColumn('class_seat_combined')" class="v-data-table__td class-badges-cell">
|
||||
<span class="class-cell">
|
||||
<CrewTooltip v-if="flight.flight_reason?.name == 'Crew'" :crew-type="flight.crew_type!">
|
||||
<FlightClassBadge v-if="flight.flight_class?.internal_name === 'crew'" :flight="flight" />
|
||||
|
||||
@@ -35,12 +35,12 @@
|
||||
<div class="stat">
|
||||
<template v-if="totalDistanceKm">
|
||||
<div class="stat-primary">
|
||||
<span class="stat-num"><Distance :unit="page.auth?.user?.distance_unit" includeSpace :value="totalDistanceKm" /></span>
|
||||
<span class="stat-num"><Distance :unit="page.auth?.user?.resolved_settings?.distance_unit" includeSpace :value="totalDistanceKm" /></span>
|
||||
</div>
|
||||
</template>
|
||||
<template v-if="upcomingDistanceKm">
|
||||
<div :class="totalDistanceKm ? 'stat-upcoming' : 'stat-primary'">
|
||||
<span :class="totalDistanceKm ? 'stat-upcoming-num' : 'stat-num'"><Distance :unit="page.auth?.user?.distance_unit" includeSpace :value="upcomingDistanceKm"/></span>
|
||||
<span :class="totalDistanceKm ? 'stat-upcoming-num' : 'stat-num'"><Distance :unit="page.auth?.user?.resolved_settings?.distance_unit" includeSpace :value="upcomingDistanceKm"/></span>
|
||||
</div>
|
||||
</template>
|
||||
</div>
|
||||
|
||||
@@ -51,6 +51,7 @@ onUnmounted(() => document.removeEventListener('click', handleClickOutside))
|
||||
</button>
|
||||
<div v-if="dropdownOpen" class="dropdown-menu">
|
||||
<Link :href="route('import.fr24')" class="dropdown-item">Import from FR24</Link>
|
||||
<Link :href="route('profile.settings')" class="dropdown-item">Settings</Link>
|
||||
<div class="dropdown-divider" />
|
||||
<button class="dropdown-item dropdown-item--danger" @click="logout">Log Out</button>
|
||||
</div>
|
||||
@@ -76,6 +77,7 @@ onUnmounted(() => document.removeEventListener('click', handleClickOutside))
|
||||
<Link :href="route('profile.view', { user: props.auth.user.name })" class="nav-link" @click="menuOpen = false">Profile</Link>
|
||||
<Link :href="route('feed')" class="nav-link nav-link" @click="menuOpen = false">Feed</Link>
|
||||
<Link :href="route('import.fr24')" class="nav-link" @click="menuOpen = false">Import from FR24</Link>
|
||||
<Link :href="route('profile.settings')" class="nav-link" @click="menuOpen = false">Settings</Link>
|
||||
<div class="dropdown-divider" />
|
||||
<button class="nav-link nav-link--danger" @click="logout">Log Out</button>
|
||||
</template>
|
||||
|
||||
@@ -1,56 +0,0 @@
|
||||
<script setup>
|
||||
import AuthenticatedLayout from '@/Layouts/AuthenticatedLayout.vue';
|
||||
import DeleteUserForm from './Partials/DeleteUserForm.vue';
|
||||
import UpdatePasswordForm from './Partials/UpdatePasswordForm.vue';
|
||||
import UpdateProfileInformationForm from './Partials/UpdateProfileInformationForm.vue';
|
||||
import { Head } from '@inertiajs/vue3';
|
||||
|
||||
defineProps({
|
||||
mustVerifyEmail: {
|
||||
type: Boolean,
|
||||
},
|
||||
status: {
|
||||
type: String,
|
||||
},
|
||||
});
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<Head title="Profile" />
|
||||
|
||||
<AuthenticatedLayout>
|
||||
<template #header>
|
||||
<h2
|
||||
class="text-xl font-semibold leading-tight text-gray-800"
|
||||
>
|
||||
Profile
|
||||
</h2>
|
||||
</template>
|
||||
|
||||
<div class="py-12">
|
||||
<div class="mx-auto max-w-7xl space-y-6 sm:px-6 lg:px-8">
|
||||
<div
|
||||
class="bg-white p-4 shadow sm:rounded-lg sm:p-8"
|
||||
>
|
||||
<UpdateProfileInformationForm
|
||||
:must-verify-email="mustVerifyEmail"
|
||||
:status="status"
|
||||
class="max-w-xl"
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div
|
||||
class="bg-white p-4 shadow sm:rounded-lg sm:p-8"
|
||||
>
|
||||
<UpdatePasswordForm class="max-w-xl" />
|
||||
</div>
|
||||
|
||||
<div
|
||||
class="bg-white p-4 shadow sm:rounded-lg sm:p-8"
|
||||
>
|
||||
<DeleteUserForm class="max-w-xl" />
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</AuthenticatedLayout>
|
||||
</template>
|
||||
@@ -107,7 +107,7 @@ const filteredUnlockedCount = computed(() =>
|
||||
:key="achievement.id"
|
||||
:achievement="achievement"
|
||||
:user-achievement="userAchievements[achievement.id]"
|
||||
:distance-unit="page.auth?.user?.distance_unit"
|
||||
:distance-unit="page.auth?.user?.resolved_settings?.distance_unit"
|
||||
/>
|
||||
</div>
|
||||
</Panel>
|
||||
|
||||
@@ -0,0 +1,140 @@
|
||||
<script lang="ts" setup>
|
||||
import { reactive, ref, computed } from 'vue'
|
||||
import axios from 'axios'
|
||||
import MainLayout from "@/Layouts/MainLayout.vue"
|
||||
import GlassBox from "@/Components/FlightsGoneBy/GlassBox.vue"
|
||||
import { Head } from "@inertiajs/vue3"
|
||||
import {SettingField} from "@/Types/types";
|
||||
defineOptions({ layout: MainLayout })
|
||||
|
||||
const props = defineProps<{
|
||||
fields: SettingField[],
|
||||
categories: Record<string, string>
|
||||
}>()
|
||||
|
||||
const values = reactive(
|
||||
Object.fromEntries(props.fields.map(f => [f.key, f.value]))
|
||||
)
|
||||
const saving = ref(false)
|
||||
const saved = ref(false)
|
||||
const error = ref(false)
|
||||
|
||||
const groupedFields = computed(() =>
|
||||
props.fields.reduce((groups: Record<string, SettingField[]>, field) => {
|
||||
const cat = field.category ?? 'General'
|
||||
;(groups[cat] ??= []).push(field)
|
||||
return groups
|
||||
}, {} as Record<string, SettingField[]>)
|
||||
)
|
||||
|
||||
|
||||
async function save() {
|
||||
saving.value = true
|
||||
error.value = false
|
||||
try {
|
||||
await axios.patch('/settings', { settings: values })
|
||||
saved.value = true
|
||||
setTimeout(() => saved.value = false, 3000)
|
||||
} catch {
|
||||
error.value = true
|
||||
} finally {
|
||||
saving.value = false
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<Head title="Settings" />
|
||||
<GlassBox title="Your Settings">
|
||||
<v-form @submit.prevent="save">
|
||||
<template v-for="(groupFields, category) in groupedFields" :key="category">
|
||||
<p class="text-overline text-medium-emphasis mb-1 mt-4">{{ category }}</p>
|
||||
<small v-if="categories[category]" class="text-body-2 text-medium-emphasis mb-3">
|
||||
{{ categories[category] }}
|
||||
</small>
|
||||
<v-divider class="mb-4" />
|
||||
|
||||
<template v-for="field in groupFields" :key="field.key">
|
||||
|
||||
<v-select
|
||||
v-if="field.type === 'select'"
|
||||
v-model="values[field.key]"
|
||||
:label="field.label"
|
||||
:items="field.options"
|
||||
item-title="label"
|
||||
item-value="value"
|
||||
variant="outlined"
|
||||
density="comfortable"
|
||||
class="mb-2"
|
||||
/>
|
||||
|
||||
<v-text-field
|
||||
v-else-if="field.type === 'text'"
|
||||
v-model="values[field.key]"
|
||||
:label="field.label"
|
||||
variant="outlined"
|
||||
density="comfortable"
|
||||
class="mb-2"
|
||||
/>
|
||||
|
||||
<v-checkbox
|
||||
v-else-if="field.type === 'checkbox'"
|
||||
v-model="values[field.key]"
|
||||
:label="field.label"
|
||||
color="primary"
|
||||
density="comfortable"
|
||||
hide-details
|
||||
class="mb-2"
|
||||
/>
|
||||
|
||||
<v-select
|
||||
v-else-if="field.type === 'multiselect'"
|
||||
v-model="values[field.key]"
|
||||
:label="field.label"
|
||||
:items="field.options"
|
||||
item-title="label"
|
||||
item-value="value"
|
||||
variant="outlined"
|
||||
density="comfortable"
|
||||
chips
|
||||
multiple
|
||||
closable-chips
|
||||
clearable
|
||||
class="mb-2"
|
||||
/>
|
||||
|
||||
|
||||
</template>
|
||||
</template>
|
||||
|
||||
<v-divider class="my-4" />
|
||||
|
||||
<div class="d-flex align-center gap-3">
|
||||
<v-btn
|
||||
type="submit"
|
||||
color="primary"
|
||||
variant="elevated"
|
||||
:loading="saving"
|
||||
min-width="140"
|
||||
>
|
||||
Save settings
|
||||
</v-btn>
|
||||
|
||||
<v-fade-transition>
|
||||
<div v-if="saved" class="d-flex align-center gap-1 text-success">
|
||||
<v-icon size="18">mdi-check-circle</v-icon>
|
||||
<span class="text-body-2">Saved</span>
|
||||
</div>
|
||||
</v-fade-transition>
|
||||
|
||||
<v-fade-transition>
|
||||
<div v-if="error" class="d-flex align-center gap-1 text-error">
|
||||
<v-icon size="18">mdi-alert-circle</v-icon>
|
||||
<span class="text-body-2">Something went wrong</span>
|
||||
</div>
|
||||
</v-fade-transition>
|
||||
</div>
|
||||
|
||||
</v-form>
|
||||
</GlassBox>
|
||||
</template>
|
||||
Vendored
+27
-1
@@ -17,7 +17,33 @@ export interface User {
|
||||
name: string
|
||||
email: string
|
||||
email_verified_at: string | null
|
||||
distance_unit: "km" | "mi" | "nm"
|
||||
resolved_settings?: UserSettings
|
||||
}
|
||||
|
||||
export type DistanceUnit = "km" | "mi" | "nm"
|
||||
|
||||
export interface UserSettings {
|
||||
distance_unit: DistanceUnit
|
||||
show_ai_tail_logos: boolean
|
||||
show_ai_livery_images: boolean
|
||||
departure_board_columns: string[]
|
||||
}
|
||||
|
||||
|
||||
export type SettingType = 'select' | 'text' | 'checkbox' | 'multiselect'
|
||||
export interface SettingOption {
|
||||
value: string
|
||||
label: string
|
||||
}
|
||||
|
||||
export interface SettingField {
|
||||
key: keyof UserSettings
|
||||
type: SettingType
|
||||
label: string
|
||||
category: string
|
||||
default: UserSettings[keyof UserSettings]
|
||||
value: UserSettings[keyof UserSettings]
|
||||
options?: SettingOption[]
|
||||
}
|
||||
|
||||
export type UserActionType = "flight_cancelled" | "flight_booked" | "flight_updated" | "flight_logged" | "flight_deleted" | "flight_imported" | "flight_departing" | "flight_arriving"
|
||||
|
||||
@@ -1,8 +1,15 @@
|
||||
<?php
|
||||
|
||||
use App\Http\Controllers\SettingsController;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Route;
|
||||
|
||||
Route::get('/user', function (Request $request) {
|
||||
return $request->user();
|
||||
})->middleware('auth:sanctum');
|
||||
|
||||
|
||||
Route::middleware('auth:sanctum')->group(function () {
|
||||
Route::get('/settings', [SettingsController::class, 'show']);
|
||||
Route::patch('/settings', [SettingsController::class, 'update']);
|
||||
});
|
||||
|
||||
@@ -14,6 +14,7 @@ use App\Http\Controllers\LogoController;
|
||||
use App\Http\Controllers\NotificationController;
|
||||
use App\Http\Controllers\ProfileController;
|
||||
use App\Http\Controllers\SearchController;
|
||||
use App\Http\Controllers\SettingsController;
|
||||
use App\Http\Controllers\UserController;
|
||||
use App\Models\Airline;
|
||||
use App\Models\FlightClass;
|
||||
@@ -63,6 +64,9 @@ Route::domain(config('app.domain'))->group(
|
||||
|
||||
Route::post('/u/{user}/follow', [UserController::class, 'follow'])->name('profile.follow');
|
||||
|
||||
Route::get('/settings', [UserController::class, 'settings'])->name('profile.settings');
|
||||
Route::patch('/settings', [SettingsController::class, 'update'])->name('settings.update');
|
||||
|
||||
Route::get('/notifications', [NotificationController::class, 'index'])->name('notifications.get');
|
||||
Route::patch('/notifications/{notification}/read', [NotificationController::class, 'markRead']);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user