From f5520d3087bf1ba6753f3384cfd4d0e6e5960ef9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julius=20H=C3=A4rtl?= Date: Fri, 5 Oct 2018 10:12:15 +0200 Subject: [PATCH] Implement comment deletion and loading indicator MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Julius Härtl --- css/style.scss | 3 +++ js/controller/ActivityController.js | 21 +++++++++------------ js/legacy/commentmodel.js | 8 ++++++++ js/service/ActivityService.js | 8 ++++---- lib/Activity/DeckProvider.php | 8 ++++++-- templates/part.card.activity.html | 6 +++--- 6 files changed, 33 insertions(+), 21 deletions(-) diff --git a/css/style.scss b/css/style.scss index b20f97b3f..a3d10e998 100644 --- a/css/style.scss +++ b/css/style.scss @@ -946,6 +946,9 @@ input.input-inline { position: absolute; top: -5px; right: 0; + a { + font-weight: normal; + } button { opacity: .5; padding: 14px 19px; diff --git a/js/controller/ActivityController.js b/js/controller/ActivityController.js index 404c980dd..43c2a4855 100644 --- a/js/controller/ActivityController.js +++ b/js/controller/ActivityController.js @@ -33,6 +33,9 @@ class ActivityController { this.$scope = $scope; this.type = ''; this.loading = false; + this.status = { + commentCreateLoading: false + }; this.$scope.newComment = ''; const self = this; @@ -51,6 +54,7 @@ class ActivityController { postComment() { const self = this; + this.status.commentCreateLoading = true; var model = this.activityservice.commentCollection.create({ actorId: OC.getCurrentUser().uid, actorDisplayName: OC.getCurrentUser().displayName, @@ -66,6 +70,7 @@ class ActivityController { console.log("SUCCESS"); self.$scope.newComment = ''; self.activityservice.fetchNewerActivities(self.type, self.element.id).then(function () {}); + self.status.commentCreateLoading = false; }, error: function() { @@ -82,8 +87,9 @@ class ActivityController { } - deleteComment() { - + deleteComment(item) { + item.commentModel.destroy(); + item.deleted = true; } getCommentDetails() {} @@ -125,17 +131,8 @@ class ActivityController { } getActivityStream() { - const self = this; let activities = this.activityservice.getData(this.type, this.element.id); - this.data = []; - for (let i in activities) { - let activity = activities[i]; - activity.timelineType = 'activity'; - activity.timelineTimestamp = activity.timestamp; - this.data.push(activity); - } - let sorted = this.data.sort((a, b) => b.timelineTimestamp - a.timelineTimestamp); - return sorted; + return activities; } page() { diff --git a/js/legacy/commentmodel.js b/js/legacy/commentmodel.js index 3f9b72e08..3ecc86249 100644 --- a/js/legacy/commentmodel.js +++ b/js/legacy/commentmodel.js @@ -66,6 +66,14 @@ var CommentModel = OC.Backbone.Model.extend( }; }, + url: function() { + if (typeof this.get('id') !== 'undefined') { + return this.collection.url() + this.get('id'); + } else { + return this.collection.url(); + } + } + }); export default CommentModel; diff --git a/js/service/ActivityService.js b/js/service/ActivityService.js index ae32983e0..7e6c8db03 100644 --- a/js/service/ActivityService.js +++ b/js/service/ActivityService.js @@ -53,11 +53,9 @@ class ActivityService { let item = this.toEnhanceWithComments[index]; item.commentModel = this.commentCollection.get(item.subject_rich[1].comment); if (typeof item.commentModel !== 'undefined') { - // FIXME: not working - this.toEnhanceWithComments.remove(item); + this.toEnhanceWithComments = this.toEnhanceWithComments.filter(entry => entry.id !== item.id); } } - console.log(this.toEnhanceWithComments); var firstUnread = this.commentCollection.findWhere({isUnread: true}); if (typeof firstUnread !== 'undefined') { this.commentCollection.updateReadMarker(); @@ -155,13 +153,15 @@ class ActivityService { return; } item.timestamp = new Date(item.datetime).getTime(); - + item.type = 'activity'; if (item.subject_rich[1].comment) { + item.type = 'comment'; item.commentModel = this.commentCollection.get(item.subject_rich[1].comment); if (typeof item.commentModel === 'undefined') { this.toEnhanceWithComments.push(item); } } + this.data[type][id].push(item); } diff --git a/lib/Activity/DeckProvider.php b/lib/Activity/DeckProvider.php index 670f2a61c..10e01121c 100644 --- a/lib/Activity/DeckProvider.php +++ b/lib/Activity/DeckProvider.php @@ -29,6 +29,7 @@ use OCA\Deck\Db\Acl; use OCP\Activity\IEvent; use OCP\Activity\IProvider; use OCP\Comments\IComment; +use OCP\Comments\NotFoundException; use OCP\IURLGenerator; use OCP\IUserManager; @@ -235,8 +236,11 @@ class DeckProvider implements IProvider { private function parseParamForComment($subjectParams, $params, IEvent $event) { if (array_key_exists('comment', $subjectParams)) { /** @var IComment $comment */ - $comment = \OC::$server->getCommentsManager()->get((int) $subjectParams['comment']); - $event->setParsedMessage($comment->getMessage()); + try { + $comment = \OC::$server->getCommentsManager()->get((int)$subjectParams['comment']); + $event->setParsedMessage($comment->getMessage()); + } catch (NotFoundException $e) { + } } $params['comment'] = $subjectParams['comment']; return $params; diff --git a/templates/part.card.activity.html b/templates/part.card.activity.html index 5fafa5a5e..f8488b47b 100644 --- a/templates/part.card.activity.html +++ b/templates/part.card.activity.html @@ -7,10 +7,10 @@
admin
-
+
- + value="" title="" data-original-title="Post" ng-click="$ctrl.postComment()" ng-if="!$ctrl.status.commentCreateLoading"> +