gitlab-org--gitlab-foss/app/assets/javascripts/diff_notes/stores/comments.js.es6

58 lines
1.7 KiB
JavaScript
Raw Normal View History

/* eslint-disable object-shorthand, func-names, camelcase, prefer-const, no-restricted-syntax, guard-for-in, comma-dangle, max-len, no-param-reassign */
/* global Vue */
/* global DiscussionModel */
2016-07-26 06:56:36 -04:00
((w) => {
w.CommentsStore = {
state: {},
get: function (discussionId, noteId) {
return this.state[discussionId].getNote(noteId);
2016-07-26 06:56:36 -04:00
},
createDiscussion: function (discussionId, canResolve) {
let discussion = this.state[discussionId];
2016-07-26 06:56:36 -04:00
if (!this.state[discussionId]) {
discussion = new DiscussionModel(discussionId);
Vue.set(this.state, discussionId, discussion);
2016-07-26 06:56:36 -04:00
}
if (canResolve !== undefined) {
discussion.canResolve = canResolve;
}
return discussion;
},
create: function (discussionId, noteId, canResolve, resolved, resolved_by) {
const discussion = this.createDiscussion(discussionId);
discussion.createNote(noteId, canResolve, resolved, resolved_by);
2016-07-26 06:56:36 -04:00
},
update: function (discussionId, noteId, resolved, resolved_by) {
const discussion = this.state[discussionId];
const note = discussion.getNote(noteId);
note.resolved = resolved;
note.resolved_by = resolved_by;
2016-07-26 06:56:36 -04:00
},
delete: function (discussionId, noteId) {
const discussion = this.state[discussionId];
discussion.deleteNote(noteId);
2016-07-26 06:56:36 -04:00
if (discussion.notesCount() === 0) {
2016-07-26 06:56:36 -04:00
Vue.delete(this.state, discussionId);
}
},
unresolvedDiscussionIds: function () {
let ids = [];
for (const discussionId in this.state) {
const discussion = this.state[discussionId];
if (!discussion.isResolved()) {
ids.push(discussion.id);
}
}
return ids;
}
2016-07-26 06:56:36 -04:00
};
})(window);