summaryrefslogtreecommitdiff
path: root/app/assets/javascripts/issue_show/components/description.vue
blob: 770bf68e0935d52ebc2406b8e01d4d998d64c539 (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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
<script>
  import animateMixin from '../mixins/animate';

  export default {
    mixins: [animateMixin],
    props: {
      canUpdate: {
        type: Boolean,
        required: true,
      },
      descriptionHtml: {
        type: String,
        required: true,
      },
      descriptionText: {
        type: String,
        required: true,
      },
      updatedAt: {
        type: String,
        required: true,
      },
      taskStatus: {
        type: String,
        required: true,
      },
    },
    data() {
      return {
        preAnimation: false,
        pulseAnimation: false,
        timeAgoEl: $('.issue_edited_ago'),
      };
    },
    watch: {
      descriptionHtml() {
        this.animateChange();

        this.$nextTick(() => {
          const toolTipTime = gl.utils.formatDate(this.updatedAt);

          this.timeAgoEl.attr('datetime', this.updatedAt)
            .attr('title', toolTipTime)
            .tooltip('fixTitle');

          this.renderGFM();
        });
      },
      taskStatus() {
        const taskRegexMatches = this.taskStatus.match(/(\d+) of (\d+)/);
        const $issuableHeader = $('.issuable-meta');
        let $tasks = $('#task_status', $issuableHeader);
        let $tasksShort = $('#task_status_short', $issuableHeader);

        if (this.taskStatus.indexOf('0 of 0') >= 0 || this.taskStatus.trim() === '') {
          $tasks.remove();
          $tasksShort.remove();
        } else if (!$tasks.length && !$tasksShort.length) {
          $tasks = $issuableHeader.append('<span id="task_status" class="hidden-xs hidden-sm"></span>')
            .find('#task_status');
          $tasksShort = $issuableHeader.append('<span id="task_status_short" class="hidden-md hidden-lg"></span>')
            .find('#task_status_short');
        }

        if (taskRegexMatches) {
          $tasks.text(this.taskStatus);
          $tasksShort.text(`${taskRegexMatches[1]}/${taskRegexMatches[2]} task${taskRegexMatches[2] > 1 ? 's' : ''}`);
        }
      },
    },
    methods: {
      renderGFM() {
        $(this.$refs['gfm-entry-content']).renderGFM();

        if (this.canUpdate) {
          // eslint-disable-next-line no-new
          new gl.TaskList({
            dataType: 'issue',
            fieldName: 'description',
            selector: '.detail-page-description',
          });
        }
      },
    },
    mounted() {
      this.renderGFM();
    },
  };
</script>

<template>
  <div
    class="description"
    :class="{
      'js-task-list-container': canUpdate
    }">
    <div
      class="wiki"
      :class="{
        'issue-realtime-pre-pulse': preAnimation,
        'issue-realtime-trigger-pulse': pulseAnimation
      }"
      v-html="descriptionHtml"
      ref="gfm-content">
    </div>
    <textarea
      class="hidden js-task-list-field"
      v-if="descriptionText"
      v-model="descriptionText">
    </textarea>
  </div>
</template>