2020-01-14 21:07:45 +00:00
|
|
|
<script>
|
2020-08-26 09:10:16 +00:00
|
|
|
/* eslint-disable vue/no-v-html */
|
2020-01-14 21:07:45 +00:00
|
|
|
import Vue from 'vue';
|
2020-09-25 06:09:42 +00:00
|
|
|
import { GlFormGroup, GlButton, GlModal, GlToast, GlToggle } from '@gitlab/ui';
|
2020-01-14 21:07:45 +00:00
|
|
|
import { mapState, mapActions } from 'vuex';
|
|
|
|
import { __, s__, sprintf } from '~/locale';
|
|
|
|
import { visitUrl, getBaseURL } from '~/lib/utils/url_utility';
|
|
|
|
|
|
|
|
Vue.use(GlToast);
|
|
|
|
|
|
|
|
export default {
|
|
|
|
components: {
|
|
|
|
GlFormGroup,
|
2020-09-25 06:09:42 +00:00
|
|
|
GlButton,
|
2020-01-14 21:07:45 +00:00
|
|
|
GlModal,
|
|
|
|
GlToggle,
|
|
|
|
},
|
|
|
|
formLabels: {
|
|
|
|
createProject: __('Create Project'),
|
|
|
|
},
|
|
|
|
data() {
|
|
|
|
return {
|
|
|
|
modalId: 'delete-self-monitor-modal',
|
|
|
|
};
|
|
|
|
},
|
|
|
|
computed: {
|
|
|
|
...mapState('selfMonitoring', [
|
|
|
|
'projectEnabled',
|
|
|
|
'projectCreated',
|
|
|
|
'showAlert',
|
|
|
|
'projectPath',
|
|
|
|
'loading',
|
|
|
|
'alertContent',
|
|
|
|
]),
|
|
|
|
selfMonitorEnabled: {
|
|
|
|
get() {
|
|
|
|
return this.projectEnabled;
|
|
|
|
},
|
|
|
|
set(projectEnabled) {
|
|
|
|
this.setSelfMonitor(projectEnabled);
|
|
|
|
},
|
|
|
|
},
|
|
|
|
selfMonitorProjectFullUrl() {
|
|
|
|
return `${getBaseURL()}/${this.projectPath}`;
|
|
|
|
},
|
|
|
|
selfMonitoringFormText() {
|
|
|
|
if (this.projectCreated) {
|
|
|
|
return sprintf(
|
|
|
|
s__(
|
|
|
|
'SelfMonitoring|Enabling this feature creates a %{projectLinkStart}project%{projectLinkEnd} that can be used to monitor the health of your instance.',
|
|
|
|
),
|
|
|
|
{
|
|
|
|
projectLinkStart: `<a href="${this.selfMonitorProjectFullUrl}">`,
|
|
|
|
projectLinkEnd: '</a>',
|
|
|
|
},
|
|
|
|
false,
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
return s__(
|
|
|
|
'SelfMonitoring|Enabling this feature creates a project that can be used to monitor the health of your instance.',
|
|
|
|
);
|
|
|
|
},
|
|
|
|
},
|
|
|
|
watch: {
|
|
|
|
selfMonitorEnabled() {
|
|
|
|
this.saveChangesSelfMonitorProject();
|
|
|
|
},
|
|
|
|
showAlert() {
|
|
|
|
let toastOptions = {
|
|
|
|
onComplete: () => {
|
|
|
|
this.resetAlert();
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
if (this.showAlert) {
|
|
|
|
if (this.alertContent.actionName && this.alertContent.actionName.length > 0) {
|
|
|
|
toastOptions = {
|
|
|
|
...toastOptions,
|
|
|
|
action: {
|
|
|
|
text: this.alertContent.actionText,
|
|
|
|
onClick: (_, toastObject) => {
|
|
|
|
this[this.alertContent.actionName]();
|
|
|
|
toastObject.goAway(0);
|
|
|
|
},
|
|
|
|
},
|
|
|
|
};
|
|
|
|
}
|
|
|
|
this.$toast.show(this.alertContent.message, toastOptions);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
},
|
|
|
|
methods: {
|
|
|
|
...mapActions('selfMonitoring', [
|
|
|
|
'setSelfMonitor',
|
|
|
|
'createProject',
|
|
|
|
'deleteProject',
|
|
|
|
'resetAlert',
|
|
|
|
]),
|
|
|
|
hideSelfMonitorModal() {
|
|
|
|
this.$root.$emit('bv::hide::modal', this.modalId);
|
|
|
|
this.setSelfMonitor(true);
|
|
|
|
},
|
|
|
|
showSelfMonitorModal() {
|
|
|
|
this.$root.$emit('bv::show::modal', this.modalId);
|
|
|
|
},
|
|
|
|
saveChangesSelfMonitorProject() {
|
|
|
|
if (this.projectCreated && !this.projectEnabled) {
|
|
|
|
this.showSelfMonitorModal();
|
2020-02-17 21:09:20 +00:00
|
|
|
} else if (!this.projectCreated && !this.loading) {
|
2020-01-14 21:07:45 +00:00
|
|
|
this.createProject();
|
|
|
|
}
|
|
|
|
},
|
|
|
|
viewSelfMonitorProject() {
|
|
|
|
visitUrl(this.selfMonitorProjectFullUrl);
|
|
|
|
},
|
|
|
|
},
|
|
|
|
};
|
|
|
|
</script>
|
|
|
|
<template>
|
|
|
|
<section class="settings no-animate js-self-monitoring-settings">
|
|
|
|
<div class="settings-header">
|
|
|
|
<h4 class="js-section-header">
|
|
|
|
{{ s__('SelfMonitoring|Self monitoring') }}
|
|
|
|
</h4>
|
2020-09-25 06:09:42 +00:00
|
|
|
<gl-button class="js-settings-toggle">{{ __('Expand') }}</gl-button>
|
2020-01-14 21:07:45 +00:00
|
|
|
<p class="js-section-sub-header">
|
|
|
|
{{ s__('SelfMonitoring|Enable or disable instance self monitoring') }}
|
|
|
|
</p>
|
|
|
|
</div>
|
|
|
|
<div class="settings-content">
|
|
|
|
<form name="self-monitoring-form">
|
2020-02-24 12:09:00 +00:00
|
|
|
<p ref="selfMonitoringFormText" v-html="selfMonitoringFormText"></p>
|
2020-01-14 21:07:45 +00:00
|
|
|
<gl-form-group :label="$options.formLabels.createProject" label-for="self-monitor-toggle">
|
|
|
|
<gl-toggle
|
|
|
|
v-model="selfMonitorEnabled"
|
|
|
|
:is-loading="loading"
|
|
|
|
name="self-monitor-toggle"
|
|
|
|
/>
|
|
|
|
</gl-form-group>
|
|
|
|
</form>
|
|
|
|
</div>
|
|
|
|
<gl-modal
|
|
|
|
:title="s__('SelfMonitoring|Disable self monitoring?')"
|
|
|
|
:modal-id="modalId"
|
|
|
|
:ok-title="__('Delete project')"
|
|
|
|
:cancel-title="__('Cancel')"
|
|
|
|
ok-variant="danger"
|
2020-09-25 06:09:42 +00:00
|
|
|
category="primary"
|
2020-01-14 21:07:45 +00:00
|
|
|
@ok="deleteProject"
|
|
|
|
@cancel="hideSelfMonitorModal"
|
|
|
|
>
|
|
|
|
<div>
|
|
|
|
{{
|
|
|
|
s__(
|
|
|
|
'SelfMonitoring|Disabling this feature will delete the self monitoring project. Are you sure you want to delete the project?',
|
|
|
|
)
|
|
|
|
}}
|
|
|
|
</div>
|
|
|
|
</gl-modal>
|
|
|
|
</section>
|
|
|
|
</template>
|