Mercurial > gemma
diff client/src/store/importschedule.js @ 2344:a5b87a695469
client: imports: fixed cron string
The inputs are now correctly converted to a cron string and the cron string coming
from the backend for an existing schedule is now correctly parsed back to the
individual inputs for editing a schedule.
author | Markus Kottlaender <markus@intevation.de> |
---|---|
date | Wed, 20 Feb 2019 10:21:16 +0100 |
parents | b87211f595ae |
children | fdec7a652f34 |
line wrap: on
line diff
--- a/client/src/store/importschedule.js Wed Feb 20 10:00:01 2019 +0100 +++ b/client/src/store/importschedule.js Wed Feb 20 10:21:16 2019 +0100 @@ -64,13 +64,13 @@ eMailNotification: false, scheduled: false, easyCron: true, - cronString: "* * * * ", - cronMode: "", - minutes: null, - month: null, - hour: null, - day: null, - dayOfMonth: null, + cronString: "0 */15 * * * *", + cronMode: "15minutes", + minutes: 0, + month: 1, + hour: 0, + day: 0, + dayOfMonth: 1, simple: null, url: null, insecure: false, @@ -121,8 +121,45 @@ Vue.set(state.currentSchedule, "id", id); if (cron) { Vue.set(state.currentSchedule, "scheduled", true); - Vue.set(state.currentSchedule, "easyCron", false); Vue.set(state.currentSchedule, "cronString", cron); + + // simple weekly or monthly? + if (cron === "0 0 0 * * 0") { + Vue.set(state.currentSchedule, "simple", "weekly"); + Vue.set(state.currentSchedule, "easyCron", true); + } else if (cron === "0 0 0 1 * *") { + Vue.set(state.currentSchedule, "simple", "monthly"); + Vue.set(state.currentSchedule, "easyCron", true); + } else { + Vue.set(state.currentSchedule, "easyCron", false); + } + + // set cronMode from cronString + if (/0 \d{1,2} \* \* \* \*/.test(cron)) + Vue.set(state.currentSchedule, "cronMode", "hour"); + if (/0 \d{1,2} \d{1,2} \* \* \*/.test(cron)) + Vue.set(state.currentSchedule, "cronMode", "day"); + if (/0 \d{1,2} \d{1,2} \* \* \d{1}/.test(cron)) + Vue.set(state.currentSchedule, "cronMode", "week"); + if (/0 \d{1,2} \d{1,2} \d{1,2} \* \*/.test(cron)) + Vue.set(state.currentSchedule, "cronMode", "month"); + if (/0 \d{1,2} \d{1,2} \d{1,2} \d{1,2} \*/.test(cron)) + Vue.set(state.currentSchedule, "cronMode", "year"); + + // set minute, hour, etc from cronString + let cronConf = cron.match( + /0 (\d{1,2}|\*) (\d{1,2}|\*) (\d{1,2}|\*) (\d{1,2}|\*) (\d{1}|\*)/ + ); + // remove first element which is the whole matched string + cronConf.shift(); + cronConf = cronConf.map(field => + field === "*" ? null : Number(field) + ); + Vue.set(state.currentSchedule, "minutes", cronConf[0]); + Vue.set(state.currentSchedule, "hour", cronConf[1]); + Vue.set(state.currentSchedule, "dayOfMonth", cronConf[2]); + Vue.set(state.currentSchedule, "month", cronConf[3]); + Vue.set(state.currentSchedule, "day", cronConf[4]); } if (eMailNotification) { Vue.set(state.currentSchedule, "eMailNotification", eMailNotification);