import { getTimeago } from '~/lib/utils/datetime_utility'; import { visitUrl } from '../../lib/utils/url_utility'; import Flash from '../../flash'; import MemoryUsage from './mr_widget_memory_usage'; import StatusIcon from './mr_widget_status_icon.vue'; import MRWidgetService from '../services/mr_widget_service'; export default { name: 'MRWidgetDeployment', props: { mr: { type: Object, required: true }, service: { type: Object, required: true }, }, components: { 'mr-widget-memory-usage': MemoryUsage, 'status-icon': StatusIcon, }, methods: { formatDate(date) { return getTimeago().format(date); }, hasExternalUrls(deployment = {}) { return deployment.external_url && deployment.external_url_formatted; }, hasDeploymentTime(deployment = {}) { return deployment.deployed_at && deployment.deployed_at_formatted; }, hasDeploymentMeta(deployment = {}) { return deployment.url && deployment.name; }, stopEnvironment(deployment) { const msg = 'Are you sure you want to stop this environment?'; const isConfirmed = confirm(msg); // eslint-disable-line if (isConfirmed) { MRWidgetService.stopEnvironment(deployment.stop_url) .then(res => res.data) .then((data) => { if (data.redirect_url) { visitUrl(data.redirect_url); } }) .catch(() => { new Flash('Something went wrong while stopping this environment. Please try again.'); // eslint-disable-line }); } }, }, template: `
Deployed to {{deployment.name}} on