note_header.vue 2.8 KB
Newer Older
1
<script>
F
Fatih Acet 已提交
2 3
import { mapActions } from 'vuex';
import timeAgoTooltip from '../../vue_shared/components/time_ago_tooltip.vue';
4

F
Fatih Acet 已提交
5 6 7 8 9 10 11
export default {
  components: {
    timeAgoTooltip,
  },
  props: {
    author: {
      type: Object,
12 13
      required: false,
      default: () => ({}),
F
Filipa Lacerda 已提交
14
    },
F
Fatih Acet 已提交
15 16
    createdAt: {
      type: String,
17 18
      required: false,
      default: null,
19
    },
F
Fatih Acet 已提交
20 21 22 23
    actionText: {
      type: String,
      required: false,
      default: '',
24
    },
F
Fatih Acet 已提交
25
    noteId: {
26 27 28
      type: [String, Number],
      required: false,
      default: null,
F
Fatih Acet 已提交
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47
    },
    includeToggle: {
      type: Boolean,
      required: false,
      default: false,
    },
    expanded: {
      type: Boolean,
      required: false,
      default: true,
    },
  },
  computed: {
    toggleChevronClass() {
      return this.expanded ? 'fa-chevron-up' : 'fa-chevron-down';
    },
    noteTimestampLink() {
      return `#note_${this.noteId}`;
    },
F
Fatih Acet 已提交
48 49 50
    hasAuthor() {
      return this.author && Object.keys(this.author).length;
    },
F
Fatih Acet 已提交
51 52 53 54 55 56 57 58 59 60 61
  },
  methods: {
    ...mapActions(['setTargetNoteHash']),
    handleToggle() {
      this.$emit('toggleHandler');
    },
    updateTargetNoteHash() {
      this.setTargetNoteHash(this.noteTimestampLink);
    },
  },
};
62 63 64 65
</script>

<template>
  <div class="note-header-info">
M
Mike Greiling 已提交
66
    <div v-if="includeToggle" class="discussion-actions">
67 68
      <button
        class="note-action-button discussion-toggle-button js-vue-toggle-button"
69
        type="button"
M
Mike Greiling 已提交
70 71
        @click="handleToggle"
      >
72
        <i :class="toggleChevronClass" class="fa" aria-hidden="true"></i>
73
        {{ __('Toggle discussion') }}
74 75
      </button>
    </div>
76 77 78 79 80 81 82 83
    <a
      v-if="hasAuthor"
      v-once
      :href="author.path"
      class="js-user-link"
      :data-user-id="author.id"
      :data-username="author.username"
    >
84
      <slot name="note-header-info"></slot>
85
      <span class="note-header-author-name bold">{{ author.name }}</span>
M
Mike Greiling 已提交
86
      <span v-if="author.status_tooltip_html" v-html="author.status_tooltip_html"></span>
87
      <span class="note-headline-light">@{{ author.username }}</span>
88
    </a>
89
    <span v-else>{{ __('A deleted user') }}</span>
90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108
    <span class="note-headline-light note-headline-meta">
      <span class="system-note-message"> <slot></slot> </span>
      <template v-if="createdAt">
        <span class="system-note-separator">
          <template v-if="actionText">{{ actionText }}</template>
        </span>
        <a
          :href="noteTimestampLink"
          class="note-timestamp system-note-separator"
          @click="updateTargetNoteHash"
        >
          <time-ago-tooltip :time="createdAt" tooltip-placement="bottom" />
        </a>
      </template>
      <i
        class="fa fa-spinner fa-spin editing-spinner"
        aria-label="Comment is being updated"
        aria-hidden="true"
      ></i>
109 110 111
    </span>
  </div>
</template>