mirror of
https://github.com/zadam/trilium.git
synced 2026-02-22 13:44:25 +01:00
feat(badges/content): configurable backend run options
This commit is contained in:
parent
ef75de63fe
commit
bd1f0909a2
@ -2295,6 +2295,11 @@
|
|||||||
"toggle_tooltip_enable_tooltip": "Click to enable this {{type}}.",
|
"toggle_tooltip_enable_tooltip": "Click to enable this {{type}}.",
|
||||||
"toggle_tooltip_disable_tooltip": "Click to disable this {{type}}.",
|
"toggle_tooltip_disable_tooltip": "Click to disable this {{type}}.",
|
||||||
"menu_docs": "Open documentation",
|
"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"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,4 +1,5 @@
|
|||||||
import { BUILTIN_ATTRIBUTES } from "@triliumnext/commons";
|
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 { useEffect, useState } from "preact/hooks";
|
||||||
|
|
||||||
import FNote from "../../entities/fnote";
|
import FNote from "../../entities/fnote";
|
||||||
@ -6,9 +7,9 @@ import attributes from "../../services/attributes";
|
|||||||
import { t } from "../../services/i18n";
|
import { t } from "../../services/i18n";
|
||||||
import { openInAppHelpFromUrl } from "../../services/utils";
|
import { openInAppHelpFromUrl } from "../../services/utils";
|
||||||
import { BadgeWithDropdown } from "../react/Badge";
|
import { BadgeWithDropdown } from "../react/Badge";
|
||||||
import { FormDropdownDivider, FormListItem } from "../react/FormList";
|
import { FormDropdownDivider, FormDropdownSubmenu, FormListItem } from "../react/FormList";
|
||||||
import FormToggle from "../react/FormToggle";
|
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 DANGEROUS_ATTRIBUTES = BUILTIN_ATTRIBUTES.filter(a => a.isDangerous);
|
||||||
const activeContentLabels = [ "iconPack" ] as const;
|
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];
|
const { icon, helpPage, apiDocsPage, isExecutable } = typeMappings[info.type];
|
||||||
return (
|
return (
|
||||||
<BadgeWithDropdown
|
<BadgeWithDropdown
|
||||||
@ -63,6 +64,7 @@ function ActiveContentBadge({ info }: { note: FNote, info: ActiveContentInfo })
|
|||||||
icon="bx bx-play"
|
icon="bx bx-play"
|
||||||
triggerCommand="runActiveNote"
|
triggerCommand="runActiveNote"
|
||||||
>{t("active_content_badges.menu_execute_now")}</FormListItem>
|
>{t("active_content_badges.menu_execute_now")}</FormListItem>
|
||||||
|
<ScriptRunOptions note={note} />
|
||||||
<FormDropdownDivider />
|
<FormDropdownDivider />
|
||||||
</>
|
</>
|
||||||
)}
|
)}
|
||||||
@ -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 (
|
||||||
|
<FormDropdownSubmenu title={t("active_content_badges.menu_run")} icon="bx bx-rss" dropStart>
|
||||||
|
{options.map(({ title, value }) => (
|
||||||
|
<FormListItem
|
||||||
|
key={value}
|
||||||
|
onClick={() => setRun(value)}
|
||||||
|
checked={run ? run === value : value === null }
|
||||||
|
>{title}</FormListItem>
|
||||||
|
))}
|
||||||
|
</FormDropdownSubmenu>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
function getTranslationForType(type: ActiveContentInfo["type"]) {
|
function getTranslationForType(type: ActiveContentInfo["type"]) {
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case "iconPack":
|
case "iconPack":
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user