import file wip
This commit is contained in:
1 parent
60b524012d
commit
de961122ab
8 files changed
+252
No files matched your search
+11
@@ -0,0 +1,11 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Clusters\StaticData\Resources\StatistikaImports\Pages;
|
||||
|
||||
use App\Filament\Clusters\StaticData\Resources\StatistikaImports\StatistikaImportResource;
|
||||
use Filament\Resources\Pages\CreateRecord;
|
||||
|
||||
class CreateStatistikaImport extends CreateRecord
|
||||
{
|
||||
protected static string $resource = StatistikaImportResource::class;
|
||||
}
|
||||
+19
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Clusters\StaticData\Resources\StatistikaImports\Pages;
|
||||
|
||||
use App\Filament\Clusters\StaticData\Resources\StatistikaImports\StatistikaImportResource;
|
||||
use Filament\Actions\DeleteAction;
|
||||
use Filament\Resources\Pages\EditRecord;
|
||||
|
||||
class EditStatistikaImport extends EditRecord
|
||||
{
|
||||
protected static string $resource = StatistikaImportResource::class;
|
||||
|
||||
protected function getHeaderActions(): array
|
||||
{
|
||||
return [
|
||||
DeleteAction::make(),
|
||||
];
|
||||
}
|
||||
}
|
||||
+21
@@ -0,0 +1,21 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Clusters\StaticData\Resources\StatistikaImports\Pages;
|
||||
|
||||
use App\Filament\Clusters\StaticData\Resources\StatistikaImports\StatistikaImportResource;
|
||||
use Filament\Actions\CreateAction;
|
||||
use Filament\Resources\Pages\ListRecords;
|
||||
|
||||
class ListStatistikaImports extends ListRecords
|
||||
{
|
||||
protected static string $resource = StatistikaImportResource::class;
|
||||
|
||||
protected function getHeaderActions(): array
|
||||
{
|
||||
return [
|
||||
CreateAction::make('upload_file')
|
||||
->label('Upload file')
|
||||
->icon('phosphor-upload'),
|
||||
];
|
||||
}
|
||||
}
|
||||
+35
@@ -0,0 +1,35 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Clusters\StaticData\Resources\StatistikaImports\Schemas;
|
||||
|
||||
use App\Models\Sport;
|
||||
use Filament\Forms\Components\FileUpload;
|
||||
use Filament\Forms\Components\Select;
|
||||
use Filament\Schemas\Schema;
|
||||
|
||||
class StatistikaImportForm
|
||||
{
|
||||
public static function configure(Schema $schema): Schema
|
||||
{
|
||||
return $schema
|
||||
->components([
|
||||
Select::make('sport_id')
|
||||
->required()
|
||||
->label('Sport')
|
||||
->options(Sport::where('is_active', 1)->pluck('name', 'id')),
|
||||
Select::make('data_type')
|
||||
->required()
|
||||
->options([
|
||||
'player' => 'Player',
|
||||
'events' => 'Events',
|
||||
'events_player' => 'Events & Player',
|
||||
]),
|
||||
|
||||
FileUpload::make('file_name')
|
||||
->directory('statistika')
|
||||
->visibility('public')
|
||||
->required()
|
||||
->storeFileNamesIn('file_name_original'),
|
||||
])->columns(1);
|
||||
}
|
||||
}
|
||||
+51
@@ -0,0 +1,51 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Clusters\StaticData\Resources\StatistikaImports;
|
||||
|
||||
use App\Filament\Clusters\StaticData\Resources\StatistikaImports\Pages\ListStatistikaImports;
|
||||
use App\Filament\Clusters\StaticData\Resources\StatistikaImports\Schemas\StatistikaImportForm;
|
||||
use App\Filament\Clusters\StaticData\Resources\StatistikaImports\Tables\StatistikaImportsTable;
|
||||
use App\Filament\Clusters\StaticData\StaticDataCluster;
|
||||
use App\Models\StatistikaImport;
|
||||
use BackedEnum;
|
||||
use Filament\Resources\Resource;
|
||||
use Filament\Schemas\Schema;
|
||||
use Filament\Tables\Table;
|
||||
use UnitEnum;
|
||||
|
||||
class StatistikaImportResource extends Resource
|
||||
{
|
||||
protected static ?string $model = StatistikaImport::class;
|
||||
|
||||
protected static string|BackedEnum|null $navigationIcon = 'phosphor-upload';
|
||||
|
||||
protected static ?string $navigationLabel = 'File Uploads';
|
||||
|
||||
protected static ?string $modelLabel = 'File Uploads';
|
||||
|
||||
protected static string|UnitEnum|null $navigationGroup = 'Statistiko';
|
||||
|
||||
protected static ?string $cluster = StaticDataCluster::class;
|
||||
|
||||
public static function form(Schema $schema): Schema
|
||||
{
|
||||
return StatistikaImportForm::configure($schema);
|
||||
}
|
||||
|
||||
public static function table(Table $table): Table
|
||||
{
|
||||
return StatistikaImportsTable::configure($table);
|
||||
}
|
||||
|
||||
public static function getNavigationBadge(): ?string
|
||||
{
|
||||
return parent::getEloquentQuery()->count();
|
||||
}
|
||||
|
||||
public static function getPages(): array
|
||||
{
|
||||
return [
|
||||
'index' => ListStatistikaImports::route('/'),
|
||||
];
|
||||
}
|
||||
}
|
||||
+58
@@ -0,0 +1,58 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Clusters\StaticData\Resources\StatistikaImports\Tables;
|
||||
|
||||
use Filament\Actions\BulkActionGroup;
|
||||
use Filament\Actions\DeleteAction;
|
||||
use Filament\Actions\DeleteBulkAction;
|
||||
use Filament\Tables\Columns\IconColumn;
|
||||
use Filament\Tables\Columns\SelectColumn;
|
||||
use Filament\Tables\Columns\TextColumn;
|
||||
use Filament\Tables\Columns\ToggleColumn;
|
||||
use Filament\Tables\Table;
|
||||
|
||||
class StatistikaImportsTable
|
||||
{
|
||||
public static function configure(Table $table): Table
|
||||
{
|
||||
return $table
|
||||
->columns([
|
||||
IconColumn::make('sport.icon')
|
||||
->label('Sport')
|
||||
->icon(fn ($record) => $record->sport->icon)
|
||||
->tooltip(fn ($record) => $record->id)
|
||||
->visibleFrom('lg'),
|
||||
SelectColumn::make('data_type')
|
||||
->native(false)
|
||||
->width('2rem')
|
||||
->allowOptionsHtml()
|
||||
->options([
|
||||
'player' => '<span class="text-blue-500">Player</span>',
|
||||
'events' => '<span class="text-green-500">Events</span>',
|
||||
'events_player' => '<span class="text-amber-500">Events & Player</span>',
|
||||
]),
|
||||
// TextColumn::make('data_type'),
|
||||
TextColumn::make('file_name_original')->searchable()->color('primary')->label('Name'),
|
||||
ToggleColumn::make('run_import')
|
||||
->tooltip('Import will run in the background, on compleation a message will be send.')
|
||||
->onColor(fn ($state) => $state ? 'success' : 'gray')
|
||||
->beforeStateUpdated(function ($record, $state) {
|
||||
if ($state) {
|
||||
$record->is_running = 1;
|
||||
}
|
||||
}),
|
||||
IconColumn::make('is_running')->boolean()->falseColor('gray'),
|
||||
IconColumn::make('has_run')->boolean()->falseColor('gray'),
|
||||
TextColumn::make('created_at')->dateTime(),
|
||||
|
||||
])
|
||||
->recordActions([
|
||||
DeleteAction::make()->iconButton(),
|
||||
])
|
||||
->toolbarActions([
|
||||
BulkActionGroup::make([
|
||||
DeleteBulkAction::make(),
|
||||
]),
|
||||
]);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class StatistikaImport extends Model
|
||||
{
|
||||
protected $fillable = [
|
||||
'id',
|
||||
'sport_id',
|
||||
'data_type',
|
||||
'file_name',
|
||||
'file_name_original',
|
||||
'file_path',
|
||||
'run_import',
|
||||
];
|
||||
|
||||
public function sport()
|
||||
{
|
||||
return $this->belongsTo(Sport::class)->where('is_active', 1);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*/
|
||||
public function up(): void
|
||||
{
|
||||
Schema::create('statistika_imports', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->integer('sport_id');
|
||||
$table->string('data_type');
|
||||
$table->string('file_name');
|
||||
$table->string('file_name_original');
|
||||
$table->boolean('run_import')->default(0);
|
||||
$table->boolean('is_running')->default(0);
|
||||
$table->boolean('has_run')->default(0);
|
||||
$table->timestamps();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
Schema::dropIfExists('statistika_imports');
|
||||
}
|
||||
};
|
||||
Reference in new issue
Block a user