2020-07-17 18:09:20 +00:00
|
|
|
<script>
|
|
|
|
import { GlFormGroup, GlFormInput, GlModal, GlSprintf, GlLink } from '@gitlab/ui';
|
|
|
|
import { mapActions, mapState } from 'vuex';
|
2020-08-17 21:09:56 +00:00
|
|
|
import { isValidCron } from 'cron-validator';
|
2020-07-17 18:09:20 +00:00
|
|
|
import { mapComputed } from '~/vuex_shared/bindings';
|
|
|
|
import { __ } from '~/locale';
|
2020-07-23 18:10:06 +00:00
|
|
|
import TimezoneDropdown from '~/vue_shared/components/timezone_dropdown.vue';
|
2020-07-17 18:09:20 +00:00
|
|
|
|
|
|
|
export default {
|
|
|
|
components: {
|
|
|
|
GlFormGroup,
|
|
|
|
GlFormInput,
|
|
|
|
GlModal,
|
|
|
|
GlSprintf,
|
|
|
|
GlLink,
|
2020-07-23 18:10:06 +00:00
|
|
|
TimezoneDropdown,
|
2020-07-17 18:09:20 +00:00
|
|
|
},
|
|
|
|
modalOptions: {
|
|
|
|
ref: 'modal',
|
2020-08-03 09:09:42 +00:00
|
|
|
modalId: 'deploy-freeze-modal',
|
2020-07-17 18:09:20 +00:00
|
|
|
title: __('Add deploy freeze'),
|
|
|
|
actionCancel: {
|
|
|
|
text: __('Cancel'),
|
|
|
|
},
|
|
|
|
static: true,
|
|
|
|
lazy: true,
|
|
|
|
},
|
|
|
|
translations: {
|
|
|
|
cronPlaceholder: __('* * * * *'),
|
|
|
|
cronSyntaxInstructions: __(
|
|
|
|
'Define a custom deploy freeze pattern with %{cronSyntaxStart}cron syntax%{cronSyntaxEnd}',
|
|
|
|
),
|
|
|
|
},
|
|
|
|
computed: {
|
|
|
|
...mapState([
|
|
|
|
'projectId',
|
|
|
|
'selectedTimezone',
|
|
|
|
'timezoneData',
|
|
|
|
'freezeStartCron',
|
|
|
|
'freezeEndCron',
|
|
|
|
]),
|
|
|
|
...mapComputed([
|
|
|
|
{ key: 'freezeStartCron', updateFn: 'setFreezeStartCron' },
|
|
|
|
{ key: 'freezeEndCron', updateFn: 'setFreezeEndCron' },
|
|
|
|
]),
|
|
|
|
addDeployFreezeButton() {
|
|
|
|
return {
|
|
|
|
text: __('Add deploy freeze'),
|
|
|
|
attributes: [
|
|
|
|
{ variant: 'success' },
|
|
|
|
{
|
|
|
|
disabled:
|
|
|
|
!isValidCron(this.freezeStartCron) ||
|
|
|
|
!isValidCron(this.freezeEndCron) ||
|
|
|
|
!this.selectedTimezone,
|
|
|
|
},
|
|
|
|
],
|
|
|
|
};
|
|
|
|
},
|
|
|
|
invalidFreezeStartCron() {
|
|
|
|
return this.invalidCronMessage(this.freezeStartCronState);
|
|
|
|
},
|
|
|
|
freezeStartCronState() {
|
|
|
|
return Boolean(!this.freezeStartCron || isValidCron(this.freezeStartCron));
|
|
|
|
},
|
|
|
|
invalidFreezeEndCron() {
|
|
|
|
return this.invalidCronMessage(this.freezeEndCronState);
|
|
|
|
},
|
|
|
|
freezeEndCronState() {
|
|
|
|
return Boolean(!this.freezeEndCron || isValidCron(this.freezeEndCron));
|
|
|
|
},
|
2020-07-23 18:10:06 +00:00
|
|
|
timezone: {
|
|
|
|
get() {
|
|
|
|
return this.selectedTimezone;
|
|
|
|
},
|
|
|
|
set(selectedTimezone) {
|
|
|
|
this.setSelectedTimezone(selectedTimezone);
|
|
|
|
},
|
|
|
|
},
|
2020-07-17 18:09:20 +00:00
|
|
|
},
|
|
|
|
methods: {
|
|
|
|
...mapActions(['addFreezePeriod', 'setSelectedTimezone', 'resetModal']),
|
|
|
|
resetModalHandler() {
|
|
|
|
this.resetModal();
|
|
|
|
},
|
|
|
|
invalidCronMessage(validCronState) {
|
|
|
|
if (!validCronState) {
|
|
|
|
return __('This Cron pattern is invalid');
|
|
|
|
}
|
|
|
|
return '';
|
|
|
|
},
|
|
|
|
},
|
|
|
|
};
|
|
|
|
</script>
|
|
|
|
|
|
|
|
<template>
|
|
|
|
<gl-modal
|
|
|
|
v-bind="$options.modalOptions"
|
|
|
|
:action-primary="addDeployFreezeButton"
|
|
|
|
@primary="addFreezePeriod"
|
|
|
|
@canceled="resetModalHandler"
|
|
|
|
>
|
|
|
|
<p>
|
|
|
|
<gl-sprintf :message="$options.translations.cronSyntaxInstructions">
|
|
|
|
<template #cronSyntax="{ content }">
|
|
|
|
<gl-link href="https://crontab.guru/" target="_blank">{{ content }}</gl-link>
|
|
|
|
</template>
|
|
|
|
</gl-sprintf>
|
|
|
|
</p>
|
|
|
|
|
|
|
|
<gl-form-group
|
|
|
|
:label="__('Freeze start')"
|
|
|
|
label-for="deploy-freeze-start"
|
|
|
|
:invalid-feedback="invalidFreezeStartCron"
|
|
|
|
:state="freezeStartCronState"
|
|
|
|
>
|
|
|
|
<gl-form-input
|
|
|
|
id="deploy-freeze-start"
|
|
|
|
v-model="freezeStartCron"
|
|
|
|
class="gl-font-monospace!"
|
|
|
|
data-qa-selector="deploy_freeze_start_field"
|
|
|
|
:placeholder="this.$options.translations.cronPlaceholder"
|
|
|
|
:state="freezeStartCronState"
|
|
|
|
trim
|
|
|
|
/>
|
|
|
|
</gl-form-group>
|
|
|
|
|
|
|
|
<gl-form-group
|
|
|
|
:label="__('Freeze end')"
|
|
|
|
label-for="deploy-freeze-end"
|
|
|
|
:invalid-feedback="invalidFreezeEndCron"
|
|
|
|
:state="freezeEndCronState"
|
|
|
|
>
|
|
|
|
<gl-form-input
|
|
|
|
id="deploy-freeze-end"
|
|
|
|
v-model="freezeEndCron"
|
|
|
|
class="gl-font-monospace!"
|
|
|
|
data-qa-selector="deploy_freeze_end_field"
|
|
|
|
:placeholder="this.$options.translations.cronPlaceholder"
|
|
|
|
:state="freezeEndCronState"
|
|
|
|
trim
|
|
|
|
/>
|
|
|
|
</gl-form-group>
|
|
|
|
|
|
|
|
<gl-form-group :label="__('Cron time zone')" label-for="cron-time-zone-dropdown">
|
2020-07-23 18:10:06 +00:00
|
|
|
<timezone-dropdown v-model="timezone" :timezone-data="timezoneData" />
|
2020-07-17 18:09:20 +00:00
|
|
|
</gl-form-group>
|
|
|
|
</gl-modal>
|
|
|
|
</template>
|