Player mongodb
This commit is contained in:
1 parent
b362fdc15f
commit
8370836efd
11 files changed
+409
-2
No files matched your search
@@ -16,6 +16,8 @@ class PlayerResource extends Resource
|
||||
{
|
||||
protected static ?string $model = Player::class;
|
||||
|
||||
protected static bool $shouldRegisterNavigation = false;
|
||||
|
||||
protected static string|BackedEnum|null $navigationIcon = 'icon-soccerplayer';
|
||||
|
||||
protected static ?string $cluster = StaticDataCluster::class;
|
||||
|
||||
@@ -28,7 +28,7 @@ class ListUbEvents extends ListRecords
|
||||
Action::make('copy')
|
||||
->tooltip('Copy header line')
|
||||
->color('success')
|
||||
->label('Copy csv header')
|
||||
->label('Copy')
|
||||
->action(function ($livewire) {
|
||||
$livewire->js('window.navigator.clipboard.writeText("league_id;home_id;away_id;starttime;player_id;home_away;home_ft;away_ft;home_ht;away_ht;Goals;assists;tackles;total_passes;passes_done;total_duels;duels_won;total_ground_duels;ground_duels_won;total_aerial_duels;aerial_duels_won;minutes_played;shots_on_target;shots_off_target;shots_blocked;total_dribble;dribble_done;position;rating;bcm;hw;pw;pm;possession_lost;fouls;was_fouled;offsides;date_acquisition");');
|
||||
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Clusters\StaticData\Resources\UbPlayers\Pages;
|
||||
|
||||
use App\Filament\Clusters\StaticData\Resources\UbPlayers\UbPlayerResource;
|
||||
use Filament\Resources\Pages\CreateRecord;
|
||||
|
||||
class CreateUbPlayer extends CreateRecord
|
||||
{
|
||||
protected static string $resource = UbPlayerResource::class;
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Clusters\StaticData\Resources\UbPlayers\Pages;
|
||||
|
||||
use App\Filament\Clusters\StaticData\Resources\UbPlayers\UbPlayerResource;
|
||||
use Filament\Actions\DeleteAction;
|
||||
use Filament\Resources\Pages\EditRecord;
|
||||
|
||||
class EditUbPlayer extends EditRecord
|
||||
{
|
||||
protected static string $resource = UbPlayerResource::class;
|
||||
|
||||
protected function getHeaderActions(): array
|
||||
{
|
||||
return [
|
||||
DeleteAction::make(),
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,55 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Clusters\StaticData\Resources\UbPlayers\Pages;
|
||||
|
||||
use App\Filament\Clusters\StaticData\Resources\UbPlayers\UbPlayerResource;
|
||||
use App\Filament\Imports\UbPlayerImporter;
|
||||
use App\Models\UbPlayer;
|
||||
use Filament\Actions\Action;
|
||||
use Filament\Actions\CreateAction;
|
||||
use Filament\Actions\ImportAction;
|
||||
use Filament\Notifications\Notification;
|
||||
use Filament\Resources\Pages\ListRecords;
|
||||
|
||||
class ListUbPlayers extends ListRecords
|
||||
{
|
||||
protected static string $resource = UbPlayerResource::class;
|
||||
|
||||
protected function getHeaderActions(): array
|
||||
{
|
||||
return [
|
||||
Action::make('truncate')
|
||||
->icon('phosphor-trash')
|
||||
->requiresConfirmation()
|
||||
->color('danger')
|
||||
->action(function () {
|
||||
UbPlayer::truncate();
|
||||
}),
|
||||
CreateAction::make()
|
||||
->label('New')
|
||||
->icon('phosphor-plus'),
|
||||
ImportAction::make('importPlayer')
|
||||
->maxRows(200000)
|
||||
->chunkSize(250)
|
||||
->icon('phosphor-upload')
|
||||
->label('Import')
|
||||
->modalDescription('Separator comma ","; Field content "content"')
|
||||
->importer(UbPlayerImporter::class)
|
||||
->extraModalFooterActions([
|
||||
Action::make('copy')
|
||||
->tooltip('Copy header line')
|
||||
->color('success')
|
||||
->label('Copy')
|
||||
->action(function ($livewire) {
|
||||
$livewire->js('window.navigator.clipboard.writeText(\'"id giocatore", "giocatore", "data di nascita", "altezza", "nazionalita", "posizione", "sport radar id", "id squadra tm", "nome completo", "giocatore senza caratteri speciali", "rigorista", "national team id", "data aggiornamento", "league_code", "team_code", "team_name"\');');
|
||||
|
||||
Notification::make()
|
||||
->title('Header copied successfully')
|
||||
->success()
|
||||
->send();
|
||||
}),
|
||||
]),
|
||||
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Clusters\StaticData\Resources\UbPlayers\Schemas;
|
||||
|
||||
use Filament\Forms\Components\DatePicker;
|
||||
use Filament\Forms\Components\TextInput;
|
||||
use Filament\Schemas\Components\Grid;
|
||||
use Filament\Schemas\Schema;
|
||||
|
||||
class UbPlayerForm
|
||||
{
|
||||
public static function configure(Schema $schema): Schema
|
||||
{
|
||||
return $schema
|
||||
->components([
|
||||
Grid::make([
|
||||
'default' => 2,
|
||||
'xl' => 4,
|
||||
])
|
||||
->schema([
|
||||
TextInput::make('id_giocatore')->required(),
|
||||
TextInput::make('giocatore')->required(),
|
||||
TextInput::make('nome_completo'),
|
||||
DatePicker::make('data_di_nascita'),
|
||||
TextInput::make('altezza'),
|
||||
TextInput::make('nazionalita'),
|
||||
TextInput::make('posizione'),
|
||||
TextInput::make('sport_radar_id'),
|
||||
TextInput::make('id_squadra_tm'),
|
||||
TextInput::make('rigorista'),
|
||||
TextInput::make('national_team_id'),
|
||||
DatePicker::make('data_aggiornamento'),
|
||||
TextInput::make('league_code'),
|
||||
TextInput::make('team_code'),
|
||||
TextInput::make('team_name'),
|
||||
]),
|
||||
|
||||
])->columns(1);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Clusters\StaticData\Resources\UbPlayers\Tables;
|
||||
|
||||
use Filament\Actions\DeleteAction;
|
||||
use Filament\Actions\EditAction;
|
||||
use Filament\Tables\Columns\Layout\Stack;
|
||||
use Filament\Tables\Columns\TextColumn;
|
||||
use Filament\Tables\Table;
|
||||
|
||||
class UbPlayersTable
|
||||
{
|
||||
public static function configure(Table $table): Table
|
||||
{
|
||||
return $table
|
||||
->poll('10sec')
|
||||
->defaultPaginationPageOption(8)
|
||||
->paginationPageOptions([8, 16, 24, 36])
|
||||
->columns([
|
||||
Stack::make([
|
||||
TextColumn::make('id_giocatore')->prefix('Id: ')->searchable()->color('success')->icon('phosphor-copy')->copyable(),
|
||||
TextColumn::make('giocatore')->searchable()->prefix('Nome: ')->color('primary')->icon('phosphor-copy')->copyable(),
|
||||
TextColumn::make('nome_completo')->color('gray')->searchable(),
|
||||
TextColumn::make('data_di_nascita')->date()->prefix('Nascita: '),
|
||||
TextColumn::make('altezza')->prefix('Altezza: ')->suffix(' cm'),
|
||||
TextColumn::make('nazionalita')->prefix('Nazionalita: '),
|
||||
TextColumn::make('posizione')->prefix('Posizione: '),
|
||||
TextColumn::make('sport_radar_id')->searchable()->prefix('Sport Radar Id: ')->icon('phosphor-copy')->copyable(),
|
||||
TextColumn::make('id_squadra_tm')->prefix('Id Squadra TM: '),
|
||||
TextColumn::make('rigorista')->prefix('Rigorista: '),
|
||||
TextColumn::make('national_team_id')->prefix('National Team Id: '),
|
||||
TextColumn::make('data_aggiornamento')->date()->prefix('Aggiornamento: '),
|
||||
TextColumn::make('created_at')->date()->prefix('Created: '),
|
||||
TextColumn::make('updated_at')->date()->prefix('Updated: '),
|
||||
// TextColumn::make('league_code')->prefix('League: '),
|
||||
// TextColumn::make('team_code')->prefix('Team Code: '),
|
||||
// TextColumn::make('team_name')->prefix('Team Name: '),
|
||||
]),
|
||||
])
|
||||
->contentGrid([
|
||||
'md' => 2,
|
||||
'xl' => 4,
|
||||
])
|
||||
->recordActions([
|
||||
EditAction::make()->hiddenLabel(),
|
||||
DeleteAction::make()->hiddenLabel(),
|
||||
]);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Clusters\StaticData\Resources\UbPlayers;
|
||||
|
||||
use App\Filament\Clusters\StaticData\Resources\UbPlayers\Pages\ListUbPlayers;
|
||||
use App\Filament\Clusters\StaticData\Resources\UbPlayers\Schemas\UbPlayerForm;
|
||||
use App\Filament\Clusters\StaticData\Resources\UbPlayers\Tables\UbPlayersTable;
|
||||
use App\Filament\Clusters\StaticData\StaticDataCluster;
|
||||
use App\Models\UbPlayer;
|
||||
use BackedEnum;
|
||||
use Filament\Resources\Resource;
|
||||
use Filament\Schemas\Schema;
|
||||
use Filament\Tables\Table;
|
||||
|
||||
class UbPlayerResource extends Resource
|
||||
{
|
||||
protected static ?string $model = UbPlayer::class;
|
||||
|
||||
protected static string|BackedEnum|null $navigationIcon = 'icon-soccerplayer';
|
||||
|
||||
protected static ?string $navigationLabel = 'Player';
|
||||
|
||||
protected static ?string $cluster = StaticDataCluster::class;
|
||||
|
||||
protected static ?string $recordTitleAttribute = 'giocatore';
|
||||
|
||||
public static function form(Schema $schema): Schema
|
||||
{
|
||||
return UbPlayerForm::configure($schema);
|
||||
}
|
||||
|
||||
public static function table(Table $table): Table
|
||||
{
|
||||
return UbPlayersTable::configure($table);
|
||||
}
|
||||
|
||||
public static function getPages(): array
|
||||
{
|
||||
return [
|
||||
'index' => ListUbPlayers::route('/'),
|
||||
];
|
||||
}
|
||||
|
||||
public static function getNavigationBadge(): ?string
|
||||
{
|
||||
return parent::getEloquentQuery()->count();
|
||||
}
|
||||
}
|
||||
@@ -90,7 +90,7 @@ class UbEventImporter extends Importer
|
||||
|
||||
public static function getCompletedNotificationBody(Import $import): string
|
||||
{
|
||||
$body = 'Your ub event import has completed and '.Number::format($import->successful_rows).' '.str('row')->plural($import->successful_rows).' imported.';
|
||||
$body = 'Your events import has completed and '.Number::format($import->successful_rows).' '.str('row')->plural($import->successful_rows).' imported.';
|
||||
|
||||
if ($failedRowsCount = $import->getFailedRowsCount()) {
|
||||
$body .= ' '.Number::format($failedRowsCount).' '.str('row')->plural($failedRowsCount).' failed to import.';
|
||||
|
||||
@@ -0,0 +1,130 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Imports;
|
||||
|
||||
use App\Models\UbPlayer;
|
||||
use Filament\Actions\Imports\ImportColumn;
|
||||
use Filament\Actions\Imports\Importer;
|
||||
use Filament\Actions\Imports\Models\Import;
|
||||
use Illuminate\Support\Carbon;
|
||||
use Illuminate\Support\Number;
|
||||
|
||||
class UbPlayerImporter extends Importer
|
||||
{
|
||||
protected static ?string $model = UbPlayer::class;
|
||||
|
||||
public static function useDatabaseTransactions(): bool
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
public function resolveRecord(): UbPlayer
|
||||
{
|
||||
$res = UbPlayer::query()
|
||||
->where('id_giocatore', $this->data['id_giocatore'])
|
||||
->first();
|
||||
if ($res) {
|
||||
return UbPlayer::find($res->id);
|
||||
} else {
|
||||
return new UbPlayer;
|
||||
}
|
||||
}
|
||||
|
||||
public static function getColumns(): array
|
||||
{
|
||||
return [
|
||||
ImportColumn::make('id_giocatore')
|
||||
->label('ID GIOCATORE'),
|
||||
ImportColumn::make('giocatore')
|
||||
->label('GIOCATORE')
|
||||
->castStateUsing(function (string $state): ?string {
|
||||
if (blank($state)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return (string) trim($state);
|
||||
}),
|
||||
ImportColumn::make('data_di_nascita')
|
||||
->label('DATA DI NASCITA')
|
||||
->castStateUsing(function ($state) {
|
||||
if (blank($state)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return Carbon::parse($state);
|
||||
}),
|
||||
ImportColumn::make('altezza')
|
||||
->label('ALTEZZA')
|
||||
->numeric(),
|
||||
ImportColumn::make('nazionalita')
|
||||
->label('NAZIONALITA')
|
||||
->castStateUsing(function (string $state): ?string {
|
||||
return (string) trim($state);
|
||||
}),
|
||||
ImportColumn::make('posizione')
|
||||
->label('POSIZIONE')
|
||||
->castStateUsing(function (string $state): ?string {
|
||||
if (blank($state)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return (string) trim($state);
|
||||
}),
|
||||
ImportColumn::make('sport_radar_id')
|
||||
->label('SPORT RADAR ID'),
|
||||
ImportColumn::make('id_squadra_tm')
|
||||
->label('ID SQUADRA TM'),
|
||||
ImportColumn::make('nome_completo')
|
||||
->label('NOME COMPLETO')
|
||||
->castStateUsing(function (?string $state): ?string {
|
||||
if (blank($state)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return (string) trim($state);
|
||||
}),
|
||||
ImportColumn::make('rigorista')
|
||||
->label('RIGORISTA')
|
||||
->castStateUsing(function (?string $state): ?string {
|
||||
if (blank($state)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return (string) trim($state);
|
||||
}),
|
||||
ImportColumn::make('national_team_id')
|
||||
->label('NATIONAL TEAM ID'),
|
||||
ImportColumn::make('data_aggiornamento')
|
||||
->label('DATA AGGIORNAMENTO')
|
||||
->castStateUsing(function ($state) {
|
||||
return Carbon::parse($state);
|
||||
}),
|
||||
ImportColumn::make('league_code')
|
||||
->label('LEAGUE CODE')
|
||||
->castStateUsing(function (string $state): ?string {
|
||||
return (string) trim($state);
|
||||
}),
|
||||
ImportColumn::make('team_code')
|
||||
->label('TEAM CODE')
|
||||
->castStateUsing(function (string $state): ?string {
|
||||
return (string) trim($state);
|
||||
}),
|
||||
ImportColumn::make('team_name')
|
||||
->label('TEAM NAME')
|
||||
->castStateUsing(function (string $state): ?string {
|
||||
return (string) trim($state);
|
||||
}),
|
||||
];
|
||||
}
|
||||
|
||||
public static function getCompletedNotificationBody(Import $import): string
|
||||
{
|
||||
$body = 'Your player import has completed and '.Number::format($import->successful_rows).' '.str('row')->plural($import->successful_rows).' imported.';
|
||||
|
||||
if ($failedRowsCount = $import->getFailedRowsCount()) {
|
||||
$body .= ' '.Number::format($failedRowsCount).' '.str('row')->plural($failedRowsCount).' failed to import.';
|
||||
}
|
||||
|
||||
return $body;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use MongoDB\Laravel\Eloquent\Model;
|
||||
|
||||
class UbPlayer extends Model
|
||||
{
|
||||
protected $connection = 'mongodb';
|
||||
|
||||
protected $table = 'player';
|
||||
|
||||
protected $fillable = [
|
||||
'id_giocatore',
|
||||
'giocatore',
|
||||
'data_di_nascita',
|
||||
'altezza',
|
||||
'nazionalita',
|
||||
'posizione',
|
||||
'sport_radar_id',
|
||||
'id_squadra_tm',
|
||||
'nome_completo',
|
||||
'rigorista',
|
||||
'national_team_id',
|
||||
'data_aggiornamento',
|
||||
'league_code',
|
||||
'team_code',
|
||||
'team_name',
|
||||
];
|
||||
|
||||
protected function casts(): array
|
||||
{
|
||||
return [
|
||||
'id_giocatore' => 'string',
|
||||
'national_team_id' => 'string',
|
||||
'altezza' => 'integer',
|
||||
'sport_radar_id' => 'string',
|
||||
'id_squadra_tm' => 'string',
|
||||
'data_di_nascita' => 'date',
|
||||
'giocatore' => 'string',
|
||||
'nazionalita' => 'string',
|
||||
'posizione' => 'string',
|
||||
'nome_completo' => 'string',
|
||||
'rigorista' => 'string',
|
||||
'data_aggiornamento' => 'string',
|
||||
'league_code' => 'string',
|
||||
'team_code' => 'string',
|
||||
'team_name' => 'string',
|
||||
];
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user