99 lines
3.4 KiB
PHP
99 lines
3.4 KiB
PHP
<?php
|
|
|
|
namespace App\Filament\Resources\Projektes\RelationManagers;
|
|
|
|
use Filament\Actions\AssociateAction;
|
|
use Filament\Actions\CreateAction;
|
|
use Filament\Actions\DeleteAction;
|
|
use Filament\Actions\EditAction;
|
|
use Filament\Forms\Components\FileUpload;
|
|
use Filament\Forms\Components\Select;
|
|
use Filament\Forms\Components\Textarea;
|
|
use Filament\Resources\RelationManagers\RelationManager;
|
|
use Filament\Schemas\Schema;
|
|
use Filament\Tables\Columns\TextColumn;
|
|
use Filament\Tables\Table;
|
|
use Illuminate\Support\Facades\Storage;
|
|
use Illuminate\Support\HtmlString;
|
|
|
|
class ProjekteImportsRelationManager extends RelationManager
|
|
{
|
|
protected static string $relationship = 'projekte_imports';
|
|
|
|
protected static ?string $title = 'Import Daten';
|
|
|
|
protected static ?string $navigationLabel = 'Import';
|
|
|
|
protected static ?string $modelLabel = 'Import';
|
|
|
|
protected static ?string $pluralModelLabel = 'Import';
|
|
|
|
public function form(Schema $schema): Schema
|
|
{
|
|
return $schema
|
|
->components([
|
|
Select::make('filetype')
|
|
->label('Dokument Type')
|
|
->required()
|
|
->options([
|
|
'allgemein' => 'Allgemeinflächen',
|
|
'nutzwerte' => 'Nutzwerte',
|
|
]),
|
|
FileUpload::make('file')
|
|
->required()
|
|
->disabledOn('edit')
|
|
->label('Datei (csv/txt) auswählen')
|
|
->directory('projekt-data-files')
|
|
->storeFileNamesIn('original_name')
|
|
->moveFiles()
|
|
->acceptedFileTypes(['text/csv', 'text/plain']),
|
|
Textarea::make('beschreibung')
|
|
->maxLength(255),
|
|
])->columns(1);
|
|
}
|
|
|
|
public function table(Table $table): Table
|
|
{
|
|
return $table
|
|
->recordTitleAttribute('name')
|
|
->columns([
|
|
TextColumn::make('filetype')
|
|
->badge()
|
|
->color(fn (string $state): string => match ($state) {
|
|
'allgemein' => 'success',
|
|
'nutzwerte' => 'info',
|
|
}),
|
|
TextColumn::make('original_name')
|
|
->label('name')
|
|
->wrap()
|
|
->description(function ($record) {
|
|
return new HtmlString($record->beschreibung);
|
|
}),
|
|
])
|
|
->filters([
|
|
//
|
|
])
|
|
->headerActions([
|
|
// CreateAction::make(),
|
|
// AssociateAction::make(),
|
|
CreateAction::make()
|
|
->createAnother(false)
|
|
->label('Hochladen')
|
|
->color('primary')
|
|
->icon('heroicon-o-document-arrow-up')
|
|
->before(function (array $data) {
|
|
|
|
$path = Storage::disk('private')->path($data['file']);
|
|
$contents = file_get_contents($path);
|
|
$arr = preg_split("/\r\n|\n|\r/", $contents);
|
|
dd($arr);
|
|
// Runs before the form fields are saved to the database.
|
|
}),
|
|
])
|
|
->recordActions([
|
|
EditAction::make()->iconButton()->color('gray'),
|
|
DeleteAction::make()->iconButton(),
|
|
]);
|
|
}
|
|
}
|