debian-mirror-gitlab/app/assets/javascripts/diff_notes/stores/comments.js
2019-12-04 20:38:33 +05:30

56 lines
1.4 KiB
JavaScript

/* eslint-disable camelcase, no-restricted-syntax, guard-for-in */
/* global DiscussionModel */
import Vue from 'vue';
window.CommentsStore = {
state: {},
get(discussionId, noteId) {
return this.state[discussionId].getNote(noteId);
},
createDiscussion(discussionId, canResolve) {
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;
},
create(noteObj) {
const discussion = this.createDiscussion(noteObj.discussionId);
discussion.createNote(noteObj);
},
update(discussionId, noteId, resolved, resolved_by) {
const discussion = this.state[discussionId];
const note = discussion.getNote(noteId);
note.resolved = resolved;
note.resolved_by = resolved_by;
},
delete(discussionId, noteId) {
const discussion = this.state[discussionId];
discussion.deleteNote(noteId);
if (discussion.notesCount() === 0) {
Vue.delete(this.state, discussionId);
}
},
unresolvedDiscussionIds() {
const ids = [];
for (const discussionId in this.state) {
const discussion = this.state[discussionId];
if (!discussion.isResolved()) {
ids.push(discussion.id);
}
}
return ids;
},
};