diff --git a/apps/client/src/translations/en/translation.json b/apps/client/src/translations/en/translation.json index c8ded0fbb4..cc468ff597 100644 --- a/apps/client/src/translations/en/translation.json +++ b/apps/client/src/translations/en/translation.json @@ -2295,6 +2295,11 @@ "toggle_tooltip_enable_tooltip": "Click to enable this {{type}}.", "toggle_tooltip_disable_tooltip": "Click to disable this {{type}}.", "menu_docs": "Open documentation", - "menu_execute_now": "Execute script now" + "menu_execute_now": "Execute script now", + "menu_run": "Run automatically", + "menu_run_disabled": "Manually", + "menu_run_backend_startup": "When the backend starts up", + "menu_run_hourly": "Hourly", + "menu_run_daily": "Daily" } } diff --git a/apps/client/src/widgets/layout/ActiveContentBadges.tsx b/apps/client/src/widgets/layout/ActiveContentBadges.tsx index 936c6da7a6..a0b3af16c7 100644 --- a/apps/client/src/widgets/layout/ActiveContentBadges.tsx +++ b/apps/client/src/widgets/layout/ActiveContentBadges.tsx @@ -1,4 +1,5 @@ import { BUILTIN_ATTRIBUTES } from "@triliumnext/commons"; +import { note } from "mermaid/dist/rendering-util/rendering-elements/shapes/note.js"; import { useEffect, useState } from "preact/hooks"; import FNote from "../../entities/fnote"; @@ -6,9 +7,9 @@ import attributes from "../../services/attributes"; import { t } from "../../services/i18n"; import { openInAppHelpFromUrl } from "../../services/utils"; import { BadgeWithDropdown } from "../react/Badge"; -import { FormDropdownDivider, FormListItem } from "../react/FormList"; +import { FormDropdownDivider, FormDropdownSubmenu, FormListItem } from "../react/FormList"; import FormToggle from "../react/FormToggle"; -import { useNoteContext, useTriliumEvent } from "../react/hooks"; +import { useNoteContext, useNoteLabel, useTriliumEvent, useTriliumOption } from "../react/hooks"; const DANGEROUS_ATTRIBUTES = BUILTIN_ATTRIBUTES.filter(a => a.isDangerous); const activeContentLabels = [ "iconPack" ] as const; @@ -49,7 +50,7 @@ export function ActiveContentBadges() { ); } -function ActiveContentBadge({ info }: { note: FNote, info: ActiveContentInfo }) { +function ActiveContentBadge({ info, note }: { note: FNote, info: ActiveContentInfo }) { const { icon, helpPage, apiDocsPage, isExecutable } = typeMappings[info.type]; return ( {t("active_content_badges.menu_execute_now")} + )} @@ -80,6 +82,49 @@ function ActiveContentBadge({ info }: { note: FNote, info: ActiveContentInfo }) ); } +function ScriptRunOptions({ note }: { note: FNote }) { + const [ run, setRun ] = useNoteLabel(note, "run"); + + const options: { + title: string; + value: string | null; + type: "backendScript" | "frontendScript"; + }[] = [ + { + title: t("active_content_badges.menu_run_disabled"), + value: null, + type: "backendScript" + }, + { + title: t("active_content_badges.menu_run_backend_startup"), + value: "backendStartup", + type: "backendScript" + }, + { + title: t("active_content_badges.menu_run_daily"), + value: "daily", + type: "backendScript" + }, + { + title: t("active_content_badges.menu_run_hourly"), + value: "hourly", + type: "backendScript" + }, + ]; + + return ( + + {options.map(({ title, value }) => ( + setRun(value)} + checked={run ? run === value : value === null } + >{title} + ))} + + ); +} + function getTranslationForType(type: ActiveContentInfo["type"]) { switch (type) { case "iconPack":