Compare commits
16
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
aeeabe81c7 | ||
|
|
87eff715f6 | ||
|
|
63c80f0bae | ||
|
|
f36c8ba315 | ||
|
|
7fc16e78de | ||
|
|
f8f38c9197 | ||
|
|
6e508547fc | ||
|
|
eea6825ac7 | ||
|
|
d8c7cc498d | ||
|
|
7d2e8cae5d | ||
|
|
f680b04533 | ||
|
|
fe5c0f94b2 | ||
|
|
664b47aa75 | ||
|
|
ce795582f9 | ||
|
|
bd87e5acf5 | ||
|
|
9081891d8f |
@@ -1,5 +1,6 @@
|
|||||||
{
|
{
|
||||||
"lockfileVersion": 1,
|
"lockfileVersion": 1,
|
||||||
|
"configVersion": 0,
|
||||||
"workspaces": {
|
"workspaces": {
|
||||||
"": {
|
"": {
|
||||||
"name": "tout-doux",
|
"name": "tout-doux",
|
||||||
|
|||||||
+1
-1
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "tout-doux",
|
"name": "tout-doux",
|
||||||
"version": "1.7.0",
|
"version": "1.7.6",
|
||||||
"private": true,
|
"private": true,
|
||||||
"type": "module",
|
"type": "module",
|
||||||
"engines": {
|
"engines": {
|
||||||
|
|||||||
+1
-1
@@ -1,6 +1,6 @@
|
|||||||
[project]
|
[project]
|
||||||
name = "tout-doux"
|
name = "tout-doux"
|
||||||
version = "1.7.0"
|
version = "1.7.6"
|
||||||
description = ""
|
description = ""
|
||||||
requires-python = ">=3.14"
|
requires-python = ">=3.14"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
|
|||||||
@@ -1,9 +1,6 @@
|
|||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import { useAlertStore } from "@/stores/alerts";
|
import { useAlertStore } from "@/stores/alerts";
|
||||||
import { defineAsyncComponent } from "vue";
|
import AlertItem from "@/components/AlertItem.vue";
|
||||||
const AlertItem = defineAsyncComponent(
|
|
||||||
() => import("@/components/AlertItem.vue"),
|
|
||||||
);
|
|
||||||
|
|
||||||
const { alerts } = useAlertStore();
|
const { alerts } = useAlertStore();
|
||||||
</script>
|
</script>
|
||||||
|
|||||||
@@ -2,6 +2,7 @@
|
|||||||
import { ref, onBeforeMount, watch } from "vue";
|
import { ref, onBeforeMount, watch } from "vue";
|
||||||
import { getCron, parseCron, validCron } from "@/lib/recurrence";
|
import { getCron, parseCron, validCron } from "@/lib/recurrence";
|
||||||
import { CronType } from "@/enums";
|
import { CronType } from "@/enums";
|
||||||
|
import DateInput from "@/components/DateInput.vue";
|
||||||
|
|
||||||
const DEFAULT_CRON = "0 0 * * *";
|
const DEFAULT_CRON = "0 0 * * *";
|
||||||
|
|
||||||
@@ -11,7 +12,7 @@ const valid = ref<boolean>(true);
|
|||||||
const props = defineProps<{ editMode: boolean }>();
|
const props = defineProps<{ editMode: boolean }>();
|
||||||
|
|
||||||
const cronType = ref<CronType>(CronType.MANUAL);
|
const cronType = ref<CronType>(CronType.MANUAL);
|
||||||
const cronValue = ref<string>('0');
|
const cronValue = ref<string>("0");
|
||||||
const cronDate = ref<Date>(new Date());
|
const cronDate = ref<Date>(new Date());
|
||||||
|
|
||||||
function onCronChanged() {
|
function onCronChanged() {
|
||||||
@@ -23,13 +24,18 @@ function onCronChanged() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function updateCron() {
|
function updateCron() {
|
||||||
cron.value = getCron(cronType.value, parseInt(cronValue.value), cronDate.value, rawCron.value);
|
cron.value = getCron(
|
||||||
|
cronType.value,
|
||||||
|
parseInt(cronValue.value),
|
||||||
|
cronDate.value,
|
||||||
|
rawCron.value,
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
function onChangeCronType() {
|
function onChangeCronType() {
|
||||||
switch (cronType.value) {
|
switch (cronType.value) {
|
||||||
case CronType.EVERY_DAY:
|
case CronType.EVERY_DAY:
|
||||||
cronValue.value = '0';
|
cronValue.value = "0";
|
||||||
break;
|
break;
|
||||||
case CronType.EVERY_WEEK:
|
case CronType.EVERY_WEEK:
|
||||||
case CronType.EVERY_MONTH:
|
case CronType.EVERY_MONTH:
|
||||||
@@ -37,7 +43,7 @@ function onChangeCronType() {
|
|||||||
case CronType.EVERY_N_DAYS:
|
case CronType.EVERY_N_DAYS:
|
||||||
case CronType.EVERY_N_WEEKS:
|
case CronType.EVERY_N_WEEKS:
|
||||||
case CronType.EVERY_N_MONTHS:
|
case CronType.EVERY_N_MONTHS:
|
||||||
cronValue.value = '1';
|
cronValue.value = "1";
|
||||||
break;
|
break;
|
||||||
case CronType.CUSTOM:
|
case CronType.CUSTOM:
|
||||||
cron.value ??= DEFAULT_CRON;
|
cron.value ??= DEFAULT_CRON;
|
||||||
@@ -50,8 +56,7 @@ function onChangeCronValue() {
|
|||||||
updateCron();
|
updateCron();
|
||||||
}
|
}
|
||||||
|
|
||||||
function onChangeCronDate(event: InputEvent) {
|
function onChangeCronDate() {
|
||||||
cronDate.value = new Date((event.target as HTMLInputElement).value);
|
|
||||||
updateCron();
|
updateCron();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -73,7 +78,11 @@ watch(cron, () => {
|
|||||||
|
|
||||||
<template>
|
<template>
|
||||||
<div class="flex gap-2 flex-wrap">
|
<div class="flex gap-2 flex-wrap">
|
||||||
<select v-model="cronType" class="select flex-1" @change="onChangeCronType">
|
<select
|
||||||
|
v-model="cronType"
|
||||||
|
class="select flex-1"
|
||||||
|
@change="onChangeCronType"
|
||||||
|
>
|
||||||
<option :value="CronType.MANUAL">
|
<option :value="CronType.MANUAL">
|
||||||
{{ $t("cron.type.manual") }}
|
{{ $t("cron.type.manual") }}
|
||||||
</option>
|
</option>
|
||||||
@@ -105,20 +114,6 @@ watch(cron, () => {
|
|||||||
{{ $t("cron.type.one_time") }}
|
{{ $t("cron.type.one_time") }}
|
||||||
</option>
|
</option>
|
||||||
</select>
|
</select>
|
||||||
<select
|
|
||||||
v-if="cronType === CronType.EVERY_DAY"
|
|
||||||
v-model="cronValue"
|
|
||||||
class="select flex-1"
|
|
||||||
@change="onChangeCronValue"
|
|
||||||
>
|
|
||||||
<option
|
|
||||||
v-for="i in Array.from(Array(24).keys())"
|
|
||||||
:key="`h${i+1}`"
|
|
||||||
:value="i"
|
|
||||||
>
|
|
||||||
{{ i.toFixed(0).padStart(2, "0") }}:00
|
|
||||||
</option>
|
|
||||||
</select>
|
|
||||||
<select
|
<select
|
||||||
v-if="cronType === CronType.EVERY_WEEK"
|
v-if="cronType === CronType.EVERY_WEEK"
|
||||||
v-model="cronValue"
|
v-model="cronValue"
|
||||||
@@ -127,7 +122,7 @@ watch(cron, () => {
|
|||||||
>
|
>
|
||||||
<option
|
<option
|
||||||
v-for="i in Array.from(Array(7).keys())"
|
v-for="i in Array.from(Array(7).keys())"
|
||||||
:key="`w${i+1}`"
|
:key="`w${i + 1}`"
|
||||||
:value="i + 1"
|
:value="i + 1"
|
||||||
>
|
>
|
||||||
{{ $t(`cron.week.${i.toFixed(0)}`) }}
|
{{ $t(`cron.week.${i.toFixed(0)}`) }}
|
||||||
@@ -139,35 +134,37 @@ watch(cron, () => {
|
|||||||
class="select flex-1"
|
class="select flex-1"
|
||||||
@change="onChangeCronValue"
|
@change="onChangeCronValue"
|
||||||
>
|
>
|
||||||
<option :value="1">{{ $t('cron.month.first_day') }}</option>
|
<option :value="1">{{ $t("cron.month.first_day") }}</option>
|
||||||
<option :value="32">{{ $t('cron.month.last_day') }}</option>
|
<option :value="32">{{ $t("cron.month.last_day") }}</option>
|
||||||
<option
|
<option
|
||||||
v-for="i in Array.from(Array(7).keys())"
|
v-for="i in Array.from(Array(7).keys())"
|
||||||
:key="`d${-(i+1)}`"
|
:key="`d${-(i + 1)}`"
|
||||||
:value="-(i + 1)"
|
:value="-(i + 1)"
|
||||||
>
|
>
|
||||||
{{ $t("cron.month.first") }} {{ $t(`cron.week.${i.toFixed(0)}`).toLowerCase() }}
|
{{ $t("cron.month.first") }}
|
||||||
|
{{ $t(`cron.week.${i.toFixed(0)}`).toLowerCase() }}
|
||||||
</option>
|
</option>
|
||||||
<option
|
<option
|
||||||
v-for="i in Array.from(Array(7).keys())"
|
v-for="i in Array.from(Array(7).keys())"
|
||||||
:key="`d${-(i+8)}`"
|
:key="`d${-(i + 8)}`"
|
||||||
:value="-(i + 8)"
|
:value="-(i + 8)"
|
||||||
>
|
>
|
||||||
{{ $t("cron.month.last") }} {{ $t(`cron.week.${i.toFixed(0)}`).toLowerCase() }}
|
{{ $t("cron.month.last") }}
|
||||||
|
{{ $t(`cron.week.${i.toFixed(0)}`).toLowerCase() }}
|
||||||
</option>
|
</option>
|
||||||
<option
|
<option
|
||||||
v-for="i in Array.from(Array(30).keys())"
|
v-for="i in Array.from(Array(30).keys())"
|
||||||
:key="`d${i+2}`"
|
:key="`d${i + 2}`"
|
||||||
:value="i + 2"
|
:value="i + 2"
|
||||||
>
|
>
|
||||||
{{
|
{{
|
||||||
(i % 10 == 9 && i !== 9)
|
i % 10 == 9 && i !== 9
|
||||||
? $t("cron.month.st", [i+2])
|
? $t("cron.month.st", [i + 2])
|
||||||
: (i % 10 === 0 && i !== 10)
|
: i % 10 === 0 && i !== 10
|
||||||
? $t("cron.month.nd", [i+2])
|
? $t("cron.month.nd", [i + 2])
|
||||||
: (i % 10 === 1 && i !== 11)
|
: i % 10 === 1 && i !== 11
|
||||||
? $t("cron.month.rd", [i+2])
|
? $t("cron.month.rd", [i + 2])
|
||||||
: $t("cron.month.th", [i+2])
|
: $t("cron.month.th", [i + 2])
|
||||||
}}
|
}}
|
||||||
</option>
|
</option>
|
||||||
</select>
|
</select>
|
||||||
@@ -194,23 +191,32 @@ watch(cron, () => {
|
|||||||
@input="onInputRawCron"
|
@input="onInputRawCron"
|
||||||
/>
|
/>
|
||||||
<input
|
<input
|
||||||
v-if="cronType === CronType.EVERY_N_DAYS || cronType === CronType.EVERY_N_WEEKS || cronType === CronType.EVERY_N_MONTHS"
|
v-if="
|
||||||
|
cronType === CronType.EVERY_N_DAYS ||
|
||||||
|
cronType === CronType.EVERY_N_WEEKS ||
|
||||||
|
cronType === CronType.EVERY_N_MONTHS
|
||||||
|
"
|
||||||
v-model="cronValue"
|
v-model="cronValue"
|
||||||
type="number"
|
type="number"
|
||||||
min="1"
|
min="1"
|
||||||
step="1"
|
step="1"
|
||||||
class="input font-mono flex-1"
|
class="input font-mono flex-1"
|
||||||
@input="onChangeCronValue"
|
@change="onChangeCronValue"
|
||||||
/>
|
/>
|
||||||
<label class="label flex-1 basis-full">
|
<label
|
||||||
|
v-if="
|
||||||
|
cronType === CronType.EVERY_N_DAYS ||
|
||||||
|
cronType === CronType.EVERY_N_WEEKS ||
|
||||||
|
cronType === CronType.EVERY_N_MONTHS
|
||||||
|
"
|
||||||
|
class="label flex-1 basis-full"
|
||||||
|
>
|
||||||
{{ $t("cron.rrule_start") }}
|
{{ $t("cron.rrule_start") }}
|
||||||
<input
|
<date-input
|
||||||
v-if="cronType === CronType.EVERY_N_DAYS || cronType === CronType.EVERY_N_WEEKS || cronType === CronType.EVERY_N_MONTHS"
|
v-model="cronDate"
|
||||||
:value="cronDate.toISOString().substring(0, 10)"
|
|
||||||
required
|
required
|
||||||
type="date"
|
|
||||||
class="input font-mono"
|
class="input font-mono"
|
||||||
@input="onChangeCronDate"
|
@change="onChangeCronDate"
|
||||||
/>
|
/>
|
||||||
</label>
|
</label>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -0,0 +1,26 @@
|
|||||||
|
<script setup lang="ts">
|
||||||
|
const emit = defineEmits<(e: "input"|"change", value: Date) => void>();
|
||||||
|
|
||||||
|
const date = defineModel<Date>({ required: true });
|
||||||
|
|
||||||
|
function onInput(event: Event) {
|
||||||
|
const inputValue = (event.target as HTMLInputElement).value;
|
||||||
|
date.value = new Date(inputValue);
|
||||||
|
emit('input', date.value);
|
||||||
|
}
|
||||||
|
|
||||||
|
function onChange(event: Event) {
|
||||||
|
const inputValue = (event.target as HTMLInputElement).value;
|
||||||
|
date.value = new Date(inputValue);
|
||||||
|
emit('change', date.value);
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<template>
|
||||||
|
<input
|
||||||
|
:value="date.toISOString().substring(0, 10)"
|
||||||
|
type="date"
|
||||||
|
@input="onInput"
|
||||||
|
@change="onChange"
|
||||||
|
/>
|
||||||
|
</template>
|
||||||
@@ -1,17 +1,13 @@
|
|||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import { getMetadata } from "@/api/meta";
|
import { getMetadata } from "@/api/meta";
|
||||||
import type { Metadata } from "@/types";
|
import type { Metadata } from "@/types";
|
||||||
import { defineAsyncComponent, onBeforeMount, ref } from "vue";
|
import { onBeforeMount, ref } from "vue";
|
||||||
|
import LangInput from "@/components/LangInput.vue";
|
||||||
|
|
||||||
const metadata = ref<Metadata|null>(null);
|
const metadata = ref<Metadata | null>(null);
|
||||||
|
|
||||||
const LangInput = defineAsyncComponent(
|
|
||||||
() => import("@/components/LangInput.vue"),
|
|
||||||
);
|
|
||||||
|
|
||||||
function fetchMetadata() {
|
function fetchMetadata() {
|
||||||
void getMetadata()
|
void getMetadata().then((data) => {
|
||||||
.then((data) => {
|
|
||||||
metadata.value = data;
|
metadata.value = data;
|
||||||
setTimeout(fetchMetadata, 600000);
|
setTimeout(fetchMetadata, 600000);
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -4,15 +4,12 @@ import {
|
|||||||
ref,
|
ref,
|
||||||
watch,
|
watch,
|
||||||
computed,
|
computed,
|
||||||
defineAsyncComponent,
|
|
||||||
nextTick,
|
nextTick,
|
||||||
} from "vue";
|
} from "vue";
|
||||||
import type { Task } from "@/types";
|
import type { Task } from "@/types";
|
||||||
import { CopyIcon, TrashIcon, SaveIcon, XIcon } from "@lucide/vue";
|
import { CopyIcon, TrashIcon, SaveIcon, XIcon } from "@lucide/vue";
|
||||||
import { updateTask } from "@/api/tasks";
|
import { updateTask } from "@/api/tasks";
|
||||||
const CronInput = defineAsyncComponent(
|
import CronInput from "@/components/CronInput.vue";
|
||||||
() => import("@/components/CronInput.vue"),
|
|
||||||
);
|
|
||||||
import {
|
import {
|
||||||
isTemporary,
|
isTemporary,
|
||||||
taskCompleted,
|
taskCompleted,
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ const ONE_TIME_VALUE = "@one-time";
|
|||||||
export function parseCron(cron: string | null): {
|
export function parseCron(cron: string | null): {
|
||||||
type: CronType;
|
type: CronType;
|
||||||
value: number;
|
value: number;
|
||||||
date: Date|null;
|
date: Date | null;
|
||||||
} {
|
} {
|
||||||
let value: RegExpMatchArray | null;
|
let value: RegExpMatchArray | null;
|
||||||
if (cron === null) {
|
if (cron === null) {
|
||||||
@@ -22,7 +22,7 @@ export function parseCron(cron: string | null): {
|
|||||||
value: 0,
|
value: 0,
|
||||||
date: null,
|
date: null,
|
||||||
};
|
};
|
||||||
} else if (cron.startsWith("RRULE:")) {
|
} else if (isRrule(cron)) {
|
||||||
return parseRrule(cron);
|
return parseRrule(cron);
|
||||||
} else if ((value = /^0 (\d+) \* \* \*$/i.exec(cron)) !== null) {
|
} else if ((value = /^0 (\d+) \* \* \*$/i.exec(cron)) !== null) {
|
||||||
return {
|
return {
|
||||||
@@ -75,6 +75,10 @@ export function parseCron(cron: string | null): {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function isRrule(cron: string): boolean {
|
||||||
|
return cron.startsWith("RRULE:") || cron.startsWith("DTSTART:");
|
||||||
|
}
|
||||||
|
|
||||||
export function parseRrule(rule: string): {
|
export function parseRrule(rule: string): {
|
||||||
type: CronType;
|
type: CronType;
|
||||||
value: number;
|
value: number;
|
||||||
@@ -128,7 +132,7 @@ export function getCron(
|
|||||||
case CronType.ONE_TIME:
|
case CronType.ONE_TIME:
|
||||||
return ONE_TIME_VALUE;
|
return ONE_TIME_VALUE;
|
||||||
case CronType.EVERY_DAY:
|
case CronType.EVERY_DAY:
|
||||||
return `0 ${value.toFixed(0)} * * *`;
|
return `0 0 * * *`;
|
||||||
case CronType.EVERY_WEEK:
|
case CronType.EVERY_WEEK:
|
||||||
return `0 0 * * ${value.toFixed(0)}`;
|
return `0 0 * * ${value.toFixed(0)}`;
|
||||||
case CronType.EVERY_MONTH:
|
case CronType.EVERY_MONTH:
|
||||||
@@ -145,11 +149,23 @@ export function getCron(
|
|||||||
case CronType.EVERY_YEAR:
|
case CronType.EVERY_YEAR:
|
||||||
return `0 0 1 ${value.toFixed(0)} *`;
|
return `0 0 1 ${value.toFixed(0)} *`;
|
||||||
case CronType.EVERY_N_MONTHS:
|
case CronType.EVERY_N_MONTHS:
|
||||||
return `RRULE:FREQ=MONTHLY;INTERVAL=${value.toFixed(0)}\nDTSTART:${dtStartFormat(date)}`;
|
return new RRule({
|
||||||
|
freq: RRule.MONTHLY,
|
||||||
|
interval: value,
|
||||||
|
dtstart: date,
|
||||||
|
}).toString();
|
||||||
case CronType.EVERY_N_WEEKS:
|
case CronType.EVERY_N_WEEKS:
|
||||||
return `RRULE:FREQ=WEEKLY;INTERVAL=${value.toFixed(0)}\nDTSTART:${dtStartFormat(date)}`;
|
return new RRule({
|
||||||
|
freq: RRule.WEEKLY,
|
||||||
|
interval: value,
|
||||||
|
dtstart: date,
|
||||||
|
}).toString();
|
||||||
case CronType.EVERY_N_DAYS:
|
case CronType.EVERY_N_DAYS:
|
||||||
return `RRULE:FREQ=DAILY;INTERVAL=${value.toFixed(0)}\nDTSTART:${dtStartFormat(date)}`;
|
return new RRule({
|
||||||
|
freq: RRule.DAILY,
|
||||||
|
interval: value,
|
||||||
|
dtstart: date,
|
||||||
|
}).toString();
|
||||||
case CronType.CUSTOM:
|
case CronType.CUSTOM:
|
||||||
if (validCron(fallback)) {
|
if (validCron(fallback)) {
|
||||||
return fallback;
|
return fallback;
|
||||||
@@ -159,10 +175,6 @@ export function getCron(
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
function dtStartFormat(date: Date): string {
|
|
||||||
return `${date.getFullYear().toFixed(0)}${(date.getMonth() + 1).toFixed(0).padStart(2, '0')}${date.getDate().toFixed(0).padStart(2, '0')}T000000Z`
|
|
||||||
}
|
|
||||||
|
|
||||||
export function isOneTime(cron: string | null): boolean {
|
export function isOneTime(cron: string | null): boolean {
|
||||||
return cron === ONE_TIME_VALUE;
|
return cron === ONE_TIME_VALUE;
|
||||||
}
|
}
|
||||||
@@ -185,7 +197,7 @@ export function nextCronReset(
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
if (cron.startsWith("RRULE:")) {
|
if (isRrule(cron)) {
|
||||||
try {
|
try {
|
||||||
const rule = new RRule({
|
const rule = new RRule({
|
||||||
...RRule.parseString(cron),
|
...RRule.parseString(cron),
|
||||||
|
|||||||
+44
-39
@@ -35,11 +35,27 @@ export function isTemporary(task: Task): boolean {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export function taskNextReset(task: Task): Date | null {
|
export function taskNextReset(task: Task): Date | null {
|
||||||
return nextCronReset(task.check_date ?? new Date(), task.reset_cron, task.id);
|
return nextCronReset(
|
||||||
|
task.check_date ?? new Date(),
|
||||||
|
task.reset_cron,
|
||||||
|
task.id,
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
export function taskFutureReset(task: Task): Date | null {
|
export function taskFutureReset(task: Task): Date | null {
|
||||||
return nextCronReset(taskNextReset(task) ?? new Date(), task.reset_cron, task.id);
|
return nextCronReset(
|
||||||
|
taskNextReset(task) ?? new Date(),
|
||||||
|
task.reset_cron,
|
||||||
|
task.id,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
export function taskSortReset(task: Task): Date | null {
|
||||||
|
let resetDate = taskNextReset(task);
|
||||||
|
while (resetDate !== null && resetDate.getTime() < new Date().getTime()) {
|
||||||
|
resetDate = nextCronReset(resetDate, task.reset_cron, task.id);
|
||||||
|
}
|
||||||
|
return resetDate;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function taskCompleted(task: Task): boolean {
|
export function taskCompleted(task: Task): boolean {
|
||||||
@@ -53,54 +69,43 @@ export function taskCompleted(task: Task): boolean {
|
|||||||
return nextReset.getTime() > new Date().getTime();
|
return nextReset.getTime() > new Date().getTime();
|
||||||
}
|
}
|
||||||
|
|
||||||
export function sortTasks(
|
export function fallbackDate(task: Task): Date {
|
||||||
tasks: Task[],
|
return new Date(
|
||||||
|
(task.check_date ?? task.created_at).getFullYear() + 100,
|
||||||
|
(task.check_date ?? task.created_at).getMonth(),
|
||||||
|
(task.check_date ?? task.created_at).getDate(),
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
export function taskSortFunction(
|
||||||
sortType: SortType,
|
sortType: SortType,
|
||||||
reverse: boolean,
|
reverse: boolean,
|
||||||
): Task[] {
|
): (a: Task, b: Task) => number {
|
||||||
switch (sortType) {
|
switch (sortType) {
|
||||||
case SortType.CREATED_AT:
|
case SortType.CREATED_AT:
|
||||||
return tasks
|
return (a: Task, b: Task) =>
|
||||||
.slice()
|
|
||||||
.sort(
|
|
||||||
(a: Task, b: Task) =>
|
|
||||||
(reverse ? -1 : 1) *
|
(reverse ? -1 : 1) *
|
||||||
(a.created_at.getTime() - b.created_at.getTime()),
|
(a.created_at.getTime() - b.created_at.getTime());
|
||||||
);
|
|
||||||
case SortType.UPDATED_AT:
|
case SortType.UPDATED_AT:
|
||||||
return tasks
|
return (a: Task, b: Task) =>
|
||||||
.slice()
|
|
||||||
.sort(
|
|
||||||
(a: Task, b: Task) =>
|
|
||||||
(reverse ? -1 : 1) *
|
(reverse ? -1 : 1) *
|
||||||
(a.updated_at.getTime() - b.updated_at.getTime()),
|
(a.updated_at.getTime() - b.updated_at.getTime());
|
||||||
);
|
|
||||||
case SortType.CHECK_DATE:
|
case SortType.CHECK_DATE:
|
||||||
return tasks
|
return (a: Task, b: Task) =>
|
||||||
.slice()
|
|
||||||
.sort(
|
|
||||||
(a: Task, b: Task) =>
|
|
||||||
(reverse ? -1 : 1) *
|
(reverse ? -1 : 1) *
|
||||||
((a.check_date ?? a.created_at).getTime() -
|
((a.check_date ?? fallbackDate(a)).getTime() -
|
||||||
(b.check_date ?? b.created_at).getTime()),
|
(b.check_date ?? fallbackDate(b)).getTime());
|
||||||
);
|
|
||||||
case SortType.RESET_DATE:
|
case SortType.RESET_DATE:
|
||||||
return tasks
|
return (a: Task, b: Task) =>
|
||||||
.slice()
|
|
||||||
.sort(
|
|
||||||
(a: Task, b: Task) =>
|
|
||||||
(reverse ? -1 : 1) *
|
(reverse ? -1 : 1) *
|
||||||
(taskNextReset(a) ?? a.created_at).getTime() -
|
((taskSortReset(a) ?? fallbackDate(a)).getTime() -
|
||||||
(taskNextReset(b) ?? b.created_at).getTime(),
|
(taskSortReset(b) ?? fallbackDate(b)).getTime());
|
||||||
);
|
|
||||||
case SortType.NAME:
|
case SortType.NAME:
|
||||||
return tasks
|
return (a: Task, b: Task) =>
|
||||||
.slice()
|
(reverse ? -1 : 1) * a.name.localeCompare(b.name);
|
||||||
.sort(
|
|
||||||
(a: Task, b: Task) =>
|
|
||||||
(reverse ? -1 : 1) * a.name.localeCompare(b.name),
|
|
||||||
);
|
|
||||||
default:
|
|
||||||
return tasks.slice();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,11 +2,9 @@
|
|||||||
import { useListStore } from "@/stores/lists";
|
import { useListStore } from "@/stores/lists";
|
||||||
import { ArrowBigRightDashIcon, DicesIcon, HistoryIcon } from "@lucide/vue";
|
import { ArrowBigRightDashIcon, DicesIcon, HistoryIcon } from "@lucide/vue";
|
||||||
import { generateSlug } from "random-word-slugs";
|
import { generateSlug } from "random-word-slugs";
|
||||||
import { defineAsyncComponent, onBeforeMount, ref } from "vue";
|
import { onBeforeMount, ref } from "vue";
|
||||||
import { onBeforeRouteUpdate } from "vue-router";
|
import { onBeforeRouteUpdate } from "vue-router";
|
||||||
const RecentItem = defineAsyncComponent(
|
import RecentItem from "@/components/RecentItem.vue";
|
||||||
() => import("@/components/RecentItem.vue"),
|
|
||||||
);
|
|
||||||
|
|
||||||
const listNameInput = ref<string>(generateSlug(4));
|
const listNameInput = ref<string>(generateSlug(4));
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import { ref, onBeforeMount, computed, defineAsyncComponent } from "vue";
|
import { ref, onBeforeMount, computed } from "vue";
|
||||||
import type { Task } from "@/types";
|
import type { Task } from "@/types";
|
||||||
import { getTasks, createTask, deleteTask } from "@/api/tasks";
|
import { getTasks, createTask, deleteTask } from "@/api/tasks";
|
||||||
import {
|
import {
|
||||||
@@ -9,13 +9,9 @@ import {
|
|||||||
SearchIcon,
|
SearchIcon,
|
||||||
Share2Icon,
|
Share2Icon,
|
||||||
} from "@lucide/vue";
|
} from "@lucide/vue";
|
||||||
const TaskItem = defineAsyncComponent(
|
import TaskItem from "@/components/TaskItem.vue";
|
||||||
() => import("@/components/TaskItem.vue"),
|
import ListOptions from "@/components/ListOptions.vue";
|
||||||
);
|
import { taskCompleted, taskSortFunction, newTemporaryTask } from "@/lib/tasks";
|
||||||
const ListOptions = defineAsyncComponent(
|
|
||||||
() => import("@/components/ListOptions.vue"),
|
|
||||||
);
|
|
||||||
import { taskCompleted, sortTasks, newTemporaryTask } from "@/lib/tasks";
|
|
||||||
import { SortType } from "@/enums";
|
import { SortType } from "@/enums";
|
||||||
import { booleanCookieRef, enumCookieRef } from "@/lib/cookies";
|
import { booleanCookieRef, enumCookieRef } from "@/lib/cookies";
|
||||||
import { useAlertStore } from "@/stores/alerts";
|
import { useAlertStore } from "@/stores/alerts";
|
||||||
@@ -79,7 +75,7 @@ function fetchTasks(requestedList: string) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function reSortTasks(update = false) {
|
function reSortTasks(update = false) {
|
||||||
tasks.value = sortTasks(tasks.value, sortType.value, sortReverse.value);
|
tasks.value.sort(taskSortFunction(sortType.value, sortReverse.value));
|
||||||
if (update) {
|
if (update) {
|
||||||
updateTitle();
|
updateTitle();
|
||||||
if (tasks.value.length && list.value) {
|
if (tasks.value.length && list.value) {
|
||||||
|
|||||||
@@ -323,7 +323,7 @@ asyncpg = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "tout-doux"
|
name = "tout-doux"
|
||||||
version = "1.7.0"
|
version = "1.7.6"
|
||||||
source = { editable = "." }
|
source = { editable = "." }
|
||||||
dependencies = [
|
dependencies = [
|
||||||
{ name = "flask", extra = ["async"] },
|
{ name = "flask", extra = ["async"] },
|
||||||
|
|||||||
Reference in New Issue
Block a user