remove days and add tasks
This commit is contained in:
1 parent
be2a16a812
commit
23a367c493
31 files changed
+237
-464
No files matched your search
@@ -2,9 +2,11 @@
|
||||
|
||||
namespace App\Filament\Clusters\StaticData\Resources\SofaScoreTasks\Pages;
|
||||
|
||||
use App\Filament\Clusters\StaticData\Resources\SofaScoreTasks\RelationManagers\SofaScoreTaskTournamentsRelationManager;
|
||||
use App\Filament\Clusters\StaticData\Resources\SofaScoreTasks\SofaScoreTaskResource;
|
||||
use Filament\Actions\DeleteAction;
|
||||
use Filament\Resources\Pages\EditRecord;
|
||||
use Guava\FilamentModalRelationManagers\Actions\RelationManagerAction;
|
||||
|
||||
class EditSofaScoreTask extends EditRecord
|
||||
{
|
||||
|
||||
@@ -2,9 +2,11 @@
|
||||
|
||||
namespace App\Filament\Clusters\StaticData\Resources\SofaScoreTasks\Pages;
|
||||
|
||||
use App\Filament\Clusters\StaticData\Resources\SofaScoreTasks\RelationManagers\SofaScoreTaskTournamentsRelationManager;
|
||||
use App\Filament\Clusters\StaticData\Resources\SofaScoreTasks\SofaScoreTaskResource;
|
||||
use Filament\Actions\CreateAction;
|
||||
use Filament\Resources\Pages\ListRecords;
|
||||
use Guava\FilamentModalRelationManagers\Actions\RelationManagerAction;
|
||||
|
||||
class ListSofaScoreTasks extends ListRecords
|
||||
{
|
||||
|
||||
+89
@@ -0,0 +1,89 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Clusters\StaticData\Resources\SofaScoreTasks\RelationManagers;
|
||||
|
||||
use App\Models\SofaScoreCategorie;
|
||||
use App\Models\SofaScoreTournament;
|
||||
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;
|
||||
use Filament\Schemas\Components\Utilities\Get;
|
||||
use Filament\Schemas\Schema;
|
||||
use Filament\Support\Enums\FontWeight;
|
||||
use Filament\Tables\Columns\TextColumn;
|
||||
use Filament\Tables\Columns\ToggleColumn;
|
||||
use Filament\Tables\Table;
|
||||
|
||||
class SofaScoreTaskTournamentsRelationManager extends RelationManager
|
||||
{
|
||||
protected static string $relationship = 'sofa_score_task_tournaments';
|
||||
|
||||
protected static ?string $title = 'Tournaments';
|
||||
|
||||
protected static ?string $navigationLabel = 'Tournaments';
|
||||
|
||||
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')
|
||||
->searchable()
|
||||
->label('Categorie')
|
||||
->options(function (Get $get) {
|
||||
$res = SofaScoreTournament::where('sport_id', $this->getOwnerRecord()['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(),
|
||||
Select::make('sofa_score_tournament_id')
|
||||
->searchable()
|
||||
->label('Tournament')
|
||||
->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'))
|
||||
->pluck('name', 'tournament_id')),
|
||||
]);
|
||||
}
|
||||
|
||||
public function table(Table $table): Table
|
||||
{
|
||||
return $table
|
||||
->columns([
|
||||
TextColumn::make('tournament.sofascore_category.name')
|
||||
->label('Country')
|
||||
->searchable(),
|
||||
TextColumn::make('tournament.name')
|
||||
->weight(FontWeight::Bold)
|
||||
->searchable(),
|
||||
ToggleColumn::make('disabled')
|
||||
->alignCenter(),
|
||||
])
|
||||
->filters([
|
||||
//
|
||||
])
|
||||
->headerActions([
|
||||
CreateAction::make()
|
||||
->icon('phosphor-plus')
|
||||
->label('Tournament'),
|
||||
])
|
||||
->recordActions([
|
||||
EditAction::make(),
|
||||
DeleteAction::make(),
|
||||
])
|
||||
->toolbarActions([
|
||||
BulkActionGroup::make([
|
||||
DeleteBulkAction::make(),
|
||||
]),
|
||||
]);
|
||||
}
|
||||
}
|
||||
+2
@@ -31,9 +31,11 @@ class SofaScoreTaskForm
|
||||
'range' => '<span class="text-green-600">Grap a date range</span>',
|
||||
]),
|
||||
DatePicker::make('day_from')
|
||||
->required()
|
||||
->native()
|
||||
->visible(fn (Get $get): bool => in_array($get('mode'), ['date', 'range'])),
|
||||
DatePicker::make('day_to')
|
||||
->required()
|
||||
->native()
|
||||
->visible(fn (Get $get): bool => $get('mode') === 'range'),
|
||||
]);
|
||||
|
||||
@@ -22,9 +22,9 @@ class SofaScoreTaskResource extends Resource
|
||||
|
||||
protected static ?string $modelLabel = 'SofaScore Tasks';
|
||||
|
||||
protected static ?int $navigationSort = 0;
|
||||
protected static ?int $navigationSort = 1;
|
||||
|
||||
protected static string|UnitEnum|null $navigationGroup = 'Statistiko';
|
||||
protected static string|UnitEnum|null $navigationGroup = 'SofaScore';
|
||||
|
||||
public static function form(Schema $schema): Schema
|
||||
{
|
||||
@@ -36,13 +36,6 @@ class SofaScoreTaskResource extends Resource
|
||||
return SofaScoreTasksTable::configure($table);
|
||||
}
|
||||
|
||||
public static function getRelations(): array
|
||||
{
|
||||
return [
|
||||
//
|
||||
];
|
||||
}
|
||||
|
||||
public static function getNavigationBadge(): ?string
|
||||
{
|
||||
return parent::getEloquentQuery()->count();
|
||||
|
||||
+33
-11
@@ -2,11 +2,16 @@
|
||||
|
||||
namespace App\Filament\Clusters\StaticData\Resources\SofaScoreTasks\Tables;
|
||||
|
||||
use App\Filament\Clusters\StaticData\Resources\SofaScoreTasks\RelationManagers\SofaScoreTaskTournamentsRelationManager;
|
||||
use App\Models\SofaScoreTask;
|
||||
use Filament\Actions\DeleteAction;
|
||||
use Filament\Actions\EditAction;
|
||||
use Filament\Schemas\Components\Utilities\Set;
|
||||
use Filament\Tables\Columns\IconColumn;
|
||||
use Filament\Tables\Columns\TextColumn;
|
||||
use Filament\Tables\Columns\ToggleColumn;
|
||||
use Filament\Tables\Table;
|
||||
use Guava\FilamentModalRelationManagers\Actions\RelationManagerAction;
|
||||
|
||||
class SofaScoreTasksTable
|
||||
{
|
||||
@@ -20,29 +25,46 @@ class SofaScoreTasksTable
|
||||
->width(30)
|
||||
->icon(fn ($record) => $record->sport->icon),
|
||||
TextColumn::make('sport.name'),
|
||||
IconColumn::make('compleated')
|
||||
->width('1rem')
|
||||
->label('Status')
|
||||
->alignCenter()
|
||||
->icon(fn (string $state): string => match ($state) {
|
||||
'0' => 'phosphor-pause-fill',
|
||||
'1' => 'phosphor-check-fat-fill',
|
||||
})
|
||||
->color(fn (string $state): string => match ($state) {
|
||||
'0' => 'gray',
|
||||
'1' => 'success',
|
||||
}),
|
||||
TextColumn::make('mode')
|
||||
->label('Grapping dates')
|
||||
->badge()
|
||||
->color(fn ($state): string => match ($state) {
|
||||
'yesterday' => 'warning',
|
||||
'date' => 'primary',
|
||||
'range' => 'success',
|
||||
})
|
||||
->formatStateUsing(fn (string $state, $record): string => match ($state) {
|
||||
'yesterday' => 'Every yesterday',
|
||||
'date' => $record->day_from->format('Y-m-d'),
|
||||
'range' => $record->day_from.' - '.$record->day_to,
|
||||
'date' => $record->day_from,
|
||||
'range' => $record->day_from.' <=> '.$record->day_to,
|
||||
}),
|
||||
ToggleColumn::make('is_active')
|
||||
->alignCenter()
|
||||
->afterStateUpdated(function ($record) {
|
||||
SofaScoreTask::where('id', $record->id)->update(['compleated' => 0]);
|
||||
}),
|
||||
ToggleColumn::make('is_active')->alignCenter(),
|
||||
ToggleColumn::make('run_slow')->alignCenter(),
|
||||
ToggleColumn::make('run_repeatedly')->alignCenter(),
|
||||
ToggleColumn::make('compleated')->alignCenter(),
|
||||
])
|
||||
->filters([
|
||||
//
|
||||
])
|
||||
->recordActions([
|
||||
EditAction::make(),
|
||||
RelationManagerAction::make()
|
||||
->icon('phosphor-trophy-fill')
|
||||
->iconButton()
|
||||
->modalHeading('Add tournaments to sofascore grapper task')
|
||||
->relationManager(SofaScoreTaskTournamentsRelationManager::make())
|
||||
->compact(),
|
||||
EditAction::make()->iconButton()
|
||||
->icon('phosphor-calendar-fill'),
|
||||
DeleteAction::make()->iconButton(),
|
||||
]);
|
||||
}
|
||||
}
|
||||
+11
@@ -0,0 +1,11 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Clusters\StaticData\Resources\SofaScoreTournaments\Pages;
|
||||
|
||||
use App\Filament\Clusters\StaticData\Resources\SofaScoreTournaments\SofaScoreTournamentResource;
|
||||
use Filament\Resources\Pages\CreateRecord;
|
||||
|
||||
class CreateSofaScoreTournament extends CreateRecord
|
||||
{
|
||||
protected static string $resource = SofaScoreTournamentResource::class;
|
||||
}
|
||||
+19
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Clusters\StaticData\Resources\SofaScoreTournaments\Pages;
|
||||
|
||||
use App\Filament\Clusters\StaticData\Resources\SofaScoreTournaments\SofaScoreTournamentResource;
|
||||
use Filament\Actions\DeleteAction;
|
||||
use Filament\Resources\Pages\EditRecord;
|
||||
|
||||
class EditSofaScoreTournament extends EditRecord
|
||||
{
|
||||
protected static string $resource = SofaScoreTournamentResource::class;
|
||||
|
||||
protected function getHeaderActions(): array
|
||||
{
|
||||
return [
|
||||
DeleteAction::make(),
|
||||
];
|
||||
}
|
||||
}
|
||||
+19
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Clusters\StaticData\Resources\SofaScoreTournaments\Pages;
|
||||
|
||||
use App\Filament\Clusters\StaticData\Resources\SofaScoreTournaments\SofaScoreTournamentResource;
|
||||
use Filament\Actions\CreateAction;
|
||||
use Filament\Resources\Pages\ListRecords;
|
||||
|
||||
class ListSofaScoreTournaments extends ListRecords
|
||||
{
|
||||
protected static string $resource = SofaScoreTournamentResource::class;
|
||||
|
||||
protected function getHeaderActions(): array
|
||||
{
|
||||
return [
|
||||
// CreateAction::make(),
|
||||
];
|
||||
}
|
||||
}
|
||||
+16
@@ -0,0 +1,16 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Clusters\StaticData\Resources\SofaScoreTournaments\Schemas;
|
||||
|
||||
use Filament\Schemas\Schema;
|
||||
|
||||
class SofaScoreTournamentForm
|
||||
{
|
||||
public static function configure(Schema $schema): Schema
|
||||
{
|
||||
return $schema
|
||||
->components([
|
||||
//
|
||||
]);
|
||||
}
|
||||
}
|
||||
+64
@@ -0,0 +1,64 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Clusters\StaticData\Resources\SofaScoreTournaments;
|
||||
|
||||
use App\Filament\Clusters\StaticData\Resources\SofaScoreTournaments\Pages\ListSofaScoreTournaments;
|
||||
use App\Filament\Clusters\StaticData\Resources\SofaScoreTournaments\Schemas\SofaScoreTournamentForm;
|
||||
use App\Filament\Clusters\StaticData\Resources\SofaScoreTournaments\Tables\SofaScoreTournamentsTable;
|
||||
use App\Filament\Clusters\StaticData\StaticDataCluster;
|
||||
use App\Models\SofaScoreTournament;
|
||||
use Filament\Resources\Resource;
|
||||
use Filament\Schemas\Schema;
|
||||
use Filament\Tables\Table;
|
||||
use Livewire\Livewire;
|
||||
use UnitEnum;
|
||||
|
||||
class SofaScoreTournamentResource extends Resource
|
||||
{
|
||||
protected static ?string $model = SofaScoreTournament::class;
|
||||
|
||||
protected static string|UnitEnum|null $navigationGroup = 'SofaScore';
|
||||
|
||||
protected static ?string $cluster = StaticDataCluster::class;
|
||||
|
||||
protected static ?string $recordTitleAttribute = 'Tournaments';
|
||||
|
||||
protected static ?string $navigationLabel = 'Tournaments';
|
||||
|
||||
protected static ?int $navigationSort = 2;
|
||||
|
||||
public static function form(Schema $schema): Schema
|
||||
{
|
||||
return SofaScoreTournamentForm::configure($schema);
|
||||
}
|
||||
|
||||
public static function table(Table $table): Table
|
||||
{
|
||||
return SofaScoreTournamentsTable::configure($table);
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
public static function getPages(): array
|
||||
{
|
||||
return [
|
||||
'index' => ListSofaScoreTournaments::route('/'),
|
||||
];
|
||||
}
|
||||
}
|
||||
+185
@@ -0,0 +1,185 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Clusters\StaticData\Resources\SofaScoreTournaments\Tables;
|
||||
|
||||
use App\Models\SofaScoreCategorie;
|
||||
use App\Models\SofaScoreTournament;
|
||||
use App\Models\Sport;
|
||||
use Filament\Actions\Action;
|
||||
use Filament\Actions\BulkAction;
|
||||
use Filament\Actions\BulkActionGroup;
|
||||
use Filament\Forms\Components\Select;
|
||||
use Filament\Forms\Components\ToggleButtons;
|
||||
use Filament\Schemas\Components\Utilities\Get;
|
||||
use Filament\Support\Enums\IconSize;
|
||||
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\Table;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use Illuminate\Database\Eloquent\Collection;
|
||||
|
||||
class SofaScoreTournamentsTable
|
||||
{
|
||||
public static function configure(Table $table): Table
|
||||
{
|
||||
return $table
|
||||
->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()->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')->label('Enable'),
|
||||
ToggleColumn::make('disabled')->label('Disable'),
|
||||
])
|
||||
->filters([
|
||||
Filter::make('filters')
|
||||
->columns(7)->columnSpan(7)
|
||||
->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()
|
||||
->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')
|
||||
->toArray();
|
||||
|
||||
return SofaScoreCategorie::query()->whereIn('id', $res)->orderBy('name')->pluck('name', 'id');
|
||||
})
|
||||
->live(),
|
||||
// ToggleButtons::make('filter-grapping')
|
||||
// ->inline()
|
||||
// ->columnSpan(2)
|
||||
// ->default('active')
|
||||
// ->options([
|
||||
// 'all' => 'All',
|
||||
// 'active' => 'Active',
|
||||
// 'disabled' => 'Disabled',
|
||||
// ]),
|
||||
ToggleButtons::make('filter-disabled')
|
||||
->inline()
|
||||
->columnSpan(2)
|
||||
->default('active')
|
||||
->options([
|
||||
'all' => 'All',
|
||||
'active' => 'Active',
|
||||
'hidden' => 'Hidden',
|
||||
]),
|
||||
])
|
||||
->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['filter-grapping'],
|
||||
function (Builder $query, $filtergrapping) {
|
||||
switch ($filtergrapping) {
|
||||
case 'active':
|
||||
$query->where('enabled', 1);
|
||||
break;
|
||||
case 'disabled':
|
||||
$query->where('enabled', 0);
|
||||
break;
|
||||
}
|
||||
}
|
||||
)->when(
|
||||
$data['filter-disabled'],
|
||||
function (Builder $query, $filterdisabled) {
|
||||
switch ($filterdisabled) {
|
||||
case 'active':
|
||||
$query->where('disabled', 0);
|
||||
break;
|
||||
case 'hidden':
|
||||
$query->where('disabled', 1);
|
||||
break;
|
||||
}
|
||||
}
|
||||
);
|
||||
}),
|
||||
], 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]
|
||||
);
|
||||
}
|
||||
}),
|
||||
])->label('Grapping'),
|
||||
BulkActionGroup::make([
|
||||
BulkAction::make('Hide')
|
||||
->icon('phosphor-toggle-right-fill')
|
||||
->color('primary')
|
||||
->action(function (Collection $records): void {
|
||||
foreach ($records as $record) {
|
||||
SofaScoreTournament::where('id', '=', $record->id)
|
||||
->update(
|
||||
['disabled' => 1]
|
||||
);
|
||||
}
|
||||
}),
|
||||
BulkAction::make('Show')
|
||||
->icon('phosphor-toggle-left-fill')
|
||||
->color('gray')
|
||||
->action(function (Collection $records): void {
|
||||
foreach ($records as $record) {
|
||||
SofaScoreTournament::where('id', '=', $record->id)
|
||||
->update(
|
||||
['disabled' => 0]
|
||||
);
|
||||
}
|
||||
}),
|
||||
])->label('Disabled'),
|
||||
]);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user