mirror of
https://github.com/zadam/trilium.git
synced 2025-10-20 15:19:01 +02:00
feat(react/bulk_actions): port execute script
This commit is contained in:
parent
18c6fe7ebd
commit
7c79fbefa6
@ -1,58 +0,0 @@
|
||||
import { t } from "../../services/i18n.js";
|
||||
import SpacedUpdate from "../../services/spaced_update.js";
|
||||
import AbstractBulkAction from "./abstract_bulk_action.js";
|
||||
|
||||
const TPL = /*html*/`
|
||||
<tr>
|
||||
<td>
|
||||
${t("execute_script.execute_script")}
|
||||
</td>
|
||||
<td>
|
||||
<input type="text"
|
||||
class="form-control script"
|
||||
placeholder="note.title = note.title + '- suffix';"/>
|
||||
</td>
|
||||
<td class="button-column">
|
||||
<div style="display: flex; align-items: center; justify-content: space-between;">
|
||||
<div class="dropdown help-dropdown">
|
||||
<span class="bx bx-help-circle icon-action" data-bs-toggle="dropdown" aria-haspopup="true" aria-expanded="false"></span>
|
||||
<div class="dropdown-menu dropdown-menu-right p-4">
|
||||
${t("execute_script.help_text")}
|
||||
|
||||
${t("execute_script.example_1")}
|
||||
|
||||
<pre>note.title = note.title + ' - suffix';</pre>
|
||||
|
||||
${t("execute_script.example_2")}
|
||||
|
||||
<pre>for (const attr of note.getOwnedAttributes) { attr.markAsDeleted(); }</pre>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<span class="bx bx-x icon-action action-conf-del"></span>
|
||||
</div>
|
||||
</td>
|
||||
</tr>`;
|
||||
|
||||
export default class ExecuteScriptBulkAction extends AbstractBulkAction {
|
||||
static get actionName() {
|
||||
return "executeScript";
|
||||
}
|
||||
static get actionTitle() {
|
||||
return t("execute_script.execute_script");
|
||||
}
|
||||
|
||||
doRender() {
|
||||
const $action = $(TPL);
|
||||
const $script = $action.find(".script");
|
||||
$script.val(this.actionDef.script || "");
|
||||
|
||||
const spacedUpdate = new SpacedUpdate(async () => {
|
||||
await this.saveAction({ script: $script.val() });
|
||||
}, 1000);
|
||||
|
||||
$script.on("input", () => spacedUpdate.scheduleUpdate());
|
||||
|
||||
return $action;
|
||||
}
|
||||
}
|
50
apps/client/src/widgets/bulk_actions/execute_script.tsx
Normal file
50
apps/client/src/widgets/bulk_actions/execute_script.tsx
Normal file
@ -0,0 +1,50 @@
|
||||
import { useEffect, useState } from "preact/hooks";
|
||||
import { t } from "../../services/i18n.js";
|
||||
import FormTextBox from "../react/FormTextBox.jsx";
|
||||
import AbstractBulkAction, { ActionDefinition } from "./abstract_bulk_action.js";
|
||||
import BulkAction from "./BulkAction.jsx";
|
||||
import { useSpacedUpdate } from "../react/hooks.jsx";
|
||||
|
||||
function ExecuteScriptBulkActionComponent({ bulkAction, actionDef }: { bulkAction: AbstractBulkAction, actionDef: ActionDefinition }) {
|
||||
const [ script, setScript ] = useState(actionDef.script);
|
||||
const spacedUpdate = useSpacedUpdate(() => bulkAction.saveAction({ script }));
|
||||
useEffect(() => spacedUpdate.scheduleUpdate(), [ script ]);
|
||||
|
||||
return (
|
||||
<BulkAction
|
||||
bulkAction={bulkAction}
|
||||
label={t("execute_script.execute_script")}
|
||||
helpText={<>
|
||||
{t("execute_script.help_text")}
|
||||
|
||||
{t("execute_script.example_1")}
|
||||
|
||||
<pre>note.title = note.title + ' - suffix';</pre>
|
||||
|
||||
{t("execute_script.example_2")}
|
||||
|
||||
<pre>{"for (const attr of note.getOwnedAttributes) { attr.markAsDeleted(); }"}</pre>
|
||||
</>}
|
||||
>
|
||||
<FormTextBox
|
||||
placeholder="note.title = note.title + '- suffix';"
|
||||
currentValue={script} onChange={setScript}
|
||||
/>
|
||||
</BulkAction>
|
||||
);
|
||||
}
|
||||
|
||||
export default class ExecuteScriptBulkAction extends AbstractBulkAction {
|
||||
|
||||
static get actionName() {
|
||||
return "executeScript";
|
||||
}
|
||||
static get actionTitle() {
|
||||
return t("execute_script.execute_script");
|
||||
}
|
||||
|
||||
doRender() {
|
||||
return <ExecuteScriptBulkActionComponent bulkAction={this} actionDef={this.actionDef} />
|
||||
}
|
||||
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user