Skip to content

Commit def3a39

Browse files
committed
Bugfix: target module was still displayed even if it had no folders after filtering
1 parent 64cbbf6 commit def3a39

File tree

5 files changed

+29
-10
lines changed

5 files changed

+29
-10
lines changed

src/Controller/Files/FileUploadController.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ class FileUploadController extends AbstractController {
3636

3737
const DEFAULT_KEY_IS_MISSING = 'Required key is missing in request';
3838

39+
const KEY_MAIN_FOLDER = 'Main folder';
40+
3941
const UPLOAD_TYPES = [
4042
self::TYPE_IMAGES => self::TYPE_IMAGES,
4143
self::TYPE_FILES => self::TYPE_FILES
@@ -152,7 +154,7 @@ public static function getSubdirectoriesForUploadType(string $uploadType, $names
152154
}
153155

154156
if( $include_main_folder ){
155-
$subdirectories['Main folder'] = "";
157+
$subdirectories[static::KEY_MAIN_FOLDER] = "";
156158
}
157159

158160
return $subdirectories;

src/Controller/Utils/Dialogs.php

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -79,29 +79,44 @@ public function buildDataTransferDialogBody(Request $request) {
7979
]);
8080
}
8181

82-
#Info: this most likely won't be enough when there will be nested menu
8382
$subfolder = basename(dirname($file_current_path));
8483
$upload_type = FileUploadController::UPLOAD_BASED_MODULES[$module_name];
8584

8685
$all_subdirectories_for_all_types = FileUploadController::getSubdirectoriesForAllUploadTypes(true, true);
86+
$all_upload_based_modules = FileUploadController::UPLOAD_BASED_MODULES;
8787

8888
#Info: filter folder from which dialog was called
89-
foreach($all_subdirectories_for_all_types as $type => $subdirectories){
89+
foreach( $all_subdirectories_for_all_types as $type => $subdirectories ) {
9090

9191
if( $type === $upload_type ){
9292

93-
$key = array_search($subfolder, $subdirectories);
94-
unset($subdirectories[$key]);
93+
$subfolder_key = array_search($subfolder, $subdirectories);
94+
$is_main_folder = !$subfolder_key;
95+
96+
if( $is_main_folder ){
97+
$subfolder_key = FileUploadController::KEY_MAIN_FOLDER;
98+
}
99+
100+
unset($subdirectories[$subfolder_key]);
101+
102+
#Info: if we filter folder then we need to make sure that we don't display current module if there are no other folders than current
103+
if( empty($subdirectories) ){
104+
$module_key = array_search($upload_type, $all_upload_based_modules);
105+
unset($all_upload_based_modules[$module_key]);
106+
break;
107+
}
95108

96109
$all_subdirectories_for_all_types[$type] = $subdirectories;
97110
break;
98111
}
99112

100113
}
101114

102-
$form_data = [FilesHandler::KEY_TARGET_SUBDIRECTORY_NAME => $all_subdirectories_for_all_types];
103-
104-
$form = $this->app->forms->moveSingleFile($form_data);
115+
$form_data = [
116+
FilesHandler::KEY_TARGET_SUBDIRECTORY_NAME => $all_subdirectories_for_all_types,
117+
FilesHandler::KEY_MODULES_NAMES => $all_upload_based_modules
118+
];
119+
$form = $this->app->forms->moveSingleFile($form_data);
105120

106121
$template_data = [
107122
'form' => $form->createView()

src/Form/Files/MoveSingleFileType.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ class MoveSingleFileType extends AbstractType
1818
public function buildForm(FormBuilderInterface $builder, array $options) {
1919
$builder
2020
->add(FilesHandler::KEY_TARGET_UPLOAD_TYPE, ChoiceType::class, [
21-
'choices' => FileUploadController::UPLOAD_BASED_MODULES,
21+
'choices' => $options[FilesHandler::KEY_MODULES_NAMES],
2222
'attr' => [
2323
'class' => 'form-control listFilterer',
2424
'data-dependent-list-selector' => '#move_single_file_target_subdirectory_name'
@@ -40,5 +40,6 @@ public function configureOptions(OptionsResolver $resolver)
4040
// Configure your form options here
4141
]);
4242
$resolver->setRequired(FilesHandler::KEY_TARGET_SUBDIRECTORY_NAME);
43+
$resolver->setRequired(FilesHandler::KEY_MODULES_NAMES);
4344
}
4445
}

src/Services/FilesHandler.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ class FilesHandler {
2626
const KEY_FILE_NEW_NAME = 'file_new_name';
2727
const KEY_FILE_CURRENT_PATH = 'file_current_location';
2828
const KEY_FILE_NEW_PATH = 'file_new_location';
29+
const KEY_MODULES_NAMES = 'modules_names';
2930

3031
const FILE_KEY = 'file';
3132

src/scss/ui/buttons.scss

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ input:checked + .slider:before {
6464
}
6565

6666
/* Actions on tables */
67-
.fa-trash, .fa-edit, .fa-save, .fa-copy {
67+
.fa-trash, .fa-edit, .fa-save, .fa-copy, .fa-random {
6868
cursor: pointer;
6969
}
7070

0 commit comments

Comments
 (0)