Enhance activity list with comment data

Signed-off-by: Julius Härtl <jus@bitgrid.net>
This commit is contained in:
Julius Härtl
2018-10-04 17:36:02 +02:00
parent 63337c1d26
commit ffd32a803f
4 changed files with 146 additions and 7 deletions

View File

@@ -22,6 +22,9 @@
/* global OC OCA */
import CommentCollection from '../legacy/commentcollection';
import CommentModel from '../legacy/commentmodel';
class ActivityController {
constructor ($scope, CardService, ActivityService) {
'ngInject';
@@ -30,12 +33,14 @@ class ActivityController {
this.$scope = $scope;
this.type = '';
this.loading = false;
this.$scope.newComment = '';
const self = this;
this.$scope.$watch(function () {
return self.element.id;
}, function (params) {
if (self.getData(self.element.id).length === 0) {
self.activityservice.loadComments(self.element.id);
self.loading = true;
self.fetchUntilResults();
}
@@ -43,6 +48,48 @@ class ActivityController {
}, true);
}
postComment() {
const self = this;
var model = this.activityservice.commentCollection.create({
actorId: OC.getCurrentUser().uid,
actorDisplayName: OC.getCurrentUser().displayName,
actorType: 'users',
verb: 'comment',
message: self.$scope.newComment,
creationDateTime: (new Date()).toUTCString()
}, {
at: 0,
// wait for real creation before adding
wait: true,
success: function() {
console.log("SUCCESS");
self.$scope.newComment = '';
self.activityservice.fetchNewerActivities(self.type, self.element.id).then(function () {});
},
error: function() {
}
});
}
updateComment(item) {
let newMessage = 'Edited at ' + (new Date());
item.commentModel.save({
message: newMessage,
});
item.message = newMessage;
}
deleteComment() {
}
getCommentDetails() {}
getData(id) {
return this.activityservice.getData(this.type, id);
}
@@ -59,7 +106,7 @@ class ActivityController {
let promise = self.activityservice.fetchMoreActivities(self.type, self.element.id);
promise.then(function (data) {
let dataLengthAfter = self.getData(self.element.id).length;
if (data !== null && (dataLengthAfter <= dataLengthBefore || dataLengthAfter < 5)) {
if (data !== null && (dataLengthAfter <= dataLengthBefore || dataLengthAfter < self.activityservice.RESULT_PER_PAGE)) {
_executeFetch();
} else {
self.loading = false;
@@ -73,6 +120,24 @@ class ActivityController {
_executeFetch();
}
getComments() {
return this.activityservice.comments;
}
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;
}
page() {
if (!this.activityservice.since[this.type][this.element.id].finished) {
this.loading = true;