refactor: format
This commit is contained in:
@@ -3,20 +3,22 @@ import { onBeforeMount, ref, watch, computed, defineAsyncComponent } from "vue";
|
||||
import type { Task } from "@/types";
|
||||
import { Copy, Trash, Save, X } from "@lucide/vue";
|
||||
import { updateTask } from "@/api/tasks";
|
||||
const CronInput = defineAsyncComponent(() => import("@/components/CronInput.vue"));
|
||||
const CronInput = defineAsyncComponent(
|
||||
() => import("@/components/CronInput.vue"),
|
||||
);
|
||||
import { taskCompleted, taskNextReset } from "@/lib/tasks";
|
||||
import { relativeTime } from "@/lib/dates";
|
||||
import { useAlertStore } from "@/stores/alerts";
|
||||
import { useI18n } from "vue-i18n";
|
||||
|
||||
const emit = defineEmits<(e: 'clone' | 'delete', task: Task) => void>();
|
||||
const emit = defineEmits<(e: "clone" | "delete", task: Task) => void>();
|
||||
|
||||
const task = defineModel<Task>({ required: true });
|
||||
defineProps<{ showLastChecked: boolean; showNextReset: boolean }>();
|
||||
|
||||
const editMode = ref<boolean>(false);
|
||||
const editName = ref<string>('');
|
||||
const editCron = ref<string|null>(null);
|
||||
const editName = ref<string>("");
|
||||
const editCron = ref<string | null>(null);
|
||||
const refreshKey = ref<number>(0);
|
||||
|
||||
const checked = computed<boolean>(() => taskCompleted(task.value));
|
||||
@@ -31,13 +33,17 @@ function onClose() {
|
||||
}
|
||||
|
||||
function onSave() {
|
||||
updateTask(task.value.id, { name: editName.value, reset_cron: editCron.value })
|
||||
updateTask(task.value.id, {
|
||||
name: editName.value,
|
||||
reset_cron: editCron.value,
|
||||
})
|
||||
.then((newTask) => {
|
||||
task.value = newTask;
|
||||
alertSuccess(i18n.t('alerts.task_updated'));
|
||||
}).catch(() => {
|
||||
alertError(i18n.t('alerts.task_update_error'))
|
||||
alertSuccess(i18n.t("alerts.task_updated"));
|
||||
})
|
||||
.catch(() => {
|
||||
alertError(i18n.t("alerts.task_update_error"));
|
||||
});
|
||||
task.value.name = editName.value;
|
||||
task.value.reset_cron = editCron.value;
|
||||
editMode.value = false;
|
||||
@@ -45,28 +51,36 @@ function onSave() {
|
||||
|
||||
function onCheck() {
|
||||
if (!checked.value) {
|
||||
updateTask(task.value.id, { check_date: (new Date()).toISOString(), previous_check_date: task.value.check_date?.toISOString() })
|
||||
updateTask(task.value.id, {
|
||||
check_date: new Date().toISOString(),
|
||||
previous_check_date: task.value.check_date?.toISOString(),
|
||||
})
|
||||
.then((newTask) => {
|
||||
task.value = newTask;
|
||||
}).catch(() => {
|
||||
alertError(i18n.t('alerts.task_update_error'))
|
||||
})
|
||||
.catch(() => {
|
||||
alertError(i18n.t("alerts.task_update_error"));
|
||||
});
|
||||
} else {
|
||||
updateTask(task.value.id, { check_date: null, previous_check_date: task.value.check_date?.toISOString() })
|
||||
updateTask(task.value.id, {
|
||||
check_date: null,
|
||||
previous_check_date: task.value.check_date?.toISOString(),
|
||||
})
|
||||
.then((newTask) => {
|
||||
task.value = newTask;
|
||||
}).catch(() => {
|
||||
alertError(i18n.t('alerts.task_update_error'))
|
||||
})
|
||||
.catch(() => {
|
||||
alertError(i18n.t("alerts.task_update_error"));
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
function onClone() {
|
||||
emit('clone', task.value);
|
||||
emit("clone", task.value);
|
||||
}
|
||||
|
||||
function onDelete() {
|
||||
emit('delete', task.value);
|
||||
emit("delete", task.value);
|
||||
}
|
||||
|
||||
onBeforeMount(() => {
|
||||
@@ -89,7 +103,13 @@ watch(task, () => {
|
||||
<template>
|
||||
<div class="list-row text-left">
|
||||
<div class="content-center">
|
||||
<input :id="refreshKey.toFixed(0)" type="checkbox" class="checkbox" :checked="checked" @click.prevent="onCheck" />
|
||||
<input
|
||||
:id="refreshKey.toFixed(0)"
|
||||
type="checkbox"
|
||||
class="checkbox"
|
||||
:checked="checked"
|
||||
@click.prevent="onCheck"
|
||||
/>
|
||||
</div>
|
||||
<div
|
||||
v-if="!editMode"
|
||||
@@ -97,11 +117,18 @@ watch(task, () => {
|
||||
@click.prevent="editMode = true"
|
||||
>
|
||||
<div>{{ task.name }}</div>
|
||||
<div v-if="showLastChecked && !checked && task.check_date" class="font-light text-xs italic">
|
||||
{{ $t('checked') }} {{ relativeTime(task.check_date, $i18n.locale) }}
|
||||
<div
|
||||
v-if="showLastChecked && !checked && task.check_date"
|
||||
class="font-light text-xs italic"
|
||||
>
|
||||
{{ $t("checked") }}
|
||||
{{ relativeTime(task.check_date, $i18n.locale) }}
|
||||
</div>
|
||||
<div v-if="showNextReset && checked && nextReset" class="font-light text-xs italic">
|
||||
{{ $t('resets') }} {{ relativeTime(nextReset, $i18n.locale) }}
|
||||
<div
|
||||
v-if="showNextReset && checked && nextReset"
|
||||
class="font-light text-xs italic"
|
||||
>
|
||||
{{ $t("resets") }} {{ relativeTime(nextReset, $i18n.locale) }}
|
||||
</div>
|
||||
</div>
|
||||
<template v-else>
|
||||
|
||||
Reference in New Issue
Block a user