filter in monitor wip
This commit is contained in:
1 parent
f5221e1d1c
commit
da257748ae
17 files changed
+339
-145
No files matched your search
@@ -26,8 +26,6 @@ class CountryResource extends Resource
|
||||
|
||||
protected static string|\BackedEnum|null $navigationIcon = 'lucide-flag';
|
||||
|
||||
protected static ?string $recordTitleAttribute = 'name';
|
||||
|
||||
protected static ?string $cluster = AdministratorCluster::class;
|
||||
|
||||
protected static string|\UnitEnum|null $navigationGroup = 'Static Data';
|
||||
|
||||
@@ -10,7 +10,9 @@ use Carbon\Carbon;
|
||||
use Filament\Resources\Resource;
|
||||
use Filament\Schemas\Schema;
|
||||
use Filament\Tables\Table;
|
||||
use Illuminate\Contracts\Support\Htmlable;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class EventResource extends Resource
|
||||
{
|
||||
@@ -22,10 +24,31 @@ class EventResource extends Resource
|
||||
|
||||
protected static ?string $modelLabel = '';
|
||||
|
||||
protected static ?string $title = '';
|
||||
protected static ?string $title = 'Monitor';
|
||||
|
||||
protected static ?string $pluralModelLabel = '';
|
||||
|
||||
// protected static ?string $recordTitleAttribute = 'tx_id';
|
||||
// public static function getGlobalSearchResultTitle(Model $record): string|Htmlable
|
||||
// {
|
||||
// return $record->home->name.' - '.$record->away->name;
|
||||
// }
|
||||
// public static function getGlobalSearchResultDetails(Model $record): array
|
||||
// {
|
||||
// return [
|
||||
// 'League' => $record->competition_group->name,
|
||||
// 'Country' => $record->country->name,
|
||||
// ];
|
||||
// }
|
||||
// public static function getGloballySearchableAttributes(): array
|
||||
// {
|
||||
// return ['tx_id', 'betradar_id', 'competition_group.name', 'country.name', 'away.name', 'home.name'];
|
||||
// }
|
||||
// public static function getGlobalSearchResultUrl(Symbol|Model $record): string
|
||||
// {
|
||||
// return EventResource::getUrl('edit', ['record' => $record]); // Links to the edit page
|
||||
// }
|
||||
|
||||
public static function form(Schema $schema): Schema
|
||||
{
|
||||
return EventForm::configure($schema);
|
||||
|
||||
@@ -3,19 +3,24 @@
|
||||
namespace App\Filament\Resources\Events\Tables;
|
||||
|
||||
use App\Filament\Tables\Columns\MultilineColumn;
|
||||
use App\Models\CompetitionGroup;
|
||||
use App\Models\Country;
|
||||
use App\Models\Event;
|
||||
use Carbon\Carbon;
|
||||
use Filament\Actions\Action;
|
||||
use Filament\Actions\ActionGroup;
|
||||
use Filament\Actions\DeleteAction;
|
||||
use Filament\Actions\EditAction;
|
||||
use Filament\Forms\Components\Select;
|
||||
use Filament\Schemas\Components\Utilities\Get;
|
||||
use Filament\Support\Enums\FontWeight;
|
||||
use Filament\Support\Enums\IconSize;
|
||||
use Filament\Tables\Columns\IconColumn;
|
||||
use Filament\Tables\Columns\TextColumn;
|
||||
use Filament\Tables\Enums\FiltersLayout;
|
||||
use Filament\Tables\Filters\SelectFilter;
|
||||
use Filament\Tables\Filters\Filter;
|
||||
use Filament\Tables\Table;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
|
||||
class EventsTable
|
||||
{
|
||||
@@ -30,7 +35,11 @@ class EventsTable
|
||||
->size(IconSize::ExtraLarge)
|
||||
->icon(fn ($record) => $record->sport->icon)
|
||||
->tooltip(fn ($record) => $record->id),
|
||||
TextColumn::make('tx_id')->label('Id')->badge()->copyable()->searchable(),
|
||||
TextColumn::make('tx_id')
|
||||
->label('Id')
|
||||
->badge()
|
||||
->searchable()
|
||||
->copyable(),
|
||||
TextColumn::make('starttime')
|
||||
->label('Start')
|
||||
->alignCenter()
|
||||
@@ -38,40 +47,88 @@ class EventsTable
|
||||
->weight(FontWeight::Bold)
|
||||
->description(fn ($state): string => Carbon::createFromDate($state)->format('H:i')),
|
||||
TextColumn::make('country.name')
|
||||
->searchable()
|
||||
->color('gray')
|
||||
->label('Event')
|
||||
->icon(fn ($record) => $record->country->icon)
|
||||
->description(fn ($record) => $record->competition_group->name),
|
||||
TextColumn::make('home.name')->alignRight()->searchable(),
|
||||
TextColumn::make('away.name')->searchable(),
|
||||
|
||||
MultilineColumn::make('id')
|
||||
TextColumn::make('home.name')
|
||||
->searchable()
|
||||
->label(fn () => view('filament.tables.columns.multiline.label')),
|
||||
|
||||
->alignRight(),
|
||||
TextColumn::make('away.name')
|
||||
->searchable(),
|
||||
MultilineColumn::make('id')->label(fn () => view('filament.tables.columns.multiline.label')),
|
||||
])
|
||||
->poll('10s')
|
||||
->defaultSort('starttime', 'ASC')
|
||||
->filters([
|
||||
SelectFilter::make('competition_group_id')
|
||||
->preload()
|
||||
->label('League')
|
||||
->multiple()
|
||||
->searchable()
|
||||
->options(function () {
|
||||
Filter::make('events')
|
||||
->schema([
|
||||
Select::make('country_id')
|
||||
->label('Country')
|
||||
->searchable()
|
||||
->preload()
|
||||
->options(function () {
|
||||
$res = Event::query()->where('starttime', '>', Carbon::now())->groupBy('country_id')->pluck('country_id')->toArray();
|
||||
|
||||
$res = Event::with('country')->with('competition_group')->where('starttime', '>', Carbon::now())->groupBy('competition_group_id')->get();
|
||||
$arr = [];
|
||||
foreach ($res as $val) {
|
||||
$arr[$val->competition_group_id] = $val->country->name.' - '.$val->competition_group->name;
|
||||
}
|
||||
return Country::query()->whereIn('tx_id', $res)->pluck('name', 'tx_id');
|
||||
})
|
||||
->live()
|
||||
->reactive()
|
||||
->afterStateUpdated(function (callable $set) {
|
||||
$set('competition_group_id', null);
|
||||
}),
|
||||
Select::make('competition_group_id')
|
||||
->label('League')
|
||||
->multiple()
|
||||
->columnSpan(2)
|
||||
->searchable()
|
||||
->options(function (Get $get) {
|
||||
if ($get('country_id')) {
|
||||
$res = Event::with('country')->with('competition_group')->where('country_id', $get('country_id'))->where('starttime', '>', Carbon::now())->groupBy('competition_group_id')->get();
|
||||
} else {
|
||||
$res = Event::with('country')->with('competition_group')->where('starttime', '>', Carbon::now())->groupBy('competition_group_id')->get();
|
||||
}
|
||||
$arr = [];
|
||||
foreach ($res as $val) {
|
||||
$arr[$val->competition_group_id] = $val->country->name.' - '.$val->competition_group->name;
|
||||
}
|
||||
asort($arr);
|
||||
|
||||
asort($arr);
|
||||
return $arr;
|
||||
})
|
||||
->live(),
|
||||
])
|
||||
// ->indicateUsing(function (array $data): array {
|
||||
// $indicators = [];
|
||||
|
||||
return $arr;
|
||||
// if ($data['country_id'] ?? null) {
|
||||
// $indicators[] = 'Country: '.Country::where('tx_id', $data['country_id'])->pluck('name')->first();
|
||||
// }
|
||||
|
||||
// if ($data['competition_group_id'] ?? null) {
|
||||
// if (is_array($data['competition_group_id'])) {
|
||||
// foreach ($data['competition_group_id'] as $competition_group_id) {
|
||||
// $indicators[] = 'League: '.CompetitionGroup::where('tx_id', $competition_group_id)->pluck('name')->first();
|
||||
// }
|
||||
// } else {
|
||||
// $indicators[] = 'League: '.CompetitionGroup::where('tx_id', $data['competition_group_id'])->pluck('name')->first();
|
||||
// }
|
||||
// }
|
||||
|
||||
// return $indicators;
|
||||
// })
|
||||
->query(function (Builder $query, array $data): Builder {
|
||||
return $query
|
||||
->when(
|
||||
$data['country_id'],
|
||||
fn (Builder $query, $sport_id) => $query->where('country_id', $sport_id)
|
||||
)->when(
|
||||
$data['competition_group_id'],
|
||||
fn (Builder $query, $competition_group_id) => $query->where('competition_group_id', $competition_group_id)
|
||||
);
|
||||
})
|
||||
->columnSpan(2)
|
||||
->selectablePlaceholder(false),
|
||||
->columns(6)->columnSpan(6),
|
||||
], layout: FiltersLayout::AboveContent)
|
||||
->filtersFormColumns(6)
|
||||
->deferFilters(false)
|
||||
|
||||
@@ -57,7 +57,7 @@ class MultilineClientsTable
|
||||
->deferFilters(false)
|
||||
->filters([
|
||||
Filter::make('multiline')
|
||||
->form([
|
||||
->schema([
|
||||
Select::make('sport_id')
|
||||
->label('Sport')
|
||||
->default(1)
|
||||
|
||||
Reference in new issue
Block a user