debian-mirror-gitlab/app/assets/javascripts/environments/components/environment_item.vue

574 lines
15 KiB
Vue
Raw Normal View History

2017-08-17 22:00:37 +05:30
<script>
2018-11-18 11:00:15 +05:30
import Timeago from 'timeago.js';
import _ from 'underscore';
2019-02-15 15:39:39 +05:30
import { GlTooltipDirective } from '@gitlab/ui';
2018-11-18 11:00:15 +05:30
import UserAvatarLink from '~/vue_shared/components/user_avatar/user_avatar_link.vue';
import { humanize } from '~/lib/utils/text_utility';
2018-12-13 13:39:08 +05:30
import Icon from '~/vue_shared/components/icon.vue';
2018-11-18 11:00:15 +05:30
import ActionsComponent from './environment_actions.vue';
import ExternalUrlComponent from './environment_external_url.vue';
import StopComponent from './environment_stop.vue';
import RollbackComponent from './environment_rollback.vue';
import TerminalButtonComponent from './environment_terminal_button.vue';
import MonitoringButtonComponent from './environment_monitoring.vue';
import CommitComponent from '../../vue_shared/components/commit.vue';
import eventHub from '../event_hub';
2018-12-13 13:39:08 +05:30
import { convertObjectPropsToCamelCase } from '~/lib/utils/common_utils';
2019-02-15 15:39:39 +05:30
import { CLUSTER_TYPE } from '~/clusters/constants';
2018-11-18 11:00:15 +05:30
/**
2018-12-13 13:39:08 +05:30
* Environment Item Component
2018-11-18 11:00:15 +05:30
*
* Renders a table row for each environment.
*/
const timeagoInstance = new Timeago();
export default {
components: {
UserAvatarLink,
CommitComponent,
2018-12-13 13:39:08 +05:30
Icon,
2018-11-18 11:00:15 +05:30
ActionsComponent,
ExternalUrlComponent,
StopComponent,
RollbackComponent,
TerminalButtonComponent,
MonitoringButtonComponent,
},
directives: {
2019-02-15 15:39:39 +05:30
GlTooltip: GlTooltipDirective,
2018-11-18 11:00:15 +05:30
},
props: {
model: {
type: Object,
required: true,
default: () => ({}),
},
canCreateDeployment: {
type: Boolean,
required: false,
default: false,
},
canReadEnvironment: {
type: Boolean,
required: false,
default: false,
},
},
computed: {
/**
2018-12-13 13:39:08 +05:30
* Verifies if `last_deployment` key exists in the current Environment.
2018-11-18 11:00:15 +05:30
* This key is required to render most of the html - this method works has
* an helper.
*
* @returns {Boolean}
*/
hasLastDeploymentKey() {
if (this.model && this.model.last_deployment && !_.isEmpty(this.model.last_deployment)) {
return true;
}
return false;
},
/**
* Checkes whether the environment is protected.
* (`is_protected` currently only set in EE)
*
* @returns {Boolean}
*/
isProtected() {
return this.model && this.model.is_protected;
},
2019-02-15 15:39:39 +05:30
/**
* Hide group cluster features which are not currently implemented.
*
* @returns {Boolean}
*/
disableGroupClusterFeatures() {
return this.model && this.model.cluster_type === CLUSTER_TYPE.GROUP;
},
2018-11-18 11:00:15 +05:30
/**
* Returns whether the environment can be stopped.
*
* @returns {Boolean}
*/
canStopEnvironment() {
return this.model && this.model.can_stop;
},
/**
* 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|Undefined}
*/
canRetry() {
return (
this.model &&
this.hasLastDeploymentKey &&
this.model.last_deployment &&
this.model.last_deployment.deployable &&
this.model.last_deployment.deployable.retry_path
);
},
/**
* Verifies if the date to be shown is present.
*
* @returns {Boolean|Undefined}
*/
canShowDate() {
return (
this.model &&
this.model.last_deployment &&
this.model.last_deployment.deployable &&
this.model.last_deployment.deployable !== undefined
);
},
/**
* Human readable date.
*
* @returns {String}
*/
createdDate() {
if (
this.model &&
this.model.last_deployment &&
this.model.last_deployment.deployable &&
this.model.last_deployment.deployable.created_at
) {
return timeagoInstance.format(this.model.last_deployment.deployable.created_at);
}
return '';
},
2018-12-13 13:39:08 +05:30
actions() {
if (!this.model || !this.model.last_deployment || !this.canCreateDeployment) {
return [];
2018-11-18 11:00:15 +05:30
}
2018-12-13 13:39:08 +05:30
const { manualActions, scheduledActions } = convertObjectPropsToCamelCase(
this.model.last_deployment,
{ deep: true },
);
const combinedActions = (manualActions || []).concat(scheduledActions || []);
return combinedActions.map(action => ({
...action,
name: humanize(action.name),
}));
2018-11-18 11:00:15 +05:30
},
/**
* Builds the string used in the user image alt attribute.
*
* @returns {String}
*/
userImageAltDescription() {
if (
this.model &&
this.model.last_deployment &&
this.model.last_deployment.user &&
this.model.last_deployment.user.username
) {
return `${this.model.last_deployment.user.username}'s avatar'`;
}
return '';
},
/**
* If provided, returns the commit tag.
*
* @returns {String|Undefined}
*/
commitTag() {
if (this.model && this.model.last_deployment && this.model.last_deployment.tag) {
return this.model.last_deployment.tag;
}
return undefined;
},
/**
* If provided, returns the commit ref.
*
* @returns {Object|Undefined}
*/
commitRef() {
if (this.model && this.model.last_deployment && this.model.last_deployment.ref) {
return this.model.last_deployment.ref;
}
return undefined;
},
/**
* If provided, returns the commit url.
*
* @returns {String|Undefined}
*/
commitUrl() {
if (
this.model &&
this.model.last_deployment &&
this.model.last_deployment.commit &&
this.model.last_deployment.commit.commit_path
) {
return this.model.last_deployment.commit.commit_path;
}
return undefined;
},
/**
* If provided, returns the commit short sha.
*
* @returns {String|Undefined}
*/
commitShortSha() {
if (
this.model &&
this.model.last_deployment &&
this.model.last_deployment.commit &&
this.model.last_deployment.commit.short_id
) {
return this.model.last_deployment.commit.short_id;
}
return undefined;
},
/**
* If provided, returns the commit title.
*
* @returns {String|Undefined}
*/
commitTitle() {
if (
this.model &&
this.model.last_deployment &&
this.model.last_deployment.commit &&
this.model.last_deployment.commit.title
) {
return this.model.last_deployment.commit.title;
}
return undefined;
},
/**
* If provided, returns the commit tag.
*
* @returns {Object|Undefined}
*/
commitAuthor() {
if (
this.model &&
this.model.last_deployment &&
this.model.last_deployment.commit &&
this.model.last_deployment.commit.author
) {
return this.model.last_deployment.commit.author;
}
return undefined;
},
/**
* Verifies if the `retry_path` key is present and returns its value.
*
* @returns {String|Undefined}
*/
retryUrl() {
if (
this.model &&
this.model.last_deployment &&
this.model.last_deployment.deployable &&
this.model.last_deployment.deployable.retry_path
) {
return this.model.last_deployment.deployable.retry_path;
}
return undefined;
},
/**
* Verifies if the `last?` key is present and returns its value.
*
* @returns {Boolean|Undefined}
*/
isLastDeployment() {
return this.model && this.model.last_deployment && this.model.last_deployment['last?'];
},
/**
* Builds the name of the builds needed to display both the name and the id.
*
* @returns {String}
*/
buildName() {
if (this.model && this.model.last_deployment && this.model.last_deployment.deployable) {
const { deployable } = this.model.last_deployment;
return `${deployable.name} #${deployable.id}`;
}
return '';
},
/**
* Builds the needed string to show the internal id.
*
* @returns {String}
*/
deploymentInternalId() {
if (this.model && this.model.last_deployment && this.model.last_deployment.iid) {
return `#${this.model.last_deployment.iid}`;
}
return '';
},
/**
* Verifies if the user object is present under last_deployment object.
*
* @returns {Boolean}
*/
deploymentHasUser() {
return (
this.model &&
!_.isEmpty(this.model.last_deployment) &&
!_.isEmpty(this.model.last_deployment.user)
);
},
/**
* Returns the user object nested with the last_deployment object.
* Used to render the template.
*
* @returns {Object}
*/
deploymentUser() {
if (
this.model &&
!_.isEmpty(this.model.last_deployment) &&
!_.isEmpty(this.model.last_deployment.user)
) {
return this.model.last_deployment.user;
}
return {};
},
/**
* Verifies if the build name column should be rendered by verifing
* if all the information needed is present
* and if the environment is not a folder.
*
* @returns {Boolean}
*/
shouldRenderBuildName() {
return (
!this.model.isFolder &&
!_.isEmpty(this.model.last_deployment) &&
!_.isEmpty(this.model.last_deployment.deployable)
);
},
/**
* Verifies the presence of all the keys needed to render the buil_path.
*
* @return {String}
*/
buildPath() {
if (
this.model &&
this.model.last_deployment &&
this.model.last_deployment.deployable &&
this.model.last_deployment.deployable.build_path
) {
return this.model.last_deployment.deployable.build_path;
}
return '';
},
/**
* Verifies the presence of all the keys needed to render the external_url.
*
* @return {String}
*/
externalURL() {
if (this.model && this.model.external_url) {
return this.model.external_url;
}
return '';
},
/**
* Verifies if deplyment internal ID should be rendered by verifing
* if all the information needed is present
* and if the environment is not a folder.
*
* @returns {Boolean}
*/
shouldRenderDeploymentID() {
return (
!this.model.isFolder &&
!_.isEmpty(this.model.last_deployment) &&
this.model.last_deployment.iid !== undefined
);
},
environmentPath() {
if (this.model && this.model.environment_path) {
return this.model.environment_path;
}
return '';
},
monitoringUrl() {
if (this.model && this.model.metrics_path) {
return this.model.metrics_path;
}
return '';
},
displayEnvironmentActions() {
return (
2018-12-13 13:39:08 +05:30
this.actions.length > 0 ||
2018-11-18 11:00:15 +05:30
this.externalURL ||
this.monitoringUrl ||
this.canStopEnvironment ||
this.canRetry
);
},
2018-12-13 13:39:08 +05:30
folderIconName() {
return this.model.isOpen ? 'chevron-down' : 'chevron-right';
},
2018-11-18 11:00:15 +05:30
},
methods: {
onClickFolder() {
eventHub.$emit('toggleFolder', this.model);
},
},
};
2017-08-17 22:00:37 +05:30
</script>
<template>
2017-09-10 17:25:29 +05:30
<div
2018-03-17 18:26:18 +05:30
:class="{
'js-child-row environment-child-row': model.isChildren,
'folder-row': model.isFolder,
}"
2018-11-08 19:23:39 +05:30
class="gl-responsive-table-row"
2019-02-15 15:39:39 +05:30
role="row"
>
2018-03-17 18:26:18 +05:30
<div
2019-02-15 15:39:39 +05:30
v-gl-tooltip
2018-12-05 23:21:45 +05:30
:title="model.name"
class="table-section section-wrap section-15 text-truncate"
2018-03-17 18:26:18 +05:30
role="gridcell"
>
2019-02-15 15:39:39 +05:30
<div v-if="!model.isFolder" class="table-mobile-header" role="rowheader">
{{ s__('Environments|Environment') }}
2017-09-10 17:25:29 +05:30
</div>
2019-02-15 15:39:39 +05:30
<span v-if="!model.isFolder" class="environment-name table-mobile-content">
<a class="qa-environment-link" :href="environmentPath"> {{ model.name }} </a>
2018-11-18 11:00:15 +05:30
</span>
2019-02-15 15:39:39 +05:30
<span v-else class="folder-name" role="button" @click="onClickFolder">
<icon :name="folderIconName" class="folder-icon" />
2017-08-17 22:00:37 +05:30
2019-02-15 15:39:39 +05:30
<icon name="folder" class="folder-icon" />
2017-08-17 22:00:37 +05:30
2019-02-15 15:39:39 +05:30
<span> {{ model.folderName }} </span>
2017-08-17 22:00:37 +05:30
2019-02-15 15:39:39 +05:30
<span class="badge badge-pill"> {{ model.size }} </span>
2017-08-17 22:00:37 +05:30
</span>
2017-09-10 17:25:29 +05:30
</div>
2017-08-17 22:00:37 +05:30
2018-03-17 18:26:18 +05:30
<div
2018-11-08 19:23:39 +05:30
class="table-section section-10 deployment-column d-none d-sm-none d-md-block"
2018-03-17 18:26:18 +05:30
role="gridcell"
>
2019-02-15 15:39:39 +05:30
<span v-if="shouldRenderDeploymentID"> {{ deploymentInternalId }} </span>
2017-08-17 22:00:37 +05:30
<span v-if="!model.isFolder && deploymentHasUser">
by
2017-09-10 17:25:29 +05:30
<user-avatar-link
:link-href="deploymentUser.web_url"
:img-src="deploymentUser.avatar_url"
:img-alt="userImageAltDescription"
:tooltip-text="deploymentUser.username"
2018-11-08 19:23:39 +05:30
class="js-deploy-user-container"
2017-09-10 17:25:29 +05:30
/>
2017-08-17 22:00:37 +05:30
</span>
2017-09-10 17:25:29 +05:30
</div>
2017-08-17 22:00:37 +05:30
2019-02-15 15:39:39 +05:30
<div class="table-section section-15 d-none d-sm-none d-md-block" role="gridcell">
<a v-if="shouldRenderBuildName" :href="buildPath" class="build-link flex-truncate-parent">
2018-03-17 18:26:18 +05:30
<span class="flex-truncate-child">{{ buildName }}</span>
2017-08-17 22:00:37 +05:30
</a>
2017-09-10 17:25:29 +05:30
</div>
2017-08-17 22:00:37 +05:30
2019-02-15 15:39:39 +05:30
<div v-if="!model.isFolder" class="table-section section-20" role="gridcell">
<div role="rowheader" class="table-mobile-header">{{ s__('Environments|Commit') }}</div>
<div v-if="hasLastDeploymentKey" class="js-commit-component table-mobile-content">
2017-08-17 22:00:37 +05:30
<commit-component
:tag="commitTag"
:commit-ref="commitRef"
:commit-url="commitUrl"
:short-sha="commitShortSha"
:title="commitTitle"
2019-02-15 15:39:39 +05:30
:author="commitAuthor"
/>
2017-08-17 22:00:37 +05:30
</div>
2019-02-15 15:39:39 +05:30
<div v-if="!hasLastDeploymentKey" class="commit-title table-mobile-content">
{{ s__('Environments|No deployments yet') }}
2017-09-10 17:25:29 +05:30
</div>
</div>
2017-08-17 22:00:37 +05:30
2019-02-15 15:39:39 +05:30
<div v-if="!model.isFolder" class="table-section section-10" role="gridcell">
<div role="rowheader" class="table-mobile-header">{{ s__('Environments|Updated') }}</div>
<span v-if="canShowDate" class="environment-created-date-timeago table-mobile-content">
2018-03-17 18:26:18 +05:30
{{ createdDate }}
2017-08-17 22:00:37 +05:30
</span>
2017-09-10 17:25:29 +05:30
</div>
<div
v-if="!model.isFolder && displayEnvironmentActions"
class="table-section section-30 table-button-footer"
2019-02-15 15:39:39 +05:30
role="gridcell"
>
<div class="btn-group table-action-buttons" role="group">
2017-08-17 22:00:37 +05:30
<external-url-component
v-if="externalURL && canReadEnvironment"
:external-url="externalURL"
2018-03-17 18:26:18 +05:30
/>
2017-08-17 22:00:37 +05:30
<monitoring-button-component
v-if="monitoringUrl && canReadEnvironment"
:monitoring-url="monitoringUrl"
2018-03-17 18:26:18 +05:30
/>
2017-08-17 22:00:37 +05:30
2019-02-15 15:39:39 +05:30
<actions-component v-if="actions.length > 0" :actions="actions" />
2018-11-18 11:00:15 +05:30
2017-08-17 22:00:37 +05:30
<terminal-button-component
v-if="model && model.terminal_path"
:terminal-path="model.terminal_path"
2019-02-15 15:39:39 +05:30
:disabled="disableGroupClusterFeatures"
2018-03-17 18:26:18 +05:30
/>
2017-08-17 22:00:37 +05:30
<rollback-component
v-if="canRetry && canCreateDeployment"
:is-last-deployment="isLastDeployment"
:retry-url="retryUrl"
2018-03-17 18:26:18 +05:30
/>
2018-11-18 11:00:15 +05:30
2019-02-15 15:39:39 +05:30
<stop-component v-if="canStopEnvironment" :environment="model" />
2017-08-17 22:00:37 +05:30
</div>
2017-09-10 17:25:29 +05:30
</div>
</div>
2017-08-17 22:00:37 +05:30
</template>