Welcome to mirror list, hosted at ThFree Co, Russian Federation.

discussion.js « models « diff_notes « javascripts « assets « app - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 02c331198053f73982800a908e68caedc67f1657 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
/* eslint-disable space-before-function-paren, camelcase, guard-for-in, no-restricted-syntax, no-unused-vars, max-len */
/* global NoteModel */

import Vue from 'vue';

class DiscussionModel {
  constructor (discussionId) {
    this.id = discussionId;
    this.notes = {};
    this.loading = false;
    this.canResolve = false;
    this.resolved = false;
  }

  createNote (noteObj) {
    Vue.set(this.notes, noteObj.noteId, new NoteModel(this.id, noteObj));

    this.resolved = noteObj.resolved;
  }

  deleteNote (noteId) {
    Vue.delete(this.notes, noteId);
  }

  getNote (noteId) {
    return this.notes[noteId];
  }

  notesCount() {
    return Object.keys(this.notes).length;
  }

  isResolved () {
    return _.every(this.notes, note => note.resolved);
  }

  resolveAllNotes (resolved_by) {
    _.each(this.notes, (note) => {
      if (!note.resolved) {
        note.resolved = true; // eslint-disable-line no-param-reassign
        note.resolved_by = resolved_by; // eslint-disable-line no-param-reassign
      }
    });

    this.resolved = true;
  }

  unResolveAllNotes () {
    _.each(this.notes, (note) => {
      if (note.resolved) {
        note.resolved = false; // eslint-disable-line no-param-reassign
        note.resolved_by = null; // eslint-disable-line no-param-reassign
      }
    });

    this.resolved = false;
  }

  updateHeadline (data) {
    const discussionSelector = `.discussion[data-discussion-id="${this.id}"]`;
    const $discussionHeadline = $(`${discussionSelector} .js-discussion-headline`);

    if (data.discussion_headline_html) {
      if ($discussionHeadline.length) {
        $discussionHeadline.replaceWith(data.discussion_headline_html);
      } else {
        $(`${discussionSelector} .discussion-header`).append(data.discussion_headline_html);
      }

      gl.utils.localTimeAgo($('.js-timeago', `${discussionSelector}`));
    } else {
      $discussionHeadline.remove();
    }
  }

  isResolvable () {
    if (!this.canResolve) {
      return false;
    }

    for (const noteId in this.notes) {
      const note = this.notes[noteId];

      if (note.canResolve) {
        return true;
      }
    }

    return false;
  }
}

window.DiscussionModel = DiscussionModel;