2018-12-13 13:39:08 +05:30
|
|
|
/* eslint-disable object-shorthand, func-names, camelcase, no-restricted-syntax, guard-for-in */
|
2017-08-17 22:00:37 +05:30
|
|
|
/* global DiscussionModel */
|
|
|
|
|
|
|
|
import Vue from 'vue';
|
|
|
|
|
|
|
|
window.CommentsStore = {
|
|
|
|
state: {},
|
2018-12-13 13:39:08 +05:30
|
|
|
get: function(discussionId, noteId) {
|
2017-08-17 22:00:37 +05:30
|
|
|
return this.state[discussionId].getNote(noteId);
|
|
|
|
},
|
2018-12-13 13:39:08 +05:30
|
|
|
createDiscussion: function(discussionId, canResolve) {
|
2017-08-17 22:00:37 +05:30
|
|
|
let discussion = this.state[discussionId];
|
|
|
|
if (!this.state[discussionId]) {
|
|
|
|
discussion = new DiscussionModel(discussionId);
|
|
|
|
Vue.set(this.state, discussionId, discussion);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (canResolve !== undefined) {
|
|
|
|
discussion.canResolve = canResolve;
|
|
|
|
}
|
|
|
|
|
|
|
|
return discussion;
|
|
|
|
},
|
2018-12-13 13:39:08 +05:30
|
|
|
create: function(noteObj) {
|
2017-08-17 22:00:37 +05:30
|
|
|
const discussion = this.createDiscussion(noteObj.discussionId);
|
|
|
|
|
|
|
|
discussion.createNote(noteObj);
|
|
|
|
},
|
2018-12-13 13:39:08 +05:30
|
|
|
update: function(discussionId, noteId, resolved, resolved_by) {
|
2017-08-17 22:00:37 +05:30
|
|
|
const discussion = this.state[discussionId];
|
|
|
|
const note = discussion.getNote(noteId);
|
|
|
|
note.resolved = resolved;
|
|
|
|
note.resolved_by = resolved_by;
|
|
|
|
},
|
2018-12-13 13:39:08 +05:30
|
|
|
delete: function(discussionId, noteId) {
|
2017-08-17 22:00:37 +05:30
|
|
|
const discussion = this.state[discussionId];
|
|
|
|
discussion.deleteNote(noteId);
|
|
|
|
|
|
|
|
if (discussion.notesCount() === 0) {
|
|
|
|
Vue.delete(this.state, discussionId);
|
|
|
|
}
|
|
|
|
},
|
2018-12-13 13:39:08 +05:30
|
|
|
unresolvedDiscussionIds: function() {
|
2017-08-17 22:00:37 +05:30
|
|
|
const ids = [];
|
|
|
|
|
|
|
|
for (const discussionId in this.state) {
|
|
|
|
const discussion = this.state[discussionId];
|
|
|
|
|
|
|
|
if (!discussion.isResolved()) {
|
|
|
|
ids.push(discussion.id);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return ids;
|
2018-12-13 13:39:08 +05:30
|
|
|
},
|
2017-08-17 22:00:37 +05:30
|
|
|
};
|