2020-03-09 13:42:32 +05:30
|
|
|
/* eslint-disable no-restricted-syntax, guard-for-in */
|
2017-08-17 22:00:37 +05:30
|
|
|
/* global DiscussionModel */
|
|
|
|
|
|
|
|
import Vue from 'vue';
|
|
|
|
|
|
|
|
window.CommentsStore = {
|
|
|
|
state: {},
|
2019-12-04 20:38:33 +05:30
|
|
|
get(discussionId, noteId) {
|
2017-08-17 22:00:37 +05:30
|
|
|
return this.state[discussionId].getNote(noteId);
|
|
|
|
},
|
2019-12-04 20:38:33 +05:30
|
|
|
createDiscussion(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;
|
|
|
|
},
|
2019-12-04 20:38:33 +05:30
|
|
|
create(noteObj) {
|
2017-08-17 22:00:37 +05:30
|
|
|
const discussion = this.createDiscussion(noteObj.discussionId);
|
|
|
|
|
|
|
|
discussion.createNote(noteObj);
|
|
|
|
},
|
2020-03-09 13:42:32 +05:30
|
|
|
update(discussionId, noteId, resolved, resolvedBy) {
|
2017-08-17 22:00:37 +05:30
|
|
|
const discussion = this.state[discussionId];
|
|
|
|
const note = discussion.getNote(noteId);
|
|
|
|
note.resolved = resolved;
|
2020-03-09 13:42:32 +05:30
|
|
|
note.resolved_by = resolvedBy;
|
2017-08-17 22:00:37 +05:30
|
|
|
},
|
2019-12-04 20:38:33 +05:30
|
|
|
delete(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);
|
|
|
|
}
|
|
|
|
},
|
2019-12-04 20:38:33 +05:30
|
|
|
unresolvedDiscussionIds() {
|
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
|
|
|
};
|