Skip to content

Commit

Permalink
Apply fixes from StyleCI
Browse files Browse the repository at this point in the history
  • Loading branch information
arthurpar06 authored Oct 7, 2023
2 parents 7326719 + 5e94f15 commit 9f8331d
Show file tree
Hide file tree
Showing 19 changed files with 104 additions and 125 deletions.
28 changes: 15 additions & 13 deletions app/Filament/Resources/AirlineResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,10 @@
namespace App\Filament\Resources;

use App\Filament\Resources\AirlineResource\Pages;
use App\Filament\Resources\AirlineResource\RelationManagers;
use App\Filament\Resources\AirlineResource\RelationManagers\FilesRelationManager;
use App\Models\Airline;
use App\Models\File;
use App\Services\FileService;
use Filament\Forms;
use Filament\Forms\Components\Section;
use Filament\Forms\Components\Select;
use Filament\Forms\Components\TextInput;
Expand Down Expand Up @@ -51,9 +49,9 @@ public static function form(Form $form): Form
->options(collect((new ISO3166())->all())->mapWithKeys(fn ($item, $key) => [strtolower($item['alpha2']) => str_replace('&bnsp;', ' ', $item['name'])]))
->searchable()
->native(false),
Toggle::make('active')->inline()->onColor('success')->onIcon('heroicon-m-check-circle')->offColor('danger')->offIcon('heroicon-m-x-circle')
])->columns(3)
]);
Toggle::make('active')->inline()->onColor('success')->onIcon('heroicon-m-check-circle')->offColor('danger')->offIcon('heroicon-m-x-circle'),
])->columns(3),
]);
}

public static function table(Table $table): Table
Expand All @@ -62,9 +60,13 @@ public static function table(Table $table): Table
->columns([
TextColumn::make('Code')->formatStateUsing(function (Airline $record) {
$html = '';
if (filled($record->country)) $html .= '<span class="flag-icon flag-icon-' .$record->country. '"></span> &nbsp;';
if (filled($record->iata)) $html .= $record->iata . '/';
return $html . $record->icao;
if (filled($record->country)) {
$html .= '<span class="flag-icon flag-icon-'.$record->country.'"></span> &nbsp;';
}
if (filled($record->iata)) {
$html .= $record->iata.'/';
}
return $html.$record->icao;
})->html(),
TextColumn::make('name')->label('Name')->searchable(),
IconColumn::make('active')->label('Active')->color(fn ($record) => $record->active ? 'success' : 'danger')->icon(fn ($state) => $state ? 'heroicon-o-check-circle' : 'heroicon-o-x-circle'),
Expand All @@ -86,11 +88,11 @@ public static function table(Table $table): Table
Tables\Actions\BulkActionGroup::make([
Tables\Actions\DeleteBulkAction::make(),
Tables\Actions\ForceDeleteBulkAction::make()->before(function (Collection $records) {
$records->each(fn(Airline $record) => $record->files()->each(function (File $file) {
$records->each(fn (Airline $record) => $record->files()->each(function (File $file) {
app(FileService::class)->removeFile($file);
}));
}),
Tables\Actions\RestoreBulkAction::make()
Tables\Actions\RestoreBulkAction::make(),
]),
])
->emptyStateActions([
Expand All @@ -109,16 +111,16 @@ public static function getEloquentQuery(): Builder
public static function getRelations(): array
{
return [
FilesRelationManager::class
FilesRelationManager::class,
];
}

public static function getPages(): array
{
return [
'index' => Pages\ListAirlines::route('/'),
'index' => Pages\ListAirlines::route('/'),
'create' => Pages\CreateAirline::route('/create'),
'edit' => Pages\EditAirline::route('/{record}/edit'),
'edit' => Pages\EditAirline::route('/{record}/edit'),
];
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
namespace App\Filament\Resources\AirlineResource\Pages;

use App\Filament\Resources\AirlineResource;
use Filament\Actions;
use Filament\Resources\Pages\CreateRecord;

class CreateAirline extends CreateRecord
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,14 @@
namespace App\Filament\Resources\AirlineResource\RelationManagers;

use App\Models\File;
use Filament\Forms;
use Filament\Forms\Components\FileUpload;
use Filament\Forms\Components\TextInput;
use Filament\Forms\Form;
use Filament\Resources\RelationManagers\RelationManager;
use Filament\Tables;
use Filament\Tables\Columns\TextColumn;
use Filament\Tables\Table;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Collection;
use Illuminate\Database\Eloquent\SoftDeletingScope;
use Illuminate\Support\Facades\Storage;
use Illuminate\Support\Str;

Expand All @@ -37,44 +34,43 @@ public function table(Table $table): Table
return $table->recordTitleAttribute('name')
->columns([
TextColumn::make('name'),
TextColumn::make('download_count')->label('Downloads')
TextColumn::make('download_count')->label('Downloads'),
])
->filters([
//
])
->headerActions([
Tables\Actions\CreateAction::make()->label('Add File')->mutateFormDataUsing(function (array $data): array {
if (!empty($data['url'])) $data['path'] = $data['url'];
else if (!empty($data['file'])) {
if (!empty($data['url'])) {
$data['path'] = $data['url'];
} elseif (!empty($data['file'])) {
$data['path'] = $data['file'];
$data['disk'] = config('filesystems.public_files');
}

return $data;
})
}),
])
->actions([
Tables\Actions\Action::make('download')->icon('heroicon-m-link')->label('Link to file')
->action(fn (File $record) => Storage::disk($record->disk)->download($record->path, Str::kebab($record->name)))
->action(fn (File $record) => Storage::disk($record->disk)->download($record->path, Str::kebab($record->name)))
->visible(fn (File $record): bool => $record->disk && !str_contains($record->path, 'http') && Storage::disk($record->disk)->exists($record->path)),

Tables\Actions\Action::make('view_file')->icon('heroicon-m-link')->label('Link to file')
->url(fn (File $record): string => $record->path, shouldOpenInNewTab: true)
->hidden(fn (File $record): bool => $record->disk && !str_contains($record->path, 'http') && Storage::disk($record->disk)->exists($record->path)),

Tables\Actions\DeleteAction::make()->before(function (File $record) {
if ($record->disk && !str_contains($record->path, 'http') && Storage::disk($record->disk)->exists($record->path))
{
if ($record->disk && !str_contains($record->path, 'http') && Storage::disk($record->disk)->exists($record->path)) {
Storage::disk($record->disk)->delete($record->path);
}
})
}),
])
->bulkActions([
Tables\Actions\BulkActionGroup::make([
Tables\Actions\DeleteBulkAction::make()->before(function (Collection $records) {
$records->each(function (File $record) {
if ($record->disk && !str_contains($record->path, 'http') && Storage::disk($record->disk)->exists($record->path))
{
if ($record->disk && !str_contains($record->path, 'http') && Storage::disk($record->disk)->exists($record->path)) {
Storage::disk($record->disk)->delete($record->path);
}
});
Expand All @@ -83,14 +79,15 @@ public function table(Table $table): Table
])
->emptyStateActions([
Tables\Actions\CreateAction::make()->label('Add File')->mutateFormDataUsing(function (array $data): array {
if (!empty($data['url'])) $data['path'] = $data['url'];
else if (!empty($data['file'])) {
if (!empty($data['url'])) {
$data['path'] = $data['url'];
} elseif (!empty($data['file'])) {
$data['path'] = $data['file'];
$data['disk'] = config('filesystems.public_files');
}

return $data;
})
}),
]);
}
}
2 changes: 1 addition & 1 deletion app/Filament/Resources/FlightResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public static function table(Table $table): Table
TextColumn::make('arr_time')->label('Arr Time'),
TextColumn::make('notes')->label('Notes'),
IconColumn::make('active')->label('Active')->color(fn ($record) => $record->active ? 'success' : 'danger')->icon(fn ($state) => $state ? 'heroicon-o-check-circle' : 'heroicon-o-x-circle'),
IconColumn::make('visible')->label('Visible')->color(fn ($record) => $record->visible ? 'success' : 'danger')->icon(fn ($record) => $record->visible ? 'heroicon-o-check-circle' : 'heroicon-o-x-circle')
IconColumn::make('visible')->label('Visible')->color(fn ($record) => $record->visible ? 'success' : 'danger')->icon(fn ($record) => $record->visible ? 'heroicon-o-check-circle' : 'heroicon-o-x-circle'),
])
->filters([
//
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@
use App\Services\ExportService;
use App\Services\ImportService;
use Filament\Actions;
use Filament\Forms\Components\FileUpload;
use Filament\Forms\Components\Toggle;
use Filament\Notifications\Notification;
use Filament\Resources\Pages\ListRecords;
use Filament\Forms\Components\FileUpload;
use Illuminate\Support\Facades\Log;
use Symfony\Component\HttpFoundation\BinaryFileResponse;

Expand Down
16 changes: 8 additions & 8 deletions app/Filament/Resources/PirepResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,19 @@
use App\Models\Enums\PirepState;
use App\Models\Pirep;
use App\Repositories\UserRepository;
use App\Support\Units\Time;
use App\Services\PirepService;
use Filament\Tables\Actions\Action;
use App\Support\Units\Time;
use Filament\Forms;
use Filament\Forms\Components\DatePicker;
use Filament\Forms\Form;
use Filament\Resources\Resource;
use Filament\Tables;
use Filament\Tables\Actions\Action;
use Filament\Tables\Actions\DeleteAction;
use Filament\Tables\Actions\EditAction;
use Filament\Tables\Columns\TextColumn;
use Filament\Tables\Filters\Filter;
use Filament\Tables\Table;
use Filament\Tables\Actions\DeleteAction;
use Filament\Tables\Actions\EditAction;
use Illuminate\Database\Eloquent\Builder;

class PirepResource extends Resource
Expand Down Expand Up @@ -113,9 +113,9 @@ public static function form(Form $form): Form
->required()
->label('Planned Distance'),
Forms\Components\TextInput::make('planned_flight_time')
->required()
]),
])]);
->required(),
]),
])]);
}

public static function table(Table $table): Table
Expand All @@ -127,7 +127,7 @@ public static function table(Table $table): Table
TextColumn::make('dpt_airport_id')->label('DEP')->searchable(),
TextColumn::make('arr_airport_id')->label('ARR')->searchable(),
TextColumn::make('flight_time')->formatStateUsing(fn (int $state): string => Time::minutesToTimeString($state)),
TextColumn::make('aircraft')->formatStateUsing(fn (Pirep $record): string => $record->aircraft->registration .' - '. $record->aircraft->name),
TextColumn::make('aircraft')->formatStateUsing(fn (Pirep $record): string => $record->aircraft->registration.' - '.$record->aircraft->name),
TextColumn::make('source')->label('Filed Using')->formatStateUsing(fn (int $state): string => PirepSource::label($state)),
TextColumn::make('state')->badge()->color(fn (int $state): string => match ($state) {
PirepState::PENDING => 'warning',
Expand Down
1 change: 0 additions & 1 deletion app/Filament/Resources/PirepResource/Pages/ListPireps.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
use Filament\Actions\Action;
use Filament\Resources\Pages\ListRecords;
use Filament\Resources\Pages\ListRecords\Tab;

use Illuminate\Database\Eloquent\Builder;

class ListPireps extends ListRecords
Expand Down
94 changes: 47 additions & 47 deletions app/Filament/Resources/UserResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
use Filament\Forms\Form;
use Filament\Resources\Resource;
use Filament\Tables;
use Filament\Tables\Table;
use Filament\Tables\Columns\TextColumn;
use Filament\Tables\Table;
use Illuminate\Database\Eloquent\Builder;
use League\ISO3166\ISO3166;

Expand Down Expand Up @@ -68,10 +68,10 @@ public static function form(Form $form): Form
->required()
->email(),

Forms\Components\TextInput::make('password')
->password()
->autocomplete('new-password')
->columnSpanFull(),
Forms\Components\TextInput::make('password')
->password()
->autocomplete('new-password')
->columnSpanFull(),
])
->columns(2),
Forms\Components\Section::make('Location Information')
Expand All @@ -89,57 +89,57 @@ public static function form(Form $form): Form

Forms\Components\Select::make('home_airport_id')
->label('Home Airport')
->options($airportRepo->all()->mapWithKeys(fn ($item) => [$item->id => $item->icao . ' - ' . $item->name]))
->options($airportRepo->all()->mapWithKeys(fn ($item) => [$item->id => $item->icao.' - '.$item->name]))
->searchable()
->native(false),

Forms\Components\Select::make('current_airport_id')
->label('Current Airport')
->options($airportRepo->all()->mapWithKeys(fn ($item) => [$item->id => $item->icao . ' - ' . $item->name]))
->options($airportRepo->all()->mapWithKeys(fn ($item) => [$item->id => $item->icao.' - '.$item->name]))
->searchable()
->native(false),
])
->columns(2),
])->columnSpan(['lg' => 2]),
Forms\Components\Group::make()
])->columnSpan(['lg' => 2]),
Forms\Components\Group::make()
->schema([
Forms\Components\Section::make('User Information')
->schema([
Forms\Components\Section::make('User Information')
->schema([
Forms\Components\Select::make('state')
->options(UserState::labels())
->searchable()
->native(false),

Forms\Components\Select::make('airline_id')
->label('Airline')
->options($airlineRepo->all()->pluck('name', 'id'))
->searchable()
->native(false),

Forms\Components\Select::make('rank_id')
->label('Rank')
->options($rankRepo->all()->pluck('name', 'id'))
->searchable()
->native(false),

Forms\Components\TextInput::make('transfer_time')
->label('Transferred Hours')
->numeric(),

Forms\Components\Select::make('roles')
->label('Roles')
//->options($roleRepo->all()->pluck('name', 'id'))
->relationship('roles', 'name')
Forms\Components\Select::make('state')
->options(UserState::labels())
->searchable()
->native(false),

Forms\Components\Select::make('airline_id')
->label('Airline')
->options($airlineRepo->all()->pluck('name', 'id'))
->searchable()
->native(false)
->multiple(),

Forms\Components\Textarea::make('notes')
->label('Management Notes')
->columnSpan('full'),
])
->columnSpan(['lg' => 1]),
]),
->native(false),

Forms\Components\Select::make('rank_id')
->label('Rank')
->options($rankRepo->all()->pluck('name', 'id'))
->searchable()
->native(false),

Forms\Components\TextInput::make('transfer_time')
->label('Transferred Hours')
->numeric(),

Forms\Components\Select::make('roles')
->label('Roles')
//->options($roleRepo->all()->pluck('name', 'id'))
->relationship('roles', 'name')
->searchable()
->native(false)
->multiple(),

Forms\Components\Textarea::make('notes')
->label('Management Notes')
->columnSpan('full'),
])
->columnSpan(['lg' => 1]),
]),
])->columns(3);
}

Expand Down Expand Up @@ -167,7 +167,7 @@ public static function table(Table $table): Table
])
->actions([
Tables\Actions\EditAction::make(),
Tables\Actions\DeleteAction::make()
Tables\Actions\DeleteAction::make(),
])
->bulkActions([
Tables\Actions\BulkActionGroup::make([
Expand All @@ -184,7 +184,7 @@ public static function getRelations(): array
RelationManagers\FieldsRelationManager::class,
RelationManagers\AwardsRelationManager::class,
RelationManagers\TypeRatingsRelationManager::class,
RelationManagers\PirepsRelationManager::class
RelationManagers\PirepsRelationManager::class,
];
}

Expand Down
1 change: 0 additions & 1 deletion app/Filament/Resources/UserResource/Pages/CreateUser.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
namespace App\Filament\Resources\UserResource\Pages;

use App\Filament\Resources\UserResource;
use Filament\Actions;
use Filament\Resources\Pages\CreateRecord;

class CreateUser extends CreateRecord
Expand Down
Loading

0 comments on commit 9f8331d

Please sign in to comment.