From 4cf1f2de7608bf8d51c88c7b2e41dbf5b3ca9204 Mon Sep 17 00:00:00 2001 From: Stephane de Labrusse Date: Tue, 24 Sep 2024 16:14:35 +0200 Subject: [PATCH 1/7] refactor: Transform cron values in Tasks.vue --- ui/src/views/Tasks.vue | 31 +++++++++++++++++++++++-------- 1 file changed, 23 insertions(+), 8 deletions(-) diff --git a/ui/src/views/Tasks.vue b/ui/src/views/Tasks.vue index 248ed89..e0f0885 100644 --- a/ui/src/views/Tasks.vue +++ b/ui/src/views/Tasks.vue @@ -138,11 +138,11 @@ {{ - row.cron === "" + row.cron === "0" ? $t("tasks.no_cron") : row.cron === "1h" - ? parseInt(row.cron) + " " + $t("tasks.hour") - : parseInt(row.cron) + " " + $t("tasks.minutes") + ? parseInt(row.cron) + " " + $t("tasks.hour") + : parseInt(row.cron) + " " + $t("tasks.minutes") }} @@ -301,7 +301,7 @@ export default { security: "", delete: "no_delete", exclude: "", - cron: "", + cron: "5", foldersynchronization: "all", }, loading: { @@ -389,8 +389,21 @@ export default { listTasksCompleted(taskContext, taskResult) { let Config = taskResult.output; this.enabled_mailboxes = Config.enabled_mailboxes; - Config.user_properties.forEach((task) => { + // Transform the cron value + let cronValue = task.cron; + let cron_enabled = false; + if (cronValue.endsWith("h")) { + cronValue = String(parseInt(cronValue) * 60); // Convert hours to minutes and ensure it's a string + cron_enabled = true; + } else if (cronValue.endsWith("m")) { + cronValue = String(parseInt(cronValue)); // Remove the 'm', keep the number, and ensure it's a string + cron_enabled = true; + } else { + cronValue = String(0); // Ensure it's a string if it's already in the desired format + cron_enabled = false; + } + this.tasks.push({ task_id: task.task_id, localuser: task.localuser, @@ -405,12 +418,13 @@ export default { : task.delete_remote ? "delete_remote" : "no_delete", - cron: task.cron, + cron: cronValue, // Use the transformed cron value as a string + cron_enabled: cron_enabled, foldersynchronization: task.foldersynchronization, exclude: task.exclude .split(",") .filter((value) => value.trim() !== "") - .join("\n"), //filter empty values + .join("\n"), // Filter empty values }); }); this.check_tasks = this.tasks.length ? true : false; @@ -445,7 +459,8 @@ export default { this.currentTask.security = "tls"; this.currentTask.delete = "no_delete"; this.currentTask.exclude = ""; - this.currentTask.cron = ""; + this.currentTask.cron_enabled = false; + this.currentTask.cron = "5"; this.currentTask.foldersynchronization = "all"; this.showCreateOrEditTask(); }, From 5057fa80166d9ad4743cd52842e38409fa795a6d Mon Sep 17 00:00:00 2001 From: Stephane de Labrusse Date: Tue, 24 Sep 2024 16:14:45 +0200 Subject: [PATCH 2/7] refactor: Transform cron values in CreateOrEditTask.vue --- ui/src/components/CreateOrEditTask.vue | 56 ++++++++++++-------------- 1 file changed, 25 insertions(+), 31 deletions(-) diff --git a/ui/src/components/CreateOrEditTask.vue b/ui/src/components/CreateOrEditTask.vue index aae5ef6..d727ef0 100644 --- a/ui/src/components/CreateOrEditTask.vue +++ b/ui/src/components/CreateOrEditTask.vue @@ -172,39 +172,25 @@ v-model="task.delete" /> --> - - {{ - $t("tasks.no_cron") - }} - {{ - $t("tasks.every_minutes", { num: 5 }) - }} - {{ - $t("tasks.every_minutes", { num: 10 }) - }} - {{ - $t("tasks.every_minutes", { num: 15 }) - }} - {{ - $t("tasks.every_minutes", { num: 30 }) - }} - {{ - $t("tasks.every_minutes", { num: 45 }) - }} - {{ - $t("tasks.every_minutes", { num: 60 }) - }} - + min="1" + max="60" + step="1" + stepMultiplier="1" + minLabel="" + maxLabel="" + showUnlimited + :unlimitedLabel="$t('tasks.disabled')" + :limitedLabel="$t('tasks.enabled')" + :isUnlimited="!task.cron_enabled" + :invalidMessage="$t(error.cron)" + :disabled="loading.createTask" + :unitLabel="$t('tasks.minutes')" + @unlimited="task.cron_enabled = !$event" + class="mg-bottom-xlg" + /> @@ -353,6 +339,14 @@ export default { `${taskAction}-completed-${eventId}`, this.setCreateTaskCompleted ); + // modify cron value to be compatible with previous format ('',5m, 10m, 15m, 30m, 45m, 1h) + if (this.task.cron === "60" && this.task.cron_enabled) { + this.task.cron = "1h"; + } else if (this.task.cron !== "0" && this.task.cron_enabled) { + this.task.cron = this.task.cron + "m"; + } else if (!this.task.cron_enabled) { + this.task.cron = ""; + } const res = await to( this.createModuleTaskForApp(this.instanceName, { action: taskAction, From 3e1ce33f2b0fafaa9ec4c145a6168bf7fed97ba0 Mon Sep 17 00:00:00 2001 From: Stephane de Labrusse Date: Tue, 24 Sep 2024 16:28:58 +0200 Subject: [PATCH 3/7] Refactor cron values in validate-input.json and list-tasks/validate-output.json --- imageroot/actions/create-task/validate-input.json | 11 +---------- imageroot/actions/list-tasks/validate-output.json | 11 +---------- 2 files changed, 2 insertions(+), 20 deletions(-) diff --git a/imageroot/actions/create-task/validate-input.json b/imageroot/actions/create-task/validate-input.json index e158850..8c6f065 100644 --- a/imageroot/actions/create-task/validate-input.json +++ b/imageroot/actions/create-task/validate-input.json @@ -49,16 +49,7 @@ "cron": { "type": "string", "title": "Cron task", - "description": "Start a task by a cron", - "enum": [ - "", - "5m", - "10m", - "15m", - "30m", - "45m", - "1h" - ] + "description": "Start a task by a cron" }, "task_id": { "type": "string", diff --git a/imageroot/actions/list-tasks/validate-output.json b/imageroot/actions/list-tasks/validate-output.json index 3bc7778..0562224 100644 --- a/imageroot/actions/list-tasks/validate-output.json +++ b/imageroot/actions/list-tasks/validate-output.json @@ -125,16 +125,7 @@ "type": "string" }, "cron": { - "type": "string", - "enum": [ - "", - "5m", - "10m", - "15m", - "30m", - "45m", - "1h" - ] + "type": "string" }, "folder_inbox": { "type": "string" From 4d4cb6b546406cd44ee07a865fff59a087460808 Mon Sep 17 00:00:00 2001 From: Stephane de Labrusse Date: Tue, 24 Sep 2024 17:43:44 +0200 Subject: [PATCH 4/7] Fix file deletion in delete-task script --- imageroot/actions/delete-task/20delete | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/imageroot/actions/delete-task/20delete b/imageroot/actions/delete-task/20delete index 3fba759..52310bf 100755 --- a/imageroot/actions/delete-task/20delete +++ b/imageroot/actions/delete-task/20delete @@ -14,5 +14,6 @@ data = json.load(sys.stdin) task_id = data["task_id"] localuser = data["localuser"] -for file in glob.iglob("imapsync/"+localuser+'_'+task_id+".*"): +# remove the task cron/env/password/lock files +for file in glob.iglob("*/"+localuser+'_'+task_id+".*"): os.remove(file) From 99ab962bc6d0642cbc1fbecd134a237c5d0325fb Mon Sep 17 00:00:00 2001 From: Stephane de Labrusse Date: Tue, 24 Sep 2024 22:35:29 +0200 Subject: [PATCH 5/7] Fix disabled state in CreateOrEditTask.vue --- ui/src/components/CreateOrEditTask.vue | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/ui/src/components/CreateOrEditTask.vue b/ui/src/components/CreateOrEditTask.vue index d727ef0..6668013 100644 --- a/ui/src/components/CreateOrEditTask.vue +++ b/ui/src/components/CreateOrEditTask.vue @@ -41,6 +41,7 @@ :invalid-message="$t(error.localuser)" tooltipAlignment="start" tooltipDirection="top" + :disabled="loading.createTask" ref="localuser" >