changeset 2377:fdec7a652f34

client: imports: avoid error when cron string cannot be parsed when trying to edit imports To prefill the form fields that generate the cron string, the currently stored cron string needs to be parsed back. This parsing only handles numerical values for each of the six cron fields. In case of something like */15 the regular expression does not match, leading to a null value. The cronMode select now has an empty option for cases where the cronString does not match any known pattern.
author Markus Kottlaender <markus@intevation.de>
date Fri, 22 Feb 2019 12:28:14 +0100
parents 6efd7ecd3a7d
children c69432c1c4ac
files client/src/components/importschedule/Importscheduledetail.vue client/src/store/importschedule.js
diffstat 2 files changed, 24 insertions(+), 15 deletions(-) [+]
line wrap: on
line diff
--- a/client/src/components/importschedule/Importscheduledetail.vue	Fri Feb 22 08:22:57 2019 +0100
+++ b/client/src/components/importschedule/Importscheduledetail.vue	Fri Feb 22 12:28:14 2019 +0100
@@ -245,6 +245,7 @@
                   class="form-control"
                   @change="clearInputs"
                 >
+                  <option :value="null"></option>
                   <option
                     v-for="(option, key) in $options.CRONMODE"
                     :value="key"
--- a/client/src/store/importschedule.js	Fri Feb 22 08:22:57 2019 +0100
+++ b/client/src/store/importschedule.js	Fri Feb 22 12:28:14 2019 +0100
@@ -135,31 +135,39 @@
         }
 
         // set cronMode from cronString
-        if (/0 \d{1,2} \* \* \* \*/.test(cron))
+        Vue.set(state.currentSchedule, "cronMode", null);
+        if (cron === "0 */15 * * * *")
+          Vue.set(state.currentSchedule, "cronMode", "15minutes");
+        else if (/^0 \d{1,2} \* \* \* \*$/.test(cron))
           Vue.set(state.currentSchedule, "cronMode", "hour");
-        if (/0 \d{1,2} \d{1,2} \* \* \*/.test(cron))
+        else 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))
+        else 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))
+        else 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))
+        else 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 cronString could not be parsed/matched (cronConf is null),
+        // skip prefilling those values
+        if (cronConf) {
+          // 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);