diff options
author | Morris Jobke <hey@morrisjobke.de> | 2016-10-05 23:56:10 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2016-10-05 23:56:10 +0200 |
commit | fe2116ecf73e707aa30130b767fd6b0b7bf17787 (patch) | |
tree | f6a3591be447f6bb191ec79ee4c31b0350035573 /apps/comments | |
parent | 8dafcab691dbab1517bb4ec77fb574b2922c625e (diff) | |
parent | 43265befac637d09c71e4f639c317e423e3bbfd6 (diff) | |
download | nextcloud-server-fe2116ecf73e707aa30130b767fd6b0b7bf17787.tar.gz nextcloud-server-fe2116ecf73e707aa30130b767fd6b0b7bf17787.zip |
Merge pull request #1519 from nextcloud/better-comments-in-activity-sidebar
Better comments in activity sidebar
Diffstat (limited to 'apps/comments')
-rw-r--r-- | apps/comments/appinfo/app.php | 1 | ||||
-rw-r--r-- | apps/comments/css/comments.css | 14 | ||||
-rw-r--r-- | apps/comments/js/activitytabviewplugin.js | 59 | ||||
-rw-r--r-- | apps/comments/lib/Activity/Extension.php | 14 |
4 files changed, 71 insertions, 17 deletions
diff --git a/apps/comments/appinfo/app.php b/apps/comments/appinfo/app.php index 00085cf9148..df41bdfa32d 100644 --- a/apps/comments/appinfo/app.php +++ b/apps/comments/appinfo/app.php @@ -32,6 +32,7 @@ $eventDispatcher->addListener( \OCP\Util::addScript('comments', 'commentsummarymodel'); \OCP\Util::addScript('comments', 'commentstabview'); \OCP\Util::addScript('comments', 'filesplugin'); + \OCP\Util::addScript('comments', 'activitytabviewplugin'); \OCP\Util::addStyle('comments', 'comments'); } ); diff --git a/apps/comments/css/comments.css b/apps/comments/css/comments.css index 7f64f1cf7db..103564c5faf 100644 --- a/apps/comments/css/comments.css +++ b/apps/comments/css/comments.css @@ -59,35 +59,39 @@ line-height: 32px; } +#activityTabView li.comment.collapsed .activitymessage, #commentsTabView .comment.collapsed .message { white-space: pre-wrap; } +#activityTabView li.comment.collapsed .activitymessage, #commentsTabView .comment.collapsed .message { max-height: 70px; overflow: hidden; } +#activityTabView li.comment .message-overlay, #commentsTabView .comment .message-overlay { display: none; } +#activityTabView li.comment.collapsed .message-overlay, #commentsTabView .comment.collapsed .message-overlay { display: block; - position: absolute; + position: absolute; z-index: 2; - height: 50px; - pointer-events: none; + height: 50px; + pointer-events: none; left: 0; right: 0; - bottom: 0; + bottom: 0; background: -moz-linear-gradient(rgba(255,255,255,0), rgba(255,255,255,1)); background: -webkit-linear-gradient(rgba(255,255,255,0), rgba(255,255,255,1)); background: -o-linear-gradient(rgba(255,255,255,0), rgba(255,255,255,1)); background: -ms-linear-gradient(rgba(255,255,255,0), rgba(255,255,255,1)); background: linear-gradient(rgba(255,255,255,0), rgba(255,255,255,1)); filter: progid:DXImageTransform.Microsoft.gradient(GradientType=0,startColorstr='#00FFFFFF', endColorstr='#FFFFFFFF'); - background-repeat: no-repeat; + background-repeat: no-repeat; } #commentsTabView .authorRow>div { diff --git a/apps/comments/js/activitytabviewplugin.js b/apps/comments/js/activitytabviewplugin.js new file mode 100644 index 00000000000..ca3253bd137 --- /dev/null +++ b/apps/comments/js/activitytabviewplugin.js @@ -0,0 +1,59 @@ +/* + * @author Joas Schilling <coding@schilljs.com> + * Copyright (c) 2016 + * + * This file is licensed under the Affero General Public License version 3 + * or later. + * + * See the COPYING-README file. + */ + +(function() { + OCA.Comments.ActivityTabViewPlugin = { + + /** + * Prepare activity for display + * + * @param {OCA.Activity.ActivityModel} model for this activity + * @param {jQuery} $el jQuery handle for this activity + * @param {string} view The view that displayes this activity + */ + prepareModelForDisplay: function (model, $el, view) { + if (model.get('app') !== 'comments' || model.get('type') !== 'comments') { + return; + } + + if (view === 'ActivityTabView') { + $el.addClass('comment'); + if (this._isLong(model.get('message_prepared'))) { + $el.addClass('collapsed'); + var $overlay = $('<div>').addClass('message-overlay'); + $el.find('.activitymessage').after($overlay); + $el.on('click', this._onClickCollapsedComment); + } + } + }, + + /* + * Copy of CommentsTabView._onClickComment() + */ + _onClickCollapsedComment: function(ev) { + var $row = $(ev.target); + if (!$row.is('.comment')) { + $row = $row.closest('.comment'); + } + $row.removeClass('collapsed'); + }, + + /* + * Copy of CommentsTabView._isLong() + */ + _isLong: function(message) { + return message.length > 250 || (message.match(/\n/g) || []).length > 1; + } + }; + + +})(); + +OC.Plugins.register('OCA.Activity.RenderingPlugins', OCA.Comments.ActivityTabViewPlugin); diff --git a/apps/comments/lib/Activity/Extension.php b/apps/comments/lib/Activity/Extension.php index 8abe42eb9df..6bf7bc9ac0b 100644 --- a/apps/comments/lib/Activity/Extension.php +++ b/apps/comments/lib/Activity/Extension.php @@ -159,7 +159,7 @@ class Extension implements IExtension { } return (string) $l->t('%1$s commented', $params); case self::ADD_COMMENT_MESSAGE: - return $this->convertParameterToComment($params[0], 120); + return $this->convertParameterToComment($params[0]); } return false; @@ -196,7 +196,6 @@ class Extension implements IExtension { try { return strip_tags($user) === $this->activityManager->getCurrentUserId(); } catch (\UnexpectedValueException $e) { - // FIXME this is awkward, but we have no access to the current user in emails return false; } } @@ -301,21 +300,12 @@ class Extension implements IExtension { * @param string $parameter * @return string */ - protected function convertParameterToComment($parameter, $maxLength = 0) { + protected function convertParameterToComment($parameter) { if (preg_match('/^\<parameter\>(\d*)\<\/parameter\>$/', $parameter, $matches)) { try { $comment = $this->commentsManager->get((int) $matches[1]); $message = $comment->getMessage(); $message = str_replace("\n", '<br />', str_replace(['<', '>'], ['<', '>'], $message)); - - if ($maxLength && isset($message[$maxLength + 20])) { - $findSpace = strpos($message, ' ', $maxLength); - if ($findSpace !== false && $findSpace < $maxLength + 20) { - return substr($message, 0, $findSpace) . '…'; - } - return substr($message, 0, $maxLength + 20) . '…'; - } - return $message; } catch (NotFoundException $e) { return ''; |