debian-mirror-gitlab/app/assets/javascripts/jobs/components/environments_block.vue

284 lines
8.7 KiB
Vue
Raw Normal View History

2018-11-20 20:47:30 +05:30
<script>
2020-03-13 15:44:24 +05:30
import { escape as esc, isEmpty } from 'lodash';
2018-12-13 13:39:08 +05:30
import CiIcon from '~/vue_shared/components/ci_icon.vue';
import { sprintf, __ } from '../../locale';
2018-11-20 20:47:30 +05:30
2018-12-13 13:39:08 +05:30
export default {
components: {
CiIcon,
},
props: {
deploymentStatus: {
type: Object,
required: true,
2018-11-20 20:47:30 +05:30
},
2020-03-13 15:44:24 +05:30
deploymentCluster: {
type: Object,
required: false,
default: null,
},
2018-12-13 13:39:08 +05:30
iconStatus: {
type: Object,
required: true,
2018-11-20 20:47:30 +05:30
},
2018-12-13 13:39:08 +05:30
},
computed: {
environment() {
switch (this.deploymentStatus.status) {
case 'last':
2019-12-21 20:55:43 +05:30
return this.lastEnvironmentMessage();
2018-12-13 13:39:08 +05:30
case 'out_of_date':
2019-12-21 20:55:43 +05:30
return this.outOfDateEnvironmentMessage();
2018-12-13 13:39:08 +05:30
case 'failed':
2019-12-21 20:55:43 +05:30
return this.failedEnvironmentMessage();
2018-12-13 13:39:08 +05:30
case 'creating':
2019-12-21 20:55:43 +05:30
return this.creatingEnvironmentMessage();
2018-12-13 13:39:08 +05:30
default:
2019-12-21 20:55:43 +05:30
return '';
2018-12-13 13:39:08 +05:30
}
2018-12-05 23:21:45 +05:30
},
2018-12-13 13:39:08 +05:30
environmentLink() {
if (this.hasEnvironment) {
2018-11-20 20:47:30 +05:30
return sprintf(
'%{startLink}%{name}%{endLink}',
{
2019-09-30 21:07:59 +05:30
startLink: `<a href="${this.deploymentStatus.environment.environment_path}" class="js-environment-link">`,
2020-03-13 15:44:24 +05:30
name: esc(this.deploymentStatus.environment.name),
2018-11-20 20:47:30 +05:30
endLink: '</a>',
},
false,
);
2018-12-13 13:39:08 +05:30
}
return '';
},
hasLastDeployment() {
return this.hasEnvironment && this.deploymentStatus.environment.last_deployment;
},
lastDeployment() {
return this.hasLastDeployment ? this.deploymentStatus.environment.last_deployment : {};
},
hasEnvironment() {
2020-03-13 15:44:24 +05:30
return !isEmpty(this.deploymentStatus.environment);
2018-12-13 13:39:08 +05:30
},
lastDeploymentPath() {
2020-03-13 15:44:24 +05:30
return !isEmpty(this.lastDeployment.deployable)
2018-12-13 13:39:08 +05:30
? this.lastDeployment.deployable.build_path
: '';
},
2019-12-04 20:38:33 +05:30
hasCluster() {
2020-03-13 15:44:24 +05:30
return Boolean(this.deploymentCluster) && Boolean(this.deploymentCluster.name);
2019-12-04 20:38:33 +05:30
},
clusterNameOrLink() {
if (!this.hasCluster) {
return '';
}
2020-03-13 15:44:24 +05:30
const { name, path } = this.deploymentCluster;
const escapedName = esc(name);
const escapedPath = esc(path);
2019-12-04 20:38:33 +05:30
if (!escapedPath) {
return escapedName;
}
return sprintf(
'%{startLink}%{name}%{endLink}',
{
startLink: `<a href="${escapedPath}" class="js-job-cluster-link">`,
name: escapedName,
endLink: '</a>',
},
false,
);
},
2020-03-13 15:44:24 +05:30
kubernetesNamespace() {
return this.hasCluster ? this.deploymentCluster.kubernetes_namespace : null;
},
2018-12-13 13:39:08 +05:30
},
methods: {
deploymentLink(name) {
return sprintf(
'%{startLink}%{name}%{endLink}',
{
startLink: `<a href="${this.lastDeploymentPath}" class="js-job-deployment-link">`,
name,
endLink: '</a>',
},
false,
);
2018-11-20 20:47:30 +05:30
},
2019-12-21 20:55:43 +05:30
failedEnvironmentMessage() {
const { environmentLink } = this;
return sprintf(
__('The deployment of this job to %{environmentLink} did not succeed.'),
{ environmentLink },
false,
);
},
lastEnvironmentMessage() {
2020-03-13 15:44:24 +05:30
const { environmentLink, clusterNameOrLink, hasCluster, kubernetesNamespace } = this;
if (hasCluster) {
if (kubernetesNamespace) {
return sprintf(
__(
'This job is deployed to %{environmentLink} using cluster %{clusterNameOrLink} and namespace %{kubernetesNamespace}.',
),
{ environmentLink, clusterNameOrLink, kubernetesNamespace },
false,
);
}
// we know the cluster but not the namespace
return sprintf(
__('This job is deployed to %{environmentLink} using cluster %{clusterNameOrLink}.'),
{ environmentLink, clusterNameOrLink },
false,
);
}
// not a cluster deployment
return sprintf(__('This job is deployed to %{environmentLink}.'), { environmentLink }, false);
2019-12-21 20:55:43 +05:30
},
outOfDateEnvironmentMessage() {
2020-03-13 15:44:24 +05:30
const {
hasLastDeployment,
hasCluster,
environmentLink,
clusterNameOrLink,
kubernetesNamespace,
} = this;
2019-12-21 20:55:43 +05:30
if (hasLastDeployment) {
2020-03-13 15:44:24 +05:30
const deploymentLink = this.deploymentLink(__('most recent deployment'));
if (hasCluster) {
if (kubernetesNamespace) {
return sprintf(
__(
'This job is an out-of-date deployment to %{environmentLink} using cluster %{clusterNameOrLink} and namespace %{kubernetesNamespace}. View the %{deploymentLink}.',
),
{ environmentLink, clusterNameOrLink, kubernetesNamespace, deploymentLink },
false,
2019-12-21 20:55:43 +05:30
);
2020-03-13 15:44:24 +05:30
}
// we know the cluster but not the namespace
return sprintf(
__(
'This job is an out-of-date deployment to %{environmentLink} using cluster %{clusterNameOrLink}. View the %{deploymentLink}.',
),
{ environmentLink, clusterNameOrLink, deploymentLink },
false,
);
}
// not a cluster deployment
2019-12-21 20:55:43 +05:30
return sprintf(
2020-03-13 15:44:24 +05:30
__(
'This job is an out-of-date deployment to %{environmentLink}. View the %{deploymentLink}.',
),
{ environmentLink, deploymentLink },
2019-12-21 20:55:43 +05:30
false,
);
}
2020-03-13 15:44:24 +05:30
// no last deployment, i.e. this is the first deployment
if (hasCluster) {
if (kubernetesNamespace) {
return sprintf(
__(
'This job is an out-of-date deployment to %{environmentLink} using cluster %{clusterNameOrLink} and namespace %{kubernetesNamespace}.',
),
{ environmentLink, clusterNameOrLink, kubernetesNamespace },
false,
);
}
// we know the cluster but not the namespace
return sprintf(
__(
2019-12-21 20:55:43 +05:30
'This job is an out-of-date deployment to %{environmentLink} using cluster %{clusterNameOrLink}.',
2020-03-13 15:44:24 +05:30
),
{ environmentLink, clusterNameOrLink },
false,
);
}
// not a cluster deployment
2019-12-21 20:55:43 +05:30
return sprintf(
2020-03-13 15:44:24 +05:30
__('This job is an out-of-date deployment to %{environmentLink}.'),
{ environmentLink },
2019-12-21 20:55:43 +05:30
false,
);
},
creatingEnvironmentMessage() {
2020-03-13 15:44:24 +05:30
const {
hasLastDeployment,
hasCluster,
environmentLink,
clusterNameOrLink,
kubernetesNamespace,
} = this;
2019-12-21 20:55:43 +05:30
if (hasLastDeployment) {
2020-03-13 15:44:24 +05:30
const deploymentLink = this.deploymentLink(__('latest deployment'));
if (hasCluster) {
if (kubernetesNamespace) {
return sprintf(
__(
'This job is creating a deployment to %{environmentLink} using cluster %{clusterNameOrLink} and namespace %{kubernetesNamespace}. This will overwrite the %{deploymentLink}.',
),
{ environmentLink, clusterNameOrLink, kubernetesNamespace, deploymentLink },
false,
2019-12-21 20:55:43 +05:30
);
2020-03-13 15:44:24 +05:30
}
// we know the cluster but not the namespace
return sprintf(
__(
'This job is creating a deployment to %{environmentLink} using cluster %{clusterNameOrLink}. This will overwrite the %{deploymentLink}.',
),
{ environmentLink, clusterNameOrLink, deploymentLink },
false,
);
}
// not a cluster deployment
2019-12-21 20:55:43 +05:30
return sprintf(
2020-03-13 15:44:24 +05:30
__(
'This job is creating a deployment to %{environmentLink}. This will overwrite the %{deploymentLink}.',
),
{ environmentLink, deploymentLink },
2019-12-21 20:55:43 +05:30
false,
);
}
2020-03-13 15:44:24 +05:30
// no last deployment, i.e. this is the first deployment
if (hasCluster) {
if (kubernetesNamespace) {
return sprintf(
__(
'This job is creating a deployment to %{environmentLink} using cluster %{clusterNameOrLink} and namespace %{kubernetesNamespace}.',
),
{ environmentLink, clusterNameOrLink, kubernetesNamespace },
false,
);
}
// we know the cluster but not the namespace
return sprintf(
__(
'This job is creating a deployment to %{environmentLink} using cluster %{clusterNameOrLink}.',
),
{ environmentLink, clusterNameOrLink },
false,
);
}
// not a cluster deployment
2019-12-21 20:55:43 +05:30
return sprintf(
__('This job is creating a deployment to %{environmentLink}.'),
{ environmentLink },
false,
);
},
2018-12-13 13:39:08 +05:30
},
};
2018-11-20 20:47:30 +05:30
</script>
<template>
2019-02-15 15:39:39 +05:30
<div class="prepend-top-default append-bottom-default js-environment-container">
2018-11-20 20:47:30 +05:30
<div class="environment-information">
2019-02-15 15:39:39 +05:30
<ci-icon :status="iconStatus" />
<p class="inline append-bottom-0" v-html="environment"></p>
2018-11-20 20:47:30 +05:30
</div>
</div>
</template>