From 39b5a8484e64cf0ee47ba3d2b30c1f733dabbfeb Mon Sep 17 00:00:00 2001 From: Bozhidar Date: Mon, 13 May 2024 19:41:27 +0300 Subject: [PATCH] update --- .../Resources/HostingSubscriptionResource.php | 7 +- .../ManageHostingSubscriptionFileManager.php} | 79 +++++++++++++------ web/app/Models/FileItem.php | 1 + 3 files changed, 60 insertions(+), 27 deletions(-) rename web/app/{Livewire/FileManager.php => Filament/Resources/HostingSubscriptionResource/Pages/ManageHostingSubscriptionFileManager.php} (68%) diff --git a/web/app/Filament/Resources/HostingSubscriptionResource.php b/web/app/Filament/Resources/HostingSubscriptionResource.php index 7457fff..cdc7f45 100644 --- a/web/app/Filament/Resources/HostingSubscriptionResource.php +++ b/web/app/Filament/Resources/HostingSubscriptionResource.php @@ -3,6 +3,7 @@ namespace App\Filament\Resources; use App\Filament\Resources\HostingSubscriptionResource\Pages; +use app\Filament\Resources\HostingSubscriptionResource\Pages\ManageHostingSubscriptionFileManager; use app\Filament\Resources\HostingSubscriptionResource\Pages\ManageHostingSubscriptionFtpAccounts; use App\Models\Customer; use App\Models\Domain; @@ -190,7 +191,8 @@ class HostingSubscriptionResource extends Resource Pages\EditHostingSubscription::class, Pages\ManageHostingSubscriptionDatabases::class, Pages\ManageHostingSubscriptionBackups::class, - ManageHostingSubscriptionFtpAccounts::class + Pages\ManageHostingSubscriptionFtpAccounts::class, + Pages\ManageHostingSubscriptionFileManager::class ]); } @@ -208,10 +210,11 @@ class HostingSubscriptionResource extends Resource 'index' => Pages\ListHostingSubscriptions::route('/'), 'create' => Pages\CreateHostingSubscription::route('/create'), 'edit' => Pages\EditHostingSubscription::route('/{record}/edit'), - 'view' => Pages\ViewHostingSubscription::route('/{record}'), + // 'view' => Pages\ViewHostingSubscription::route('/{record}'), 'databases' => Pages\ManageHostingSubscriptionDatabases::route('/{record}/databases'), 'backups' => Pages\ManageHostingSubscriptionBackups::route('/{record}/backups'), 'ftp-accounts' => Pages\ManageHostingSubscriptionFtpAccounts::route('/{record}/ftp-accounts'), + 'file-manager' => Pages\ManageHostingSubscriptionFileManager::route('/{record}/file-manager'), ]; } diff --git a/web/app/Livewire/FileManager.php b/web/app/Filament/Resources/HostingSubscriptionResource/Pages/ManageHostingSubscriptionFileManager.php similarity index 68% rename from web/app/Livewire/FileManager.php rename to web/app/Filament/Resources/HostingSubscriptionResource/Pages/ManageHostingSubscriptionFileManager.php index 956dd53..31a14d0 100644 --- a/web/app/Livewire/FileManager.php +++ b/web/app/Filament/Resources/HostingSubscriptionResource/Pages/ManageHostingSubscriptionFileManager.php @@ -1,48 +1,75 @@ '$refresh']; + public function getTitle(): string|Htmlable + { + $recordTitle = $this->getRecordTitle(); + + $recordTitle = $recordTitle instanceof Htmlable ? $recordTitle->toHtml() : $recordTitle; + + return "File Manager {$recordTitle} "; + } + + public function getBreadcrumb(): string + { + return 'File Manager'; + } + + public static function getNavigationLabel(): string + { + return 'File Manager'; + } + public function table(Table $table): Table { - $hostingSubscription = HostingSubscription::where('id', 16)->first(); - $findDomain = Domain::where('hosting_subscription_id', $hostingSubscription->id)->where('is_main',1)->first(); + $hostingSubscription = HostingSubscription::select(['id'])->where('id', 16)->first(); + $findDomain = Domain::select(['home_root', 'hosting_subscription_id', 'is_main'])->where('hosting_subscription_id', $hostingSubscription->id)->where('is_main',1)->first(); $this->disk = $findDomain->home_root; $storage = Storage::build([ @@ -52,7 +79,8 @@ class FileManager extends Page implements HasTable ]); return $table - ->heading($this->path ?: 'Root') + ->deferLoading() + ->heading($this->disk .'/'. $this->path ?: 'Root') ->query( FileItem::queryForDiskAndPath($this->disk, $this->path) ) @@ -82,25 +110,25 @@ class FileManager extends Page implements 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(), - Action::make('download') - ->label('Download') - ->icon('heroicon-o-document-arrow-down') - ->hidden(fn (FileItem $record): bool => $record->isFolder()) - ->action(fn (FileItem $record) => $storage->download($record->path)), - DeleteAction::make('delete') - ->successNotificationTitle('File deleted') - ->hidden(fn (FileItem $record): bool => $record->isPreviousPath()) - ->action(function (FileItem $record, Action $action) { - if ($record->delete()) { - $action->sendSuccessNotification(); - } + ViewAction::make('open') + ->label('Open') + ->hidden(fn (FileItem $record): bool => ! $record->canOpen()) + ->url(fn (FileItem $record): string => $storage->url($record->path)) + ->openUrlInNewTab(), + Action::make('download') + ->label('Download') + ->icon('heroicon-o-document-arrow-down') + ->hidden(fn (FileItem $record): bool => $record->isFolder()) + ->action(fn (FileItem $record) => $storage->download($record->path)), + DeleteAction::make('delete') + ->successNotificationTitle('File deleted') + ->hidden(fn (FileItem $record): bool => $record->isPreviousPath()) + ->action(function (FileItem $record, Action $action) { + if ($record->delete()) { + $action->sendSuccessNotification(); + } - }), + }), ]), ]) ->bulkActions([ @@ -116,6 +144,7 @@ class FileManager extends Page implements HasTable }), ]) ->checkIfRecordIsSelectableUsing(fn (FileItem $record): bool => ! $record->isPreviousPath()) + ->headerActionsPosition(HeaderActionsPosition::Bottom) ->headerActions([ Action::make('create_folder') ->label('Create Folder') diff --git a/web/app/Models/FileItem.php b/web/app/Models/FileItem.php index 7e4dcd9..530f9f7 100644 --- a/web/app/Models/FileItem.php +++ b/web/app/Models/FileItem.php @@ -109,5 +109,6 @@ class FileItem extends Model ] ) )->toArray(); + } }