Merge pull request #8203 from Cybso/split-move-copy

Split move and copy operations
This commit is contained in:
Morris Jobke 2018-02-26 16:06:20 +01:00 committed by GitHub
commit a3c09f51c6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 54 additions and 11 deletions

View File

@ -625,12 +625,23 @@
this.registerAction({ this.registerAction({
name: 'MoveCopy', name: 'MoveCopy',
displayName: t('files', 'Move or copy'), displayName: function(context) {
var permissions = context.fileInfoModel.attributes.permissions;
if (permissions & OC.PERMISSION_UPDATE) {
return t('files', 'Move or copy');
}
return t('files', 'Copy');
},
mime: 'all', mime: 'all',
order: -25, order: -25,
permissions: OC.PERMISSION_UPDATE, permissions: $('#isPublic').val() ? OC.PERMISSION_UPDATE : OC.PERMISSION_READ,
iconClass: 'icon-external', iconClass: 'icon-external',
actionHandler: function (filename, context) { actionHandler: function (filename, context) {
var permissions = context.fileInfoModel.attributes.permissions;
var actions = OC.dialogs.FILEPICKER_TYPE_COPY;
if (permissions & OC.PERMISSION_UPDATE) {
actions = OC.dialogs.FILEPICKER_TYPE_COPY_MOVE;
}
OC.dialogs.filepicker(t('files', 'Target folder'), function(targetPath, type) { OC.dialogs.filepicker(t('files', 'Target folder'), function(targetPath, type) {
if (type === OC.dialogs.FILEPICKER_TYPE_COPY) { if (type === OC.dialogs.FILEPICKER_TYPE_COPY) {
context.fileList.copy(filename, targetPath); context.fileList.copy(filename, targetPath);
@ -638,7 +649,7 @@
if (type === OC.dialogs.FILEPICKER_TYPE_MOVE) { if (type === OC.dialogs.FILEPICKER_TYPE_MOVE) {
context.fileList.move(filename, targetPath); context.fileList.move(filename, targetPath);
} }
}, false, "httpd/unix-directory", true, OC.dialogs.FILEPICKER_TYPE_COPY_MOVE); }, false, "httpd/unix-directory", true, actions);
} }
}); });

View File

@ -798,6 +798,7 @@
OCA.Files.FileActions.updateFileActionSpinner(moveFileAction, false); OCA.Files.FileActions.updateFileActionSpinner(moveFileAction, false);
}; };
var actions = this.isSelectedMovable() ? OC.dialogs.FILEPICKER_TYPE_COPY_MOVE : OC.dialogs.FILEPICKER_TYPE_COPY;
OC.dialogs.filepicker(t('files', 'Target folder'), function(targetPath, type) { OC.dialogs.filepicker(t('files', 'Target folder'), function(targetPath, type) {
if (type === OC.dialogs.FILEPICKER_TYPE_COPY) { if (type === OC.dialogs.FILEPICKER_TYPE_COPY) {
self.copy(files, targetPath, disableLoadingState); self.copy(files, targetPath, disableLoadingState);
@ -805,7 +806,7 @@
if (type === OC.dialogs.FILEPICKER_TYPE_MOVE) { if (type === OC.dialogs.FILEPICKER_TYPE_MOVE) {
self.move(files, targetPath, disableLoadingState); self.move(files, targetPath, disableLoadingState);
} }
}, false, "httpd/unix-directory", true, OC.dialogs.FILEPICKER_TYPE_COPY_MOVE); }, false, "httpd/unix-directory", true, actions);
return false; return false;
}, },
@ -2871,18 +2872,39 @@
this.$el.find('#headerName a.name>span:first').text(selection); this.$el.find('#headerName a.name>span:first').text(selection);
this.$el.find('#modified a>span:first').text(''); this.$el.find('#modified a>span:first').text('');
this.$el.find('table').addClass('multiselect'); this.$el.find('table').addClass('multiselect');
this.$el.find('.selectedActions .copy-move').toggleClass('hidden', !this.isSelectedCopiableOrMovable());
this.$el.find('.selectedActions .download').toggleClass('hidden', !this.isSelectedDownloadable()); this.$el.find('.selectedActions .download').toggleClass('hidden', !this.isSelectedDownloadable());
this.$el.find('.delete-selected').toggleClass('hidden', !this.isSelectedDeletable()); this.$el.find('.delete-selected').toggleClass('hidden', !this.isSelectedDeletable());
var $copyMove = this.$el.find('.selectedActions .copy-move');
if (this.isSelectedCopiable()) {
$copyMove.toggleClass('hidden', false);
if (this.isSelectedMovable()) {
$copyMove.find('.label').text(t('files', 'Move or copy'));
} else {
$copyMove.find('.label').text(t('files', 'Copy'));
}
} else {
$copyMove.toggleClass('hidden', true);
}
} }
}, },
/** /**
* Check whether all selected files are copiable or movable * Check whether all selected files are copiable
*/ */
isSelectedCopiableOrMovable: function() { isSelectedCopiable: function() {
return _.reduce(this.getSelectedFiles(), function(copiableOrMovable, file) { return _.reduce(this.getSelectedFiles(), function(copiable, file) {
return copiableOrMovable && (file.permissions & OC.PERMISSION_UPDATE); var requiredPermission = $('#isPublic').val() ? OC.PERMISSION_UPDATE : OC.PERMISSION_READ;
return copiable && (file.permissions & requiredPermission);
}, true);
},
/**
* Check whether all selected files are movable
*/
isSelectedMovable: function() {
return _.reduce(this.getSelectedFiles(), function(movable, file) {
return movable && (file.permissions & OC.PERMISSION_UPDATE);
}, true); }, true);
}, },

View File

@ -53,7 +53,7 @@
<span id="selectedActionsList" class="selectedActions"> <span id="selectedActionsList" class="selectedActions">
<a href="" class="copy-move"> <a href="" class="copy-move">
<span class="icon icon-external"></span> <span class="icon icon-external"></span>
<span><?php p($l->t('Move or copy'))?></span> <span class="label"><?php p($l->t('Move or copy'))?></span>
</a> </a>
<a href="" class="download"> <a href="" class="download">
<span class="icon icon-download"></span> <span class="icon icon-download"></span>

View File

@ -271,6 +271,7 @@ describe('OCA.Files.FileActionsMenu tests', function() {
$file: $tr, $file: $tr,
fileList: fileList, fileList: fileList,
fileActions: fileActions, fileActions: fileActions,
fileInfoModel: new OCA.Files.FileInfoModel(fileData),
dir: fileList.getCurrentDirectory() dir: fileList.getCurrentDirectory()
}; };
menu = new OCA.Files.FileActionsMenu(); menu = new OCA.Files.FileActionsMenu();
@ -304,6 +305,7 @@ describe('OCA.Files.FileActionsMenu tests', function() {
$file: $tr, $file: $tr,
fileList: fileList, fileList: fileList,
fileActions: fileActions, fileActions: fileActions,
fileInfoModel: new OCA.Files.FileInfoModel(fileData),
dir: '/anotherpath/there' dir: '/anotherpath/there'
}; };
menu = new OCA.Files.FileActionsMenu(); menu = new OCA.Files.FileActionsMenu();
@ -336,6 +338,7 @@ describe('OCA.Files.FileActionsMenu tests', function() {
$file: $tr, $file: $tr,
fileList: fileList, fileList: fileList,
fileActions: fileActions, fileActions: fileActions,
fileInfoModel: new OCA.Files.FileInfoModel(fileData),
dir: '/somepath/dir' dir: '/somepath/dir'
}; };
menu = new OCA.Files.FileActionsMenu(); menu = new OCA.Files.FileActionsMenu();

View File

@ -94,7 +94,7 @@ describe('OCA.Files.FileList tests', function() {
'<input type="checkbox" id="select_all_files" class="select-all checkbox">' + '<input type="checkbox" id="select_all_files" class="select-all checkbox">' +
'<a class="name columntitle" data-sort="name"><span>Name</span><span class="sort-indicator"></span></a>' + '<a class="name columntitle" data-sort="name"><span>Name</span><span class="sort-indicator"></span></a>' +
'<span id="selectedActionsList" class="selectedActions hidden">' + '<span id="selectedActionsList" class="selectedActions hidden">' +
'<a href class="copy-move">Move or copy</a>' + '<a href class="copy-move"><span class="label">Move or copy</span></a>' +
'<a href class="download"><img src="actions/download.svg">Download</a>' + '<a href class="download"><img src="actions/download.svg">Download</a>' +
'<a href class="delete-selected">Delete</a></span>' + '<a href class="delete-selected">Delete</a></span>' +
'</th>' + '</th>' +
@ -2101,10 +2101,17 @@ describe('OCA.Files.FileList tests', function() {
$('#permissions').val(OC.PERMISSION_READ | OC.PERMISSION_UPDATE); $('#permissions').val(OC.PERMISSION_READ | OC.PERMISSION_UPDATE);
$('.select-all').click(); $('.select-all').click();
expect(fileList.$el.find('.selectedActions .copy-move').hasClass('hidden')).toEqual(false); expect(fileList.$el.find('.selectedActions .copy-move').hasClass('hidden')).toEqual(false);
expect(fileList.$el.find('.selectedActions .copy-move .label').text()).toEqual('Move or copy');
testFiles[0].permissions = OC.PERMISSION_READ; testFiles[0].permissions = OC.PERMISSION_READ;
$('.select-all').click(); $('.select-all').click();
fileList.setFiles(testFiles); fileList.setFiles(testFiles);
$('.select-all').click(); $('.select-all').click();
expect(fileList.$el.find('.selectedActions .copy-move').hasClass('hidden')).toEqual(false);
expect(fileList.$el.find('.selectedActions .copy-move .label').text()).toEqual('Copy');
testFiles[0].permissions = OC.PERMISSION_NONE;
$('.select-all').click();
fileList.setFiles(testFiles);
$('.select-all').click();
expect(fileList.$el.find('.selectedActions .copy-move').hasClass('hidden')).toEqual(true); expect(fileList.$el.find('.selectedActions .copy-move').hasClass('hidden')).toEqual(true);
}); });
it('show doesnt show the download action if one or more files are not downloadable', function () { it('show doesnt show the download action if one or more files are not downloadable', function () {