diff --git a/Advanced showcases.md b/Advanced showcases.md new file mode 100644 index 0000000..e601941 --- /dev/null +++ b/Advanced showcases.md @@ -0,0 +1 @@ +Good \ No newline at end of file diff --git a/Attribute inheritance.md b/Attribute inheritance.md new file mode 100644 index 0000000..8bc8f41 --- /dev/null +++ b/Attribute inheritance.md @@ -0,0 +1,7 @@ +Every [[attribute|attributes]] has a flag called `isInheritable`. If this is true, then this attribute (key-value) is also applied to all its children notes, children's children notes etc. + +## Copying inheritance + +Different kind of inheritance is achieved using "child:" attribute name prefix. If we create a child note in a note with "child:exampleAttribute" attribute, then child note will have "exampleAttribute" created. This can be even chained, e.g. "child:child:exampleAttribute", in this case "exampleAttribute" will be created in the child of the child. + +Which kind of attribute inheritance (or if any at all) should be used depends on specific use case. \ No newline at end of file diff --git a/Attributes.md b/Attributes.md index 1e07e1b..70ac1a7 100644 --- a/Attributes.md +++ b/Attributes.md @@ -55,8 +55,4 @@ Attributes allow multiplicity - there can be multiple attributes with the same n ## Attribute inheritance -Every attribute has a flag called `isInheritable`. If this is true, then this attribute (key-value) is also applied to all its children notes, children's children notes etc. - -Different kind of inheritance is achieved using "child:" attribute name prefix. If we create a child note in a note with "child:exampleAttribute" attribute, then child note will have "exampleAttribute" created. This can be even chained, e.g. "child:child:exampleAttribute", in this case "exampleAttribute" will be created in the child of the child. - -Which kind of attribute inheritance (or if any at all) should be used depends on specific use case. \ No newline at end of file +See [[Attribute inheritance]]. \ No newline at end of file diff --git a/Day notes.md b/Day notes.md index a5d4e09..ee55af7 100644 --- a/Day notes.md +++ b/Day notes.md @@ -17,6 +17,6 @@ Trilium has some special support for day notes in the form of [backend Script AP Day (and year, month) notes are created with a label - e.g. `@dateNote=2018-08-16` this can then be used by other scripts to add new notes to day note etc. -Journal has [[attributes]] `@sorted @child:sorted @child:sorted:sorted` which keeps notes sorted on all three levels of years, months and dates. +Journal has [[attributes]] `@sorted @child:sorted @child:sorted:sorted` (see [[attribute inheritance]]) which keeps notes sorted on all three levels of years, months and dates. Journal also has relation "child:child:child:template=Day template" which effectively adds [[template]] to day notes (grand-grand-grand children of Journal). The template is pretty simple - it just adds "weight" promoted attribute to keep track of our daily weight. \ No newline at end of file diff --git a/Events.md b/Events.md new file mode 100644 index 0000000..5af9421 --- /dev/null +++ b/Events.md @@ -0,0 +1,17 @@ +In general we may say that [[script|scripts]] notes are triggered by events. "run" represents global events: + +* `run` + * `frontendStartup` - executes on frontend upon startup + * `backendStartup` - executes on backend upon startup + * `hourly` - executes once an hour on backend + * `daily` - executes once a day on backend + +Other events are bound to some entity, these are defined as [[relations|Attributes]] - meaning that script is triggered only if note has this script attached to it through relations (or it can inherit it). + +* `runOnNoteView` - executes when note is displayed on frontend +* `runOnNoteCreation` - executes when note is created on backend +* `runOnNoteTitleChange` - executes when note title is changed (includes note creation as well) +* `runOnNoteChange` - executes when note is changed (includes note creation as well) +* `runOnChildNoteCreation` - executes when new note is created under *this* note +* `runOnAttributeCreation` - executes when new attribute is created under *this* note +* `runOnAttributeChange` - executes when attribute is changed under *this* note \ No newline at end of file diff --git a/Family tree.md b/Family tree.md index 7639486..4997550 100644 --- a/Family tree.md +++ b/Family tree.md @@ -9,7 +9,7 @@ Sometimes it can be difficult to remember all the extended family, relations and ## Implementation -Members note has `child:template` [[attribute|attributes]] defined which means that any note created as a child to Members will have `template` attribute pointing to the `Person template` note (see [[template]]). +Members note has `child:template` [[attribute|attributes]] (see [[attribute inheritance]]) defined which means that any note created as a child to Members will have `template` attribute pointing to the `Person template` note (see [[template]]). This `Person template` defines multiple [[promoted attributes]], some of which (isPartnerOf, isChildOf) allow multiplicity - there can be multiple such relations. diff --git a/Scripts.md b/Scripts.md index 62715b3..418139a 100644 --- a/Scripts.md +++ b/Scripts.md @@ -47,23 +47,7 @@ The solution is marked by red circle at the bottom - this note has [[label|Attri ### Events -In general we may say that script notes are triggered by events. "run" represents global events: - -* `run` - * `frontendStartup` - executes on frontend upon startup - * `backendStartup` - executes on backend upon startup - * `hourly` - executes once an hour on backend - * `daily` - executes once a day on backend - -Other events are bound to some entity, these are defined as [[relations|Attributes]] - meaning that script is triggered only if note has this script attached to it through relations (or it can inherit it). - -* `runOnNoteView` - executes when note is displayed on frontend -* `runOnNoteCreation` - executes when note is created on backend -* `runOnNoteTitleChange` - executes when note title is changed (includes note creation as well) -* `runOnNoteChange` - executes when note is changed (includes note creation as well) -* `runOnChildNoteCreation` - executes when new note is created under *this* note -* `runOnAttributeCreation` - executes when new attribute is created under *this* note -* `runOnAttributeChange` - executes when attribute is changed under *this* note +See [[Events]]. ## Script API diff --git a/Task manager.md b/Task manager.md index e69de29..99481a6 100644 --- a/Task manager.md +++ b/Task manager.md @@ -0,0 +1,61 @@ +Task Manager is a [[promoted attributes]] and [[scripts]] showcase present in the [[demo document|Document#demo-document]]. + +## Demo +[[images/weight-tracker.png]] + +Task Manager manages outstanding (TODO) tasks and finished tasks (non-empty doneDate attribute). Outstanding tasks are further categorized by location and arbitrary tags - whenever you change tag attribute in the task note, this task is then automatically moved to appropriate location. + +Task Manager also integrates with [[day notes]] - notes are [[cloned|cloning notes]] into day note to both todoDate note and doneDate note (with [[prefix|Tree concepts#prefix]] of either "TODO" or "DONE"). + +## Implementation + +New tasks are created in the TODO note which has "child:template" [[relation|attributes]] (see [[attribute inheritance]]) pointing to the task template. + +### Attributes + +Task template defines several [[promoted attributes]] - todoDate, doneData, tags, location. Importantly it also defines `runOnAttributeChange` relation - [[event|events]] handler which is run on attribute change. This [[script|scripts]] handles when e.g. we fill out the doneDate attribute - meaning the task is done and should be moved to "Done" note and removed from TODO, locations and tags. + +### New task button + +There's also "button" note which contains simple script which adds a button to create new note (task) in the TODO note. + +```javascript +api.addButtonToToolbar({ + title: 'New task', + icon: 'check', + shortcut: 'alt+n', + action: async () => { + // creating notes is backend (server) responsibility so we need to pass + // the control there + const taskNoteId = await api.runOnServer(async () => { + const todoRootNote = await api.getNoteWithLabel('taskTodoRoot'); + const {note} = await api.createNote(todoRootNote.noteId, 'new task', ''); + + return note.noteId; + }); + + // we got an ID of newly created note and we want to immediatelly display it + await api.activateNewNote(taskNoteId); + } +}); +``` + +### CSS + +In the demo screenshot above you may notice that TODO tasks are in red color and DONE tasks are green. + +This is done by having this CSS code note which defines extra CSS classes: + +```CSS +span.fancytree-node.todo .fancytree-title { + color: red !important; +} + +span.fancytree-node.done .fancytree-title { + color: green !important; +} +``` + +This code note has `appCss` [[label|attributes]] which is recognized by Trilium on startup and loaded as CSS into the application. + +Second part of this functionality is based in event handler described above which assigns `cssClass` label to the task to either "done" or "todo" based on the task status. \ No newline at end of file diff --git a/Template.md b/Template.md index 852a692..0a3b924 100644 --- a/Template.md +++ b/Template.md @@ -6,6 +6,6 @@ To make these attributes really obvious, we make them "promoted" so they are vis Then whenever we create a new note for book we'll just link the template to the book note via [[relation|Attributes]] "template". Book note will then automatically inherit all the promoted attributes and display them. -To make this even more automated, we can create "child:template" attribute on common parent note of our books and whenever we create new note inside this parent, the book note will get the template relation automatically. +To make this even more automated, we can create "child:template" (see [[attribute inheritance]]) attribute on common parent note of our books and whenever we create new note inside this parent, the book note will get the template relation automatically. You can check out the concept in the [[demo document|Document#demo-document]] in e.g. [[Family tree]], [[Task manager]] or [[Day notes]]. \ No newline at end of file diff --git a/images/task-manager.png b/images/task-manager.png new file mode 100644 index 0000000..82b7884 Binary files /dev/null and b/images/task-manager.png differ