Skip to content

Commit

Permalink
add remove points in bulk delete imports, make adminstrated by search…
Browse files Browse the repository at this point in the history
…eable
  • Loading branch information
gheorghelupu17 committed Oct 17, 2024
1 parent 0721f50 commit 878899b
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 3 deletions.
20 changes: 17 additions & 3 deletions app/Filament/Resources/ImportResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,13 @@
use App\Filament\Resources\ImportResource\Pages;
use App\Models\Import;
use Carbon\Carbon;
use Filament\Forms\Components\Toggle;
use Filament\Resources\Resource;
use Filament\Tables;
use Filament\Tables\Enums\FiltersLayout;
use Filament\Tables\Table;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Support\Collection;
use Illuminate\Support\Facades\Cache;

class ImportResource extends Resource
Expand Down Expand Up @@ -40,7 +42,7 @@ public static function getNavigationGroup(): ?string
public static function getNavigationBadge(): ?string
{
return (string) Cache::remember('import_count', now()->addMinutes(5), function () {
return Import::whereNull('completed_at')->count();
return Import::count();
});
}

Expand Down Expand Up @@ -70,7 +72,7 @@ public static function table(Table $table): Table
->label(__('import.columns.completed_at'))
->placeholder(__('import.status.processing'))
->formatStateUsing(function (string $state) {
return $state ? Carbon::createFromTimestamp($state)->format('Y-m-d H:m:s') : 'N/A';
return $state ? Carbon::createFromTimestamp($state)->diffForHumans() : 'N/A';
})
->searchable(),

Expand Down Expand Up @@ -118,7 +120,19 @@ public static function table(Table $table): Table
])
->bulkActions([
Tables\Actions\BulkActionGroup::make([
Tables\Actions\DeleteBulkAction::make(),
Tables\Actions\DeleteBulkAction::make()
->form([
Toggle::make('remove_points')
->label(__('imports.remove_points'))
->default(false),
])->action(function (Collection $records, array $data) {
$records->each(function (Import $record) use ($data) {
if ($data['remove_points']) {
$record->points()->delete();
}
$record->delete();
});
}),
]),
]);
}
Expand Down
2 changes: 2 additions & 0 deletions app/Filament/Resources/PointResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,8 @@ public static function getColumns()

TextColumn::make('administered_by')
->label(__('map_points.managed_by'))
->searchable()
->sortable()
->wrap(),

TextColumn::make('materials.name')
Expand Down
1 change: 1 addition & 0 deletions lang/ro/imports.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
'import_map_points_label' => 'Adauga o lista de import de format .xlsx',
'sub_heading' => 'Import initiat de %s la %s finalizat la %s',
'not_imported' => 'Neimportate (%s)',
'remove_points' => 'Sterge punctele',
'imported' => 'Importate (%s)',
'import_record_label' => 'Import Report #',
'status' => [
Expand Down

0 comments on commit 878899b

Please sign in to comment.