133 lines
5.5 KiB
PHP
133 lines
5.5 KiB
PHP
<?php
|
|
|
|
namespace App\Livewire;
|
|
|
|
use App\Filament\Tables\Columns\BookmakerIcon;
|
|
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\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\ToggleColumn;
|
|
use Filament\Tables\Concerns\InteractsWithTable;
|
|
use Filament\Tables\Contracts\HasTable;
|
|
use Filament\Tables\Enums\FiltersLayout;
|
|
use Filament\Tables\Filters\TernaryFilter;
|
|
use Filament\Tables\Table;
|
|
use Illuminate\Contracts\View\View;
|
|
use Illuminate\Support\Collection;
|
|
use Livewire\Component;
|
|
|
|
class ComparingBookmakerMenu extends Component implements HasActions, HasSchemas, HasTable
|
|
{
|
|
use InteractsWithActions;
|
|
use InteractsWithSchemas;
|
|
use InteractsWithTable;
|
|
|
|
public $active_methode = 1;
|
|
|
|
protected $listeners = [
|
|
'refresh' => '$refresh',
|
|
];
|
|
|
|
public function table(Table $table): Table
|
|
{
|
|
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')
|
|
->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'))
|
|
->columns([
|
|
TextColumn::make('Position')
|
|
->alignCenter()
|
|
->badge()
|
|
->rowIndex(),
|
|
// IconColumn::make('sport.icon')
|
|
// ->label('')
|
|
// ->icon(fn ($record) => $record->sport->icon)
|
|
// ->visibleFrom('lg'),
|
|
BookmakerIcon::make('bookmaker.icon')->label('Icon'),
|
|
TextColumn::make('time_lastcheck')->label('Time Passed'),
|
|
TextColumn::make('margin_threshold'),
|
|
ToggleColumn::make('is_active'),
|
|
])
|
|
->filters([
|
|
TernaryFilter::make('is_active')->default(1)->label('Show active'),
|
|
], layout: FiltersLayout::AboveContent)
|
|
->deferFilters(false)
|
|
->toolbarActions([
|
|
BulkActionGroup::make([
|
|
BulkAction::make('time_lastcheck')
|
|
->label('Max time since last check in seconds')
|
|
->icon('phosphor-timer')
|
|
->action(function (Collection $records, array $data): void {
|
|
foreach ($records as $record) {
|
|
ComparingBookmaker::where('id', '=', $record->id)
|
|
->update(
|
|
['time_lastcheck' => $data['time_lastcheck']]
|
|
);
|
|
}
|
|
})
|
|
->form([
|
|
TextInput::make('time_lastcheck')->hiddenLabel()->prefix('Seconds'),
|
|
]),
|
|
BulkAction::make('Switch On')
|
|
->icon('phosphor-play')
|
|
->action(function (Collection $records): void {
|
|
foreach ($records as $record) {
|
|
ComparingBookmaker::where('id', '=', $record->id)
|
|
->update(
|
|
['is_active' => 1]
|
|
);
|
|
}
|
|
}),
|
|
BulkAction::make('Switch Off')
|
|
->icon('phosphor-stop')
|
|
->action(function (Collection $records): void {
|
|
foreach ($records as $record) {
|
|
ComparingBookmaker::where('id', '=', $record->id)
|
|
->update(
|
|
['is_active' => 0]
|
|
);
|
|
}
|
|
}),
|
|
]),
|
|
]);
|
|
}
|
|
|
|
public function render(): View
|
|
{
|
|
return view('livewire.comparing-bookmaker-menu');
|
|
}
|
|
}
|