Edit SofaScore Tasks add filter
This commit is contained in:
1 parent
210aed8c97
commit
b25cf15a9e
10 files changed
+120
-39
No files matched your search
+67
-19
@@ -2,12 +2,14 @@
|
||||
|
||||
namespace App\Filament\Clusters\StaticData\Resources\SofaScoreTasks\RelationManagers;
|
||||
|
||||
use App\Models\SofaScoreCategorie;
|
||||
use App\Models\SofaScoreCategory;
|
||||
use App\Models\SofaScoreTaskTournament;
|
||||
use App\Models\SofaScoreTournament;
|
||||
use Filament\Actions\Action;
|
||||
use Filament\Actions\BulkAction;
|
||||
use Filament\Actions\BulkActionGroup;
|
||||
use Filament\Actions\CreateAction;
|
||||
use Filament\Actions\DeleteAction;
|
||||
use Filament\Actions\DeleteBulkAction;
|
||||
use Filament\Actions\EditAction;
|
||||
use Filament\Forms\Components\Select;
|
||||
use Filament\Resources\RelationManagers\RelationManager;
|
||||
@@ -16,7 +18,10 @@ use Filament\Schemas\Schema;
|
||||
use Filament\Support\Enums\FontWeight;
|
||||
use Filament\Tables\Columns\TextColumn;
|
||||
use Filament\Tables\Columns\ToggleColumn;
|
||||
use Filament\Tables\Enums\FiltersLayout;
|
||||
use Filament\Tables\Filters\SelectFilter;
|
||||
use Filament\Tables\Table;
|
||||
use Illuminate\Support\Collection;
|
||||
|
||||
class SofaScoreTaskTournamentsRelationManager extends RelationManager
|
||||
{
|
||||
@@ -29,20 +34,20 @@ class SofaScoreTaskTournamentsRelationManager extends RelationManager
|
||||
protected static ?string $modelLabel = 'Tournament';
|
||||
|
||||
protected static ?string $pluralModelLabel = 'Tournaments';
|
||||
|
||||
|
||||
public function form(Schema $schema): Schema
|
||||
{
|
||||
return $schema
|
||||
->components([
|
||||
Select::make('sofa_score_categorie_id')
|
||||
Select::make('sofa_score_category_id')
|
||||
->searchable()
|
||||
->label('Categorie')
|
||||
->options(function (Get $get) {
|
||||
->label('Category')
|
||||
->options(function () {
|
||||
$res = SofaScoreTournament::where('sport_id', $this->getOwnerRecord()['sport_id'])
|
||||
->groupBy('sofa_score_categorie_id')
|
||||
->pluck('sofa_score_categorie_id')
|
||||
->groupBy('sofa_score_category_id')
|
||||
->pluck('sofa_score_category_id')
|
||||
->toArray();
|
||||
return SofaScoreCategorie::query()->whereIn('id', $res)->orderBy('name')->pluck('name', 'id');
|
||||
return SofaScoreCategory::query()->whereIn('id', $res)->orderBy('name')->pluck('name', 'id');
|
||||
})
|
||||
->live(),
|
||||
Select::make('sofa_score_tournament_id')
|
||||
@@ -50,10 +55,10 @@ class SofaScoreTaskTournamentsRelationManager extends RelationManager
|
||||
->label('Tournament')
|
||||
->placeholder('Select a categorie first.')
|
||||
->noOptionsMessage('Select a categorie first.')
|
||||
->disabled(fn (Get $get):bool => (bool) $get('sofa_score_categorie_id') ? false : true)
|
||||
->options(fn (Get $get) => SofaScoreTournament::where('sport_id', $this->getOwnerRecord()['sport_id'])
|
||||
->disabled(fn(Get $get): bool => (bool) $get('sofa_score_category_id') ? false : true)
|
||||
->options(fn(Get $get) => SofaScoreTournament::where('sport_id', $this->getOwnerRecord()['sport_id'])
|
||||
->where('disabled', 0)
|
||||
->where('sofa_score_categorie_id', $get('sofa_score_categorie_id'))
|
||||
->where('sofa_score_category_id', $get('sofa_score_category_id'))
|
||||
->orderBY('name')
|
||||
->pluck('name', 'tournament_id')),
|
||||
]);
|
||||
@@ -63,30 +68,73 @@ class SofaScoreTaskTournamentsRelationManager extends RelationManager
|
||||
{
|
||||
return $table
|
||||
->columns([
|
||||
TextColumn::make('tournament.sofascore_category.name')
|
||||
->label('Country')
|
||||
TextColumn::make('category.name')
|
||||
->label('Category')
|
||||
->searchable(),
|
||||
TextColumn::make('tournament.name')
|
||||
->weight(FontWeight::Bold)
|
||||
->searchable(),
|
||||
ToggleColumn::make('disabled')
|
||||
->onColor('danger')
|
||||
->alignCenter(),
|
||||
])
|
||||
->filters([
|
||||
//
|
||||
])
|
||||
SelectFilter::make('sofa_score_category_id')
|
||||
->searchable()
|
||||
->label('Categorie')
|
||||
->options(function () {
|
||||
$res = SofaScoreTaskTournament::where('sofa_score_task_id', $this->getOwnerRecord()['id'])
|
||||
->groupBy('sofa_score_category_id')
|
||||
->pluck('sofa_score_category_id')
|
||||
->toArray();
|
||||
return SofaScoreCategory::query()->whereIn('id', $res)->orderBy('name')->pluck('name', 'id');
|
||||
})
|
||||
], layout: FiltersLayout::AboveContent)
|
||||
->deferFilters(false)
|
||||
->headerActions([
|
||||
Action::make('all_on')
|
||||
->icon('phosphor-toggle-right-fill')
|
||||
->action(function (): void {
|
||||
SofaScoreTaskTournament::where('sofa_score_task_id', $this->getOwnerRecord()['id'])->update(['disabled' => 0]);
|
||||
}),
|
||||
Action::make('all_off')
|
||||
->icon('phosphor-toggle-left-fill')
|
||||
->color('danger')
|
||||
->action(function (): void {
|
||||
SofaScoreTaskTournament::where('sofa_score_task_id', $this->getOwnerRecord()['id'])->update(['disabled' => 1]);
|
||||
}),
|
||||
CreateAction::make()
|
||||
->icon('phosphor-plus')
|
||||
->label('Tournament'),
|
||||
])
|
||||
->recordActions([
|
||||
EditAction::make(),
|
||||
DeleteAction::make(),
|
||||
EditAction::make()->iconButton(),
|
||||
DeleteAction::make()->iconButton(),
|
||||
])
|
||||
->toolbarActions([
|
||||
BulkActionGroup::make([
|
||||
DeleteBulkAction::make(),
|
||||
BulkAction::make('Disable selected')
|
||||
->icon('phosphor-toggle-left-fill')
|
||||
->color('danger')
|
||||
->action(function (Collection $records): void {
|
||||
foreach ($records as $record) {
|
||||
SofaScoreTaskTournament::where('id', '=', $record->id)
|
||||
->update(
|
||||
['disabled' => 1]
|
||||
);
|
||||
}
|
||||
}),
|
||||
BulkAction::make('Enable selected')
|
||||
->icon('phosphor-toggle-right-fill')
|
||||
->action(function (Collection $records): void {
|
||||
foreach ($records as $record) {
|
||||
SofaScoreTaskTournament::where('id', '=', $record->id)
|
||||
->update(
|
||||
['disabled' => 0]
|
||||
);
|
||||
}
|
||||
}),
|
||||
// DeleteBulkAction::make(),
|
||||
]),
|
||||
]);
|
||||
}
|
||||
|
||||
+11
-11
@@ -2,7 +2,7 @@
|
||||
|
||||
namespace App\Filament\Clusters\StaticData\Resources\SofaScoreTournaments\Tables;
|
||||
|
||||
use App\Models\SofaScoreCategorie;
|
||||
use App\Models\SofaScoreCategory;
|
||||
use App\Models\SofaScoreTournament;
|
||||
use App\Models\Sport;
|
||||
use Filament\Actions\Action;
|
||||
@@ -54,21 +54,21 @@ class SofaScoreTournamentsTable
|
||||
->label('Sport')
|
||||
->options(Sport::where('is_active', 1)->pluck('name', 'id'))
|
||||
->afterStateUpdated(function (callable $set) {
|
||||
$set('sofa_score_categorie_id', null);
|
||||
$set('sofa_score_category_id', null);
|
||||
})
|
||||
->live(),
|
||||
Select::make('sofa_score_categorie_id')
|
||||
Select::make('sofa_score_category_id')
|
||||
->searchable()
|
||||
->multiple()
|
||||
->columnSpan(2)
|
||||
->label('Categorie')
|
||||
->options(function (Get $get) {
|
||||
$res = SofaScoreTournament::where('sport_id', $get('sport_id'))
|
||||
->groupBy('sofa_score_categorie_id')
|
||||
->pluck('sofa_score_categorie_id')
|
||||
->groupBy('sofa_score_category_id')
|
||||
->pluck('sofa_score_category_id')
|
||||
->toArray();
|
||||
|
||||
return SofaScoreCategorie::query()->whereIn('id', $res)->orderBy('name')->pluck('name', 'id');
|
||||
return SofaScoreCategory::query()->whereIn('id', $res)->orderBy('name')->pluck('name', 'id');
|
||||
})
|
||||
->live(),
|
||||
ToggleButtons::make('filter-disabled')
|
||||
@@ -86,12 +86,12 @@ class SofaScoreTournamentsTable
|
||||
$data['sport_id'],
|
||||
fn(Builder $query, $sport_id) => $query->where('sport_id', $sport_id)
|
||||
)->when(
|
||||
$data['sofa_score_categorie_id'],
|
||||
function (Builder $query, $sofa_score_categorie_id) {
|
||||
if (is_array($sofa_score_categorie_id)) {
|
||||
$query->whereIn('sofa_score_categorie_id', $sofa_score_categorie_id);
|
||||
$data['sofa_score_category_id'],
|
||||
function (Builder $query, $sofa_score_category_id) {
|
||||
if (is_array($sofa_score_category_id)) {
|
||||
$query->whereIn('sofa_score_category_id', $sofa_score_category_id);
|
||||
} else {
|
||||
$query->where('sofa_score_categorie_id', $sofa_score_categorie_id);
|
||||
$query->where('sofa_score_category_id', $sofa_score_category_id);
|
||||
}
|
||||
}
|
||||
// )->when(
|
||||
|
||||
Reference in new issue
Block a user