Skip to content

Commit

Permalink
Apply fixes from StyleCI
Browse files Browse the repository at this point in the history
  • Loading branch information
StyleCIBot committed Oct 8, 2023
1 parent 7573b00 commit 9fd44b3
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 31 deletions.
8 changes: 4 additions & 4 deletions app/Filament/Resources/FareResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
namespace App\Filament\Resources;

use App\Filament\Resources\FareResource\Pages;
use App\Filament\Resources\FareResource\RelationManagers;
use App\Models\Enums\FareType;
use App\Models\Fare;
use Filament\Forms;
Expand Down Expand Up @@ -62,7 +61,7 @@ public static function table(Table $table): Table
TextColumn::make('cost')->label('Cost')->money(setting('units.currency')),
TextColumn::make('notes')->label('Notes'),
IconColumn::make('active')->label('Active')->color(fn (Fare $record) => $record->active ? 'success' : 'danger')->icon(fn ($state) => $state ? 'heroicon-o-check-circle' : 'heroicon-o-x-circle'),
])
])
->filters([
Tables\Filters\TrashedFilter::make(),
])
Expand Down Expand Up @@ -91,6 +90,7 @@ public static function getEloquentQuery(): Builder
SoftDeletingScope::class,
]);
}

public static function getRelations(): array
{
return [
Expand All @@ -101,9 +101,9 @@ public static function getRelations(): array
public static function getPages(): array
{
return [
'index' => Pages\ListFares::route('/'),
'index' => Pages\ListFares::route('/'),
'create' => Pages\CreateFare::route('/create'),
'edit' => Pages\EditFare::route('/{record}/edit'),
'edit' => Pages\EditFare::route('/{record}/edit'),
];
}
}
1 change: 0 additions & 1 deletion app/Filament/Resources/FareResource/Pages/CreateFare.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
namespace App\Filament\Resources\FareResource\Pages;

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

class CreateFare extends CreateRecord
Expand Down
51 changes: 25 additions & 26 deletions app/Filament/Resources/FareResource/Pages/ListFares.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,47 +23,46 @@ protected function getHeaderActions(): array
return [
Actions\Action::make('export')->label('Export to CSV')
->action(function (): BinaryFileResponse {
$exporter = app(ExportService::class);
$fareRepo = app(FareRepository::class);
$fares = $fareRepo->all();
$exporter = app(ExportService::class);
$fareRepo = app(FareRepository::class);
$fares = $fareRepo->all();

$path = $exporter->exportFares($fares);
return response()->download($path, 'fares.csv', ['content-type' => 'text/csv',])->deleteFileAfterSend(true);
$path = $exporter->exportFares($fares);
return response()->download($path, 'fares.csv', ['content-type' => 'text/csv'])->deleteFileAfterSend(true);
})->after(function (): void {
Notification::make()
->title('Fares Exported')
->success()
->send();
}),
}),
Actions\Action::make('import')->label('Import from CSV')
->form([
FileUpload::make('importFile')->acceptedFileTypes(['text/csv'])->disk('local')->directory('import'),
Toggle::make('delete')->label('Delete Previous Fares')->default(false),
])->action(function (array $data, Actions\Action $action): void {
$importSvc = app(ImportService::class);
$importSvc = app(ImportService::class);

$path = storage_path('app/'.$data['importFile']);
Log::info('Uploaded Fare import file to '.$path);
$path = storage_path('app/'.$data['importFile']);
Log::info('Uploaded Fare import file to '.$path);

$logs = $importSvc->importFares($path, $data['delete']);
$logs = $importSvc->importFares($path, $data['delete']);

session(['logs' => $logs]);
session(['logs' => $logs]);

if (count($logs['errors']) === 0)
{
Notification::make()
->title('Fares Imported Successfully')
->success()
->send();
} else {
Notification::make()
->title('There were '.count($logs['errors']).' errors importing the fares')
->body(implode('<br>', $logs['errors']))
->persistent()
->danger()
->send();
}
}),
if (count($logs['errors']) === 0) {
Notification::make()
->title('Fares Imported Successfully')
->success()
->send();
} else {
Notification::make()
->title('There were '.count($logs['errors']).' errors importing the fares')
->body(implode('<br>', $logs['errors']))
->persistent()
->danger()
->send();
}
}),
Actions\CreateAction::make()->label('Add Fare'),
];
}
Expand Down

0 comments on commit 9fd44b3

Please sign in to comment.