Merge branch 'MDL-68758-master' of git://github.com/peterRd/moodle

This commit is contained in:
Sara Arjona 2020-05-27 09:46:47 +02:00
commit 3d0541c03a
5 changed files with 17 additions and 10 deletions

View File

@ -99,8 +99,6 @@ $string['displaytree'] = 'Display folder as file tree';
$string['download'] = 'Download';
$string['downloadallfiles'] = 'Download all files';
$string['downloadfolder'] = 'Download all';
$string['downloadselected'] = 'Download selected files';
$string['deleteselected'] = 'Delete selected';
$string['downloadsucc'] = 'The file has been downloaded successfully';
$string['draftareanofiles'] = 'Cannot be downloaded because there is no files attached';
$string['editrepositoryinstance'] = 'Edit repository instance';

View File

@ -45,12 +45,12 @@
</a>
</div>
<div class="fp-btn-download">
<a role="button" title="{{#str}}downloadselected, repository{{/str}}" class="btn btn-secondary btn-sm" href="#">
<a role="button" title="{{#str}}download, repository{{/str}}" class="btn btn-secondary btn-sm" href="#">
{{#pix}}a/download_all{{/pix}}
</a>
</div>
<div class="fp-btn-delete">
<a role="button" title="{{#str}}deleteselected, repository{{/str}}" class="btn btn-secondary btn-sm" href="#">
<a role="button" title="{{#str}}delete{{/str}}" class="btn btn-secondary btn-sm" href="#">
{{#pix}}i/trash{{/pix}}
</a>
</div>

View File

@ -175,6 +175,13 @@ switch ($action) {
case 'downloadselected':
$selected = required_param('selected', PARAM_RAW);
$selectedfiles = json_decode($selected);
if (!count($selectedfiles)) {
$filepath = required_param('filepath', PARAM_PATH);
$selectedfiles = [(object)[
'filename' => '',
'filepath' => $filepath
]];
}
$return = repository_download_selected_files($usercontext, 'user', 'draft', $draftid, $selectedfiles);
echo (json_encode($return));
die;

View File

@ -3267,7 +3267,7 @@ function repository_download_selected_files($context, string $component, string
$filestoarchive = [];
foreach ($files as $selectedfile) {
$filename = clean_filename($selectedfile->filename); // Default to '.' for root.
$filename = $selectedfile->filename ? clean_filename($selectedfile->filename) : '.'; // Default to '.' for root.
$filepath = clean_param($selectedfile->filepath, PARAM_PATH); // Default to '/' for downloadall.
$filepath = file_correct_filepath($filepath);
$area = file_get_draft_area_info($itemid, $filepath);
@ -3279,7 +3279,9 @@ function repository_download_selected_files($context, string $component, string
// If it is empty we are downloading a directory.
$archivefile = $storedfile->get_filename();
if (!$filename || $filename == '.' ) {
$archivefile = $filepath;
$foldername = explode('/', trim($filepath, '/'));
$folder = trim(array_pop($foldername), '/');
$archivefile = $folder ?? '/';
}
$filestoarchive[$archivefile] = $storedfile;

View File

@ -30,7 +30,7 @@ Feature: Delete files and folders from the file manager
And I follow "Manage private files"
And I click on "Display folder with file details" "link"
And I set the field "Select file 'empty.txt'" to "1"
When I click on "Delete selected" "link"
When I click on "Delete" "link"
Then I should see "Are you sure you want to delete the selected 1 file(s)?"
When I click on "OK" "button" in the "Confirm" "dialogue"
Then I should not see "empty.txt"
@ -40,7 +40,7 @@ Feature: Delete files and folders from the file manager
Then I should not see "empty.txt"
But I should see "Delete me later"
And I set the field "Select file 'Delete me later'" to "1"
And I click on "Delete selected" "link"
And I click on "Delete" "link"
And I click on "OK" "button" in the "Confirm" "dialogue"
Then I should not see "Delete me later"
When I press "Save changes"
@ -58,7 +58,7 @@ Feature: Delete files and folders from the file manager
And I click on "Display folder with file details" "link"
And I set the field "Select file 'empty.txt'" to "1"
And I set the field "Select file 'Delete me'" to "1"
When I click on "Delete selected" "link"
When I click on "Delete" "link"
Then I should see "Are you sure you want to delete the selected 2 file(s)?"
When I click on "OK" "button" in the "Confirm" "dialogue"
Then I should not see "Delete me"
@ -84,7 +84,7 @@ Feature: Delete files and folders from the file manager
| Select file 'empty.txt' | 1 |
| Select file 'Delete me' | 1 |
| Select file 'Delete me too' | 1 |
When I click on "Delete selected" "link"
When I click on "Delete" "link"
Then I should see "Are you sure you want to delete the selected 3 file(s)?"
When I click on "OK" "button" in the "Confirm" "dialogue"
Then I should not see "Delete me"