From 937717f73495c4e4f6075908a184a753b0a75e24 Mon Sep 17 00:00:00 2001 From: MathewEm Date: Tue, 7 Jan 2025 13:18:07 -0330 Subject: [PATCH] pint fixes --- .../Resources/AnnouncementResource.php | 336 +++++++++--------- .../Pages/CreateAnnouncement.php | 7 +- .../Pages/EditAnnouncement.php | 1 - .../Pages/ViewAnnouncement.php | 4 +- app/Models/Announcement.php | 14 +- 5 files changed, 178 insertions(+), 184 deletions(-) diff --git a/app/Filament/Resources/AnnouncementResource.php b/app/Filament/Resources/AnnouncementResource.php index bd9d9cc6..9e745614 100644 --- a/app/Filament/Resources/AnnouncementResource.php +++ b/app/Filament/Resources/AnnouncementResource.php @@ -3,19 +3,15 @@ namespace App\Filament\Resources; use App\Filament\Resources\AnnouncementResource\Pages; -use App\Filament\Resources\AnnouncementResource\RelationManagers; use App\Models\Announcement; use Filament\Forms; use Filament\Forms\Form; -use Filament\Forms\Components\Actions; use Filament\Infolists\Components; use Filament\Infolists\Components\TextEntry; use Filament\Infolists\Infolist; use Filament\Resources\Resource; use Filament\Tables; use Filament\Tables\Table; -use Illuminate\Database\Eloquent\Builder; -use Illuminate\Database\Eloquent\SoftDeletingScope; use Illuminate\Support\Carbon; class AnnouncementResource extends Resource @@ -28,45 +24,45 @@ public static function form(Form $form): Form { return $form ->schema([ - Forms\Components\Section::make('Announcement Content') - ->columns(2) - ->schema([ - Forms\Components\TextInput::make('title_en') - ->label('Title English') - ->required() - ->maxLength(255), - Forms\Components\TextInput::make('title_fr') - ->label('Title French') - ->required() - ->maxLength(255), - Forms\Components\Textarea::make('text_en') - ->label('Announcement English') - ->autosize() - ->required() - ->maxLength(500), - Forms\Components\Textarea::make('text_fr') - ->label('Announcement French') - ->autosize() - ->required() - ->maxLength(500), - ]), - Forms\Components\Section::make('Dates') - ->description('All announcements will start at 00:00:00 UTC and end at 23:59:59 UTC of the dates selected!') - ->schema([ - Forms\Components\DateTimePicker::make('start_at') - ->label('Start Date') - ->withoutTime() - ->default(fn () => now()->startOfDay()) - ->required() - ->afterOrEqual('yesterday') - ->beforeOrEqual('end_at'), - Forms\Components\DateTimePicker::make('end_at') - ->label('End Date') - ->withoutTime() - ->default(fn () => now()->endOfDay()) - ->required() - ->afterOrEqual('start_at'), - ]) + Forms\Components\Section::make('Announcement Content') + ->columns(2) + ->schema([ + Forms\Components\TextInput::make('title_en') + ->label('Title English') + ->required() + ->maxLength(255), + Forms\Components\TextInput::make('title_fr') + ->label('Title French') + ->required() + ->maxLength(255), + Forms\Components\Textarea::make('text_en') + ->label('Announcement English') + ->autosize() + ->required() + ->maxLength(500), + Forms\Components\Textarea::make('text_fr') + ->label('Announcement French') + ->autosize() + ->required() + ->maxLength(500), + ]), + Forms\Components\Section::make('Dates') + ->description('All announcements will start at 00:00:00 UTC and end at 23:59:59 UTC of the dates selected!') + ->schema([ + Forms\Components\DateTimePicker::make('start_at') + ->label('Start Date') + ->Time(false) + ->default(fn () => now()->startOfDay()) + ->required() + ->afterOrEqual('yesterday') + ->beforeOrEqual('end_at'), + Forms\Components\DateTimePicker::make('end_at') + ->label('End Date') + ->Time(false) + ->default(fn () => now()->endOfDay()) + ->required() + ->afterOrEqual('start_at'), + ]), ]); } @@ -74,136 +70,136 @@ public static function table(Table $table): Table { return $table ->columns([ - Tables\Columns\TextColumn::make('title_en') - ->label('Title English') - ->wrap() - ->sortable(), - Tables\Columns\TextColumn::make('title_fr') - ->label('Title French') - ->wrap() - ->sortable(), - Tables\Columns\TextColumn::make('created_at') - ->label('Created (UTC)') - ->datetime('M d, Y H:i'), - Tables\Columns\TextColumn::make('start_at') - ->label('Start (UTC)') - ->datetime('M d, Y H:i') - ->sortable(), - Tables\Columns\TextColumn::make('end_at') - ->label('End (UTC)') - ->datetime('M d, Y H:i') - ->sortable(), - Tables\Columns\BadgeColumn::make('status') - ->label('Status') - ->getStateUsing(function ($record) { - $now = Carbon::now(); - if ($record->start_at > $now) { - return 'Upcoming'; - } - if ($record->start_at <= $now && $record->end_at >= $now) { - return 'Active'; - } - if ($record->end_at < $now) { - return 'Passed'; - } - }) - ->colors([ - 'warning' => 'Upcoming', - 'success' => 'Active', - 'info' => 'Passed', - ]) + Tables\Columns\TextColumn::make('title_en') + ->label('Title English') + ->wrap() + ->sortable(), + Tables\Columns\TextColumn::make('title_fr') + ->label('Title French') + ->wrap() + ->sortable(), + Tables\Columns\TextColumn::make('created_at') + ->label('Created (UTC)') + ->datetime('M d, Y H:i'), + Tables\Columns\TextColumn::make('start_at') + ->label('Start (UTC)') + ->datetime('M d, Y H:i') + ->sortable(), + Tables\Columns\TextColumn::make('end_at') + ->label('End (UTC)') + ->datetime('M d, Y H:i') + ->sortable(), + Tables\Columns\BadgeColumn::make('status') + ->label('Status') + ->getStateUsing(function ($record) { + $now = Carbon::now(); + if ($record->start_at > $now) { + return 'Upcoming'; + } + if ($record->start_at <= $now && $record->end_at >= $now) { + return 'Active'; + } + if ($record->end_at < $now) { + return 'Passed'; + } + }) + ->colors([ + 'warning' => 'Upcoming', + 'success' => 'Active', + 'info' => 'Passed', + ]), ]) - ->defaultSort('start_at','desc') + ->defaultSort('start_at', 'desc') ->filters([ - // - ]) - ->actions([ - Tables\Actions\ViewAction::make(), - Tables\Actions\EditAction::make() - ->mutateFormDataUsing(function (array $data): array { - $data['end_at'] = $data['end_at'] . 'T23:59:59'; + // + ]) + ->actions([ + Tables\Actions\ViewAction::make(), + Tables\Actions\EditAction::make() + ->mutateFormDataUsing(function (array $data): array { + $data['end_at'] = $data['end_at'].'T23:59:59'; - return $data; - }), - Tables\Actions\DeleteAction::make(), - ]) - ->bulkActions([ - Tables\Actions\BulkActionGroup::make([ - Tables\Actions\DeleteBulkAction::make(), - ]), - ]); - } + return $data; + }), + Tables\Actions\DeleteAction::make(), + ]) + ->bulkActions([ + Tables\Actions\BulkActionGroup::make([ + Tables\Actions\DeleteBulkAction::make(), + ]), + ]); + } - public static function infolist(Infolist $infolist): Infolist - { - return $infolist - ->schema([ - Components\Section::make('Info') - ->schema([ - Components\Grid::make(2) - ->schema([ - Components\Group::make([ - TextEntry::make('title_en') - ->label('Title English'), - TextEntry::make('created_at') - ->label('Created (UTC)') - ->datetime('M d, Y H:i'), - TextEntry::make('start_at') - ->label('Start (UTC)') - ->datetime('M d, Y H:i'), - ]), - Components\Group::make([ - TextEntry::make('title_fr') - ->label('Title French'), - TextEntry::make('status') - ->badge() - ->getStateUsing(function ($record) { - $now = Carbon::now(); - if ($record->start_at > $now) { - return 'Upcoming'; - } - if ($record->start_at <= $now && $record->end_at >= $now) { - return 'Active'; - } - if ($record->end_at < $now) { - return 'Passed'; - } - }) - ->colors([ - 'secondary' => 'Upcoming', - 'success' => 'Active', - 'danger' => 'Passed', - ]), - TextEntry::make('end_at') - ->label('End (UTC)') - ->datetime('M d, Y H:i'), - ]) - ->columns(1) - ]) - ]), - Components\Section::make('Message') - ->schema([ - Components\TextEntry::make('text_en') - ->label('English'), - Components\TextEntry::make('text_fr') - ->label('French'), - ]) - ]); - } + public static function infolist(Infolist $infolist): Infolist + { + return $infolist + ->schema([ + Components\Section::make('Info') + ->schema([ + Components\Grid::make(2) + ->schema([ + Components\Group::make([ + TextEntry::make('title_en') + ->label('Title English'), + TextEntry::make('created_at') + ->label('Created (UTC)') + ->datetime('M d, Y H:i'), + TextEntry::make('start_at') + ->label('Start (UTC)') + ->datetime('M d, Y H:i'), + ]), + Components\Group::make([ + TextEntry::make('title_fr') + ->label('Title French'), + TextEntry::make('status') + ->badge() + ->getStateUsing(function ($record) { + $now = Carbon::now(); + if ($record->start_at > $now) { + return 'Upcoming'; + } + if ($record->start_at <= $now && $record->end_at >= $now) { + return 'Active'; + } + if ($record->end_at < $now) { + return 'Passed'; + } + }) + ->colors([ + 'secondary' => 'Upcoming', + 'success' => 'Active', + 'danger' => 'Passed', + ]), + TextEntry::make('end_at') + ->label('End (UTC)') + ->datetime('M d, Y H:i'), + ]) + ->columns(1), + ]), + ]), + Components\Section::make('Message') + ->schema([ + Components\TextEntry::make('text_en') + ->label('English'), + Components\TextEntry::make('text_fr') + ->label('French'), + ]), + ]); + } - public static function getRelations(): array - { - return [ - // - ]; - } + public static function getRelations(): array + { + return [ + // + ]; + } - public static function getPages(): array - { - return [ - 'index' => Pages\ListAnnouncements::route('/'), - 'create' => Pages\CreateAnnouncement::route('/create'), - // 'edit' => Pages\EditAnnouncement::route('/{record}/edit'), - ]; - } - } + public static function getPages(): array + { + return [ + 'index' => Pages\ListAnnouncements::route('/'), + 'create' => Pages\CreateAnnouncement::route('/create'), + // 'edit' => Pages\EditAnnouncement::route('/{record}/edit'), + ]; + } +} diff --git a/app/Filament/Resources/AnnouncementResource/Pages/CreateAnnouncement.php b/app/Filament/Resources/AnnouncementResource/Pages/CreateAnnouncement.php index 5077009a..83d14fd6 100644 --- a/app/Filament/Resources/AnnouncementResource/Pages/CreateAnnouncement.php +++ b/app/Filament/Resources/AnnouncementResource/Pages/CreateAnnouncement.php @@ -3,7 +3,6 @@ namespace App\Filament\Resources\AnnouncementResource\Pages; use App\Filament\Resources\AnnouncementResource; -use Filament\Actions; use Filament\Resources\Pages\CreateRecord; class CreateAnnouncement extends CreateRecord @@ -11,11 +10,11 @@ class CreateAnnouncement extends CreateRecord protected static string $resource = AnnouncementResource::class; protected static bool $canCreateAnother = false; - + protected function mutateFormDataBeforeCreate(array $data): array { - $data['end_at'] = $data['end_at'] . 'T23:59:59'; + $data['end_at'] = $data['end_at'].'T23:59:59'; - return $data; + return $data; } } diff --git a/app/Filament/Resources/AnnouncementResource/Pages/EditAnnouncement.php b/app/Filament/Resources/AnnouncementResource/Pages/EditAnnouncement.php index abe3b343..b38bea63 100644 --- a/app/Filament/Resources/AnnouncementResource/Pages/EditAnnouncement.php +++ b/app/Filament/Resources/AnnouncementResource/Pages/EditAnnouncement.php @@ -2,7 +2,6 @@ namespace App\Filament\Resources\AnnouncementResource\Pages; -use App\Models\Announcement; use App\Filament\Resources\AnnouncementResource; use Filament\Actions; use Filament\Resources\Pages\EditRecord; diff --git a/app/Filament/Resources/AnnouncementResource/Pages/ViewAnnouncement.php b/app/Filament/Resources/AnnouncementResource/Pages/ViewAnnouncement.php index c1aa12b0..df95700b 100644 --- a/app/Filament/Resources/AnnouncementResource/Pages/ViewAnnouncement.php +++ b/app/Filament/Resources/AnnouncementResource/Pages/ViewAnnouncement.php @@ -9,11 +9,11 @@ class ViewAnnouncement extends ViewRecord { protected static string $resource = AnnouncementResource::class; - + protected function getHeaderActions(): array { return [ - Actions\EditAction::make(), + Actions\EditAction::make(), ]; } } diff --git a/app/Models/Announcement.php b/app/Models/Announcement.php index 1bfcbc65..6744f511 100644 --- a/app/Models/Announcement.php +++ b/app/Models/Announcement.php @@ -30,12 +30,12 @@ public function casts(): array * @var array */ protected $fillable = [ - 'title_en', - 'title_fr', - 'text_en', - 'text_fr', - 'start_at', - 'end_at', + 'title_en', + 'title_fr', + 'text_en', + 'text_fr', + 'start_at', + 'end_at', ]; /** @@ -44,6 +44,6 @@ public function casts(): array public function scopeActive(Builder $query) { return $query->where('start_at', '<=', now()) - ->where('end_at', '>=', now()); + ->where('end_at', '>=', now()); } }