2016-01-27 20:28:55 +03:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2016 Vincent Petry <pvince81@owncloud.com>
|
|
|
|
*
|
|
|
|
* This file is licensed under the Affero General Public License version 3
|
|
|
|
* or later.
|
|
|
|
*
|
|
|
|
* See the COPYING-README file.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
(function() {
|
2016-11-21 17:03:45 +03:00
|
|
|
|
|
|
|
_.extend(OC.Files.Client, {
|
2019-11-13 15:05:10 +03:00
|
|
|
PROPERTY_COMMENTS_UNREAD: '{' + OC.Files.Client.NS_OWNCLOUD + '}comments-unread',
|
2019-09-25 19:19:42 +03:00
|
|
|
})
|
2016-11-21 17:03:45 +03:00
|
|
|
|
2019-09-25 19:19:42 +03:00
|
|
|
OCA.Comments = _.extend({}, OCA.Comments)
|
2016-01-27 20:28:55 +03:00
|
|
|
if (!OCA.Comments) {
|
|
|
|
/**
|
|
|
|
* @namespace
|
|
|
|
*/
|
2019-09-25 19:19:42 +03:00
|
|
|
OCA.Comments = {}
|
2016-01-27 20:28:55 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @namespace
|
|
|
|
*/
|
|
|
|
OCA.Comments.FilesPlugin = {
|
2016-02-16 13:24:44 +03:00
|
|
|
ignoreLists: [
|
2019-04-02 12:33:20 +03:00
|
|
|
'trashbin',
|
2019-11-13 15:05:10 +03:00
|
|
|
'files.public',
|
2016-01-27 20:28:55 +03:00
|
|
|
],
|
|
|
|
|
2016-02-03 15:00:55 +03:00
|
|
|
_formatCommentCount: function(count) {
|
2018-10-15 20:52:22 +03:00
|
|
|
return OCA.Comments.Templates['filesplugin']({
|
2016-02-03 15:00:55 +03:00
|
|
|
count: count,
|
2016-09-28 11:54:37 +03:00
|
|
|
countMessage: n('comments', '%n unread comment', '%n unread comments', count),
|
2019-11-13 15:05:10 +03:00
|
|
|
iconUrl: OC.imagePath('core', 'actions/comment'),
|
2019-09-25 19:19:42 +03:00
|
|
|
})
|
2016-02-03 15:00:55 +03:00
|
|
|
},
|
|
|
|
|
2016-01-27 20:28:55 +03:00
|
|
|
attach: function(fileList) {
|
2019-11-13 15:05:10 +03:00
|
|
|
const self = this
|
2016-02-16 13:24:44 +03:00
|
|
|
if (this.ignoreLists.indexOf(fileList.id) >= 0) {
|
2019-09-25 19:19:42 +03:00
|
|
|
return
|
2016-01-27 20:28:55 +03:00
|
|
|
}
|
|
|
|
|
2019-09-25 19:19:42 +03:00
|
|
|
fileList.registerTabView(new OCA.Comments.CommentsTabView('commentsTabView'))
|
2016-02-03 15:00:55 +03:00
|
|
|
|
2019-11-13 15:05:10 +03:00
|
|
|
const oldGetWebdavProperties = fileList._getWebdavProperties
|
2016-02-03 15:00:55 +03:00
|
|
|
fileList._getWebdavProperties = function() {
|
2019-11-13 15:05:10 +03:00
|
|
|
const props = oldGetWebdavProperties.apply(this, arguments)
|
2019-09-25 19:19:42 +03:00
|
|
|
props.push(OC.Files.Client.PROPERTY_COMMENTS_UNREAD)
|
|
|
|
return props
|
|
|
|
}
|
2016-02-03 15:00:55 +03:00
|
|
|
|
|
|
|
fileList.filesClient.addFileInfoParser(function(response) {
|
2019-11-13 15:05:10 +03:00
|
|
|
const data = {}
|
|
|
|
const props = response.propStat[0].properties
|
|
|
|
const commentsUnread = props[OC.Files.Client.PROPERTY_COMMENTS_UNREAD]
|
2016-02-03 15:00:55 +03:00
|
|
|
if (!_.isUndefined(commentsUnread) && commentsUnread !== '') {
|
2019-09-25 19:19:42 +03:00
|
|
|
data.commentsUnread = parseInt(commentsUnread, 10)
|
2016-02-03 15:00:55 +03:00
|
|
|
}
|
2019-09-25 19:19:42 +03:00
|
|
|
return data
|
|
|
|
})
|
2016-02-03 15:00:55 +03:00
|
|
|
|
2019-09-25 19:19:42 +03:00
|
|
|
fileList.$el.addClass('has-comments')
|
2019-11-13 15:05:10 +03:00
|
|
|
const oldCreateRow = fileList._createRow
|
2016-02-03 15:00:55 +03:00
|
|
|
fileList._createRow = function(fileData) {
|
2019-11-13 15:05:10 +03:00
|
|
|
const $tr = oldCreateRow.apply(this, arguments)
|
2016-02-03 15:00:55 +03:00
|
|
|
if (fileData.commentsUnread) {
|
2019-09-25 19:19:42 +03:00
|
|
|
$tr.attr('data-comments-unread', fileData.commentsUnread)
|
2016-02-03 15:00:55 +03:00
|
|
|
}
|
2019-09-25 19:19:42 +03:00
|
|
|
return $tr
|
|
|
|
}
|
2016-02-03 15:00:55 +03:00
|
|
|
|
|
|
|
// register "comment" action for reading comments
|
|
|
|
fileList.fileActions.registerAction({
|
|
|
|
name: 'Comment',
|
2019-04-02 12:33:20 +03:00
|
|
|
displayName: function(context) {
|
|
|
|
if (context && context.$file) {
|
2019-11-13 15:05:10 +03:00
|
|
|
const unread = parseInt(context.$file.data('comments-unread'), 10)
|
2019-04-02 12:33:20 +03:00
|
|
|
if (unread >= 0) {
|
|
|
|
return n('comments', '1 new comment', '{unread} new comments', unread, { unread: unread })
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return t('comments', 'Comment')
|
|
|
|
},
|
2016-02-03 15:00:55 +03:00
|
|
|
mime: 'all',
|
2019-04-02 12:33:20 +03:00
|
|
|
order: -140,
|
|
|
|
iconClass: 'icon-comment',
|
2016-02-03 15:00:55 +03:00
|
|
|
permissions: OC.PERMISSION_READ,
|
|
|
|
type: OCA.Files.FileActions.TYPE_INLINE,
|
|
|
|
render: function(actionSpec, isDefault, context) {
|
2019-11-13 15:05:10 +03:00
|
|
|
const $file = context.$file
|
|
|
|
const unreadComments = $file.data('comments-unread')
|
2016-02-03 15:00:55 +03:00
|
|
|
if (unreadComments) {
|
2019-11-13 15:05:10 +03:00
|
|
|
const $actionLink = $(self._formatCommentCount(unreadComments))
|
2019-09-25 19:19:42 +03:00
|
|
|
context.$file.find('a.name>span.fileactions').append($actionLink)
|
|
|
|
return $actionLink
|
2016-02-03 15:00:55 +03:00
|
|
|
}
|
2019-09-25 19:19:42 +03:00
|
|
|
return ''
|
2016-02-03 15:00:55 +03:00
|
|
|
},
|
|
|
|
actionHandler: function(fileName, context) {
|
2019-09-25 19:19:42 +03:00
|
|
|
context.$file.find('.action-comment').tooltip('hide')
|
2016-02-03 15:00:55 +03:00
|
|
|
// open sidebar in comments section
|
2019-05-23 18:03:04 +03:00
|
|
|
context.fileList.showDetailsView(fileName, 'comments')
|
2019-11-13 15:05:10 +03:00
|
|
|
},
|
2019-09-25 19:19:42 +03:00
|
|
|
})
|
2016-02-03 15:00:55 +03:00
|
|
|
|
|
|
|
// add attribute to "elementToFile"
|
2019-11-13 15:05:10 +03:00
|
|
|
const oldElementToFile = fileList.elementToFile
|
2016-02-03 15:00:55 +03:00
|
|
|
fileList.elementToFile = function($el) {
|
2019-11-13 15:05:10 +03:00
|
|
|
const fileInfo = oldElementToFile.apply(this, arguments)
|
|
|
|
const commentsUnread = $el.data('comments-unread')
|
2016-02-03 15:00:55 +03:00
|
|
|
if (commentsUnread) {
|
2019-09-25 19:19:42 +03:00
|
|
|
fileInfo.commentsUnread = commentsUnread
|
2016-02-03 15:00:55 +03:00
|
|
|
}
|
2019-09-25 19:19:42 +03:00
|
|
|
return fileInfo
|
|
|
|
}
|
2019-11-13 15:05:10 +03:00
|
|
|
},
|
2019-09-25 19:19:42 +03:00
|
|
|
}
|
2016-01-27 20:28:55 +03:00
|
|
|
|
2019-09-25 19:19:42 +03:00
|
|
|
})()
|
2016-01-27 20:28:55 +03:00
|
|
|
|
2019-09-25 19:19:42 +03:00
|
|
|
OC.Plugins.register('OCA.Files.FileList', OCA.Comments.FilesPlugin)
|