grapper wip

This commit is contained in:
salam committed 2026-06-24 13:06:46 +02:00
1 parent 6a9173e3eb
commit 361e5ed3ed
15 files changed
+310 -120

No files matched your search

@@ -0,0 +1,11 @@
<?php
namespace App\Filament\Clusters\StaticData\Resources\SofaScoreDayTournaments\Pages;
use App\Filament\Clusters\StaticData\Resources\SofaScoreDayTournaments\SofaScoreDayTournamentResource;
use Filament\Resources\Pages\CreateRecord;
class CreateSofaScoreDayTournament extends CreateRecord
{
protected static string $resource = SofaScoreDayTournamentResource::class;
}
@@ -0,0 +1,19 @@
<?php
namespace App\Filament\Clusters\StaticData\Resources\SofaScoreDayTournaments\Pages;
use App\Filament\Clusters\StaticData\Resources\SofaScoreDayTournaments\SofaScoreDayTournamentResource;
use Filament\Actions\DeleteAction;
use Filament\Resources\Pages\EditRecord;
class EditSofaScoreDayTournament extends EditRecord
{
protected static string $resource = SofaScoreDayTournamentResource::class;
protected function getHeaderActions(): array
{
return [
DeleteAction::make(),
];
}
}
@@ -0,0 +1,19 @@
<?php
namespace App\Filament\Clusters\StaticData\Resources\SofaScoreDayTournaments\Pages;
use App\Filament\Clusters\StaticData\Resources\SofaScoreDayTournaments\SofaScoreDayTournamentResource;
use Filament\Actions\CreateAction;
use Filament\Resources\Pages\ListRecords;
class ListSofaScoreDayTournaments extends ListRecords
{
protected static string $resource = SofaScoreDayTournamentResource::class;
protected function getHeaderActions(): array
{
return [
CreateAction::make(),
];
}
}
@@ -0,0 +1,16 @@
<?php
namespace App\Filament\Clusters\StaticData\Resources\SofaScoreDayTournaments\Schemas;
use Filament\Schemas\Schema;
class SofaScoreDayTournamentForm
{
public static function configure(Schema $schema): Schema
{
return $schema
->components([
//
]);
}
}
@@ -0,0 +1,66 @@
<?php
namespace App\Filament\Clusters\StaticData\Resources\SofaScoreDayTournaments;
use App\Filament\Clusters\StaticData\Resources\SofaScoreDayTournaments\Pages\CreateSofaScoreDayTournament;
use App\Filament\Clusters\StaticData\Resources\SofaScoreDayTournaments\Pages\EditSofaScoreDayTournament;
use App\Filament\Clusters\StaticData\Resources\SofaScoreDayTournaments\Pages\ListSofaScoreDayTournaments;
use App\Filament\Clusters\StaticData\Resources\SofaScoreDayTournaments\Schemas\SofaScoreDayTournamentForm;
use App\Filament\Clusters\StaticData\Resources\SofaScoreDayTournaments\Tables\SofaScoreDayTournamentsTable;
use App\Filament\Clusters\StaticData\StaticDataCluster;
use App\Models\SofaScoreDayTournament;
use Filament\Resources\Resource;
use Filament\Schemas\Schema;
use Filament\Tables\Table;
use Livewire\Livewire;
use UnitEnum;
class SofaScoreDayTournamentResource extends Resource
{
protected static bool $shouldRegisterNavigation = false;
protected static ?string $model = SofaScoreDayTournament::class;
protected static string|UnitEnum|null $navigationGroup = 'SofaScore';
protected static ?string $cluster = StaticDataCluster::class;
protected static ?string $recordTitleAttribute = 'Days & Tournaments';
protected static ?string $navigationLabel = 'Days & Tournaments';
public static function form(Schema $schema): Schema
{
return SofaScoreDayTournamentForm::configure($schema);
}
public static function table(Table $table): Table
{
return SofaScoreDayTournamentsTable::configure($table);
}
public static function getPages(): array
{
return [
'index' => ListSofaScoreDayTournaments::route('/'),
];
}
public static function getNavigationBadge(): ?string
{
// return parent::getEloquentQuery()->count();
// Ensure we are on the list page
if (! class_exists(Livewire::class) || Livewire::current() === null) {
return null;
}
$livewire = Livewire::current();
// Check if the current component has the table filtering traits
if (method_exists($livewire, 'getFilteredTableQuery')) {
return (string) $livewire->getFilteredTableQuery()->count();
}
return null;
}
}
@@ -0,0 +1,30 @@
<?php
namespace App\Filament\Clusters\StaticData\Resources\SofaScoreDayTournaments\Tables;
use Filament\Actions\BulkActionGroup;
use Filament\Actions\DeleteBulkAction;
use Filament\Actions\EditAction;
use Filament\Tables\Table;
class SofaScoreDayTournamentsTable
{
public static function configure(Table $table): Table
{
return $table
->columns([
//
])
->filters([
//
])
->recordActions([
EditAction::make(),
])
->toolbarActions([
BulkActionGroup::make([
DeleteBulkAction::make(),
]),
]);
}
}
@@ -2,82 +2,72 @@
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\DatePicker;
use Filament\Forms\Components\Select;
use Filament\Tables\Columns\CheckboxColumn;
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;
use Filament\Tables\Filters\Filter;
use Filament\Tables\Filters\Indicator;
use Filament\Tables\Table;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Support\Carbon;
class SofaScoreDaysTable
{
public static function configure(Table $table): Table
{
return $table
->description('Sport checked is grapped, uncheck to grap data for specivic day again.')
->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])),
])
->columns([
TextColumn::make('day')->sortable(),
CheckboxColumn::make('football'),
CheckboxColumn::make('basketball'),
CheckboxColumn::make('ice-hockey'),
CheckboxColumn::make('tennis'),
TextColumn::make('sport.name'),
ToggleColumn::make('enabled'),
])
->filters([
Filter::make('day')
->columns(3)->columnSpan(3)
->columns(4)->columnSpan(4)
->schema([
DatePicker::make('from')->native(),
DatePicker::make('until')->native(),
Select::make('sports-grapper')
->options([
'1' => 'Soccer Grapped',
'2' => 'Soccer Not Grapped',
'3' => 'Basketball Grapped',
'4' => 'Basketball Not Grapped',
'5' => 'Ice-Hockey Grapped',
'6' => 'Ice-Hockey Not Grapped',
'7' => 'Tennis Grapped',
'8' => 'Tennis Not Grapped',
]),
Select::make('sport_id')
->default(1)
->selectablePlaceholder(false)
->label('Sport')
->options(Sport::where('is_active', 1)->pluck('name', 'id')),
Select::make('year')->options(self::years()),
Select::make('month')->options(self::month()),
Toggle::make('enabled'),
])
->query(function (Builder $query, array $data): Builder {
return $query
->when(
$data['from'],
fn(Builder $query, $date): Builder => $query->whereDate('day', '>=', $date),
)
->when(
$data['until'],
fn(Builder $query, $date): Builder => $query->whereDate('day', '<=', $date),
)->when(
$data['sports-grapper'],
function (Builder $query, $sports_grapper) {
switch ($sports_grapper) {
case 1:
return $query->where('football', 1);
case 2:
return $query->where('football', 0);
case 3:
return $query->where('basketball', 1);
case 4:
return $query->where('basketball', 0);
case 5:
return $query->where('ice-hockey', 1);
case 6:
return $query->where('ice-hockey', 0);
case 7:
return $query->where('tennis', 1);
case 8:
return $query->where('tennis', 0);
}
}
);
}),
return $query->when(
$data['year'],
fn(Builder $query, $year): Builder => $query->whereYear('day', $year),
)->when(
$data['month'],
fn(Builder $query, $month): Builder => $query->whereMonth('day', $month),
)->when(
$data['enabled'],
fn(Builder $query, $enabled): Builder => $query->where('enabled', $enabled),
);
})->indicateUsing(function (array $data): array {
$indicators = [];
if ($data['year'] ?? null) {
$indicators[] = Indicator::make('Year: '.$data['year']);
}
if ($data['month'] ?? null) {
$indicators[] = Indicator::make('Month: '.$data['month']);
}
return $indicators;
}),
], layout: FiltersLayout::AboveContent)
->deferFilters(false)
->recordActions([
@@ -85,8 +75,22 @@ class SofaScoreDaysTable
])
->toolbarActions([
BulkActionGroup::make([
DeleteBulkAction::make(),
// DeleteBulkAction::make(),
]),
]);
}
public static function years() {
$years = range(date('Y'), date('Y')-10);
return array_combine($years, $years);
}
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;
}
}
@@ -25,6 +25,7 @@ class SofaScoreTournamentResource extends Resource
protected static ?string $navigationLabel = 'Tournaments';
public static function form(Schema $schema): Schema
{
return SofaScoreTournamentForm::configure($schema);
@@ -6,13 +6,13 @@ use App\Models\SofaScoreCategorie;
use App\Models\SofaScoreDayTournament;
use App\Models\SofaScoreTournament;
use App\Models\Sport;
use Filament\Actions\Action;
use Filament\Actions\BulkAction;
use Filament\Actions\BulkActionGroup;
use Filament\Forms\Components\DatePicker;
use Filament\Forms\Components\Select;
use Filament\Schemas\Components\Utilities\Get;
use Filament\Support\Enums\IconSize;
use Filament\Tables\Columns\CheckboxColumn;
use Filament\Tables\Columns\IconColumn;
use Filament\Tables\Columns\TextColumn;
use Filament\Tables\Columns\ToggleColumn;
@@ -28,6 +28,32 @@ class SofaScoreTournamentsTable
public static function configure(Table $table): Table
{
return $table
->headerActions([
Action::make('soccer')
->icon('phosphor-power')
->requiresConfirmation()
->modalDescription('This will disable all leagues for soccer')
->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::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::make('tennis')
->icon('phosphor-power')
->requiresConfirmation()
->modalDescription('This will disable all leagues for tennis')
->action(fn() => SofaScoreTournament::where('sport_id', 5)->update(['enabled' => 0])
),
])
->poll()
->columns([
IconColumn::make('sport.icon')
@@ -39,13 +65,12 @@ class SofaScoreTournamentsTable
->size(IconSize::Medium)
->tooltip(fn($record) => $record->id)
->visibleFrom('lg'),
TextColumn::make('tournament_id'),
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('grap')->tooltip('When active liga will be grapped'),
ToggleColumn::make('grapped')->onColor('success')->tooltip('When active liga has been grapped, to grap again disactivate'),
ToggleColumn::make('enabled'),
])
->filters([
Filter::make('filters')
@@ -96,28 +121,30 @@ class SofaScoreTournamentsTable
}
);
}),
TernaryFilter::make('grap')->placeholder('All')->label('Grapping'),
TernaryFilter::make('enabled')->placeholder('All'),
], layout: FiltersLayout::AboveContent)
->deferFilters(false)
->toolbarActions([
BulkActionGroup::make([
BulkAction::make('Grap On')
->icon('phosphor-play')
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(
['grap' => 1]
['enabled' => 1]
);
}
}),
BulkAction::make('Grap Off')
->icon('phosphor-stop')
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(
['grap' => 0]
['enabled' => 0]
);
}
}),