debian-mirror-gitlab/app/assets/javascripts/vue_merge_request_widget/components/deployment.vue

246 lines
7.8 KiB
Vue
Raw Normal View History

2018-05-09 12:01:36 +05:30
<script>
2019-02-15 15:39:39 +05:30
import { GlTooltipDirective } from '@gitlab/ui';
2018-11-08 19:23:39 +05:30
import Icon from '~/vue_shared/components/icon.vue';
2018-11-20 20:47:30 +05:30
import TooltipOnTruncate from '~/vue_shared/components/tooltip_on_truncate.vue';
2018-12-13 13:39:08 +05:30
import FilteredSearchDropdown from '~/vue_shared/components/filtered_search_dropdown.vue';
import { __ } from '~/locale';
2018-05-09 12:01:36 +05:30
import timeagoMixin from '../../vue_shared/mixins/timeago';
import LoadingButton from '../../vue_shared/components/loading_button.vue';
import { visitUrl } from '../../lib/utils/url_utility';
import createFlash from '../../flash';
import MemoryUsage from './memory_usage.vue';
import StatusIcon from './mr_widget_status_icon.vue';
2018-12-13 13:39:08 +05:30
import ReviewAppLink from './review_app_link.vue';
2018-05-09 12:01:36 +05:30
import MRWidgetService from '../services/mr_widget_service';
export default {
2019-10-12 21:52:04 +05:30
// name: 'Deployment' is a false positive: https://gitlab.com/gitlab-org/frontend/eslint-plugin-i18n/issues/26#possible-false-positives
// eslint-disable-next-line @gitlab/i18n/no-non-i18n-strings
2018-05-09 12:01:36 +05:30
name: 'Deployment',
components: {
LoadingButton,
MemoryUsage,
StatusIcon,
2018-11-08 19:23:39 +05:30
Icon,
2018-11-20 20:47:30 +05:30
TooltipOnTruncate,
2018-12-13 13:39:08 +05:30
FilteredSearchDropdown,
ReviewAppLink,
2019-09-04 21:01:54 +05:30
VisualReviewAppLink: () =>
import('ee_component/vue_merge_request_widget/components/visual_review_app_link.vue'),
2018-05-09 12:01:36 +05:30
},
directives: {
2018-12-13 13:39:08 +05:30
GlTooltip: GlTooltipDirective,
2018-05-09 12:01:36 +05:30
},
2018-12-13 13:39:08 +05:30
mixins: [timeagoMixin],
2018-05-09 12:01:36 +05:30
props: {
deployment: {
type: Object,
required: true,
},
2019-02-15 15:39:39 +05:30
showMetrics: {
type: Boolean,
required: true,
},
2019-09-04 21:01:54 +05:30
showVisualReviewApp: {
type: Boolean,
required: false,
default: false,
},
visualReviewAppMeta: {
type: Object,
required: false,
default: () => ({
sourceProjectId: '',
sourceProjectPath: '',
mergeRequestId: '',
appUrl: '',
}),
},
2018-05-09 12:01:36 +05:30
},
2018-12-13 13:39:08 +05:30
deployedTextMap: {
running: __('Deploying to'),
success: __('Deployed to'),
failed: __('Failed to deploy to'),
2019-02-15 15:39:39 +05:30
created: __('Will deploy to'),
canceled: __('Failed to deploy to'),
2018-12-13 13:39:08 +05:30
},
2018-05-09 12:01:36 +05:30
data() {
return {
isStopping: false,
};
},
computed: {
deployTimeago() {
return this.timeFormated(this.deployment.deployed_at);
},
2019-07-07 11:18:12 +05:30
deploymentExternalUrl() {
if (this.deployment.changes && this.deployment.changes.length === 1) {
return this.deployment.changes[0].external_url;
}
return this.deployment.external_url;
},
2018-05-09 12:01:36 +05:30
hasExternalUrls() {
2019-09-04 21:01:54 +05:30
return Boolean(this.deployment.external_url && this.deployment.external_url_formatted);
2018-05-09 12:01:36 +05:30
},
hasDeploymentTime() {
2019-09-04 21:01:54 +05:30
return Boolean(this.deployment.deployed_at && this.deployment.deployed_at_formatted);
2018-05-09 12:01:36 +05:30
},
hasDeploymentMeta() {
2019-09-04 21:01:54 +05:30
return Boolean(this.deployment.url && this.deployment.name);
2018-05-09 12:01:36 +05:30
},
hasMetrics() {
2019-09-04 21:01:54 +05:30
return Boolean(this.deployment.metrics_url);
2018-12-13 13:39:08 +05:30
},
deployedText() {
return this.$options.deployedTextMap[this.deployment.status];
},
isDeployInProgress() {
return this.deployment.status === 'running';
},
deployInProgressTooltip() {
return this.isDeployInProgress
? __('Stopping this environment is currently not possible as a deployment is in progress')
: '';
},
shouldRenderDropdown() {
2019-07-07 11:18:12 +05:30
return this.deployment.changes && this.deployment.changes.length > 1;
2019-02-15 15:39:39 +05:30
},
showMemoryUsage() {
return this.hasMetrics && this.showMetrics;
2018-05-09 12:01:36 +05:30
},
},
methods: {
stopEnvironment() {
2018-12-13 13:39:08 +05:30
const msg = __('Are you sure you want to stop this environment?');
2018-05-09 12:01:36 +05:30
const isConfirmed = confirm(msg); // eslint-disable-line
if (isConfirmed) {
this.isStopping = true;
MRWidgetService.stopEnvironment(this.deployment.stop_url)
.then(res => res.data)
2018-12-13 13:39:08 +05:30
.then(data => {
2018-05-09 12:01:36 +05:30
if (data.redirect_url) {
visitUrl(data.redirect_url);
}
this.isStopping = false;
})
.catch(() => {
2019-09-30 21:07:59 +05:30
createFlash(
__('Something went wrong while stopping this environment. Please try again.'),
);
2018-05-09 12:01:36 +05:30
this.isStopping = false;
});
}
},
},
};
</script>
<template>
2019-02-15 15:39:39 +05:30
<div class="deploy-heading">
2018-05-09 12:01:36 +05:30
<div class="ci-widget media">
<div class="media-body">
<div class="deploy-body">
2018-12-13 13:39:08 +05:30
<div class="js-deployment-info deployment-info">
2018-11-08 19:23:39 +05:30
<template v-if="hasDeploymentMeta">
2019-02-15 15:39:39 +05:30
<span> {{ deployedText }} </span>
2018-11-20 20:47:30 +05:30
<tooltip-on-truncate
:title="deployment.name"
truncate-target="child"
class="deploy-link label-truncate"
2018-11-08 19:23:39 +05:30
>
2018-11-20 20:47:30 +05:30
<a
:href="deployment.url"
target="_blank"
rel="noopener noreferrer nofollow"
class="js-deploy-meta"
>
{{ deployment.name }}
</a>
</tooltip-on-truncate>
2018-11-08 19:23:39 +05:30
</template>
<span
v-if="hasDeploymentTime"
2018-12-13 13:39:08 +05:30
v-gl-tooltip
2018-11-08 19:23:39 +05:30
:title="deployment.deployed_at_formatted"
class="js-deploy-time"
2018-05-09 12:01:36 +05:30
>
2018-11-08 19:23:39 +05:30
{{ deployTimeago }}
2018-05-09 12:01:36 +05:30
</span>
2018-11-08 19:23:39 +05:30
<memory-usage
2019-02-15 15:39:39 +05:30
v-if="showMemoryUsage"
2018-11-08 19:23:39 +05:30
:metrics-url="deployment.metrics_url"
:metrics-monitoring-url="deployment.metrics_monitoring_url"
/>
</div>
<div>
2018-12-13 13:39:08 +05:30
<template v-if="hasExternalUrls">
<filtered-search-dropdown
v-if="shouldRenderDropdown"
class="js-mr-wigdet-deployment-dropdown inline"
:items="deployment.changes"
2019-07-07 11:18:12 +05:30
:main-action-link="deploymentExternalUrl"
2018-12-13 13:39:08 +05:30
filter-key="path"
>
2019-02-15 15:39:39 +05:30
<template slot="mainAction" slot-scope="slotProps">
2018-12-13 13:39:08 +05:30
<review-app-link
2019-07-07 11:18:12 +05:30
:link="deploymentExternalUrl"
2018-12-13 13:39:08 +05:30
:css-class="`deploy-link js-deploy-url inline ${slotProps.className}`"
/>
</template>
2019-02-15 15:39:39 +05:30
<template slot="result" slot-scope="slotProps">
2018-12-13 13:39:08 +05:30
<a
:href="slotProps.result.external_url"
target="_blank"
rel="noopener noreferrer nofollow"
class="menu-item"
>
<strong class="str-truncated-100 append-bottom-0 d-block">
{{ slotProps.result.path }}
</strong>
<p class="text-secondary str-truncated-100 append-bottom-0 d-block">
{{ slotProps.result.external_url }}
</p>
</a>
</template>
</filtered-search-dropdown>
2019-09-04 21:01:54 +05:30
<template v-else>
<review-app-link
:link="deploymentExternalUrl"
css-class="js-deploy-url js-deploy-url-feature-flag deploy-link btn btn-default btn-sm inline"
/>
</template>
<visual-review-app-link
v-if="showVisualReviewApp"
2019-07-07 11:18:12 +05:30
:link="deploymentExternalUrl"
2019-09-04 21:01:54 +05:30
:app-metadata="visualReviewAppMeta"
2018-12-13 13:39:08 +05:30
/>
</template>
2019-02-15 15:39:39 +05:30
<span
2018-11-08 19:23:39 +05:30
v-if="deployment.stop_url"
2018-12-13 13:39:08 +05:30
v-gl-tooltip
:title="deployInProgressTooltip"
2019-02-15 15:39:39 +05:30
class="d-inline-block"
2018-12-13 13:39:08 +05:30
tabindex="0"
2018-11-08 19:23:39 +05:30
>
2018-12-13 13:39:08 +05:30
<loading-button
:loading="isStopping"
:disabled="isDeployInProgress"
:title="__('Stop environment')"
container-class="js-stop-env btn btn-default btn-sm inline prepend-left-4"
@click="stopEnvironment"
>
<icon name="stop" />
</loading-button>
</span>
2018-11-08 19:23:39 +05:30
</div>
2018-05-09 12:01:36 +05:30
</div>
</div>
</div>
</div>
</template>