2016-11-16 06:23:36 -05:00
|
|
|
/*= require vue */
|
2016-11-09 05:55:00 -05:00
|
|
|
/* global Vue */
|
|
|
|
(() => {
|
|
|
|
window.gl = window.gl || {};
|
|
|
|
|
2016-11-09 12:36:42 -05:00
|
|
|
window.gl.CommitComponent = Vue.component('commit-component', {
|
2016-11-09 05:55:00 -05:00
|
|
|
|
|
|
|
props: {
|
|
|
|
/**
|
|
|
|
* Indicates the existance of a tag.
|
|
|
|
* Used to render the correct icon, if true will render `fa-tag` icon,
|
|
|
|
* if false will render `fa-code-fork` icon.
|
|
|
|
*/
|
|
|
|
tag: {
|
|
|
|
type: Boolean,
|
|
|
|
required: false,
|
|
|
|
default: false,
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* If provided is used to render the branch name and url.
|
|
|
|
* Should contain the following properties:
|
|
|
|
* name
|
|
|
|
* ref_url
|
|
|
|
*/
|
|
|
|
ref: {
|
|
|
|
type: Object,
|
|
|
|
required: false,
|
2016-11-15 07:07:11 -05:00
|
|
|
default: () => ({}),
|
2016-11-09 05:55:00 -05:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Used to link to the commit sha.
|
|
|
|
*/
|
|
|
|
commit_url: {
|
|
|
|
type: String,
|
|
|
|
required: false,
|
|
|
|
default: '',
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Used to show the commit short_sha that links to the commit url.
|
|
|
|
*/
|
|
|
|
short_sha: {
|
|
|
|
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,
|
2016-11-15 07:07:11 -05:00
|
|
|
default: () => ({}),
|
2016-11-09 05:55:00 -05:00
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
computed: {
|
|
|
|
/**
|
|
|
|
* Used to verify if all the properties needed to render the commit
|
|
|
|
* ref section were provided.
|
|
|
|
*
|
|
|
|
* TODO: Improve this! Use lodash _.has when we have it.
|
|
|
|
*
|
|
|
|
* @returns {Boolean}
|
|
|
|
*/
|
|
|
|
hasRef() {
|
|
|
|
return this.ref && this.ref.name && this.ref.ref_url;
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Used to verify if all the properties needed to render the commit
|
|
|
|
* author section were provided.
|
|
|
|
*
|
|
|
|
* TODO: Improve this! Use lodash _.has when we have it.
|
|
|
|
*
|
|
|
|
* @returns {Boolean}
|
|
|
|
*/
|
|
|
|
hasAuthor() {
|
|
|
|
return this.author &&
|
|
|
|
this.author.avatar_url &&
|
|
|
|
this.author.web_url &&
|
|
|
|
this.author.username;
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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;
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
2016-11-09 13:04:57 -05:00
|
|
|
* In order to reuse the svg instead of copy and paste in this template
|
2016-11-09 05:55:00 -05:00
|
|
|
* we need to render it outside this component using =custom_icon partial.
|
|
|
|
* Make sure it has this structure:
|
|
|
|
* .commit-icon-svg.hidden
|
|
|
|
* svg
|
|
|
|
*
|
|
|
|
* TODO: Find a better way to include SVG
|
|
|
|
*/
|
2016-11-14 06:17:02 -05:00
|
|
|
mounted() {
|
2016-11-09 11:45:45 -05:00
|
|
|
const commitIconContainer = this.$el.querySelector('.commit-icon-container');
|
2016-11-09 05:55:00 -05:00
|
|
|
const commitIcon = document.querySelector('.commit-icon-svg.hidden svg');
|
|
|
|
|
|
|
|
if (commitIconContainer && commitIcon) {
|
2016-11-09 11:45:45 -05:00
|
|
|
commitIconContainer.appendChild(commitIcon.cloneNode(true));
|
2016-11-09 05:55:00 -05:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
template: `
|
|
|
|
<div class="branch-commit">
|
|
|
|
|
|
|
|
<div v-if="hasRef" class="icon-container">
|
|
|
|
<i v-if="tag" class="fa fa-tag"></i>
|
2016-11-16 06:53:05 -05:00
|
|
|
<i v-if="!tag" class="fa fa-code-fork"></i>
|
2016-11-09 05:55:00 -05:00
|
|
|
</div>
|
|
|
|
|
2016-11-14 06:17:02 -05:00
|
|
|
<a v-if="hasRef"
|
|
|
|
class="monospace branch-name"
|
2016-11-21 06:45:22 -05:00
|
|
|
:href="ref.ref_url">
|
|
|
|
{{ref.name}}
|
2016-11-09 05:55:00 -05:00
|
|
|
</a>
|
|
|
|
|
2016-11-21 06:45:22 -05:00
|
|
|
<div class="icon-container commit-icon commit-icon-container"></div>
|
2016-11-09 05:55:00 -05:00
|
|
|
|
2016-11-14 06:17:02 -05:00
|
|
|
<a class="commit-id monospace"
|
2016-11-21 06:45:22 -05:00
|
|
|
:href="commit_url">
|
|
|
|
{{short_sha}}
|
2016-11-09 05:55:00 -05:00
|
|
|
</a>
|
|
|
|
|
|
|
|
<p class="commit-title">
|
|
|
|
<span v-if="title">
|
2016-11-14 06:17:02 -05:00
|
|
|
<a v-if="hasAuthor"
|
|
|
|
class="avatar-image-container"
|
|
|
|
:href="author.web_url">
|
2016-11-09 05:55:00 -05:00
|
|
|
<img
|
2016-11-21 06:45:22 -05:00
|
|
|
class="avatar has-tooltip s20"
|
2016-11-09 05:55:00 -05:00
|
|
|
:src="author.avatar_url"
|
|
|
|
:alt="userImageAltDescription"
|
|
|
|
:title="author.username" />
|
|
|
|
</a>
|
|
|
|
|
2016-11-14 06:17:02 -05:00
|
|
|
<a class="commit-row-message"
|
2016-11-21 06:45:22 -05:00
|
|
|
:href="commit_url">
|
|
|
|
{{title}}
|
2016-11-09 05:55:00 -05:00
|
|
|
</a>
|
|
|
|
</span>
|
|
|
|
<span v-else>
|
|
|
|
Cant find HEAD commit for this branch
|
|
|
|
</span>
|
|
|
|
</p>
|
|
|
|
</div>
|
|
|
|
`,
|
|
|
|
});
|
|
|
|
})();
|