debian-mirror-gitlab/app/assets/javascripts/diff_notes/models/discussion.js

98 lines
2.1 KiB
JavaScript
Raw Normal View History

2017-08-17 22:00:37 +05:30
/* eslint-disable space-before-function-paren, camelcase, guard-for-in, no-restricted-syntax, no-unused-vars, max-len */
/* global NoteModel */
import Vue from 'vue';
2016-09-13 17:45:13 +05:30
class DiscussionModel {
constructor (discussionId) {
this.id = discussionId;
this.notes = {};
this.loading = false;
this.canResolve = false;
}
2017-08-17 22:00:37 +05:30
createNote (noteObj) {
Vue.set(this.notes, noteObj.noteId, new NoteModel(this.id, noteObj));
2016-09-13 17:45:13 +05:30
}
deleteNote (noteId) {
Vue.delete(this.notes, noteId);
}
getNote (noteId) {
return this.notes[noteId];
}
notesCount() {
return Object.keys(this.notes).length;
}
isResolved () {
for (const noteId in this.notes) {
const note = this.notes[noteId];
if (!note.resolved) {
return false;
}
}
return true;
}
resolveAllNotes (resolved_by) {
for (const noteId in this.notes) {
const note = this.notes[noteId];
if (!note.resolved) {
note.resolved = true;
note.resolved_by = resolved_by;
}
}
}
unResolveAllNotes () {
for (const noteId in this.notes) {
const note = this.notes[noteId];
if (note.resolved) {
note.resolved = false;
note.resolved_by = null;
}
}
}
updateHeadline (data) {
2017-08-17 22:00:37 +05:30
const discussionSelector = `.discussion[data-discussion-id="${this.id}"]`;
const $discussionHeadline = $(`${discussionSelector} .js-discussion-headline`);
2016-09-13 17:45:13 +05:30
if (data.discussion_headline_html) {
if ($discussionHeadline.length) {
$discussionHeadline.replaceWith(data.discussion_headline_html);
} else {
2017-08-17 22:00:37 +05:30
$(`${discussionSelector} .discussion-header`).append(data.discussion_headline_html);
2016-09-13 17:45:13 +05:30
}
2017-08-17 22:00:37 +05:30
gl.utils.localTimeAgo($('.js-timeago', `${discussionSelector}`));
2016-09-13 17:45:13 +05:30
} else {
2017-08-17 22:00:37 +05:30
$discussionHeadline.remove();
2016-09-13 17:45:13 +05:30
}
}
isResolvable () {
if (!this.canResolve) {
return false;
}
2017-08-17 22:00:37 +05:30
2016-09-13 17:45:13 +05:30
for (const noteId in this.notes) {
const note = this.notes[noteId];
if (note.canResolve) {
return true;
}
}
return false;
}
}
2017-08-17 22:00:37 +05:30
window.DiscussionModel = DiscussionModel;