comparing bookmaker wip

This commit is contained in:
salam committed 2026-01-20 18:48:01 +01:00
1 parent de95867692
commit be80128226
11 files changed
+237 -93

No files matched your search

+129 -34
View File
@@ -3,24 +3,29 @@
namespace App\Livewire;
use App\Filament\Tables\Columns\BookmakerIcon;
use App\Livewire\ComparingBookmaker\LoadBookmaker;
use App\Models\ComparingBookmaker;
use Filament\Actions\Action;
use Filament\Actions\BulkAction;
use Filament\Actions\BulkActionGroup;
use Filament\Actions\Concerns\InteractsWithActions;
use Filament\Actions\Contracts\HasActions;
use Filament\Forms\Components\Radio;
use Filament\Forms\Components\TextInput;
use Filament\Schemas\Concerns\InteractsWithSchemas;
use Filament\Schemas\Contracts\HasSchemas;
use Filament\Tables\Columns\IconColumn;
use Filament\Tables\Columns\TextColumn;
use Filament\Tables\Columns\TextInputColumn;
use Filament\Tables\Columns\ToggleColumn;
use Filament\Tables\Concerns\InteractsWithTable;
use Filament\Tables\Contracts\HasTable;
use Filament\Tables\Enums\FiltersLayout;
use Filament\Tables\Filters\Filter;
use Filament\Tables\Filters\Indicator;
use Filament\Tables\Filters\TernaryFilter;
use Filament\Tables\Table;
use Illuminate\Contracts\View\View;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Support\Collection;
use Livewire\Component;
@@ -30,8 +35,6 @@ class ComparingBookmakerMenu extends Component implements HasActions, HasSchemas
use InteractsWithSchemas;
use InteractsWithTable;
public $active_methode = 1;
protected $listeners = [
'refresh' => '$refresh',
];
@@ -41,49 +44,74 @@ class ComparingBookmakerMenu extends Component implements HasActions, HasSchemas
return $table
->description('')
->description('Bookmaker order is priority. Maximum time than can pass since last check or update. If older bookmaker will be ignored')
->headerActions([
Action::make('top')
->color(fn () => $this->active_methode == 1 ? 'primary' : 'gray')
->icon('phosphor-cell-signal-full')
->action(fn () => $this->active_methode = 1)
->after(fn () => $this->dispatch('refresh')),
Action::make('middle')->action(fn () => $this->active_methode = 2)
->color(fn () => $this->active_methode == 2 ? 'primary' : 'gray')
->icon('phosphor-cell-signal-high')
->after(fn () => $this->dispatch('refresh')),
Action::make('low')->action(fn () => $this->active_methode = 3)
->color(fn () => $this->active_methode == 3 ? 'primary' : 'gray')
->icon('phosphor-cell-signal-medium')
->after(fn () => $this->dispatch('refresh')),
])
->reorderable('sorting')
->reorderRecordsTriggerAction(function (Action $action) {
return $action->button();
})
->paginated(false)
->striped()
->query(ComparingBookmaker::query()
->with('bookmaker')
// ->where('is_hidden', 0)
->where('sport_id', auth()->user()->sport_id)
->where('client_bookmaker_id', auth()->user()->bookmaker_id)
->where('method_id', $this->active_methode)
->orderBy('sorting'))
->query(LoadBookmaker::load())
->columns([
TextColumn::make('Position')
->alignCenter()
->badge()
->rowIndex(),
// IconColumn::make('sport.icon')
// ->label('')
// ->icon(fn ($record) => $record->sport->icon)
// ->visibleFrom('lg'),
TextColumn::make('bookmaker_id')->label('Id'),
BookmakerIcon::make('bookmaker.icon')->label('Icon'),
TextColumn::make('time_lastcheck')->label('Time Passed'),
TextColumn::make('margin_threshold'),
TextInputColumn::make('time_lastcheck')
->label('Time Passed')
->prefix('Seconds:')
->rules(['required', 'max:200', 'min:100']),
TextInputColumn::make('margin_threshold')
->label('Maximum Margin')
->prefix('Threshold:')
->rules(['required', 'max:200', 'min:100']),
ToggleColumn::make('is_active'),
])
->filters([
TernaryFilter::make('is_active')->default(1)->label('Show active'),
Filter::make('method_id')
->schema([
Radio::make('method_id')
->inline()
->default(1)
->label('League / Tournament Level')
->options([
1 => 'TOP',
2 => 'MIDDLE',
3 => 'LOW',
]),
])
->query(function (Builder $query, array $data): Builder {
return $query
->when(
$data['method_id'],
fn (Builder $query, $method_id): Builder => $query->where('method_id', $method_id),
);
})->indicateUsing(function (array $data): array {
$indicators = [];
if ($data['method_id'] ?? null) {
switch ($data['method_id']) {
case 1:
$indicators[] = Indicator::make('Method: TOP');
break;
case 2:
$indicators[] = Indicator::make('Method: MIDDLE');
break;
case 3:
$indicators[] = Indicator::make('Method: LOW');
break;
}
}
return $indicators;
})->columnSpan(6),
TernaryFilter::make('is_active')
->columnSpan(2)
->default(1)
->label('Show active'),
], layout: FiltersLayout::AboveContent)
->filtersFormColumns(8)
->deferFilters(false)
->toolbarActions([
BulkActionGroup::make([
@@ -99,7 +127,29 @@ class ComparingBookmakerMenu extends Component implements HasActions, HasSchemas
}
})
->form([
TextInput::make('time_lastcheck')->hiddenLabel()->prefix('Seconds'),
TextInput::make('time_lastcheck')
->numeric()
->hiddenLabel()
->prefix('Seconds'),
]),
BulkAction::make('margin_threshold')
->label('Maximum height of marging')
->icon('phosphor-timer')
->action(function (Collection $records, array $data): void {
foreach ($records as $record) {
ComparingBookmaker::where('id', '=', $record->id)
->update(
['margin_threshold' => $data['margin_threshold']]
);
}
})
->form([
TextInput::make('margin_threshold')
->hiddenLabel()
->numeric()
->rules(['required', 'max:200', 'min:100'])
->prefix('Threshold'),
]),
BulkAction::make('Switch On')
->icon('phosphor-play')
@@ -122,6 +172,51 @@ class ComparingBookmakerMenu extends Component implements HasActions, HasSchemas
}
}),
]),
])->recordActions([
Action::make('end')
->iconButton()
->icon('phosphor-arrow-fat-line-down')
->tooltip('Move to the end')
->action(function ($record) {
$res = ComparingBookmaker::where('method_id', $record->method_id)
->where('sport_id', $record->sport_id)
->where('client_bookmaker_id', $record->client_bookmaker_id)
->orderBy('sorting')
->pluck('bookmaker_id', 'id');
$sorting = 1;
foreach ($res as $id => $bookmaker_id) {
if ($bookmaker_id == $record->bookmaker_id) {
ComparingBookmaker::where('id', $id)
->update(['sorting' => \count($res)]);
} else {
ComparingBookmaker::where('id', $id)
->update(['sorting' => $sorting]);
$sorting++;
}
}
}),
Action::make('start')
->iconButton()
->icon('phosphor-arrow-fat-line-up')
->tooltip('Move to begining')
->action(function ($record) {
$res = ComparingBookmaker::where('method_id', $record->method_id)
->where('sport_id', $record->sport_id)
->where('client_bookmaker_id', $record->client_bookmaker_id)
->orderBy('sorting')
->pluck('bookmaker_id', 'id');
$sorting = 2;
foreach ($res as $id => $bookmaker_id) {
if ($bookmaker_id == $record->bookmaker_id) {
ComparingBookmaker::where('id', $id)
->update(['sorting' => 1]);
} else {
ComparingBookmaker::where('id', $id)
->update(['sorting' => $sorting]);
$sorting++;
}
}
}),
]);
}