import Vue from 'vue'; import Translate from '../../vue_shared/translate'; Vue.use(Translate); const inputNameAttribute = 'schedule[cron]'; export default { props: { initialCronInterval: { type: String, required: false, default: '', }, }, data() { return { inputNameAttribute, cronInterval: this.initialCronInterval, cronIntervalPresets: { everyDay: '0 4 * * *', everyWeek: '0 4 * * 0', everyMonth: '0 4 1 * *', }, cronSyntaxUrl: 'https://en.wikipedia.org/wiki/Cron', customInputEnabled: false, }; }, computed: { intervalIsPreset() { return _.contains(this.cronIntervalPresets, this.cronInterval); }, // The text input is editable when there's a custom interval, or when it's // a preset interval and the user clicks the 'custom' radio button isEditable() { return !!(this.customInputEnabled || !this.intervalIsPreset); }, }, methods: { toggleCustomInput(shouldEnable) { this.customInputEnabled = shouldEnable; if (shouldEnable) { // We need to change the value so other radios don't remain selected // because the model (cronInterval) hasn't changed. The server trims it. this.cronInterval = `${this.cronInterval} `; } }, }, created() { if (this.intervalIsPreset) { this.enableCustomInput = false; } }, watch: { cronInterval() { // updates field validation state when model changes, as // glFieldError only updates on input. Vue.nextTick(() => { gl.pipelineScheduleFieldErrors.updateFormValidityState(); }); }, }, template: `
({{ __('Cron syntax') }})
`, };