description.vue 2.3 KB
Newer Older
1 2
<script>
  import animateMixin from '../mixins/animate';
3
  import TaskList from '../../task_list';
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21

  export default {
    mixins: [animateMixin],
    props: {
      canUpdate: {
        type: Boolean,
        required: true,
      },
      descriptionHtml: {
        type: String,
        required: true,
      },
      descriptionText: {
        type: String,
        required: true,
      },
      taskStatus: {
        type: String,
22 23
        required: false,
        default: '',
24 25 26 27 28 29 30 31 32 33 34 35 36
      },
    },
    data() {
      return {
        preAnimation: false,
        pulseAnimation: false,
      };
    },
    watch: {
      descriptionHtml() {
        this.animateChange();

        this.$nextTick(() => {
37
          this.renderGFM();
38 39 40
        });
      },
      taskStatus() {
41
        this.updateTaskStatusText();
42 43
      },
    },
44 45
    methods: {
      renderGFM() {
46
        $(this.$refs['gfm-content']).renderGFM();
47 48 49

        if (this.canUpdate) {
          // eslint-disable-next-line no-new
50
          new TaskList({
51 52 53 54 55 56
            dataType: 'issue',
            fieldName: 'description',
            selector: '.detail-page-description',
          });
        }
      },
57 58 59 60 61 62 63 64 65 66 67 68 69 70
      updateTaskStatusText() {
        const taskRegexMatches = this.taskStatus.match(/(\d+) of ((?!0)\d+)/);
        const $issuableHeader = $('.issuable-meta');
        const $tasks = $('#task_status', $issuableHeader);
        const $tasksShort = $('#task_status_short', $issuableHeader);

        if (taskRegexMatches) {
          $tasks.text(this.taskStatus);
          $tasksShort.text(`${taskRegexMatches[1]}/${taskRegexMatches[2]} task${taskRegexMatches[2] > 1 ? 's' : ''}`);
        } else {
          $tasks.text('');
          $tasksShort.text('');
        }
      },
71 72 73
    },
    mounted() {
      this.renderGFM();
74
      this.updateTaskStatusText();
75
    },
76 77 78 79 80
  };
</script>

<template>
  <div
Phil Hughes's avatar
Phil Hughes committed
81
    v-if="descriptionHtml"
82 83 84
    class="description"
    :class="{
      'js-task-list-container': canUpdate
85
    }">
86 87 88 89 90 91 92
    <div
      class="wiki"
      :class="{
        'issue-realtime-pre-pulse': preAnimation,
        'issue-realtime-trigger-pulse': pulseAnimation
      }"
      v-html="descriptionHtml"
93
      ref="gfm-content">
94 95 96 97
    </div>
    <textarea
      class="hidden js-task-list-field"
      v-if="descriptionText"
98 99
      v-model="descriptionText">
    </textarea>
100 101
  </div>
</template>