Skip to content

Commit f9b0d24

Browse files
Roland Scheidelrolandinus
authored andcommitted
add an option to the multiple files selected actions to add and remove tags from multiple files at once
Signed-off-by: Roland Scheidel <kontakt@scheidel.at>
1 parent 8ccf207 commit f9b0d24

3 files changed

Lines changed: 126 additions & 0 deletions

File tree

apps/files/css/files.scss

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1131,3 +1131,15 @@ table.dragshadow td.size {
11311131
#gallery-button {
11321132
display: none;
11331133
}
1134+
1135+
#tag_multiple_files_container {
1136+
overflow: hidden;
1137+
background-color: #fff;
1138+
border-radius: 3px;
1139+
position: relative;
1140+
1141+
td {
1142+
padding: 0 0.5em 0 0.5em;
1143+
}
1144+
}
1145+

apps/files/js/app.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,11 @@
102102
displayName: t('files', 'Delete'),
103103
iconClass: 'icon-delete',
104104
},
105+
{ name: 'tags',
106+
displayName: 'Tags',
107+
iconClass: 'icon-tag'
108+
109+
}
105110
],
106111
sorting: {
107112
mode: $('#defaultFileSorting').val(),

apps/files/js/filelist.js

Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -515,6 +515,9 @@
515515
case 'restore':
516516
this._onClickRestoreSelected(ev);
517517
break;
518+
case 'tags':
519+
this._onClickTagSelected(ev);
520+
break;
518521
}
519522
},
520523
/**
@@ -1070,6 +1073,112 @@
10701073
event.preventDefault();
10711074
},
10721075

1076+
/**
1077+
* CUSTOM CODE
1078+
* Event handler for when clicking on "Tags" for the selected files
1079+
*/
1080+
_onClickTagSelected: function(event) {
1081+
var self = this;
1082+
event.preventDefault();
1083+
var commonTags = [];
1084+
1085+
var selectedFiles = _.pluck(this.getSelectedFiles(),'id')
1086+
var tagCollections=[];
1087+
var fetchTagPromises = [];
1088+
1089+
1090+
selectedFiles.forEach(function(fileId) {
1091+
var deferred = new $.Deferred();
1092+
var tagCollection = new OC.SystemTags.SystemTagsMappingCollection([], {
1093+
objectType: 'files',
1094+
objectId: fileId});
1095+
tagCollections.push(tagCollection);
1096+
tagCollection.fetch({
1097+
success: function(){
1098+
deferred.resolve('success');
1099+
},
1100+
error: function() {deferred.resolve('failed');}
1101+
})
1102+
fetchTagPromises.push(deferred);
1103+
});
1104+
if (!self._inputView) {
1105+
self._inputView = new OC.SystemTags.SystemTagsInputField({
1106+
multiple: true,
1107+
allowActions: true,
1108+
allowCreate: true,
1109+
isAdmin: OC.isUserAdmin(),
1110+
});
1111+
self._inputView.on('select', self._onSelectTag, self);
1112+
self._inputView.on('deselect', self._onDeselectTag, self);
1113+
self._inputView.render();
1114+
self.tagsContainer = $('<tr id="tag_multiple_files_container"><th colspan="4"></th></tr>');
1115+
// console.log('inputView',self._inputView, self._inputView.$el,'tag container', self.tagsContainer);
1116+
self.tagsContainer.children()[0].append(self._inputView.$el.context);
1117+
$('#app-content-files>#filestable>thead').append(self.tagsContainer);
1118+
1119+
}
1120+
self._inputView.$el.addClass('icon-loading');
1121+
self.tagsContainer.show();
1122+
Promise.all(fetchTagPromises).then(function() {
1123+
//find tags which are common to all selected files
1124+
commonTags =_.intersection.apply(null, tagCollections.map(function (tagCollection) {return tagCollection.getTagIds();}));
1125+
self._inputView.setValues(commonTags);
1126+
self._inputView.$el.removeClass('icon-loading');
1127+
$(document).on('click',function(ev){
1128+
self._onClickDocument(ev);
1129+
});
1130+
});
1131+
},
1132+
1133+
_onClickDocument: function(ev) {
1134+
if(!$(ev.target).closest('#editor_container').length) {
1135+
this._inputView.setValues([]);
1136+
this.tagsContainer.hide();
1137+
$(document).unbind('click', this._onClickDocument);
1138+
}
1139+
1140+
},
1141+
1142+
/**
1143+
* Custom code
1144+
* Set tag for all selected files
1145+
* @param tagModel
1146+
* @private
1147+
*/
1148+
_onSelectTag: function(tagModel) {
1149+
console.log('selected',tagModel.attributes);
1150+
var selectedFiles = _.pluck(this.getSelectedFiles(),'id')
1151+
if (!_.isArray(selectedFiles)) {
1152+
console.log('selected files - no array!', selectedFiles);
1153+
}
1154+
selectedFiles.forEach(function(fileId) {
1155+
$.ajax({
1156+
url: OC.linkToRemote('dav') + '/systemtags-relations/files/' +fileId + '/'+ tagModel.attributes.id,
1157+
type: 'PUT',
1158+
});
1159+
});
1160+
1161+
},
1162+
/**
1163+
* remove tag from all selected files
1164+
* @param tagId
1165+
* @private
1166+
*/
1167+
_onDeselectTag: function(tagId) {
1168+
var selectedFiles = _.pluck(this.getSelectedFiles(),'id')
1169+
console.log('removing tag', tagId, 'for files', selectedFiles, this.getSelectedFiles())
1170+
if (!_.isArray(selectedFiles)) {
1171+
console.log('selected files - no array!', selectedFiles);
1172+
}
1173+
selectedFiles.forEach(function(fileId) {
1174+
console.log('remove tag route',OC.linkToRemote('dav') + '/systemtags-relations/files/' +fileId + '/'+ tagId)
1175+
$.ajax({
1176+
url: OC.linkToRemote('dav') + '/systemtags-relations/files/' +fileId + '/'+ tagId,
1177+
type: 'DELETE'
1178+
});
1179+
});
1180+
},
1181+
10731182
/**
10741183
* Event handler when clicking on a table header
10751184
*/

0 commit comments

Comments
 (0)