diff --git a/app/Enums/ResultStatus.php b/app/Enums/ResultStatus.php index 9deb24443..9445e03b8 100644 --- a/app/Enums/ResultStatus.php +++ b/app/Enums/ResultStatus.php @@ -11,11 +11,6 @@ enum ResultStatus: string implements HasColor, HasLabel case Failed = 'failed'; // a speedtest that failed to run successfully. case Started = 'started'; // a speedtest that has been started by a worker but has not finish running. - public function getLabel(): ?string - { - return $this->name; - } - public function getColor(): ?string { return match ($this) { @@ -24,4 +19,13 @@ public function getColor(): ?string self::Started => 'warning', }; } + + public function getLabel(): ?string + { + return match ($this) { + self::Completed => 'Completed', + self::Failed => 'Failed', + self::Started => 'Started', + }; + } } diff --git a/app/Enums/UserRole.php b/app/Enums/UserRole.php new file mode 100644 index 000000000..7154ae8c8 --- /dev/null +++ b/app/Enums/UserRole.php @@ -0,0 +1,28 @@ + 'success', + self::User => 'gray', + }; + } + + public function getLabel(): ?string + { + return match ($this) { + self::Admin => 'Admin', + self::User => 'User', + }; + } +} diff --git a/app/Filament/Resources/ResultResource.php b/app/Filament/Resources/ResultResource.php index 36f06d412..26f408f92 100644 --- a/app/Filament/Resources/ResultResource.php +++ b/app/Filament/Resources/ResultResource.php @@ -216,6 +216,7 @@ public static function table(Table $table): Table ->toggleable() ->toggledHiddenByDefault(), Tables\Columns\TextColumn::make('status') + ->badge() ->toggleable() ->sortable(), Tables\Columns\IconColumn::make('scheduled') diff --git a/app/Filament/Resources/UserResource.php b/app/Filament/Resources/UserResource.php index 3d034555b..9256ed6f1 100644 --- a/app/Filament/Resources/UserResource.php +++ b/app/Filament/Resources/UserResource.php @@ -2,15 +2,19 @@ namespace App\Filament\Resources; +use App\Enums\UserRole; use App\Filament\Resources\UserResource\Pages; use App\Filament\Resources\UserResource\Pages\CreateUser; use App\Filament\Resources\UserResource\Pages\EditUser; +use App\Helpers\TimeZoneHelper; use App\Models\User; +use App\Settings\GeneralSettings; use Filament\Forms; use Filament\Forms\Form; use Filament\Resources\Resource; use Filament\Tables; use Filament\Tables\Table; +use Illuminate\Support\Facades\Auth; use Illuminate\Support\Facades\Hash; use Illuminate\Support\HtmlString; use Illuminate\Validation\Rules\Password; @@ -71,12 +75,8 @@ public static function form(Form $form): Form Forms\Components\Section::make() ->schema([ Forms\Components\Select::make('role') - ->options([ - 'admin' => 'Admin', - 'user' => 'User', - ]) - ->default('user') - ->disabled(fn (): bool => ! auth()->user()->is_admin || auth()->user()->is_user) + ->options(UserRole::class) + ->disabled(fn (): bool => ! Auth::user()->is_admin) ->required(), ]) ->columns(1) @@ -106,6 +106,8 @@ public static function form(Form $form): Form public static function table(Table $table): Table { + $settings = new GeneralSettings(); + return $table ->columns([ Tables\Columns\TextColumn::make('id') @@ -116,20 +118,20 @@ public static function table(Table $table): Table ->searchable(), Tables\Columns\TextColumn::make('role') ->badge() - ->color(fn (string $state): string => match ($state) { - 'admin' => 'success', - 'user' => 'gray', - }), + ->color(UserRole::class), + Tables\Columns\TextColumn::make('created_at') + ->alignEnd() + ->dateTime($settings->time_format ?? 'M j, Y G:i:s') + ->timezone(TimeZoneHelper::displayTimeZone($settings)), Tables\Columns\TextColumn::make('updated_at') - ->label('Last updated') - ->dateTime(), + ->alignEnd() + ->dateTime($settings->time_format ?? 'M j, Y G:i:s') + ->timezone(TimeZoneHelper::displayTimeZone($settings)) + ->toggleable(isToggledHiddenByDefault: true), ]) ->filters([ Tables\Filters\SelectFilter::make('role') - ->options([ - 'admin' => 'Admin', - 'user' => 'User', - ]), + ->options(UserRole::class), ]) ->actions([ Tables\Actions\ActionGroup::make([ diff --git a/app/Models/User.php b/app/Models/User.php index da3bfa37c..f1c90bbb0 100644 --- a/app/Models/User.php +++ b/app/Models/User.php @@ -2,9 +2,9 @@ namespace App\Models; +use App\Enums\UserRole; use Filament\Models\Contracts\FilamentUser; use Filament\Panel; -// use Illuminate\Contracts\Auth\MustVerifyEmail; use Illuminate\Database\Eloquent\Casts\Attribute; use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Foundation\Auth\User as Authenticatable; @@ -46,6 +46,7 @@ class User extends Authenticatable implements FilamentUser protected $casts = [ 'email_verified_at' => 'datetime', 'password' => 'hashed', + 'role' => UserRole::class, ]; /** @@ -62,7 +63,7 @@ public function canAccessPanel(Panel $panel): bool protected function isAdmin(): Attribute { return Attribute::make( - get: fn (mixed $value, array $attributes): bool => $attributes['role'] == 'admin', + get: fn (): bool => $this->role === UserRole::Admin, ); } @@ -72,7 +73,7 @@ protected function isAdmin(): Attribute protected function isUser(): Attribute { return Attribute::make( - get: fn (mixed $value, array $attributes): bool => $attributes['role'] == 'user', + get: fn (): bool => $this->role === UserRole::User, ); } }