diff --git a/src/components/obsidian/ObsidianNumberInput.vue b/src/components/obsidian/ObsidianNumberInput.vue index 6f9c38b..30fbfe4 100644 --- a/src/components/obsidian/ObsidianNumberInput.vue +++ b/src/components/obsidian/ObsidianNumberInput.vue @@ -2,11 +2,21 @@ defineProps<{ placeholder?: string; disabled?: boolean; + min?: number; + max?: number; }>(); const model = defineModel(); diff --git a/src/defaults.ts b/src/defaults.ts index fc8fe7d..5a40f2d 100644 --- a/src/defaults.ts +++ b/src/defaults.ts @@ -34,10 +34,7 @@ export const defaultJournalSettings: JournalSettings = { folder: "", templates: [], - start: { - enabled: false, - date: "", - }, + start: "", end: { type: "never", diff --git a/src/journals/fixed-interval.ts b/src/journals/fixed-interval.ts index 4f7abf4..9b71adc 100644 --- a/src/journals/fixed-interval.ts +++ b/src/journals/fixed-interval.ts @@ -4,6 +4,7 @@ import type { IntervalResolver, JournalInterval } from "../types/journal.types"; import type { FixedWriteIntervals, JournalCommand } from "../types/settings.types"; import { FRONTMATTER_DATE_FORMAT } from "../constants"; import type { MomentDate } from "../types/date.types"; +import { date } from "../calendar"; // TODO: write tests export class FixedInterval implements IntervalResolver { @@ -57,6 +58,12 @@ export class FixedInterval implements IntervalResolver { return null; } + countRepeats(startDate: string, endDate: string): number { + const start = date(startDate); + const end = date(endDate); + return Math.ceil(start.diff(end, this.#settings.value.type)); + } + #buildInterval(base: MomentDate): JournalInterval { const type = this.#settings.value.type; const start_date = base.startOf(type).format(FRONTMATTER_DATE_FORMAT); diff --git a/src/journals/journal.ts b/src/journals/journal.ts index 8552442..e2af13a 100644 --- a/src/journals/journal.ts +++ b/src/journals/journal.ts @@ -15,7 +15,7 @@ import { FRONTMATTER_START_DATE_KEY, } from "../constants"; import { FixedInterval } from "./fixed-interval"; -import { today } from "../calendar"; +import { date, today } from "../calendar"; export class Journal { #config: ComputedRef; @@ -67,6 +67,7 @@ export class Journal { if (metadata) return metadata; const interval = this.#intervalResolver.resolveForDate(date); if (!interval) return null; + if (!this.#checkBounds(interval)) return null; return await this.#buildMetadata(interval); } @@ -79,6 +80,7 @@ export class Journal { if (!interval) return null; const nextMetadata = plugin$.value.index.find(this.id, interval.start_date); if (nextMetadata) return nextMetadata; + if (!this.#checkBounds(interval)) return null; return await this.#buildMetadata(interval); } @@ -91,6 +93,7 @@ export class Journal { if (!interval) return null; const previousMetadata = plugin$.value.index.find(this.id, interval.end_date); if (previousMetadata) return previousMetadata; + if (!this.#checkBounds(interval)) return null; return await this.#buildMetadata(interval); } @@ -229,4 +232,22 @@ export class Journal { if (command.context === "only_open_note") return null; return today().format(FRONTMATTER_DATE_FORMAT); } + + #checkBounds(interval: JournalInterval): boolean { + if (this.#config.value.start) { + const startDate = date(this.#config.value.start); + if (startDate.isValid() && date(interval.end_date).isBefore(startDate)) return false; + } + + if (this.#config.value.end.type === "date" && this.#config.value.end.date) { + const endDate = date(this.#config.value.end.date); + if (endDate.isValid() && date(interval.start_date).isAfter(endDate)) return false; + } + if (this.#config.value.end.type === "repeats" && this.#config.value.end.repeats && this.#config.value.start) { + const repeats = this.#intervalResolver.countRepeats(this.#config.value.start, interval.start_date); + if (repeats > this.#config.value.end.repeats) return false; + } + + return true; + } } diff --git a/src/settings/JournalSettingsDashboard.vue b/src/settings/JournalSettingsDashboard.vue index 295da5a..d0c3c4c 100644 --- a/src/settings/JournalSettingsDashboard.vue +++ b/src/settings/JournalSettingsDashboard.vue @@ -14,8 +14,6 @@ import type { JournalSettings, NotesProcessing } from "../types/settings.types"; import { plugin$ } from "../stores/obsidian.store"; import { updateLocale } from "../calendar"; -import DatePicker from "../components/DatePicker.vue"; - const emit = defineEmits<(event: "edit", id: string) => void>(); const fow = moment().localeData().firstDayOfWeek(); @@ -61,9 +59,6 @@ function remove(id: string): void {