debian-mirror-gitlab/app/assets/javascripts/notes/components/note_actions.vue

252 lines
6 KiB
Vue
Raw Normal View History

2018-03-17 18:26:18 +05:30
<script>
2018-05-09 12:01:36 +05:30
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 resolveDiscussionSvg from 'icons/_icon_resolve_discussion.svg';
import resolvedDiscussionSvg from 'icons/_icon_status_success_solid.svg';
import ellipsisSvg from 'icons/_ellipsis_v.svg';
import loadingIcon from '~/vue_shared/components/loading_icon.vue';
import tooltip from '~/vue_shared/directives/tooltip';
2018-03-17 18:26:18 +05:30
2018-05-09 12:01:36 +05:30
export default {
name: 'NoteActions',
directives: {
tooltip,
},
components: {
loadingIcon,
},
props: {
authorId: {
type: Number,
required: true,
},
noteId: {
2018-11-20 20:47:30 +05:30
type: String,
2018-05-09 12:01:36 +05:30
required: true,
},
2018-11-08 19:23:39 +05:30
noteUrl: {
type: String,
2018-11-20 20:47:30 +05:30
required: false,
default: '',
2018-11-08 19:23:39 +05:30
},
2018-05-09 12:01:36 +05:30
accessLevel: {
type: String,
required: false,
default: '',
},
reportAbusePath: {
type: String,
required: true,
},
canEdit: {
type: Boolean,
required: true,
},
canAwardEmoji: {
type: Boolean,
required: true,
},
canDelete: {
type: Boolean,
required: true,
},
2018-11-08 19:23:39 +05:30
canResolve: {
type: Boolean,
required: false,
default: false,
},
2018-05-09 12:01:36 +05:30
resolvable: {
type: Boolean,
required: false,
default: false,
},
isResolved: {
type: Boolean,
required: false,
default: false,
},
isResolving: {
type: Boolean,
required: false,
default: false,
},
resolvedBy: {
type: Object,
required: false,
default: () => ({}),
},
canReportAsAbuse: {
type: Boolean,
required: true,
},
},
computed: {
...mapGetters(['getUserDataByProp']),
shouldShowActionsDropdown() {
return this.currentUserId && (this.canEdit || this.canReportAsAbuse);
},
isAuthoredByCurrentUser() {
return this.authorId === this.currentUserId;
},
currentUserId() {
return this.getUserDataByProp('id');
},
resolveButtonTitle() {
let title = 'Mark as resolved';
2018-03-27 19:54:05 +05:30
2018-05-09 12:01:36 +05:30
if (this.resolvedBy) {
title = `Resolved by ${this.resolvedBy.name}`;
}
2018-03-27 19:54:05 +05:30
2018-05-09 12:01:36 +05:30
return title;
},
},
created() {
this.emojiSmiling = emojiSmiling;
this.emojiSmile = emojiSmile;
this.emojiSmiley = emojiSmiley;
this.editSvg = editSvg;
this.ellipsisSvg = ellipsisSvg;
this.resolveDiscussionSvg = resolveDiscussionSvg;
this.resolvedDiscussionSvg = resolvedDiscussionSvg;
},
methods: {
onEdit() {
this.$emit('handleEdit');
},
onDelete() {
this.$emit('handleDelete');
},
onResolve() {
this.$emit('handleResolve');
},
},
};
2018-03-17 18:26:18 +05:30
</script>
<template>
<div class="note-actions">
<span
v-if="accessLevel"
class="note-role user-access-role">
{{ accessLevel }}
</span>
2018-03-27 19:54:05 +05:30
<div
2018-11-08 19:23:39 +05:30
v-if="canResolve"
2018-03-27 19:54:05 +05:30
class="note-actions-item">
<button
v-tooltip
:class="{ 'is-disabled': !resolvable, 'is-active': isResolved }"
:title="resolveButtonTitle"
:aria-label="resolveButtonTitle"
type="button"
2018-11-08 19:23:39 +05:30
class="line-resolve-btn note-action-button"
@click="onResolve">
2018-03-27 19:54:05 +05:30
<template v-if="!isResolving">
<div
v-if="isResolved"
v-html="resolvedDiscussionSvg"></div>
<div
v-else
v-html="resolveDiscussionSvg"></div>
</template>
<loading-icon
v-else
:inline="true"
/>
</button>
</div>
2018-03-17 18:26:18 +05:30
<div
2018-05-09 12:01:36 +05:30
v-if="canAwardEmoji"
2018-03-17 18:26:18 +05:30
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
2018-11-08 19:23:39 +05:30
class="link-highlight award-control-icon-neutral"
v-html="emojiSmiling">
2018-03-17 18:26:18 +05:30
</span>
<span
2018-11-08 19:23:39 +05:30
class="link-highlight award-control-icon-positive"
v-html="emojiSmiley">
2018-03-17 18:26:18 +05:30
</span>
<span
2018-11-08 19:23:39 +05:30
class="link-highlight award-control-icon-super-positive"
v-html="emojiSmile">
2018-03-17 18:26:18 +05:30
</span>
</a>
</div>
<div
v-if="canEdit"
class="note-actions-item">
<button
v-tooltip
type="button"
title="Edit comment"
class="note-action-button js-note-edit btn btn-transparent"
data-container="body"
2018-11-08 19:23:39 +05:30
data-placement="bottom"
@click="onEdit">
2018-03-17 18:26:18 +05:30
<span
2018-11-08 19:23:39 +05:30
class="link-highlight"
v-html="editSvg">
2018-03-17 18:26:18 +05:30
</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>
2018-11-20 20:47:30 +05:30
<li v-if="noteUrl">
2018-11-08 19:23:39 +05:30
<button
:data-clipboard-text="noteUrl"
type="button"
2018-11-20 20:47:30 +05:30
class="btn-default btn-transparent js-btn-copy-note-link"
2018-11-08 19:23:39 +05:30
>
Copy link
</button>
</li>
2018-03-17 18:26:18 +05:30
<li v-if="canEdit">
<button
class="btn btn-transparent js-note-delete js-note-delete"
2018-11-08 19:23:39 +05:30
type="button"
@click.prevent="onDelete">
2018-03-17 18:26:18 +05:30
<span class="text-danger">
Delete comment
</span>
</button>
</li>
</ul>
</div>
</div>
</template>