2017-01-12 00:52:42 -05:00
|
|
|
/* eslint-disable object-shorthand, func-names, camelcase, no-restricted-syntax, guard-for-in, comma-dangle, max-len, no-param-reassign */
|
2016-12-13 22:01:05 -05:00
|
|
|
/* global Vue */
|
|
|
|
/* global DiscussionModel */
|
|
|
|
|
2016-07-26 06:56:36 -04:00
|
|
|
((w) => {
|
|
|
|
w.CommentsStore = {
|
|
|
|
state: {},
|
|
|
|
get: function (discussionId, noteId) {
|
2016-07-29 06:19:56 -04:00
|
|
|
return this.state[discussionId].getNote(noteId);
|
2016-07-26 06:56:36 -04:00
|
|
|
},
|
2016-08-12 16:10:05 -04:00
|
|
|
createDiscussion: function (discussionId, canResolve) {
|
2016-07-29 06:19:56 -04:00
|
|
|
let discussion = this.state[discussionId];
|
2016-07-26 06:56:36 -04:00
|
|
|
if (!this.state[discussionId]) {
|
2016-07-29 06:19:56 -04:00
|
|
|
discussion = new DiscussionModel(discussionId);
|
|
|
|
Vue.set(this.state, discussionId, discussion);
|
2016-07-26 06:56:36 -04:00
|
|
|
}
|
|
|
|
|
2016-08-12 16:10:05 -04:00
|
|
|
if (canResolve !== undefined) {
|
|
|
|
discussion.canResolve = canResolve;
|
|
|
|
}
|
|
|
|
|
|
|
|
return discussion;
|
|
|
|
},
|
|
|
|
create: function (discussionId, noteId, canResolve, resolved, resolved_by) {
|
|
|
|
const discussion = this.createDiscussion(discussionId);
|
|
|
|
|
2016-08-04 04:52:17 -04:00
|
|
|
discussion.createNote(noteId, canResolve, resolved, resolved_by);
|
2016-07-26 06:56:36 -04:00
|
|
|
},
|
2016-08-01 05:06:31 -04:00
|
|
|
update: function (discussionId, noteId, resolved, resolved_by) {
|
2016-07-29 06:19:56 -04:00
|
|
|
const discussion = this.state[discussionId];
|
|
|
|
const note = discussion.getNote(noteId);
|
|
|
|
note.resolved = resolved;
|
2016-08-01 05:06:31 -04:00
|
|
|
note.resolved_by = resolved_by;
|
2016-07-26 06:56:36 -04:00
|
|
|
},
|
|
|
|
delete: function (discussionId, noteId) {
|
2016-07-29 06:19:56 -04:00
|
|
|
const discussion = this.state[discussionId];
|
|
|
|
discussion.deleteNote(noteId);
|
2016-07-26 06:56:36 -04:00
|
|
|
|
2016-08-01 05:06:31 -04:00
|
|
|
if (discussion.notesCount() === 0) {
|
2016-07-26 06:56:36 -04:00
|
|
|
Vue.delete(this.state, discussionId);
|
|
|
|
}
|
2016-08-04 06:02:04 -04:00
|
|
|
},
|
|
|
|
unresolvedDiscussionIds: function () {
|
2017-01-12 00:52:42 -05:00
|
|
|
const ids = [];
|
2016-08-04 06:02:04 -04:00
|
|
|
|
|
|
|
for (const discussionId in this.state) {
|
|
|
|
const discussion = this.state[discussionId];
|
|
|
|
|
|
|
|
if (!discussion.isResolved()) {
|
|
|
|
ids.push(discussion.id);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return ids;
|
2016-07-26 08:44:51 -04:00
|
|
|
}
|
2016-07-26 06:56:36 -04:00
|
|
|
};
|
2016-07-28 10:07:47 -04:00
|
|
|
})(window);
|