mirror of
https://github.com/pelican-dev/panel.git
synced 2025-10-30 04:06:52 +01:00
Refresh page after file updates (#1759)
Co-authored-by: RMartinOscar <40749467+RMartinOscar@users.noreply.github.com>
This commit is contained in:
parent
2fc30e14fd
commit
8aa0fc7fc2
@ -97,8 +97,7 @@ class EditFiles extends Page
|
|||||||
->body(fn () => $this->path)
|
->body(fn () => $this->path)
|
||||||
->send();
|
->send();
|
||||||
|
|
||||||
$url = ListFiles::getUrl(['path' => dirname($this->path)]);
|
$this->redirectToList();
|
||||||
$this->redirect($url, FilamentView::hasSpaMode($url));
|
|
||||||
}),
|
}),
|
||||||
Action::make('save')
|
Action::make('save')
|
||||||
->label(trans('server/file.actions.edit.save'))
|
->label(trans('server/file.actions.edit.save'))
|
||||||
@ -178,39 +177,34 @@ class EditFiles extends Page
|
|||||||
->danger()
|
->danger()
|
||||||
->closable()
|
->closable()
|
||||||
->send();
|
->send();
|
||||||
|
|
||||||
$url = ListFiles::getUrl(['path' => dirname($this->path)]);
|
|
||||||
$this->redirect($url, FilamentView::hasSpaMode($url));
|
|
||||||
} catch (FileNotFoundException) {
|
} catch (FileNotFoundException) {
|
||||||
AlertBanner::make('file_not_found')
|
AlertBanner::make('file_not_found')
|
||||||
->title(trans('server/file.alerts.file_not_found.title', ['name' => basename($this->path)]))
|
->title(trans('server/file.alerts.file_not_found.title', ['name' => basename($this->path)]))
|
||||||
->danger()
|
->danger()
|
||||||
->closable()
|
->closable()
|
||||||
->send();
|
->send();
|
||||||
|
|
||||||
$url = ListFiles::getUrl(['path' => dirname($this->path)]);
|
|
||||||
$this->redirect($url, FilamentView::hasSpaMode($url));
|
|
||||||
} catch (FileNotEditableException) {
|
} catch (FileNotEditableException) {
|
||||||
AlertBanner::make('file_is_directory')
|
AlertBanner::make('file_is_directory')
|
||||||
->title(trans('server/file.alerts.file_not_found.title', ['name' => basename($this->path)]))
|
->title(trans('server/file.alerts.file_not_found.title', ['name' => basename($this->path)]))
|
||||||
->danger()
|
->danger()
|
||||||
->closable()
|
->closable()
|
||||||
->send();
|
->send();
|
||||||
|
|
||||||
$url = ListFiles::getUrl(['path' => dirname($this->path)]);
|
|
||||||
$this->redirect($url, FilamentView::hasSpaMode($url));
|
|
||||||
} catch (ConnectionException) {
|
} catch (ConnectionException) {
|
||||||
// Alert banner for this one will be handled by ListFiles
|
// Alert banner for this one will be handled by ListFiles
|
||||||
|
|
||||||
$url = ListFiles::getUrl(['path' => dirname($this->path)]);
|
|
||||||
$this->redirect($url, FilamentView::hasSpaMode($url));
|
|
||||||
}
|
}
|
||||||
|
$this->redirectToList();
|
||||||
}),
|
}),
|
||||||
])
|
])
|
||||||
->columnSpanFull(),
|
->columnSpanFull(),
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private function redirectToList(): void
|
||||||
|
{
|
||||||
|
$url = ListFiles::getUrl(['path' => dirname($this->path)]);
|
||||||
|
$this->redirect($url, FilamentView::hasSpaMode($url));
|
||||||
|
}
|
||||||
|
|
||||||
public function mount(string $path): void
|
public function mount(string $path): void
|
||||||
{
|
{
|
||||||
$this->authorizeAccess();
|
$this->authorizeAccess();
|
||||||
|
|||||||
@ -36,6 +36,7 @@ use Filament\Schemas\Components\Tabs;
|
|||||||
use Filament\Schemas\Components\Tabs\Tab;
|
use Filament\Schemas\Components\Tabs\Tab;
|
||||||
use Filament\Schemas\Components\Utilities\Get;
|
use Filament\Schemas\Components\Utilities\Get;
|
||||||
use Filament\Support\Enums\IconSize;
|
use Filament\Support\Enums\IconSize;
|
||||||
|
use Filament\Support\Facades\FilamentView;
|
||||||
use Filament\Tables\Columns\TextColumn;
|
use Filament\Tables\Columns\TextColumn;
|
||||||
use Filament\Tables\Enums\PaginationMode;
|
use Filament\Tables\Enums\PaginationMode;
|
||||||
use Filament\Tables\Table;
|
use Filament\Tables\Table;
|
||||||
@ -58,6 +59,11 @@ class ListFiles extends ListRecords
|
|||||||
|
|
||||||
private DaemonFileRepository $fileRepository;
|
private DaemonFileRepository $fileRepository;
|
||||||
|
|
||||||
|
public function getTitle(): string
|
||||||
|
{
|
||||||
|
return trans('server/file.title');
|
||||||
|
}
|
||||||
|
|
||||||
public function getBreadcrumbs(): array
|
public function getBreadcrumbs(): array
|
||||||
{
|
{
|
||||||
$resource = static::getResource();
|
$resource = static::getResource();
|
||||||
@ -83,15 +89,13 @@ class ListFiles extends ListRecords
|
|||||||
/** @var Server $server */
|
/** @var Server $server */
|
||||||
$server = Filament::getTenant();
|
$server = Filament::getTenant();
|
||||||
|
|
||||||
$files = File::get($server, $this->path);
|
|
||||||
|
|
||||||
return $table
|
return $table
|
||||||
->paginated([25, 50, 100, 150, 200])
|
->paginated([25, 50, 100, 150, 200])
|
||||||
->paginationMode(PaginationMode::Simple)
|
->paginationMode(PaginationMode::Simple)
|
||||||
->defaultPaginationPageOption(50)
|
->defaultPaginationPageOption(50)
|
||||||
->deferLoading()
|
->deferLoading()
|
||||||
->searchable()
|
->searchable()
|
||||||
->query(fn () => $files->orderByDesc('is_directory'))
|
->query(fn () => File::get($server, $this->path)->orderByDesc('is_directory'))
|
||||||
->defaultSort('name')
|
->defaultSort('name')
|
||||||
->columns([
|
->columns([
|
||||||
TextColumn::make('name')
|
TextColumn::make('name')
|
||||||
@ -161,6 +165,8 @@ class ListFiles extends ListRecords
|
|||||||
->body(fn () => $file->name . ' -> ' . $data['name'])
|
->body(fn () => $file->name . ' -> ' . $data['name'])
|
||||||
->success()
|
->success()
|
||||||
->send();
|
->send();
|
||||||
|
|
||||||
|
$this->refreshPage();
|
||||||
}),
|
}),
|
||||||
Action::make('copy')
|
Action::make('copy')
|
||||||
->authorize(fn () => auth()->user()->can(Permission::ACTION_FILE_CREATE, $server))
|
->authorize(fn () => auth()->user()->can(Permission::ACTION_FILE_CREATE, $server))
|
||||||
@ -179,7 +185,7 @@ class ListFiles extends ListRecords
|
|||||||
->success()
|
->success()
|
||||||
->send();
|
->send();
|
||||||
|
|
||||||
return redirect(ListFiles::getUrl(['path' => $this->path]));
|
$this->refreshPage();
|
||||||
}),
|
}),
|
||||||
Action::make('download')
|
Action::make('download')
|
||||||
->authorize(fn () => auth()->user()->can(Permission::ACTION_FILE_READ_CONTENT, $server))
|
->authorize(fn () => auth()->user()->can(Permission::ACTION_FILE_READ_CONTENT, $server))
|
||||||
@ -221,6 +227,8 @@ class ListFiles extends ListRecords
|
|||||||
->body($oldLocation . ' -> ' . $newLocation)
|
->body($oldLocation . ' -> ' . $newLocation)
|
||||||
->success()
|
->success()
|
||||||
->send();
|
->send();
|
||||||
|
|
||||||
|
$this->refreshPage();
|
||||||
}),
|
}),
|
||||||
Action::make('permissions')
|
Action::make('permissions')
|
||||||
->authorize(fn () => auth()->user()->can(Permission::ACTION_FILE_UPDATE, $server))
|
->authorize(fn () => auth()->user()->can(Permission::ACTION_FILE_UPDATE, $server))
|
||||||
@ -309,7 +317,7 @@ class ListFiles extends ListRecords
|
|||||||
->success()
|
->success()
|
||||||
->send();
|
->send();
|
||||||
|
|
||||||
return redirect(ListFiles::getUrl(['path' => $this->path]));
|
$this->refreshPage();
|
||||||
}),
|
}),
|
||||||
Action::make('unarchive')
|
Action::make('unarchive')
|
||||||
->authorize(fn () => auth()->user()->can(Permission::ACTION_FILE_ARCHIVE, $server))
|
->authorize(fn () => auth()->user()->can(Permission::ACTION_FILE_ARCHIVE, $server))
|
||||||
@ -329,7 +337,7 @@ class ListFiles extends ListRecords
|
|||||||
->success()
|
->success()
|
||||||
->send();
|
->send();
|
||||||
|
|
||||||
return redirect(ListFiles::getUrl(['path' => $this->path]));
|
$this->refreshPage();
|
||||||
}),
|
}),
|
||||||
])->iconSize(IconSize::Large),
|
])->iconSize(IconSize::Large),
|
||||||
DeleteAction::make()
|
DeleteAction::make()
|
||||||
@ -346,6 +354,8 @@ class ListFiles extends ListRecords
|
|||||||
->property('directory', $this->path)
|
->property('directory', $this->path)
|
||||||
->property('files', $file->name)
|
->property('files', $file->name)
|
||||||
->log();
|
->log();
|
||||||
|
|
||||||
|
$this->refreshPage();
|
||||||
}),
|
}),
|
||||||
])
|
])
|
||||||
->toolbarActions([
|
->toolbarActions([
|
||||||
@ -376,6 +386,8 @@ class ListFiles extends ListRecords
|
|||||||
->title(trans('server/file.actions.move.bulk_notification', ['count' => count($files), 'directory' => resolve_path(join_paths($this->path, $location))]))
|
->title(trans('server/file.actions.move.bulk_notification', ['count' => count($files), 'directory' => resolve_path(join_paths($this->path, $location))]))
|
||||||
->success()
|
->success()
|
||||||
->send();
|
->send();
|
||||||
|
|
||||||
|
$this->refreshPage();
|
||||||
}),
|
}),
|
||||||
BulkAction::make('archive')
|
BulkAction::make('archive')
|
||||||
->authorize(fn () => auth()->user()->can(Permission::ACTION_FILE_ARCHIVE, $server))
|
->authorize(fn () => auth()->user()->can(Permission::ACTION_FILE_ARCHIVE, $server))
|
||||||
@ -402,7 +414,7 @@ class ListFiles extends ListRecords
|
|||||||
->success()
|
->success()
|
||||||
->send();
|
->send();
|
||||||
|
|
||||||
return redirect(ListFiles::getUrl(['path' => $this->path]));
|
$this->refreshPage();
|
||||||
}),
|
}),
|
||||||
DeleteBulkAction::make()
|
DeleteBulkAction::make()
|
||||||
->authorize(fn () => auth()->user()->can(Permission::ACTION_FILE_DELETE, $server))
|
->authorize(fn () => auth()->user()->can(Permission::ACTION_FILE_DELETE, $server))
|
||||||
@ -419,6 +431,8 @@ class ListFiles extends ListRecords
|
|||||||
->title(trans('server/file.actions.delete.bulk_notification', ['count' => count($files)]))
|
->title(trans('server/file.actions.delete.bulk_notification', ['count' => count($files)]))
|
||||||
->success()
|
->success()
|
||||||
->send();
|
->send();
|
||||||
|
|
||||||
|
$this->refreshPage();
|
||||||
}),
|
}),
|
||||||
]),
|
]),
|
||||||
|
|
||||||
@ -436,6 +450,8 @@ class ListFiles extends ListRecords
|
|||||||
Activity::event('server:file.write')
|
Activity::event('server:file.write')
|
||||||
->property('file', $path)
|
->property('file', $path)
|
||||||
->log();
|
->log();
|
||||||
|
|
||||||
|
$this->refreshPage();
|
||||||
} catch (FileExistsException) {
|
} catch (FileExistsException) {
|
||||||
AlertBanner::make('file_already_exists')
|
AlertBanner::make('file_already_exists')
|
||||||
->title(trans('server/file.alerts.file_already_exists.title', ['name' => $path]))
|
->title(trans('server/file.alerts.file_already_exists.title', ['name' => $path]))
|
||||||
@ -443,7 +459,7 @@ class ListFiles extends ListRecords
|
|||||||
->closable()
|
->closable()
|
||||||
->send();
|
->send();
|
||||||
|
|
||||||
$this->redirect(self::getUrl(['path' => dirname($path)]));
|
$this->refreshPage(true);
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
->schema([
|
->schema([
|
||||||
@ -465,15 +481,18 @@ class ListFiles extends ListRecords
|
|||||||
Activity::event('server:file.create-directory')
|
Activity::event('server:file.create-directory')
|
||||||
->property(['directory' => $this->path, 'name' => $data['name']])
|
->property(['directory' => $this->path, 'name' => $data['name']])
|
||||||
->log();
|
->log();
|
||||||
|
|
||||||
|
$this->refreshPage();
|
||||||
} catch (FileExistsException) {
|
} catch (FileExistsException) {
|
||||||
$path = join_paths($this->path, $data['name']);
|
$path = join_paths($this->path, $data['name']);
|
||||||
|
|
||||||
AlertBanner::make('folder_already_exists')
|
AlertBanner::make('folder_already_exists')
|
||||||
->title(trans('server/file.alerts.file_already_exists.title', ['name' => $path]))
|
->title(trans('server/file.alerts.file_already_exists.title', ['name' => $path]))
|
||||||
->danger()
|
->danger()
|
||||||
->closable()
|
->closable()
|
||||||
->send();
|
->send();
|
||||||
|
|
||||||
$this->redirect(self::getUrl(['path' => dirname($path)]));
|
$this->refreshPage(true);
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
->schema([
|
->schema([
|
||||||
@ -506,7 +525,7 @@ class ListFiles extends ListRecords
|
|||||||
->log();
|
->log();
|
||||||
}
|
}
|
||||||
|
|
||||||
return redirect(ListFiles::getUrl(['path' => $this->path]));
|
$this->refreshPage();
|
||||||
})
|
})
|
||||||
->schema([
|
->schema([
|
||||||
Tabs::make()
|
Tabs::make()
|
||||||
@ -557,6 +576,12 @@ class ListFiles extends ListRecords
|
|||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private function refreshPage(bool $oneBack = false): void
|
||||||
|
{
|
||||||
|
$url = self::getUrl(['path' => $oneBack ? dirname($this->path) : $this->path]);
|
||||||
|
$this->redirect($url, FilamentView::hasSpaMode($url));
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return string[]
|
* @return string[]
|
||||||
*/
|
*/
|
||||||
@ -593,9 +618,4 @@ class ListFiles extends ListRecords
|
|||||||
->where('path', '.*'),
|
->where('path', '.*'),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getTitle(): string
|
|
||||||
{
|
|
||||||
return trans('server/file.title');
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user