summaryrefslogtreecommitdiff
path: root/app/assets/javascripts/issue_show/components/title.vue
blob: 00002709ac677efd1d207b0d19d973dc3d7277b3 (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
<script>
  import animateMixin from '../mixins/animate';
  import eventHub from '../event_hub';
  import tooltip from '../../vue_shared/directives/tooltip';
  import { spriteIcon } from '../../lib/utils/common_utils';

  export default {
    mixins: [animateMixin],
    data() {
      return {
        preAnimation: false,
        pulseAnimation: false,
        titleEl: document.querySelector('title'),
      };
    },
    props: {
      issuableRef: {
        type: String,
        required: true,
      },
      canUpdate: {
        required: false,
        type: Boolean,
        default: false,
      },
      titleHtml: {
        type: String,
        required: true,
      },
      titleText: {
        type: String,
        required: true,
      },
      showInlineEditButton: {
        type: Boolean,
        required: false,
        default: false,
      },
    },
    directives: {
      tooltip,
    },
    watch: {
      titleHtml() {
        this.setPageTitle();
        this.animateChange();
      },
    },
    computed: {
      pencilIcon() {
        return spriteIcon('pencil', 'link-highlight');
      },
    },
    methods: {
      setPageTitle() {
        const currentPageTitleScope = this.titleEl.innerText.split('·');
        currentPageTitleScope[0] = `${this.titleText} (${this.issuableRef}) `;
        this.titleEl.textContent = currentPageTitleScope.join('·');
      },
      edit() {
        eventHub.$emit('open.form');
      },
    },
  };
</script>

<template>
  <div class="title-container">
    <h2
      class="title"
      :class="{
        'issue-realtime-pre-pulse': preAnimation,
        'issue-realtime-trigger-pulse': pulseAnimation
      }"
      v-html="titleHtml"
    >
    </h2>
    <button
      v-tooltip
      v-if="showInlineEditButton && canUpdate"
      type="button"
      class="btn-blank btn-edit note-action-button"
      v-html="pencilIcon"
      title="Edit title and description"
      data-placement="bottom"
      data-container="body"
      @click="edit"
      >
    </button>
  </div>
</template>