diff --git a/apps/client/src/services/frontend_script_api.ts b/apps/client/src/services/frontend_script_api.ts index 8a1497cd9..e16670d38 100644 --- a/apps/client/src/services/frontend_script_api.ts +++ b/apps/client/src/services/frontend_script_api.ts @@ -77,6 +77,10 @@ export interface Api { /** * Entity whose event triggered this execution. + * + *

+ * For front-end scripts, generally there's no origin entity specified since the scripts are run by the user or automatically by the UI (widgets). + * If there is an origin entity specified, then it's going to be a note entity. */ originEntity: unknown | null; @@ -278,12 +282,16 @@ export interface Api { getActiveContextNote(): FNote; /** - * @returns returns active context (split) + * Obtains the currently active/focused split in the current tab. + * + * Note that this method does not return the note context of the "Quick edit" panel, it will return the note context behind it. */ getActiveContext(): NoteContext; /** - * @returns returns active main context (first split in a tab, represents the tab as a whole) + * Obtains the main context of the current tab. This is the left-most split. + * + * Note that this method does not return the note context of the "Quick edit" panel, it will return the note context behind it. */ getActiveMainContext(): NoteContext; diff --git a/apps/server/src/assets/doc_notes/en/User Guide/User Guide/Installation & Setup/Server Installation/2. Reverse proxy/Traefik.html b/apps/server/src/assets/doc_notes/en/User Guide/User Guide/Installation & Setup/Server Installation/2. Reverse proxy/Traefik.html index b2aea2650..8132e7672 100644 --- a/apps/server/src/assets/doc_notes/en/User Guide/User Guide/Installation & Setup/Server Installation/2. Reverse proxy/Traefik.html +++ b/apps/server/src/assets/doc_notes/en/User Guide/User Guide/Installation & Setup/Server Installation/2. Reverse proxy/Traefik.html @@ -4,7 +4,7 @@

Breaking change in Traefik 3.6.4

Traefik 3.6.4 introduced a breaking change regarding how percent-encoded characters are handled in URLs. More specifically some - URLs used by Trilium (such as search/%23workspace%20%23!template) + URLs used by Trilium (such as search/%23workspace%20%23!template) are automatically rejected by Traefik, resulting in HTTP 400 errors.

To solve this, the Traefik static configuration must be modified in order to allow those characters:

entryPoints:
@@ -36,7 +36,7 @@
 

Setup needed environment variables

After setting up a reverse proxy, make sure to configure the Trusted proxy.

-

Example docker-compose.yaml

services:
+

Example docker-compose.yaml

services:
   trilium:
     image: triliumnext/trilium
     container_name: trilium
diff --git a/apps/server/src/assets/doc_notes/en/User Guide/User Guide/Scripting/Backend scripts/Events.html b/apps/server/src/assets/doc_notes/en/User Guide/User Guide/Scripting/Backend scripts/Events.html
index 1d9c56fb3..59a2a8738 100644
--- a/apps/server/src/assets/doc_notes/en/User Guide/User Guide/Scripting/Backend scripts/Events.html	
+++ b/apps/server/src/assets/doc_notes/en/User Guide/User Guide/Scripting/Backend scripts/Events.html	
@@ -5,122 +5,169 @@
 

Global events are attached to the script note via label. Simply create e.g. "run" label with some of these values and script note will be executed once the event occurs.

- - - - - - - - - - - - - - - - - - - - - -
LabelDescription
run - -

Defines on which events script should run. Possible values are:

-
    -
  • frontendStartup - when Trilium frontend starts up (or is refreshed), - but not on mobile.
  • -
  • mobileStartup - when Trilium frontend starts up (or is refreshed), - on mobile.
  • -
  • backendStartup - when Trilium backend starts up
  • -
  • hourly - run once an hour. You can use additional label runAtHour to - specify at which hour, on the back-end.
  • -
  • daily - run once a day, on the back-end
  • -
-
runOnInstance - Specifies that the script should only run on a particular Trilium instance.
runAtHour - On which hour should this run. Should be used together with #run=hourly. - Can be defined multiple times for more runs during the day.
- +
+ + + + + + + + + + + + + + + + + + + + + +
LabelDescription
run + +

Defines on which events script should run. Possible values are:

+
    +
  • frontendStartup - when Trilium frontend + starts up (or is refreshed), but not on mobile.
  • +
  • mobileStartup - when Trilium frontend starts + up (or is refreshed), on mobile.
  • +
  • backendStartup - when Trilium backend starts + up
  • +
  • hourly - run once an hour. You can use + additional label runAtHour to specify at + which hour, on the back-end.
  • +
  • daily - run once a day, on the back-end
  • +
+
runOnInstance + Specifies that the script should only run on a particular Trilium instance.
runAtHour + On which hour should this run. Should be used together with #run=hourly. + Can be defined multiple times for more runs during the day.
+

Entity events

Other events are bound to some entity, these are defined as relations - meaning that script is triggered only if note has this script attached to it through relations (or it can inherit it).

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
RelationDescription
runOnNoteCreation - executes when note is created on backend. Use this relation if you want - to run the script for all notes created under a specific subtree. In that - case, create it on the subtree root note and make it inheritable. A new - note created within the subtree (any depth) will trigger the script.
runOnChildNoteCreation - executes when new note is created under the note where this relation is - defined
runOnNoteTitleChange - executes when note title is changed (includes note creation as well)
runOnNoteContentChange - executes when note content is changed (includes note creation as well).
runOnNoteChange - executes when note is changed (includes note creation as well). Does not - include content changes
runOnNoteDeletion - executes when note is being deleted
runOnBranchCreation - executes when a branch is created. Branch is a link between parent note - and child note and is created e.g. when cloning or moving note.
runOnBranchChange - executes when a branch is updated. (since v0.62)
runOnBranchDeletion - executes when a branch is deleted. Branch is a link between parent note - and child note and is deleted e.g. when moving note (old branch/link is - deleted).
runOnAttributeCreation - executes when new attribute is created for the note which defines this - relation
runOnAttributeChange - executes when the attribute is changed of a note which defines this relation. - This is triggered also when the attribute is deleted
\ No newline at end of file +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
RelationTrigger conditionOrigin entity (see below)
runOnNoteCreation + executes when note is created on backend. Use this relation if you want + to run the script for all notes created under a specific subtree. In that + case, create it on the subtree root note and make it inheritable. A new + note created within the subtree (any depth) will trigger the script.The BNote that got created.
runOnChildNoteCreation + executes when new note is created under the note where this relation is + definedThe BNote of the child that got created.
runOnNoteTitleChange + executes when note title is changed (includes note creation as well)The BNote of the note whose title got changed.
runOnNoteContentChange + executes when note content is changed (includes note creation as well).The BNote of the note whose content got + changed.
runOnNoteChange + executes when note is changed (includes note creation as well). Does not + include content changesThe BNote of the note that got changed.
runOnNoteDeletion + executes when note is being deletedThe BNote of the note that got (soft) deleted.
runOnBranchCreation + executes when a branch is created. Branch is a link between parent note + and child note and is created e.g. when cloning or moving note.The BBranch that got created.
runOnBranchChange + executes when a branch is updated. (since v0.62)The BBranch that got changed.
runOnBranchDeletion + executes when a branch is deleted. Branch is a link between parent note + and child note and is deleted e.g. when moving note (old branch/link is + deleted).The BBranch that got (soft) deleted.
runOnAttributeCreation + executes when new attribute is created for the note which defines this + relationThe BAttribute that got created.
runOnAttributeChange + executes when the attribute is changed of a note which defines this relation. + This is triggered also when the attribute is deletedThe BAttribute that got changed.
+
+

Origin entity

+

When a script is run by an event such as the ones described above, + api.originEntitywill get populated with the note, branch or attribute + that triggered the change.

+

For example, here's a script with ~runOnAttributeChange which + automatically changes the color of a note based on the value of the + mycategorylabel:

const attr = api.originEntity;
+
+if (attr.name !== "mycategory") return;
+
+const note = api.getNote(attr.noteId);
+
+if (attr.value === "Health") {
+
+    note.setLabel("color", "green");
+
+} else {
+
+    note.removeLabel("color");
+
+}
\ No newline at end of file diff --git a/docs/Developer Guide/Developer Guide/Documentation.md b/docs/Developer Guide/Developer Guide/Documentation.md index cb411c0f7..5889ed1be 100644 --- a/docs/Developer Guide/Developer Guide/Documentation.md +++ b/docs/Developer Guide/Developer Guide/Documentation.md @@ -1,5 +1,5 @@ # Documentation -There are multiple types of documentation for Trilium: +There are multiple types of documentation for Trilium: * The _User Guide_ represents the user-facing documentation. This documentation can be browsed by users directly from within Trilium, by pressing F1. * The _Developer's Guide_ represents a set of Markdown documents that present the internals of Trilium, for developers. diff --git a/docs/User Guide/User Guide/Scripting/Backend scripts/Events.md b/docs/User Guide/User Guide/Scripting/Backend scripts/Events.md index 227acd5f1..2ffd2bbdb 100644 --- a/docs/User Guide/User Guide/Scripting/Backend scripts/Events.md +++ b/docs/User Guide/User Guide/Scripting/Backend scripts/Events.md @@ -5,22 +5,39 @@ Global events are attached to the script note via label. Simply create e.g. "run" label with some of these values and script note will be executed once the event occurs. -
LabelDescription
run

Defines on which events script should run. Possible values are:

  • frontendStartup - when Trilium frontend starts up (or is refreshed), but not on mobile.
  • mobileStartup - when Trilium frontend starts up (or is refreshed), on mobile.
  • backendStartup - when Trilium backend starts up
  • hourly - run once an hour. You can use additional label runAtHour to specify at which hour, on the back-end.
  • daily - run once a day, on the back-end
runOnInstanceSpecifies that the script should only run on a particular Trilium instance.
runAtHourOn which hour should this run. Should be used together with #run=hourly. Can be defined multiple times for more runs during the day.
+
LabelDescription
run

Defines on which events script should run. Possible values are:

  • frontendStartup - when Trilium frontend starts up (or is refreshed), but not on mobile.
  • mobileStartup - when Trilium frontend starts up (or is refreshed), on mobile.
  • backendStartup - when Trilium backend starts up
  • hourly - run once an hour. You can use additional label runAtHour to specify at which hour, on the back-end.
  • daily - run once a day, on the back-end
runOnInstanceSpecifies that the script should only run on a particular Trilium instance.
runAtHourOn which hour should this run. Should be used together with #run=hourly. Can be defined multiple times for more runs during the day.
## Entity events Other events are bound to some entity, these are defined as [relations](../../Advanced%20Usage/Attributes.md) - meaning that script is triggered only if note has this script attached to it through relations (or it can inherit it). -| Relation | Description | -| --- | --- | -| `runOnNoteCreation` | executes when note is created on backend. Use this relation if you want to run the script for all notes created under a specific subtree. In that case, create it on the subtree root note and make it inheritable. A new note created within the subtree (any depth) will trigger the script. | -| `runOnChildNoteCreation` | executes when new note is created under the note where this relation is defined | -| `runOnNoteTitleChange` | executes when note title is changed (includes note creation as well) | -| `runOnNoteContentChange` | executes when note content is changed (includes note creation as well). | -| `runOnNoteChange` | executes when note is changed (includes note creation as well). Does not include content changes | -| `runOnNoteDeletion` | executes when note is being deleted | -| `runOnBranchCreation` | executes when a branch is created. Branch is a link between parent note and child note and is created e.g. when cloning or moving note. | -| `runOnBranchChange` | executes when a branch is updated. (since v0.62) | -| `runOnBranchDeletion` | executes when a branch is deleted. Branch is a link between parent note and child note and is deleted e.g. when moving note (old branch/link is deleted). | -| `runOnAttributeCreation` | executes when new attribute is created for the note which defines this relation | -| `runOnAttributeChange` | executes when the attribute is changed of a note which defines this relation. This is triggered also when the attribute is deleted | \ No newline at end of file +| Relation | Trigger condition | Origin entity (see below) | +| --- | --- | --- | +| `runOnNoteCreation` | executes when note is created on backend. Use this relation if you want to run the script for all notes created under a specific subtree. In that case, create it on the subtree root note and make it inheritable. A new note created within the subtree (any depth) will trigger the script. | The `BNote` that got created. | +| `runOnChildNoteCreation` | executes when new note is created under the note where this relation is defined | The `BNote` of the child that got created. | +| `runOnNoteTitleChange` | executes when note title is changed (includes note creation as well) | The `BNote` of the note whose title got changed. | +| `runOnNoteContentChange` | executes when note content is changed (includes note creation as well). | The `BNote` of the note whose content got changed. | +| `runOnNoteChange` | executes when note is changed (includes note creation as well). Does not include content changes | The `BNote` of the note that got changed. | +| `runOnNoteDeletion` | executes when note is being deleted | The `BNote` of the note that got (soft) deleted. | +| `runOnBranchCreation` | executes when a branch is created. Branch is a link between parent note and child note and is created e.g. when cloning or moving note. | The `BBranch` that got created. | +| `runOnBranchChange` | executes when a branch is updated. (since v0.62) | The `BBranch` that got changed. | +| `runOnBranchDeletion` | executes when a branch is deleted. Branch is a link between parent note and child note and is deleted e.g. when moving note (old branch/link is deleted). | The `BBranch` that got (soft) deleted. | +| `runOnAttributeCreation` | executes when new attribute is created for the note which defines this relation | The `BAttribute` that got created. | +| `runOnAttributeChange` | executes when the attribute is changed of a note which defines this relation. This is triggered also when the attribute is deleted | The `BAttribute` that got changed. | + +## Origin entity + +When a script is run by an event such as the ones described above, `api.originEntity` will get populated with the note, branch or attribute that triggered the change. + +For example, here's a script with `~runOnAttributeChange` which automatically changes the color of a note based on the value of the `mycategory` label: + +```javascript +const attr = api.originEntity; +if (attr.name !== "mycategory") return; +const note = api.getNote(attr.noteId); +if (attr.value === "Health") { + note.setLabel("color", "green"); +} else { + note.removeLabel("color"); +} +``` \ No newline at end of file