Add bulk move (#1117)

This commit is contained in:
Boy132 2025-03-18 17:36:13 +01:00 committed by GitHub
parent 3d29243cf0
commit 4a7951995e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -332,21 +332,19 @@ class ListFiles extends ListRecords
BulkActionGroup::make([ BulkActionGroup::make([
BulkAction::make('move') BulkAction::make('move')
->authorize(fn () => auth()->user()->can(Permission::ACTION_FILE_UPDATE, $server)) ->authorize(fn () => auth()->user()->can(Permission::ACTION_FILE_UPDATE, $server))
->hidden() // TODO
->form([ ->form([
TextInput::make('location') TextInput::make('location')
->label('File name') ->label('Directory')
->hint('Enter the new name and directory of this file or folder, relative to the current directory.') ->hint('Enter the new directory, relative to the current directory.')
->default(fn (File $file) => $file->name)
->required() ->required()
->live(), ->live(),
Placeholder::make('new_location') Placeholder::make('new_location')
->content(fn (Get $get) => resolve_path('./' . join_paths($this->path, $get('location') ?? ''))), ->content(fn (Get $get) => resolve_path('./' . join_paths($this->path, $get('location') ?? ''))),
]) ])
->action(function (Collection $files, $data) { ->action(function (Collection $files, $data) {
$location = resolve_path(join_paths($this->path, $data['location'])); $location = rtrim($data['location'], '/');
$files = $files->map(fn ($file) => ['to' => $location, 'from' => $file['name']])->toArray(); $files = $files->map(fn ($file) => ['to' => join_paths($location, $file['name']), 'from' => $file['name']])->toArray();
$this->getDaemonFileRepository() $this->getDaemonFileRepository()
->renameFiles($this->path, $files); ->renameFiles($this->path, $files);
@ -356,7 +354,7 @@ class ListFiles extends ListRecords
->log(); ->log();
Notification::make() Notification::make()
->title(count($files) . ' Files were moved from ' . $location) ->title(count($files) . ' Files were moved to ' . resolve_path(join_paths($this->path, $location)))
->success() ->success()
->send(); ->send();
}), }),