changes to grapper wip
This commit is contained in:
1 parent
361e5ed3ed
commit
9214da8a15
9 files changed
+445
-201
No files matched your search
+56
-25
@@ -5,12 +5,8 @@ namespace App\Filament\Clusters\StaticData\Resources\SofaScoreDays\Tables;
|
||||
use App\Models\SofaScoreDay;
|
||||
use App\Models\Sport;
|
||||
use Filament\Actions\Action;
|
||||
use Filament\Actions\BulkActionGroup;
|
||||
use Filament\Actions\DeleteBulkAction;
|
||||
use Filament\Actions\EditAction;
|
||||
use Filament\Forms\Components\Select;
|
||||
use Filament\Forms\Components\Toggle;
|
||||
use Filament\Tables\Columns\IconColumn;
|
||||
use Filament\Tables\Columns\TextColumn;
|
||||
use Filament\Tables\Columns\ToggleColumn;
|
||||
use Filament\Tables\Enums\FiltersLayout;
|
||||
@@ -26,16 +22,53 @@ class SofaScoreDaysTable
|
||||
{
|
||||
return $table
|
||||
->description('For days checked events active in tournaments will be grapped.')
|
||||
->headerActions([
|
||||
Action::make('reset')->icon('phosphor-power')->action(fn() => SofaScoreDay::query()->update(['football' => 0])),
|
||||
->headerActions([
|
||||
Action::make('generate')->icon('phosphor-calendar')
|
||||
->schema([
|
||||
Select::make('sport_id')
|
||||
->options(Sport::where('is_active', 1)
|
||||
->pluck('name', 'id'))
|
||||
->required(),
|
||||
Select::make('year')
|
||||
->options(self::years())
|
||||
->required(),
|
||||
Select::make('month')
|
||||
->options(self::month())
|
||||
->required(),
|
||||
])
|
||||
->action(function (array $data, $table): void {
|
||||
$sport_id = $data['sport_id'];
|
||||
$date = Carbon::createFromDate($data['year'], $data['month'], 1)->startOfMonth();
|
||||
$daysCount = $date->daysInMonth;
|
||||
|
||||
$allDates = [];
|
||||
for ($i = 1; $i <= $daysCount; $i++) {
|
||||
$allDates[] = $date->copy()->day($i)->format('Y-m-d');
|
||||
}
|
||||
foreach ($allDates as $day) {
|
||||
SofaScoreDay::updateOrCreate(['day' => $day, 'sport_id' => $sport_id]);
|
||||
}
|
||||
}),
|
||||
Action::make('reset')
|
||||
->icon('phosphor-power')
|
||||
->schema([
|
||||
Select::make('sport_id')
|
||||
->options(Sport::where('is_active', 1)
|
||||
->pluck('name', 'id'))
|
||||
->required(),
|
||||
])
|
||||
->action(function (array $data): void {
|
||||
$sport_id = $data['sport_id'];
|
||||
SofaScoreDay::where('sport_id', $sport_id)->update(['enabled' => 0]);
|
||||
}),
|
||||
])
|
||||
->columns([
|
||||
TextColumn::make('day')->sortable(),
|
||||
TextColumn::make('sport.name'),
|
||||
TextColumn::make('day')->sortable(),
|
||||
ToggleColumn::make('enabled'),
|
||||
])
|
||||
->filters([
|
||||
Filter::make('day')
|
||||
Filter::make('filter')
|
||||
->columns(4)->columnSpan(4)
|
||||
->schema([
|
||||
Select::make('sport_id')
|
||||
@@ -50,13 +83,13 @@ class SofaScoreDaysTable
|
||||
->query(function (Builder $query, array $data): Builder {
|
||||
return $query->when(
|
||||
$data['year'],
|
||||
fn(Builder $query, $year): Builder => $query->whereYear('day', $year),
|
||||
fn (Builder $query, $year): Builder => $query->whereYear('day', $year),
|
||||
)->when(
|
||||
$data['month'],
|
||||
fn(Builder $query, $month): Builder => $query->whereMonth('day', $month),
|
||||
fn (Builder $query, $month): Builder => $query->whereMonth('day', $month),
|
||||
)->when(
|
||||
$data['enabled'],
|
||||
fn(Builder $query, $enabled): Builder => $query->where('enabled', $enabled),
|
||||
fn (Builder $query, $enabled): Builder => $query->where('enabled', $enabled),
|
||||
);
|
||||
})->indicateUsing(function (array $data): array {
|
||||
$indicators = [];
|
||||
@@ -66,31 +99,29 @@ class SofaScoreDaysTable
|
||||
if ($data['month'] ?? null) {
|
||||
$indicators[] = Indicator::make('Month: '.$data['month']);
|
||||
}
|
||||
return $indicators;
|
||||
}),
|
||||
|
||||
return $indicators;
|
||||
}),
|
||||
], layout: FiltersLayout::AboveContent)
|
||||
->deferFilters(false)
|
||||
->recordActions([
|
||||
EditAction::make(),
|
||||
])
|
||||
->toolbarActions([
|
||||
BulkActionGroup::make([
|
||||
// DeleteBulkAction::make(),
|
||||
]),
|
||||
]);
|
||||
->persistFiltersInSession()
|
||||
->deferFilters(false);
|
||||
}
|
||||
|
||||
public static function years() {
|
||||
$years = range(date('Y'), date('Y')-10);
|
||||
public static function years()
|
||||
{
|
||||
$years = range(date('Y'), date('Y') - 10);
|
||||
|
||||
return array_combine($years, $years);
|
||||
}
|
||||
|
||||
public static function month() {
|
||||
public static function month()
|
||||
{
|
||||
$months = [];
|
||||
for ($m = 1; $m <= 12; $m++) {
|
||||
$date = Carbon::create(null, $m, 1);
|
||||
$months[$date->format('m')] = $date->format('F');
|
||||
}
|
||||
|
||||
return $months;
|
||||
}
|
||||
}
|
||||
+92
-92
@@ -33,121 +33,121 @@ class SofaScoreTournamentsTable
|
||||
->icon('phosphor-power')
|
||||
->requiresConfirmation()
|
||||
->modalDescription('This will disable all leagues for soccer')
|
||||
->action(fn() => SofaScoreTournament::where('sport_id', 1)->update(['enabled' => 0])
|
||||
),
|
||||
->action(fn () => SofaScoreTournament::where('sport_id', 1)->update(['enabled' => 0])
|
||||
),
|
||||
Action::make('ice-hockey')
|
||||
->icon('phosphor-power')
|
||||
->requiresConfirmation()
|
||||
->modalDescription('This will disable all leagues for ice hockey')
|
||||
->action(fn() => SofaScoreTournament::where('sport_id', 2)->update(['enabled' => 0])
|
||||
),
|
||||
->action(fn () => SofaScoreTournament::where('sport_id', 2)->update(['enabled' => 0])
|
||||
),
|
||||
Action::make('basketball')
|
||||
->icon('phosphor-power')
|
||||
->requiresConfirmation()
|
||||
->modalDescription('This will disable all leagues for basketball')
|
||||
->action(fn() => SofaScoreTournament::where('sport_id', 3)->update(['enabled' => 0])
|
||||
),
|
||||
->action(fn () => SofaScoreTournament::where('sport_id', 3)->update(['enabled' => 0])
|
||||
),
|
||||
Action::make('tennis')
|
||||
->icon('phosphor-power')
|
||||
->requiresConfirmation()
|
||||
->modalDescription('This will disable all leagues for tennis')
|
||||
->action(fn() => SofaScoreTournament::where('sport_id', 5)->update(['enabled' => 0])
|
||||
),
|
||||
->action(fn () => SofaScoreTournament::where('sport_id', 5)->update(['enabled' => 0])
|
||||
),
|
||||
])
|
||||
->poll()
|
||||
->columns([
|
||||
IconColumn::make('sport.icon')
|
||||
->label('')
|
||||
->grow(false)
|
||||
->width(30)
|
||||
->color(fn($record) => $record->sport->color)
|
||||
->icon(fn($record) => $record->sport->icon)
|
||||
->size(IconSize::Medium)
|
||||
->tooltip(fn($record) => $record->id)
|
||||
->visibleFrom('lg'),
|
||||
TextColumn::make('tournament_id')->sortable(),
|
||||
TextColumn::make('sport.name'),
|
||||
TextColumn::make('sofascore_category.name')
|
||||
->icon(fn($record) => $record->sofascore_category->country->icon),
|
||||
TextColumn::make('name')->searchable()->sortable(),
|
||||
ToggleColumn::make('enabled'),
|
||||
IconColumn::make('sport.icon')
|
||||
->label('')
|
||||
->grow(false)
|
||||
->width(30)
|
||||
->color(fn ($record) => $record->sport->color)
|
||||
->icon(fn ($record) => $record->sport->icon)
|
||||
->size(IconSize::Medium)
|
||||
->tooltip(fn ($record) => $record->id)
|
||||
->visibleFrom('lg'),
|
||||
TextColumn::make('tournament_id')->sortable()->searchable(),
|
||||
TextColumn::make('sport.name'),
|
||||
TextColumn::make('sofascore_category.name')
|
||||
->icon(fn ($record) => $record->sofascore_category->country->icon),
|
||||
TextColumn::make('name')->searchable()->sortable(),
|
||||
ToggleColumn::make('enabled'),
|
||||
])
|
||||
->filters([
|
||||
Filter::make('filters')
|
||||
->columns(3)->columnSpan(3)
|
||||
->schema([
|
||||
Select::make('sport_id')
|
||||
->default(1)
|
||||
->selectablePlaceholder(false)
|
||||
->label('Sport')
|
||||
->options(Sport::where('is_active', 1)->pluck('name', 'id'))
|
||||
->afterStateUpdated(function (callable $set) {
|
||||
$set('sofa_score_categorie_id', null);
|
||||
})
|
||||
->live(),
|
||||
Select::make('sofa_score_categorie_id')
|
||||
->searchable()
|
||||
->multiple()
|
||||
->label('Categorie')
|
||||
->options(function (Get $get) {
|
||||
$res = SofaScoreTournament::where('sport_id', $get('sport_id'))
|
||||
->groupBy('sofa_score_categorie_id')
|
||||
->pluck('sofa_score_categorie_id')
|
||||
->toArray();
|
||||
Filter::make('filters')
|
||||
->columns(3)->columnSpan(3)
|
||||
->schema([
|
||||
Select::make('sport_id')
|
||||
->default(1)
|
||||
->selectablePlaceholder(false)
|
||||
->label('Sport')
|
||||
->options(Sport::where('is_active', 1)->pluck('name', 'id'))
|
||||
->afterStateUpdated(function (callable $set) {
|
||||
$set('sofa_score_categorie_id', null);
|
||||
})
|
||||
->live(),
|
||||
Select::make('sofa_score_categorie_id')
|
||||
->searchable()
|
||||
->multiple()
|
||||
->label('Categorie')
|
||||
->options(function (Get $get) {
|
||||
$res = SofaScoreTournament::where('sport_id', $get('sport_id'))
|
||||
->groupBy('sofa_score_categorie_id')
|
||||
->pluck('sofa_score_categorie_id')
|
||||
->toArray();
|
||||
|
||||
return SofaScoreCategorie::query()->whereIn('id', $res)->orderBy('name')->pluck('name', 'id');
|
||||
})
|
||||
->live(),
|
||||
DatePicker::make('day')->live(),
|
||||
])
|
||||
->query(function (Builder $query, array $data): Builder {
|
||||
return $query->when(
|
||||
$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);
|
||||
} else {
|
||||
$query->where('sofa_score_categorie_id', $sofa_score_categorie_id);
|
||||
return SofaScoreCategorie::query()->whereIn('id', $res)->orderBy('name')->pluck('name', 'id');
|
||||
})
|
||||
->live(),
|
||||
DatePicker::make('day')->live(),
|
||||
])
|
||||
->query(function (Builder $query, array $data): Builder {
|
||||
return $query->when(
|
||||
$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);
|
||||
} else {
|
||||
$query->where('sofa_score_categorie_id', $sofa_score_categorie_id);
|
||||
}
|
||||
}
|
||||
}
|
||||
)->when(
|
||||
$data['day'],
|
||||
function (Builder $query, $day) {
|
||||
$res = SofaScoreDayTournament::where('day', $day)->pluck('tournament_id')->toArray();
|
||||
$query->whereIn('tournament_id', $res);
|
||||
}
|
||||
);
|
||||
}),
|
||||
TernaryFilter::make('enabled')->placeholder('All'),
|
||||
)->when(
|
||||
$data['day'],
|
||||
function (Builder $query, $day) {
|
||||
$res = SofaScoreDayTournament::where('day', $day)->pluck('tournament_id')->toArray();
|
||||
$query->whereIn('tournament_id', $res);
|
||||
}
|
||||
);
|
||||
}),
|
||||
TernaryFilter::make('enabled')->placeholder('All'),
|
||||
], layout: FiltersLayout::AboveContent)
|
||||
->deferFilters(false)
|
||||
->toolbarActions([
|
||||
BulkActionGroup::make([
|
||||
BulkAction::make('Enable')
|
||||
->icon('phosphor-toggle-right-fill')
|
||||
->color('primary')
|
||||
->action(function (Collection $records): void {
|
||||
foreach ($records as $record) {
|
||||
SofaScoreTournament::where('id', '=', $record->id)
|
||||
->update(
|
||||
['enabled' => 1]
|
||||
);
|
||||
}
|
||||
}),
|
||||
BulkAction::make('Disable')
|
||||
->icon('phosphor-toggle-left-fill')
|
||||
->color('gray')
|
||||
->action(function (Collection $records): void {
|
||||
foreach ($records as $record) {
|
||||
SofaScoreTournament::where('id', '=', $record->id)
|
||||
->update(
|
||||
['enabled' => 0]
|
||||
);
|
||||
}
|
||||
}),
|
||||
BulkAction::make('Enable')
|
||||
->icon('phosphor-toggle-right-fill')
|
||||
->color('primary')
|
||||
->action(function (Collection $records): void {
|
||||
foreach ($records as $record) {
|
||||
SofaScoreTournament::where('id', '=', $record->id)
|
||||
->update(
|
||||
['enabled' => 1]
|
||||
);
|
||||
}
|
||||
}),
|
||||
BulkAction::make('Disable')
|
||||
->icon('phosphor-toggle-left-fill')
|
||||
->color('gray')
|
||||
->action(function (Collection $records): void {
|
||||
foreach ($records as $record) {
|
||||
SofaScoreTournament::where('id', '=', $record->id)
|
||||
->update(
|
||||
['enabled' => 0]
|
||||
);
|
||||
}
|
||||
}),
|
||||
]),
|
||||
]);
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user