Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add an option to the multiple files selected actions to add and remov… #28133

Merged
merged 1 commit into from
Jul 23, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions apps/files/css/files.scss
Original file line number Diff line number Diff line change
Expand Up @@ -1215,3 +1215,25 @@ table.dragshadow td.size {
#gallery-button {
display: none;
}

#tag_multiple_files_container {
overflow: hidden;
background-color: #fff;
border-radius: 3px;
position: relative;
display: flex;
flex-wrap: wrap;
margin-bottom: 10px;

h3 {
width: 100%;
padding: 0 18px;
}

.systemTagsInputFieldContainer {
flex: 1 1 80%;
min-width: 0;
margin: 0 12px;
}
}

5 changes: 5 additions & 0 deletions apps/files/js/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,11 @@
iconClass: 'icon-delete',
order: 99,
},
{
name: 'tags',
displayName: 'Tags',
iconClass: 'icon-tag'
},
],
sorting: {
mode: $('#defaultFileSorting').val(),
Expand Down
121 changes: 121 additions & 0 deletions apps/files/js/filelist.js
Original file line number Diff line number Diff line change
Expand Up @@ -555,6 +555,9 @@
case 'restore':
this._onClickRestoreSelected(ev);
break;
case 'tags':
this._onClickTagSelected(ev);
break;
}
},
/**
Expand Down Expand Up @@ -1116,6 +1119,124 @@
event.preventDefault();
},

/**
* CUSTOM CODE
* Event handler for when clicking on "Tags" for the selected files
*/
_onClickTagSelected: function(event) {
var self = this;
event.preventDefault();
var commonTags = [];

var selectedFiles = _.pluck(this.getSelectedFiles(), 'id')
var tagCollections = [];
var fetchTagPromises = [];


selectedFiles.forEach(function(fileId) {
var deferred = new $.Deferred();
var tagCollection = new OC.SystemTags.SystemTagsMappingCollection([], {
objectType: 'files',
objectId: fileId});
tagCollections.push(tagCollection);
tagCollection.fetch({
success: function(){
deferred.resolve('success');
},
error: function() {
deferred.resolve('failed');
}
})
fetchTagPromises.push(deferred);
});

if (!self._inputView) {
self._inputView = new OC.SystemTags.SystemTagsInputField({
multiple: true,
allowActions: true,
allowCreate: true,
isAdmin: OC.isUserAdmin(),
});
self._inputView.on('select', self._onSelectTag, self);
self._inputView.on('deselect', self._onDeselectTag, self);
self._inputView.render();

// Build dom
self.tagsTitle = $('<h3>'+ t('files', 'Please select tag(s) to add to the selection') +'</h3>');
self.tagsSubmit = $('<button>' + t('files', 'Apply tag(s) to selection') + '</button>');
self.tagsContainer = $('<tr id="tag_multiple_files_container"></tr>');
self.tagsTitle.appendTo(self.tagsContainer)
self.tagsContainer.append(self._inputView.el);
self.tagsSubmit.appendTo(self.tagsContainer)

// Inject everything
self.$table.find('thead').append(self.tagsContainer);

self.tagsSubmit.on('click', function(ev){
self._onClickDocument(ev);
});
}

self._inputView.$el.addClass('icon-loading');
self.tagsContainer.show();

Promise.all(fetchTagPromises).then(function() {
//find tags which are common to all selected files
commonTags =_.intersection.apply(null, tagCollections.map(function (tagCollection) {return tagCollection.getTagIds();}));
self._inputView.setValues(commonTags);
PVince81 marked this conversation as resolved.
Show resolved Hide resolved
self._inputView.$el.removeClass('icon-loading');
$(document).on('click',function(ev){
self._onClickDocument(ev);
});
});
},

_onClickDocument: function(ev) {
if(!$(ev.target).closest('#editor_container').length) {
this._inputView.setValues([]);
this.tagsContainer.hide();
$(document).off('click', this._onClickDocument);
}

},

/**
* Custom code
* Set tag for all selected files
* @param tagModel
* @private
*/
_onSelectTag: function(tagModel) {
var selectedFiles = _.pluck(this.getSelectedFiles(),'id')
if (!_.isArray(selectedFiles)) {
return;
}
selectedFiles.forEach(function(fileId) {
$.ajax({
url: OC.linkToRemote('dav') + '/systemtags-relations/files/' + fileId + '/'+ tagModel.attributes.id,
type: 'PUT',
});
});

},
/**
* remove tag from all selected files
* @param tagId
* @private
*/
_onDeselectTag: function(tagId) {
var selectedFiles = _.pluck(this.getSelectedFiles(),'id');
if (!_.isArray(selectedFiles)) {
return;
}
selectedFiles.forEach(function(fileId) {
$.ajax({
url: OC.linkToRemote('dav') + '/systemtags-relations/files/' +fileId + '/'+ tagId,
PVince81 marked this conversation as resolved.
Show resolved Hide resolved
type: 'DELETE'
});
});
},

/**
* Event handler when clicking on a table header
*/
Expand Down