summaryrefslogtreecommitdiff
path: root/app/assets/javascripts/notes/components/note_actions.vue
blob: 45fc6196be43ab02c74824d27f531c29c35e8cd4 (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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
<script>
  import { mapGetters } from 'vuex';
  import emojiSmiling from 'icons/_emoji_slightly_smiling_face.svg';
  import emojiSmile from 'icons/_emoji_smile.svg';
  import emojiSmiley from 'icons/_emoji_smiley.svg';
  import editSvg from 'icons/_icon_pencil.svg';
  import ellipsisSvg from 'icons/_ellipsis_v.svg';
  import loadingIcon from '~/vue_shared/components/loading_icon.vue';
  import tooltip from '~/vue_shared/directives/tooltip';

  export default {
    name: 'noteActions',
    props: {
      authorId: {
        type: Number,
        required: true,
      },
      noteId: {
        type: Number,
        required: true,
      },
      accessLevel: {
        type: String,
        required: false,
        default: '',
      },
      reportAbusePath: {
        type: String,
        required: true,
      },
      canEdit: {
        type: Boolean,
        required: true,
      },
      canDelete: {
        type: Boolean,
        required: true,
      },
      canReportAsAbuse: {
        type: Boolean,
        required: true,
      },
    },
    directives: {
      tooltip,
    },
    components: {
      loadingIcon,
    },
    computed: {
      ...mapGetters([
        'getUserDataByProp',
      ]),
      shouldShowActionsDropdown() {
        return this.currentUserId && (this.canEdit || this.canReportAsAbuse);
      },
      canAddAwardEmoji() {
        return this.currentUserId;
      },
      isAuthoredByCurrentUser() {
        return this.authorId === this.currentUserId;
      },
      currentUserId() {
        return this.getUserDataByProp('id');
      },
    },
    methods: {
      onEdit() {
        this.$emit('handleEdit');
      },
      onDelete() {
        this.$emit('handleDelete');
      },
    },
    created() {
      this.emojiSmiling = emojiSmiling;
      this.emojiSmile = emojiSmile;
      this.emojiSmiley = emojiSmiley;
      this.editSvg = editSvg;
      this.ellipsisSvg = ellipsisSvg;
    },
  };
</script>

<template>
  <div class="note-actions">
    <span
      v-if="accessLevel"
      class="note-role note-role-access">{{accessLevel}}</span>
    <div
      v-if="canAddAwardEmoji"
      class="note-actions-item">
      <a
        v-tooltip
        :class="{ 'js-user-authored': isAuthoredByCurrentUser }"
        class="note-action-button note-emoji-button js-add-award js-note-emoji"
        data-position="right"
        data-placement="bottom"
        data-container="body"
        href="#"
        title="Add reaction">
          <loading-icon :inline="true" />
          <span
            v-html="emojiSmiling"
            class="link-highlight award-control-icon-neutral">
          </span>
          <span
            v-html="emojiSmiley"
            class="link-highlight award-control-icon-positive">
          </span>
          <span
            v-html="emojiSmile"
            class="link-highlight award-control-icon-super-positive">
          </span>
      </a>
    </div>
    <div
      v-if="canEdit"
      class="note-actions-item">
      <button
        @click="onEdit"
        v-tooltip
        type="button"
        title="Edit comment"
        class="note-action-button js-note-edit btn btn-transparent"
        data-container="body"
        data-placement="bottom">
          <span
            v-html="editSvg"
            class="link-highlight"></span>
      </button>
    </div>
    <div
      v-if="shouldShowActionsDropdown"
      class="dropdown more-actions note-actions-item">
      <button
        v-tooltip
        type="button"
        title="More actions"
        class="note-action-button more-actions-toggle btn btn-transparent"
        data-toggle="dropdown"
        data-container="body"
        data-placement="bottom">
          <span
            class="icon"
            v-html="ellipsisSvg"></span>
      </button>
      <ul class="dropdown-menu more-actions-dropdown dropdown-open-left">
        <li v-if="canReportAsAbuse">
          <a :href="reportAbusePath">
            Report as abuse
          </a>
        </li>
        <li v-if="canEdit">
          <button
            @click.prevent="onDelete"
            class="btn btn-transparent js-note-delete js-note-delete"
            type="button">
            <span class="text-danger">
              Delete comment
            </span>
          </button>
        </li>
      </ul>
    </div>
  </div>
</template>