wip relation manager :(
This commit is contained in:
1 parent
ae5b566231
commit
94a3c6c472
24 files changed
+318
-217
No files matched your search
@@ -32,13 +32,6 @@ class BettypeResource extends Resource
|
||||
return BettypesTable::configure($table);
|
||||
}
|
||||
|
||||
public static function getRelations(): array
|
||||
{
|
||||
return [
|
||||
//
|
||||
];
|
||||
}
|
||||
|
||||
public static function getPages(): array
|
||||
{
|
||||
return [
|
||||
|
||||
@@ -3,6 +3,9 @@
|
||||
namespace App\Filament\Resources\Events;
|
||||
|
||||
use App\Filament\Resources\Events\Pages\ListEvents;
|
||||
use App\Filament\Resources\Events\RelationManagers\BettypesRelationManager;
|
||||
use App\Filament\Resources\Events\RelationManagers\CountriesRelationManager;
|
||||
use App\Filament\Resources\Events\RelationManagers\UserNoteRelationManager;
|
||||
use App\Filament\Resources\Events\Schemas\EventForm;
|
||||
use App\Filament\Resources\Events\Tables\EventsTable;
|
||||
use App\Filament\Resources\Events\Tables\Tools\LoadPartnerDifferences;
|
||||
@@ -43,6 +46,15 @@ class EventResource extends Resource
|
||||
];
|
||||
}
|
||||
|
||||
public static function getRelations(): array
|
||||
{
|
||||
return [
|
||||
UserNoteRelationManager::class,
|
||||
CountriesRelationManager::class,
|
||||
BettypesRelationManager::class,
|
||||
];
|
||||
}
|
||||
|
||||
public static function getNavigationBadge(): ?string
|
||||
{
|
||||
return parent::getEloquentQuery()
|
||||
@@ -60,6 +72,7 @@ class EventResource extends Resource
|
||||
->with('away')
|
||||
->with('event_user_star')
|
||||
->with('event_bookmaker')
|
||||
->with('user_notes')
|
||||
->where('sport_id', auth()->user()->sport_id)
|
||||
->where('starttime', '>=', now());
|
||||
|
||||
|
||||
@@ -19,6 +19,7 @@ class ListEvents extends ListRecords
|
||||
'filterUpdateYellow' => 'updateTableFiltersYellow',
|
||||
'filterUpdateRed' => 'updateTableFiltersRed',
|
||||
'filterUpdatePeriode' => 'updateTablePeriode',
|
||||
'filterClearFilter' => 'clearFilters',
|
||||
];
|
||||
|
||||
protected function getHeaderWidgets(): array
|
||||
@@ -28,6 +29,11 @@ class ListEvents extends ListRecords
|
||||
];
|
||||
}
|
||||
|
||||
public function clearFilters(): void
|
||||
{
|
||||
$this->removeTableFilters();
|
||||
}
|
||||
|
||||
public function updateTablePeriode(string $filter): void
|
||||
{
|
||||
$filter = json_decode($filter, true);
|
||||
|
||||
@@ -0,0 +1,60 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\Events\RelationManagers;
|
||||
|
||||
use Filament\Actions\AssociateAction;
|
||||
use Filament\Actions\BulkActionGroup;
|
||||
use Filament\Actions\CreateAction;
|
||||
use Filament\Actions\DeleteAction;
|
||||
use Filament\Actions\DeleteBulkAction;
|
||||
use Filament\Actions\DissociateAction;
|
||||
use Filament\Actions\DissociateBulkAction;
|
||||
use Filament\Actions\EditAction;
|
||||
use Filament\Forms\Components\TextInput;
|
||||
use Filament\Resources\RelationManagers\RelationManager;
|
||||
use Filament\Schemas\Schema;
|
||||
use Filament\Tables\Columns\TextColumn;
|
||||
use Filament\Tables\Table;
|
||||
|
||||
class BettypesRelationManager extends RelationManager
|
||||
{
|
||||
protected static string $relationship = 'bettypes';
|
||||
|
||||
public function form(Schema $schema): Schema
|
||||
{
|
||||
return $schema
|
||||
->components([
|
||||
TextInput::make('name')
|
||||
->required()
|
||||
->maxLength(255),
|
||||
]);
|
||||
}
|
||||
|
||||
public function table(Table $table): Table
|
||||
{
|
||||
return $table
|
||||
->recordTitleAttribute('name')
|
||||
->columns([
|
||||
TextColumn::make('name')
|
||||
->searchable(),
|
||||
])
|
||||
->filters([
|
||||
//
|
||||
])
|
||||
->headerActions([
|
||||
CreateAction::make(),
|
||||
AssociateAction::make(),
|
||||
])
|
||||
->recordActions([
|
||||
EditAction::make(),
|
||||
DissociateAction::make(),
|
||||
DeleteAction::make(),
|
||||
])
|
||||
->toolbarActions([
|
||||
BulkActionGroup::make([
|
||||
DissociateBulkAction::make(),
|
||||
DeleteBulkAction::make(),
|
||||
]),
|
||||
]);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,60 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\Events\RelationManagers;
|
||||
|
||||
use Filament\Actions\AssociateAction;
|
||||
use Filament\Actions\BulkActionGroup;
|
||||
use Filament\Actions\CreateAction;
|
||||
use Filament\Actions\DeleteAction;
|
||||
use Filament\Actions\DeleteBulkAction;
|
||||
use Filament\Actions\DissociateAction;
|
||||
use Filament\Actions\DissociateBulkAction;
|
||||
use Filament\Actions\EditAction;
|
||||
use Filament\Forms\Components\TextInput;
|
||||
use Filament\Resources\RelationManagers\RelationManager;
|
||||
use Filament\Schemas\Schema;
|
||||
use Filament\Tables\Columns\TextColumn;
|
||||
use Filament\Tables\Table;
|
||||
|
||||
class CountriesRelationManager extends RelationManager
|
||||
{
|
||||
protected static string $relationship = 'countries';
|
||||
|
||||
public function form(Schema $schema): Schema
|
||||
{
|
||||
return $schema
|
||||
->components([
|
||||
TextInput::make('name')
|
||||
->required()
|
||||
->maxLength(255),
|
||||
]);
|
||||
}
|
||||
|
||||
public function table(Table $table): Table
|
||||
{
|
||||
return $table
|
||||
->recordTitleAttribute('name')
|
||||
->columns([
|
||||
TextColumn::make('name')
|
||||
->searchable(),
|
||||
])
|
||||
->filters([
|
||||
//
|
||||
])
|
||||
->headerActions([
|
||||
CreateAction::make(),
|
||||
AssociateAction::make(),
|
||||
])
|
||||
->recordActions([
|
||||
EditAction::make(),
|
||||
DissociateAction::make(),
|
||||
DeleteAction::make(),
|
||||
])
|
||||
->toolbarActions([
|
||||
BulkActionGroup::make([
|
||||
DissociateBulkAction::make(),
|
||||
DeleteBulkAction::make(),
|
||||
]),
|
||||
]);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,55 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\Events\RelationManagers;
|
||||
|
||||
use Filament\Actions\CreateAction;
|
||||
use Filament\Actions\DeleteAction;
|
||||
use Filament\Actions\EditAction;
|
||||
use Filament\Forms\Components\TextInput;
|
||||
use Filament\Resources\RelationManagers\RelationManager;
|
||||
use Filament\Schemas\Schema;
|
||||
use Filament\Tables\Columns\TextColumn;
|
||||
use Filament\Tables\Table;
|
||||
|
||||
class UserNoteRelationManager extends RelationManager
|
||||
{
|
||||
protected static string $relationship = 'user_notes';
|
||||
|
||||
protected static ?string $title = 'Allgemeinflächen';
|
||||
|
||||
protected static ?string $navigationLabel = 'Allgemeinflächen';
|
||||
|
||||
protected static ?string $modelLabel = 'Allgemeinflächen';
|
||||
|
||||
protected static ?string $pluralModelLabel = 'Allgemeinflächen';
|
||||
|
||||
public function form(Schema $schema): Schema
|
||||
{
|
||||
return $schema
|
||||
->components([
|
||||
TextInput::make('event_id')
|
||||
->required()
|
||||
->maxLength(255),
|
||||
]);
|
||||
}
|
||||
|
||||
public function table(Table $table): Table
|
||||
{
|
||||
return $table
|
||||
->recordTitleAttribute('event_id')
|
||||
->columns([
|
||||
TextColumn::make('event_id')
|
||||
->searchable(),
|
||||
])
|
||||
->filters([
|
||||
//
|
||||
])
|
||||
->headerActions([
|
||||
CreateAction::make(),
|
||||
])
|
||||
->recordActions([
|
||||
EditAction::make(),
|
||||
DeleteAction::make(),
|
||||
]);
|
||||
}
|
||||
}
|
||||
@@ -2,7 +2,6 @@
|
||||
|
||||
namespace App\Filament\Resources\Events\Schemas;
|
||||
|
||||
use Filament\Forms\Components\DateTimePicker;
|
||||
use Filament\Forms\Components\TextInput;
|
||||
use Filament\Schemas\Schema;
|
||||
|
||||
@@ -12,22 +11,7 @@ class EventForm
|
||||
{
|
||||
return $schema
|
||||
->components([
|
||||
DateTimePicker::make('starttime'),
|
||||
TextInput::make('sport_id')
|
||||
->required()
|
||||
->numeric(),
|
||||
TextInput::make('country_id')
|
||||
->numeric()
|
||||
->default(0),
|
||||
TextInput::make('group_id')
|
||||
->numeric()
|
||||
->default(0),
|
||||
TextInput::make('home_id')
|
||||
->numeric()
|
||||
->default(0),
|
||||
TextInput::make('away_id')
|
||||
->numeric()
|
||||
->default(0),
|
||||
|
||||
TextInput::make('provider_id')
|
||||
->numeric()
|
||||
->default(0),
|
||||
|
||||
@@ -23,6 +23,8 @@ use Filament\Actions\ActionGroup;
|
||||
use Filament\Actions\BulkActionGroup;
|
||||
use Filament\Actions\DeleteAction;
|
||||
use Filament\Actions\DeleteBulkAction;
|
||||
use Filament\Actions\EditAction;
|
||||
use Filament\Actions\ViewAction;
|
||||
use Filament\Forms\Components\Hidden;
|
||||
use Filament\Forms\Components\Select;
|
||||
use Filament\Forms\Components\TextInput;
|
||||
@@ -35,7 +37,6 @@ use Filament\Tables\Enums\FiltersLayout;
|
||||
use Filament\Tables\Filters\Filter;
|
||||
use Filament\Tables\Filters\Indicator;
|
||||
use Filament\Tables\Table;
|
||||
use Illuminate\Contracts\View\View;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use Illuminate\Support\Carbon;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
@@ -59,8 +60,8 @@ class EventsTable
|
||||
LoadBettype::load();
|
||||
|
||||
return $table
|
||||
->poll('10s')
|
||||
->striped()
|
||||
->poll('5s')
|
||||
->deferLoading()
|
||||
->defaultPaginationPageOption(50)
|
||||
->paginated([5, 10, 15])
|
||||
@@ -167,7 +168,6 @@ class EventsTable
|
||||
->visible(fn () => \in_array('odds_dnb', self::$bettype_settings))
|
||||
->verticalAlignment(VerticalAlignment::Start)
|
||||
->label('Draw No Bet'),
|
||||
|
||||
])->searchable(['id', 'home.name', 'away.name', 'betsapi_id', 'betradar_id', 'bet365_id', 'bwin_id', 'event_bookmaker.event_id'])
|
||||
->defaultSort('starttime', 'ASC')
|
||||
->extremePaginationLinks()
|
||||
@@ -509,19 +509,9 @@ class EventsTable
|
||||
->persistFiltersInSession()
|
||||
->emptyStateHeading('No events')
|
||||
->emptyStateDescription('Modify the filter')
|
||||
->recordUrl(null) // disable row click for page
|
||||
->recordAction(null) // disable row click for modal
|
||||
->recordActions([
|
||||
Action::make('note')
|
||||
->before(fn () => $this->pollingInterval = null)
|
||||
->after(fn () => $this->pollingInterval = '1s')
|
||||
->iconButton()->icon('phosphor-note')->color('gray')
|
||||
->tooltip('Add a note')
|
||||
->modalSubmitAction(false)
|
||||
->modalCancelAction(fn (Action $action) => $action->label('Close'))
|
||||
->modalContent(fn ($record): View => view(
|
||||
'filament.tables.columns.make-note',
|
||||
['record' => $record],
|
||||
)),
|
||||
Action::make('notify')->iconButton()->icon('phosphor-bell')->color('gray')->tooltip('Add a notifications'),
|
||||
Action::make('star')
|
||||
->iconButton()
|
||||
->color(function ($record) {
|
||||
@@ -549,8 +539,9 @@ class EventsTable
|
||||
EventUserStar::insert(['event_id' => $record->id, 'user_id' => auth()->user()->id]);
|
||||
}
|
||||
}),
|
||||
EditAction::make()->iconButton()->color(fn ($record) => $record->user_notes->isEmpty() ? 'gray' : 'info')->icon('phosphor-note-pencil'),
|
||||
ViewAction::make()->iconButton()->color('gray')->icon('phosphor-note-pencil'),
|
||||
ActionGroup::make([
|
||||
// EditAction::make(),
|
||||
DeleteAction::make()->visible(fn () => auth()->user()->hasRole('super_admin')),
|
||||
Action::make('txodds_odds')
|
||||
->label('TxOdds')
|
||||
|
||||
@@ -18,7 +18,6 @@ class LoadBettype
|
||||
foreach ($res as $value) {
|
||||
$arr[] = $value->multiline_setting->table;
|
||||
}
|
||||
|
||||
EventsTable::$bettype_settings = $arr;
|
||||
}
|
||||
}
|
||||
@@ -51,6 +51,7 @@ class BettypeToggle extends Component
|
||||
{
|
||||
User::where('id', auth()->user()->id)->update(['stars' => DB::raw('!stars')]);
|
||||
|
||||
$this->dispatch('filterClearFilter');
|
||||
$this->dispatch('refreshBettypeMenu');
|
||||
}
|
||||
|
||||
|
||||
@@ -1,77 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Livewire;
|
||||
|
||||
use App\Models\UserNote;
|
||||
use Filament\Actions\Concerns\InteractsWithActions;
|
||||
use Filament\Actions\Contracts\HasActions;
|
||||
use Filament\Forms\Components\Textarea;
|
||||
use Filament\Schemas\Concerns\InteractsWithSchemas;
|
||||
use Filament\Schemas\Contracts\HasSchemas;
|
||||
use Filament\Schemas\Schema;
|
||||
use Filament\Tables\Columns\TextColumn;
|
||||
use Filament\Tables\Concerns\InteractsWithTable;
|
||||
use Filament\Tables\Contracts\HasTable;
|
||||
use Filament\Tables\Table;
|
||||
use Illuminate\Contracts\View\View;
|
||||
use Livewire\Component;
|
||||
|
||||
class EditUserNote extends Component implements HasActions, HasSchemas, HasTable
|
||||
{
|
||||
use InteractsWithActions;
|
||||
use InteractsWithSchemas;
|
||||
use InteractsWithTable;
|
||||
|
||||
public $record;
|
||||
|
||||
public ?array $data = [];
|
||||
|
||||
public function mount($record)
|
||||
{
|
||||
$this->record = $record;
|
||||
}
|
||||
|
||||
public function form(Schema $schema): Schema
|
||||
{
|
||||
return $schema
|
||||
->components([
|
||||
Textarea::make('message')->required()->rows(2)->label('Add a new note'),
|
||||
])
|
||||
->statePath('data');
|
||||
}
|
||||
|
||||
public function create(): void
|
||||
{
|
||||
dd($this->form->getState());
|
||||
}
|
||||
|
||||
public function table(Table $table): Table
|
||||
{
|
||||
return $table
|
||||
// ->headerActions([
|
||||
// Action::make()
|
||||
// ->label('New note')
|
||||
// ->icon('phosphor-plus')
|
||||
// ->action(function () {
|
||||
// UserNote::insert(['event_id' => $this->record->id, 'bookmaker_id' => auth()->user()->bookmaker_id, 'user_id' => auth()->user()->id]);
|
||||
// }),
|
||||
// ])
|
||||
->query(UserNote::query()->where('event_id', $this->record->id)->where('bookmaker_id', auth()->user()->bookmaker_id)->where('user_id', auth()->user()->id))
|
||||
->columns([
|
||||
TextColumn::make('message')->label('Notes'),
|
||||
])
|
||||
->filters([
|
||||
// ...
|
||||
])
|
||||
->recordActions([
|
||||
// ...
|
||||
])
|
||||
->toolbarActions([
|
||||
]);
|
||||
}
|
||||
|
||||
public function render(): View
|
||||
{
|
||||
return view('livewire.edit-user-note');
|
||||
}
|
||||
}
|
||||
+10
-5
@@ -28,10 +28,10 @@ class Event extends Model
|
||||
'away_id',
|
||||
];
|
||||
|
||||
// protected static function booted(): void
|
||||
// {
|
||||
// static::addGlobalScope(new SportScope);
|
||||
// }
|
||||
protected static function booted(): void
|
||||
{
|
||||
static::addGlobalScope(new SportScope);
|
||||
}
|
||||
|
||||
public function provider()
|
||||
{
|
||||
@@ -53,6 +53,11 @@ class Event extends Model
|
||||
return $this->belongsTo(Group::class);
|
||||
}
|
||||
|
||||
public function user_notes()
|
||||
{
|
||||
return $this->hasMany(UserNote::class, 'event_id', 'id');
|
||||
}
|
||||
|
||||
public function competition_group()
|
||||
{
|
||||
return $this->belongsTo(CompetitionGroup::class);
|
||||
@@ -140,7 +145,7 @@ class Event extends Model
|
||||
|
||||
public function event_user_star()
|
||||
{
|
||||
return $this->hasOne(EventUserStar::class, 'event_id', 'id')->where('user_id', auth()->user()->id);
|
||||
return $this->hasOne(EventUserStar::class, 'event_id', 'id');
|
||||
}
|
||||
|
||||
public function event_bookmaker()
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use App\Models\Scopes\UserScope;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class EventUserStar extends Model
|
||||
@@ -10,4 +11,9 @@ class EventUserStar extends Model
|
||||
'event_id',
|
||||
'user_id',
|
||||
];
|
||||
|
||||
protected static function booted(): void
|
||||
{
|
||||
static::addGlobalScope(new UserScope);
|
||||
}
|
||||
}
|
||||
@@ -2,23 +2,36 @@
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use App\Models\Scopes\ClientScope;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class UserNote extends Model
|
||||
{
|
||||
protected $fillable = [
|
||||
'user_messageid',
|
||||
'event_id',
|
||||
'bookmaker_id',
|
||||
'user_id',
|
||||
'client_id',
|
||||
'message',
|
||||
'deleted',
|
||||
];
|
||||
|
||||
protected static function booted(): void
|
||||
{
|
||||
static::addGlobalScope(new ClientScope);
|
||||
}
|
||||
|
||||
public function user()
|
||||
{
|
||||
return $this->belongsTo(User::class);
|
||||
}
|
||||
|
||||
public function client()
|
||||
{
|
||||
return $this->belongsTo(Client::class);
|
||||
}
|
||||
|
||||
public function bookmaker()
|
||||
{
|
||||
return $this->belongsTo(Bookmaker::class);
|
||||
|
||||
@@ -67,6 +67,7 @@ class AdminPanelProvider extends PanelProvider
|
||||
->viteTheme('resources/css/filament/admin/theme.css')
|
||||
->discoverResources(in: app_path('Filament/Resources'), for: 'App\Filament\Resources')
|
||||
->discoverPages(in: app_path('Filament/Pages'), for: 'App\Filament\Pages')
|
||||
->discoverWidgets(in: app_path('Filament/Widgets'), for: 'App\Filament\Widgets')
|
||||
->discoverClusters(in: app_path('Filament/Clusters'), for: 'App\\Filament\\Clusters')
|
||||
->pages([
|
||||
// Dashboard::class,
|
||||
|
||||
Reference in new issue
Block a user