2016-07-26 06:56:36 -04:00
|
|
|
((w) => {
|
|
|
|
w.CommentsStore = {
|
|
|
|
state: {},
|
|
|
|
loading: {},
|
|
|
|
get: function (discussionId, noteId) {
|
|
|
|
return this.state[discussionId][noteId];
|
|
|
|
},
|
2016-07-26 10:47:19 -04:00
|
|
|
create: function (discussionId, noteId, resolved, user) {
|
2016-07-26 06:56:36 -04:00
|
|
|
if (!this.state[discussionId]) {
|
|
|
|
Vue.set(this.state, discussionId, {});
|
|
|
|
Vue.set(this.loading, discussionId, false);
|
|
|
|
}
|
|
|
|
|
2016-07-26 10:47:19 -04:00
|
|
|
Vue.set(this.state[discussionId], noteId, { resolved, user});
|
2016-07-26 06:56:36 -04:00
|
|
|
},
|
2016-07-26 10:47:19 -04:00
|
|
|
update: function (discussionId, noteId, resolved, user) {
|
|
|
|
this.state[discussionId][noteId].resolved = resolved;
|
|
|
|
this.state[discussionId][noteId].user = user;
|
2016-07-26 06:56:36 -04:00
|
|
|
},
|
|
|
|
delete: function (discussionId, noteId) {
|
|
|
|
Vue.delete(this.state[discussionId], noteId);
|
|
|
|
|
|
|
|
if (Object.keys(this.state[discussionId]).length === 0) {
|
|
|
|
Vue.delete(this.state, discussionId);
|
|
|
|
Vue.delete(this.loading, discussionId);
|
|
|
|
}
|
|
|
|
},
|
2016-07-26 10:47:19 -04:00
|
|
|
updateCommentsForDiscussion: function (discussionId, resolve, user) {
|
2016-07-26 09:30:57 -04:00
|
|
|
const noteIds = CommentsStore.resolvedNotesForDiscussion(discussionId, resolve);
|
2016-07-26 08:44:51 -04:00
|
|
|
|
|
|
|
for (const noteId of noteIds) {
|
2016-07-26 10:47:19 -04:00
|
|
|
CommentsStore.update(discussionId, noteId, resolve, user);
|
2016-07-26 08:44:51 -04:00
|
|
|
}
|
|
|
|
},
|
2016-07-26 09:30:57 -04:00
|
|
|
notesForDiscussion: function (discussionId) {
|
|
|
|
let ids = [];
|
|
|
|
|
|
|
|
for (const noteId in CommentsStore.state[discussionId]) {
|
|
|
|
ids.push(noteId);
|
|
|
|
}
|
|
|
|
|
|
|
|
return ids;
|
|
|
|
},
|
|
|
|
resolvedNotesForDiscussion: function (discussionId, resolve) {
|
2016-07-26 08:44:51 -04:00
|
|
|
let ids = [];
|
|
|
|
|
|
|
|
for (const noteId in CommentsStore.state[discussionId]) {
|
2016-07-26 10:47:19 -04:00
|
|
|
const resolved = CommentsStore.state[discussionId][noteId].resolved;
|
2016-07-26 08:44:51 -04:00
|
|
|
|
|
|
|
if (resolved !== resolve) {
|
|
|
|
ids.push(noteId);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return ids;
|
|
|
|
}
|
2016-07-26 06:56:36 -04:00
|
|
|
};
|
|
|
|
}(window));
|