Compare commits
5
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
fe5c0f94b2 | ||
|
|
664b47aa75 | ||
|
|
ce795582f9 | ||
|
|
bd87e5acf5 | ||
|
|
9081891d8f |
+1
-1
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "tout-doux",
|
||||
"version": "1.7.0",
|
||||
"version": "1.7.2",
|
||||
"private": true,
|
||||
"type": "module",
|
||||
"engines": {
|
||||
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
[project]
|
||||
name = "tout-doux"
|
||||
version = "1.7.0"
|
||||
version = "1.7.2"
|
||||
description = ""
|
||||
requires-python = ">=3.14"
|
||||
dependencies = [
|
||||
|
||||
@@ -1,7 +1,10 @@
|
||||
<script setup lang="ts">
|
||||
import { ref, onBeforeMount, watch } from "vue";
|
||||
import { ref, onBeforeMount, watch, defineAsyncComponent } from "vue";
|
||||
import { getCron, parseCron, validCron } from "@/lib/recurrence";
|
||||
import { CronType } from "@/enums";
|
||||
const DateInput = defineAsyncComponent(
|
||||
() => import("@/components/DateInput.vue"),
|
||||
);
|
||||
|
||||
const DEFAULT_CRON = "0 0 * * *";
|
||||
|
||||
@@ -11,7 +14,7 @@ const valid = ref<boolean>(true);
|
||||
const props = defineProps<{ editMode: boolean }>();
|
||||
|
||||
const cronType = ref<CronType>(CronType.MANUAL);
|
||||
const cronValue = ref<string>('0');
|
||||
const cronValue = ref<string>("0");
|
||||
const cronDate = ref<Date>(new Date());
|
||||
|
||||
function onCronChanged() {
|
||||
@@ -23,13 +26,18 @@ function onCronChanged() {
|
||||
}
|
||||
|
||||
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() {
|
||||
switch (cronType.value) {
|
||||
case CronType.EVERY_DAY:
|
||||
cronValue.value = '0';
|
||||
cronValue.value = "0";
|
||||
break;
|
||||
case CronType.EVERY_WEEK:
|
||||
case CronType.EVERY_MONTH:
|
||||
@@ -37,7 +45,7 @@ function onChangeCronType() {
|
||||
case CronType.EVERY_N_DAYS:
|
||||
case CronType.EVERY_N_WEEKS:
|
||||
case CronType.EVERY_N_MONTHS:
|
||||
cronValue.value = '1';
|
||||
cronValue.value = "1";
|
||||
break;
|
||||
case CronType.CUSTOM:
|
||||
cron.value ??= DEFAULT_CRON;
|
||||
@@ -50,8 +58,7 @@ function onChangeCronValue() {
|
||||
updateCron();
|
||||
}
|
||||
|
||||
function onChangeCronDate(event: InputEvent) {
|
||||
cronDate.value = new Date((event.target as HTMLInputElement).value);
|
||||
function onChangeCronDate() {
|
||||
updateCron();
|
||||
}
|
||||
|
||||
@@ -73,7 +80,11 @@ watch(cron, () => {
|
||||
|
||||
<template>
|
||||
<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">
|
||||
{{ $t("cron.type.manual") }}
|
||||
</option>
|
||||
@@ -139,21 +150,23 @@ watch(cron, () => {
|
||||
class="select flex-1"
|
||||
@change="onChangeCronValue"
|
||||
>
|
||||
<option :value="1">{{ $t('cron.month.first_day') }}</option>
|
||||
<option :value="32">{{ $t('cron.month.last_day') }}</option>
|
||||
<option :value="1">{{ $t("cron.month.first_day") }}</option>
|
||||
<option :value="32">{{ $t("cron.month.last_day") }}</option>
|
||||
<option
|
||||
v-for="i in Array.from(Array(7).keys())"
|
||||
:key="`d${-(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
|
||||
v-for="i in Array.from(Array(7).keys())"
|
||||
:key="`d${-(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
|
||||
v-for="i in Array.from(Array(30).keys())"
|
||||
@@ -161,11 +174,11 @@ watch(cron, () => {
|
||||
:value="i + 2"
|
||||
>
|
||||
{{
|
||||
(i % 10 == 9 && i !== 9)
|
||||
i % 10 == 9 && i !== 9
|
||||
? $t("cron.month.st", [i + 2])
|
||||
: (i % 10 === 0 && i !== 10)
|
||||
: i % 10 === 0 && i !== 10
|
||||
? $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.th", [i + 2])
|
||||
}}
|
||||
@@ -194,23 +207,32 @@ watch(cron, () => {
|
||||
@input="onInputRawCron"
|
||||
/>
|
||||
<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"
|
||||
type="number"
|
||||
min="1"
|
||||
step="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") }}
|
||||
<input
|
||||
v-if="cronType === CronType.EVERY_N_DAYS || cronType === CronType.EVERY_N_WEEKS || cronType === CronType.EVERY_N_MONTHS"
|
||||
:value="cronDate.toISOString().substring(0, 10)"
|
||||
<date-input
|
||||
v-model="cronDate"
|
||||
required
|
||||
type="date"
|
||||
class="input font-mono"
|
||||
@input="onChangeCronDate"
|
||||
@change="onChangeCronDate"
|
||||
/>
|
||||
</label>
|
||||
</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>
|
||||
@@ -22,7 +22,7 @@ export function parseCron(cron: string | null): {
|
||||
value: 0,
|
||||
date: null,
|
||||
};
|
||||
} else if (cron.startsWith("RRULE:")) {
|
||||
} else if (cron.startsWith("RRULE:") || cron.startsWith("DTSTART:")) {
|
||||
return parseRrule(cron);
|
||||
} else if ((value = /^0 (\d+) \* \* \*$/i.exec(cron)) !== null) {
|
||||
return {
|
||||
@@ -145,11 +145,23 @@ export function getCron(
|
||||
case CronType.EVERY_YEAR:
|
||||
return `0 0 1 ${value.toFixed(0)} *`;
|
||||
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:
|
||||
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:
|
||||
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:
|
||||
if (validCron(fallback)) {
|
||||
return fallback;
|
||||
@@ -160,7 +172,7 @@ export function getCron(
|
||||
}
|
||||
|
||||
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`
|
||||
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 {
|
||||
|
||||
Reference in New Issue
Block a user