98 lines
4.0 KiB
PHP
98 lines
4.0 KiB
PHP
<?php
|
|
|
|
namespace App\Livewire;
|
|
|
|
use App\Filament\Tables\Columns\BookmakerIcon;
|
|
use App\Models\Bookmaker;
|
|
use App\Models\PersonalNotification;
|
|
use App\Models\Sport;
|
|
use Filament\Actions\Action;
|
|
use Filament\Actions\Concerns\InteractsWithActions;
|
|
use Filament\Actions\Contracts\HasActions;
|
|
use Filament\Schemas\Concerns\InteractsWithSchemas;
|
|
use Filament\Schemas\Contracts\HasSchemas;
|
|
use Filament\Support\Enums\FontWeight;
|
|
use Filament\Support\Enums\IconSize;
|
|
use Filament\Tables\Columns\IconColumn;
|
|
use Filament\Tables\Columns\TextColumn;
|
|
use Filament\Tables\Concerns\InteractsWithTable;
|
|
use Filament\Tables\Contracts\HasTable;
|
|
use Filament\Tables\Enums\FiltersLayout;
|
|
use Filament\Tables\Filters\SelectFilter;
|
|
use Filament\Tables\Table;
|
|
use Illuminate\Contracts\View\View;
|
|
use Livewire\Component;
|
|
|
|
class PersonalNotificationTable extends Component implements HasActions, HasSchemas, HasTable
|
|
{
|
|
use InteractsWithActions;
|
|
use InteractsWithSchemas;
|
|
use InteractsWithTable;
|
|
|
|
public function table(Table $table): Table
|
|
{
|
|
return $table
|
|
->query(PersonalNotification::query()->with('bookmaker')->where('user_id', auth()->user()->id))
|
|
->description('Send a notification when favorit enters an alarm level.')
|
|
->striped()
|
|
->columns([
|
|
// TextColumn::make('sport.name'),
|
|
BookmakerIcon::make('bookmaker.icon')
|
|
->label('Bookmaker')->size('lg'),
|
|
// IconColumn::make('sport.icon')
|
|
// ->label('')
|
|
// ->color(fn ($record) => $record->sport->color)
|
|
// ->icon(fn ($record) => $record->sport->icon)
|
|
// ->size(IconSize::ExtraLarge),
|
|
TextColumn::make('alarm_level.name')
|
|
->color(fn ($record) => $record->alarm_level->color)
|
|
->weight(FontWeight::Black)
|
|
->extraCellAttributes(['class' => 'alarm-level-style']),
|
|
])
|
|
->defaultSort('alarm_level_id', 'desc')
|
|
->deferFilters(false)
|
|
->deferFilters(false)
|
|
->filters([
|
|
SelectFilter::make('bookmaker_id')
|
|
->label('Bookmaker')
|
|
->visible(fn () => auth()->user()->partner_bookmaker_id)
|
|
->default(auth()->user()->bookmaker->id)
|
|
->selectablePlaceholder(false)
|
|
->options(Bookmaker::options([auth()->user()->partner_bookmaker_id, auth()->user()->bookmaker_id]))
|
|
->preload(),
|
|
SelectFilter::make('sport_id')
|
|
->label('Sport')
|
|
->default(1)
|
|
->selectablePlaceholder(false)
|
|
->options(Sport::getSportForClient(auth()->user()->client_id))
|
|
->preload(),
|
|
], FiltersLayout::AboveContent)
|
|
->filtersFormColumns(3)
|
|
->hiddenFilterIndicators()
|
|
->recordActions([
|
|
Action::make('notify_by_system')
|
|
->button()
|
|
->label('Send Notification')
|
|
->color(fn ($record) => $record->notify_by_system ? 'primary' : 'gray')
|
|
->icon('phosphor-bell-duotone')
|
|
->action(function ($record) {
|
|
PersonalNotification::where('id', $record->id)->update(['notify_by_system' => ! $record->notify_by_system]);
|
|
}),
|
|
Action::make('notify_by_email')
|
|
->label('Send E-Mail')
|
|
->button()
|
|
->color(fn ($record) => $record->notify_by_email ? 'primary' : 'gray')
|
|
->icon('phosphor-envelope-duotone')
|
|
->action(function ($record) {
|
|
PersonalNotification::where('id', $record->id)->update(['notify_by_email' => ! $record->notify_by_email]);
|
|
}),
|
|
]);
|
|
|
|
}
|
|
|
|
public function render(): View
|
|
{
|
|
return view('livewire.personal-notification-table');
|
|
}
|
|
}
|