debian-mirror-gitlab/app/assets/javascripts/vue_shared/components/commit.vue

174 lines
3.8 KiB
Vue
Raw Normal View History

2017-09-10 17:25:29 +05:30
<script>
2018-10-15 14:42:47 +05:30
import UserAvatarLink from './user_avatar/user_avatar_link.vue';
2019-01-03 12:48:30 +05:30
import tooltip from '../directives/tooltip';
2018-10-15 14:42:47 +05:30
import Icon from '../../vue_shared/components/icon.vue';
2017-09-10 17:25:29 +05:30
2018-10-15 14:42:47 +05:30
export default {
directives: {
2019-01-03 12:48:30 +05:30
tooltip,
2018-10-15 14:42:47 +05:30
},
components: {
UserAvatarLink,
Icon,
},
props: {
/**
2018-12-13 13:39:08 +05:30
* Indicates the existence of a tag.
2018-10-15 14:42:47 +05:30
* Used to render the correct icon, if true will render `fa-tag` icon,
* if false will render a svg sprite fork icon
*/
tag: {
type: Boolean,
required: false,
default: false,
2018-03-17 18:26:18 +05:30
},
2018-10-15 14:42:47 +05:30
/**
* If provided is used to render the branch name and url.
* Should contain the following properties:
* name
* ref_url
*/
commitRef: {
type: Object,
required: false,
default: () => ({}),
},
/**
* Used to link to the commit sha.
*/
commitUrl: {
type: String,
required: false,
default: '',
2018-03-17 18:26:18 +05:30
},
2017-09-10 17:25:29 +05:30
2018-10-15 14:42:47 +05:30
/**
* Used to show the commit short sha that links to the commit url.
*/
shortSha: {
type: String,
required: false,
default: '',
},
/**
* If provided shows the commit tile.
*/
title: {
type: String,
required: false,
default: '',
},
/**
* If provided renders information about the author of the commit.
* When provided should include:
* `avatar_url` to render the avatar icon
* `web_url` to link to user profile
* `username` to render alt and title tags
*/
author: {
type: Object,
required: false,
default: () => ({}),
},
showBranch: {
type: Boolean,
required: false,
default: true,
2017-09-10 17:25:29 +05:30
},
2018-10-15 14:42:47 +05:30
},
computed: {
/**
* Used to verify if all the properties needed to render the commit
* ref section were provided.
*
* @returns {Boolean}
*/
hasCommitRef() {
return this.commitRef && this.commitRef.name && this.commitRef.ref_url;
2017-09-10 17:25:29 +05:30
},
2018-10-15 14:42:47 +05:30
/**
* Used to verify if all the properties needed to render the commit
* author section were provided.
*
* @returns {Boolean}
*/
hasAuthor() {
return this.author && this.author.avatar_url && this.author.path && this.author.username;
2017-09-10 17:25:29 +05:30
},
2018-10-15 14:42:47 +05:30
/**
* If information about the author is provided will return a string
* to be rendered as the alt attribute of the img tag.
*
* @returns {String}
*/
userImageAltDescription() {
return this.author && this.author.username ? `${this.author.username}'s avatar` : null;
},
},
};
2017-09-10 17:25:29 +05:30
</script>
<template>
<div class="branch-commit">
2018-03-17 18:26:18 +05:30
<template v-if="hasCommitRef && showBranch">
<div class="icon-container">
2019-01-03 12:48:30 +05:30
<i
v-if="tag"
class="fa fa-tag"
aria-hidden="true"
>
</i>
<icon
v-if="!tag"
name="fork"
/>
2018-03-17 18:26:18 +05:30
</div>
2017-09-10 17:25:29 +05:30
2019-01-03 12:48:30 +05:30
<a
v-tooltip
:href="commitRef.ref_url"
:title="commitRef.name"
class="ref-name"
data-container="body"
>
2018-03-17 18:26:18 +05:30
{{ commitRef.name }}
</a>
</template>
2019-01-03 12:48:30 +05:30
<icon
name="commit"
class="commit-icon js-commit-icon"
/>
2017-09-10 17:25:29 +05:30
2019-01-03 12:48:30 +05:30
<a
:href="commitUrl"
class="commit-sha"
>
{{ shortSha }}
</a>
2017-09-10 17:25:29 +05:30
<div class="commit-title flex-truncate-parent">
2019-01-03 12:48:30 +05:30
<span
v-if="title"
class="flex-truncate-child"
>
2017-09-10 17:25:29 +05:30
<user-avatar-link
v-if="hasAuthor"
:link-href="author.path"
:img-src="author.avatar_url"
:img-alt="userImageAltDescription"
:tooltip-text="author.username"
2018-11-08 19:23:39 +05:30
class="avatar-image-container"
2017-09-10 17:25:29 +05:30
/>
2019-01-03 12:48:30 +05:30
<a
:href="commitUrl"
class="commit-row-message"
>
{{ title }}
</a>
</span>
<span v-else>
Can't find HEAD commit for this branch
2017-09-10 17:25:29 +05:30
</span>
</div>
</div>
</template>