From 720859064c4ab0256f47b09a8439a6055f63f659 Mon Sep 17 00:00:00 2001 From: Bozhidar Date: Fri, 13 Sep 2024 13:26:03 +0300 Subject: [PATCH] update --- .../App/Filament/Pages/FileManager.php | 18 +++++++++++++----- web/app/Models/FileItem.php | 19 +++++++++++++++++++ 2 files changed, 32 insertions(+), 5 deletions(-) diff --git a/web/Modules/Customer/App/Filament/Pages/FileManager.php b/web/Modules/Customer/App/Filament/Pages/FileManager.php index 216101e..4ee933b 100644 --- a/web/Modules/Customer/App/Filament/Pages/FileManager.php +++ b/web/Modules/Customer/App/Filament/Pages/FileManager.php @@ -11,11 +11,14 @@ use Filament\Forms\Components\TextInput; use Filament\Forms\Concerns\InteractsWithForms; use Filament\Forms\Contracts\HasForms; use Filament\Pages\Page; +use Filament\Support\Enums\MaxWidth; use Filament\Tables\Actions\Action; use Filament\Tables\Actions\ActionGroup; use Filament\Tables\Actions\BulkAction; use Filament\Tables\Actions\DeleteAction; +use Filament\Tables\Actions\EditAction; use Filament\Tables\Actions\HeaderActionsPosition; +use Filament\Tables\Actions\ViewAction; use Filament\Tables\Columns\TextColumn; use Filament\Tables\Concerns\InteractsWithTable; use Filament\Tables\Contracts\HasTable; @@ -94,11 +97,16 @@ class FileManager extends Page implements HasForms, HasTable ->actions([ ActionGroup::make([ -// ViewAction::make('open') -// ->label('Open') -// ->hidden(fn (FileItem $record): bool => ! $record->canOpen()) -// ->url(fn (FileItem $record): string => $storage->url($record->path)) -// ->openUrlInNewTab(), + EditAction::make('edit') + ->label('Edit') + ->hidden(fn (FileItem $record): bool => ! $record->canOpen()) + ->form([ + Textarea::make('content') + ->label('Content') + ->rows(30) + , + ]), + Action::make('download') ->label('Download') ->icon('heroicon-o-document-arrow-down') diff --git a/web/app/Models/FileItem.php b/web/app/Models/FileItem.php index b7f64fd..dce706b 100644 --- a/web/app/Models/FileItem.php +++ b/web/app/Models/FileItem.php @@ -22,8 +22,24 @@ class FileItem extends Model 'dateModified' => 'datetime', 'size' => 'integer', 'type' => 'string', + 'content' => 'string', ]; + protected $fillable = [ + 'content', + ]; + + public static function boot() + { + parent::boot(); + + static::updating(function ($model) { + if (!empty($model->content)) { + $model->storageInstance()->put($model->path, $model->content); + } + }); + } + public static function queryForDiskAndPath(string $rootPath = 'public', string $path = ''): Builder { static::$rootPath = $rootPath; @@ -76,6 +92,7 @@ class FileItem extends Model $backPath = [ [ + 'content' => null, 'name' => '..', 'dateModified' => null, 'size' => null, @@ -96,6 +113,7 @@ class FileItem extends Model 'size' => null, 'type' => 'Folder', 'path' => $directory, + 'content' => null, ]), ...collect($storage->files(static::$path)) ->sort() @@ -105,6 +123,7 @@ class FileItem extends Model 'size' => $storage->size($file), 'type' => $storage->mimeType($file) ?: 'File', 'path' => $file, + 'content' => $storage->exists($file) ? $storage->get($file) : null, ]) )->toArray();