feat: one-time tasks
This commit is contained in:
@@ -82,6 +82,9 @@ watch(cron, () => {
|
||||
<option :value="CronType.CUSTOM">
|
||||
{{ $t("cron.type.custom") }}
|
||||
</option>
|
||||
<option :value="CronType.ONE_TIME">
|
||||
{{ $t("cron.type.one_time") }}
|
||||
</option>
|
||||
</select>
|
||||
<select
|
||||
v-if="cronType === CronType.EVERY_DAY"
|
||||
|
||||
@@ -17,6 +17,7 @@ import { isTemporary, taskCompleted, taskNextReset } from "@/lib/tasks";
|
||||
import { relativeTime } from "@/lib/dates";
|
||||
import { useAlertStore } from "@/stores/alerts";
|
||||
import { useI18n } from "vue-i18n";
|
||||
import { isOneTime } from "@/lib/cron";
|
||||
|
||||
const emit =
|
||||
defineEmits<(e: "clone" | "delete" | "updated", task: Task) => void>();
|
||||
@@ -75,20 +76,24 @@ function onSave() {
|
||||
function onCheck() {
|
||||
if (!isTemporary(task.value)) {
|
||||
if (!checked.value) {
|
||||
const data = {
|
||||
check_date: new Date().toISOString(),
|
||||
previous_check_date: task.value.check_date?.toISOString(),
|
||||
};
|
||||
task.value.previous_check_date = task.value.check_date;
|
||||
task.value.check_date = new Date();
|
||||
updateTask(task.value.id, data)
|
||||
.then((data) => {
|
||||
task.value = data;
|
||||
emit("updated", data);
|
||||
})
|
||||
.catch(() => {
|
||||
alertError(i18n.t("alerts.task_update_error"));
|
||||
});
|
||||
if (isOneTime(task.value.reset_cron)) {
|
||||
emit("delete", task.value);
|
||||
} else {
|
||||
const data = {
|
||||
check_date: new Date().toISOString(),
|
||||
previous_check_date: task.value.check_date?.toISOString(),
|
||||
};
|
||||
task.value.previous_check_date = task.value.check_date;
|
||||
task.value.check_date = new Date();
|
||||
updateTask(task.value.id, data)
|
||||
.then((data) => {
|
||||
task.value = data;
|
||||
emit("updated", data);
|
||||
})
|
||||
.catch(() => {
|
||||
alertError(i18n.t("alerts.task_update_error"));
|
||||
});
|
||||
}
|
||||
} else {
|
||||
const data = {
|
||||
check_date: null,
|
||||
|
||||
Reference in New Issue
Block a user