2016-11-09 05:55:00 -05:00
|
|
|
/*= require vue_common_component/commit
|
2016-11-09 12:36:42 -05:00
|
|
|
/*= require ./environment_actions
|
2016-11-09 06:26:27 -05:00
|
|
|
/* globals Vue, timeago */
|
2016-11-09 05:55:00 -05:00
|
|
|
|
2016-10-14 13:38:13 -04:00
|
|
|
(() => {
|
2016-10-19 05:06:03 -04:00
|
|
|
/**
|
|
|
|
* Envrionment Item Component
|
2016-10-26 11:00:16 -04:00
|
|
|
*
|
2016-10-19 05:06:03 -04:00
|
|
|
* Used in a hierarchical structure to show folders with children
|
|
|
|
* in a table.
|
2016-10-26 11:00:16 -04:00
|
|
|
* Recursive component based on [Tree View](https://vuejs.org/examples/tree-view.html)
|
|
|
|
*
|
|
|
|
* See this [issue](https://gitlab.com/gitlab-org/gitlab-ce/issues/22539)
|
2016-10-19 05:06:03 -04:00
|
|
|
* for more information.
|
|
|
|
*/
|
2016-10-26 11:00:16 -04:00
|
|
|
|
2016-10-14 13:38:13 -04:00
|
|
|
window.gl = window.gl || {};
|
|
|
|
window.gl.environmentsList = window.gl.environmentsList || {};
|
2016-10-26 11:00:16 -04:00
|
|
|
|
2016-10-21 07:05:31 -04:00
|
|
|
gl.environmentsList.EnvironmentItem = Vue.component('environment-item', {
|
2016-10-26 11:00:16 -04:00
|
|
|
|
2016-11-09 05:55:00 -05:00
|
|
|
components: {
|
2016-11-09 12:36:42 -05:00
|
|
|
'commit-component': window.gl.CommitComponent,
|
|
|
|
'actions-component': window.gl.environmentsList.ActionsComponent,
|
2016-11-09 05:55:00 -05:00
|
|
|
},
|
2016-10-14 13:38:13 -04:00
|
|
|
|
|
|
|
props: {
|
2016-11-07 13:44:16 -05:00
|
|
|
model: Object,
|
2016-10-14 13:38:13 -04:00
|
|
|
},
|
|
|
|
|
2016-11-07 13:44:16 -05:00
|
|
|
data() {
|
2016-10-14 13:38:13 -04:00
|
|
|
return {
|
2016-11-07 13:44:16 -05:00
|
|
|
open: false,
|
2016-11-09 05:55:00 -05:00
|
|
|
rowClass: {
|
|
|
|
'children-row': this.model['vue-isChildren'],
|
|
|
|
},
|
2016-10-14 13:38:13 -04:00
|
|
|
};
|
|
|
|
},
|
2016-10-24 07:42:01 -04:00
|
|
|
|
2016-10-14 13:38:13 -04:00
|
|
|
computed: {
|
2016-10-26 11:00:16 -04:00
|
|
|
|
2016-10-19 05:06:03 -04:00
|
|
|
/**
|
|
|
|
* If an item has a `children` entry it means it is a folder.
|
|
|
|
* Folder items have different behaviours - it is possible to toggle
|
2016-10-26 11:00:16 -04:00
|
|
|
* them and show their children.
|
2016-10-19 05:06:03 -04:00
|
|
|
*
|
2016-10-24 06:03:08 -04:00
|
|
|
* @returns {Boolean}
|
2016-10-19 05:06:03 -04:00
|
|
|
*/
|
2016-11-07 13:44:16 -05:00
|
|
|
isFolder() {
|
2016-11-09 05:55:00 -05:00
|
|
|
return this.$options.hasKey(this.model, 'children') &&
|
|
|
|
this.model.children.length > 0;
|
2016-10-21 07:05:31 -04:00
|
|
|
},
|
2016-10-24 07:42:01 -04:00
|
|
|
|
2016-10-21 07:05:31 -04:00
|
|
|
/**
|
|
|
|
* If an item is inside a folder structure will return true.
|
|
|
|
* Used for css purposes.
|
|
|
|
*
|
|
|
|
* @returns {Boolean|undefined}
|
|
|
|
*/
|
2016-11-07 13:44:16 -05:00
|
|
|
isChildren() {
|
2016-10-21 07:05:31 -04:00
|
|
|
return this.model['vue-isChildren'];
|
2016-10-24 06:03:08 -04:00
|
|
|
},
|
2016-10-24 07:42:01 -04:00
|
|
|
|
2016-10-24 06:03:08 -04:00
|
|
|
/**
|
|
|
|
* Counts the number of environments in each folder.
|
|
|
|
* Used to show a badge with the counter.
|
|
|
|
*
|
|
|
|
* @returns {Boolean} The number of environments for the current folder
|
|
|
|
*/
|
2016-11-07 13:44:16 -05:00
|
|
|
childrenCounter() {
|
2016-11-09 05:55:00 -05:00
|
|
|
return this.$options.hasKey(this.model, 'children') &&
|
|
|
|
this.model.children.length;
|
2016-11-07 13:44:16 -05:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns the value of the `last?` key sent in the API.
|
|
|
|
* Used to know wich title to render when the environment can be re-deployed
|
|
|
|
*
|
|
|
|
* @returns {Boolean}
|
|
|
|
*/
|
|
|
|
isLast() {
|
2016-11-09 05:55:00 -05:00
|
|
|
return this.$options.hasKey(this.model, 'last_deployment') &&
|
|
|
|
this.model.last_deployment['last?'];
|
2016-11-07 13:44:16 -05:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Verifies if `last_deployment` key exists in the current Envrionment.
|
|
|
|
* This key is required to render most of the html - this method works has
|
|
|
|
* an helper.
|
|
|
|
*
|
|
|
|
* @returns {Boolean}
|
|
|
|
*/
|
|
|
|
hasLastDeploymentKey() {
|
|
|
|
return this.$options.hasKey(this.model, 'last_deployment');
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Verifies is the given environment has manual actions.
|
|
|
|
* Used to verify if we should render them or nor.
|
|
|
|
*
|
2016-11-07 16:53:20 -05:00
|
|
|
* @returns {Boolean}
|
2016-11-07 13:44:16 -05:00
|
|
|
*/
|
|
|
|
hasManualActions() {
|
2016-11-09 05:55:00 -05:00
|
|
|
return this.$options.hasKey(this.model, 'manual_actions') &&
|
|
|
|
this.model.manual_actions.length;
|
2016-11-07 13:44:16 -05:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns the value of the `stoppable?` key provided in the response.
|
|
|
|
*
|
|
|
|
* @returns {Boolean}
|
|
|
|
*/
|
|
|
|
isStoppable() {
|
|
|
|
return this.model['stoppable?'];
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Verifies if the `deployable` key is present in `last_deployment` key.
|
|
|
|
* Used to verify whether we should or not render the rollback partial.
|
|
|
|
*
|
|
|
|
* @returns {Boolean}
|
|
|
|
*/
|
|
|
|
canRetry() {
|
2016-11-09 05:55:00 -05:00
|
|
|
return this.hasLastDeploymentKey &&
|
|
|
|
this.model.last_deployment &&
|
|
|
|
this.$options.hasKey(this.model.last_deployment, 'deployable');
|
2016-11-07 13:44:16 -05:00
|
|
|
},
|
|
|
|
|
2016-11-07 15:52:04 -05:00
|
|
|
/**
|
|
|
|
* Human readable date.
|
|
|
|
*
|
|
|
|
* @returns {String}
|
|
|
|
*/
|
2016-11-07 13:44:16 -05:00
|
|
|
createdDate() {
|
2016-11-09 06:23:04 -05:00
|
|
|
const timeagoInstance = new timeago();
|
|
|
|
|
|
|
|
return timeagoInstance.format(this.model.created_at);
|
2016-11-07 13:44:16 -05:00
|
|
|
},
|
|
|
|
|
2016-11-09 12:36:42 -05:00
|
|
|
/**
|
|
|
|
* Verifies if the environment has any manual actions to be rendered.
|
|
|
|
*
|
|
|
|
* @returns {Boolean}
|
|
|
|
*/
|
|
|
|
hasManualActions() {
|
|
|
|
return this.model.last_deployment &&
|
|
|
|
this.model.last_deployment.manual_actions &&
|
|
|
|
this.model.last_deployment.manual_actions.length > 0;
|
|
|
|
},
|
|
|
|
|
2016-11-07 15:52:04 -05:00
|
|
|
/**
|
|
|
|
* Returns the manual actions with the name parsed.
|
|
|
|
*
|
|
|
|
* @returns {Array.<Object>}
|
|
|
|
*/
|
2016-11-07 13:44:16 -05:00
|
|
|
manualActions() {
|
2016-11-09 12:36:42 -05:00
|
|
|
return this.model.last_deployment.manual_actions.map((action) => {
|
2016-11-07 15:52:04 -05:00
|
|
|
const parsedAction = {
|
|
|
|
name: gl.text.humanize(action.name),
|
|
|
|
play_url: action.play_url,
|
|
|
|
};
|
|
|
|
return parsedAction;
|
|
|
|
});
|
2016-11-07 13:44:16 -05:00
|
|
|
},
|
2016-11-09 05:55:00 -05:00
|
|
|
|
|
|
|
userImageAltDescription() {
|
|
|
|
return `${this.model.last_deployment.user.username}'s avatar'`;
|
|
|
|
},
|
2016-11-09 06:26:27 -05:00
|
|
|
|
2016-11-09 05:55:00 -05:00
|
|
|
/**
|
|
|
|
* If provided, returns the commit tag.
|
|
|
|
*
|
|
|
|
* @returns {String|Undefined}
|
|
|
|
*/
|
|
|
|
commitTag() {
|
|
|
|
if (this.model.last_deployment && this.model.last_deployment.tag) {
|
|
|
|
return this.model.last_deployment.tag;
|
|
|
|
}
|
2016-11-09 06:26:27 -05:00
|
|
|
return undefined;
|
2016-11-09 05:55:00 -05:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* If provided, returns the commit ref.
|
|
|
|
*
|
|
|
|
* @returns {Object|Undefined}
|
|
|
|
*/
|
|
|
|
commitRef() {
|
|
|
|
if (this.model.last_deployment && this.model.last_deployment.ref) {
|
2016-11-09 06:26:27 -05:00
|
|
|
return this.model.last_deployment.ref;
|
2016-11-09 05:55:00 -05:00
|
|
|
}
|
2016-11-09 06:26:27 -05:00
|
|
|
return undefined;
|
2016-11-09 05:55:00 -05:00
|
|
|
},
|
2016-11-09 06:26:27 -05:00
|
|
|
|
2016-11-09 05:55:00 -05:00
|
|
|
/**
|
|
|
|
* If provided, returns the commit url.
|
|
|
|
*
|
|
|
|
* @returns {String|Undefined}
|
|
|
|
*/
|
|
|
|
commitUrl() {
|
|
|
|
if (this.model.last_deployment &&
|
|
|
|
this.model.last_deployment.commit &&
|
|
|
|
this.model.last_deployment.commit.commit_url) {
|
|
|
|
return this.model.last_deployment.commit.commit_url;
|
|
|
|
}
|
2016-11-09 06:26:27 -05:00
|
|
|
return undefined;
|
2016-11-09 05:55:00 -05:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* If provided, returns the commit short sha.
|
|
|
|
*
|
|
|
|
* @returns {String|Undefined}
|
|
|
|
*/
|
|
|
|
commitShortSha() {
|
|
|
|
if (this.model.last_deployment &&
|
|
|
|
this.model.last_deployment.commit &&
|
|
|
|
this.model.last_deployment.commit.short_id) {
|
2016-11-09 06:26:27 -05:00
|
|
|
return this.model.last_deployment.commit.short_id;
|
2016-11-09 05:55:00 -05:00
|
|
|
}
|
2016-11-09 06:26:27 -05:00
|
|
|
return undefined;
|
2016-11-09 05:55:00 -05:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* If provided, returns the commit title.
|
|
|
|
*
|
|
|
|
* @returns {String|Undefined}
|
|
|
|
*/
|
2016-11-09 06:26:27 -05:00
|
|
|
commitTitle() {
|
2016-11-09 05:55:00 -05:00
|
|
|
if (this.model.last_deployment &&
|
|
|
|
this.model.last_deployment.commit &&
|
|
|
|
this.model.last_deployment.commit.title) {
|
2016-11-09 06:26:27 -05:00
|
|
|
return this.model.last_deployment.commit.title;
|
2016-11-09 05:55:00 -05:00
|
|
|
}
|
2016-11-09 06:26:27 -05:00
|
|
|
return undefined;
|
2016-11-09 05:55:00 -05:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* If provided, returns the commit tag.
|
|
|
|
*
|
|
|
|
* @returns {Object|Undefined}
|
|
|
|
*/
|
2016-11-09 06:26:27 -05:00
|
|
|
commitAuthor() {
|
2016-11-09 05:55:00 -05:00
|
|
|
if (this.model.last_deployment &&
|
|
|
|
this.model.last_deployment.commit &&
|
|
|
|
this.model.last_deployment.commit.author) {
|
|
|
|
return this.model.last_deployment.commit.author;
|
|
|
|
}
|
2016-11-09 06:26:27 -05:00
|
|
|
|
|
|
|
return undefined;
|
2016-11-09 05:55:00 -05:00
|
|
|
},
|
2016-11-07 13:44:16 -05:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Helper to verify if key is present in an object.
|
|
|
|
* Can be removed once we start using lodash.
|
|
|
|
*
|
|
|
|
* @param {Object} obj
|
|
|
|
* @param {String} key
|
|
|
|
* @returns {Boolean}
|
|
|
|
*/
|
|
|
|
hasKey(obj, key) {
|
|
|
|
return {}.hasOwnProperty.call(obj, key);
|
2016-10-14 13:38:13 -04:00
|
|
|
},
|
|
|
|
|
|
|
|
methods: {
|
2016-10-19 05:06:03 -04:00
|
|
|
/**
|
|
|
|
* Toggles the visibility of a folders' children.
|
|
|
|
*/
|
2016-11-07 13:44:16 -05:00
|
|
|
toggle() {
|
2016-10-14 13:38:13 -04:00
|
|
|
if (this.isFolder) {
|
|
|
|
this.open = !this.open;
|
|
|
|
}
|
2016-11-07 13:44:16 -05:00
|
|
|
},
|
|
|
|
},
|
2016-11-09 05:55:00 -05:00
|
|
|
|
|
|
|
template: `
|
|
|
|
<tr>
|
|
|
|
<td v-bind:class="rowClass">
|
|
|
|
<a v-if="!isFolder" class="environment-name" :href="model.environment_url">
|
|
|
|
{{model.name}}
|
|
|
|
</a>
|
|
|
|
<span v-else v-on:click="toggle" class="folder-name">
|
|
|
|
<span class="folder-icon">
|
|
|
|
<i v-show="open" class="fa fa-caret-down"></i>
|
|
|
|
<i v-show="!open" class="fa fa-caret-right"></i>
|
|
|
|
</span>
|
|
|
|
|
|
|
|
{{model.name}}
|
|
|
|
|
|
|
|
<span class="badge">
|
|
|
|
{{childrenCounter}}
|
|
|
|
</span>
|
|
|
|
</span>
|
|
|
|
</td>
|
|
|
|
|
|
|
|
<td class="deployment-column">
|
|
|
|
<span v-if="!isFolder && model.last_deployment && model.last_deployment.iid">
|
|
|
|
#{{model.last_deployment.iid}}
|
|
|
|
|
|
|
|
<span v-if="model.last_deployment.user">
|
|
|
|
by
|
|
|
|
<a :href="model.last_deployment.user.web_url">
|
|
|
|
<img class="avatar has-tooltip s20"
|
|
|
|
:src="model.last_deployment.user.avatar_url"
|
|
|
|
:alt="userImageAltDescription"
|
|
|
|
:title="model.last_deployment.user.username" />
|
|
|
|
</a>
|
|
|
|
</span>
|
|
|
|
</span>
|
|
|
|
</td>
|
|
|
|
|
|
|
|
<td>
|
|
|
|
<a v-if="!isFolder && model.last_deployment && model.last_deployment.deployable"
|
|
|
|
class="build-link"
|
|
|
|
:href="model.last_deployment.deployable.build_url">
|
|
|
|
{{model.last_deployment.deployable.name}} #{{model.last_deployment.deployable.id}}
|
|
|
|
</a>
|
|
|
|
</td>
|
|
|
|
|
|
|
|
<td>
|
|
|
|
<div v-if="!isFolder && model.last_deployment">
|
|
|
|
<commit-component
|
|
|
|
:tag="commitTag"
|
|
|
|
:ref="commitRef"
|
|
|
|
:commit_url="commitUrl"
|
|
|
|
:short_sha="commitShortSha"
|
|
|
|
:title="commitTitle"
|
|
|
|
:author="commitAuthor">
|
|
|
|
</commit-component>
|
|
|
|
</div>
|
|
|
|
<p v-if="!isFolder && !model.last_deployment" class="commit-title">
|
|
|
|
No deployments yet
|
|
|
|
</p>
|
|
|
|
</td>
|
|
|
|
|
|
|
|
<td>
|
|
|
|
<span v-if="!isFolder && model.last_deployment" class="environment-created-date-timeago">
|
|
|
|
{{createdDate}}
|
|
|
|
</span>
|
|
|
|
</td>
|
|
|
|
|
|
|
|
<td class="hidden-xs">
|
|
|
|
<div v-if="!isFolder">
|
2016-11-09 12:36:42 -05:00
|
|
|
<div v-if="hasManualActions">
|
|
|
|
<actions-component :actions="manualActions"></actions-component>
|
|
|
|
</div>
|
2016-11-09 05:55:00 -05:00
|
|
|
</div>
|
|
|
|
</td>
|
|
|
|
</tr>
|
|
|
|
|
|
|
|
<tr v-if="open && isFolder"
|
|
|
|
is="environment-item"
|
|
|
|
v-for="model in model.children"
|
|
|
|
:model="model">
|
|
|
|
</tr>
|
|
|
|
`,
|
2016-11-07 13:44:16 -05:00
|
|
|
});
|
2016-10-20 07:09:35 -04:00
|
|
|
})();
|