mirror of
				https://github.com/zadam/trilium.git
				synced 2025-10-31 10:26:08 +01:00 
			
		
		
		
	chore(demo): move to right directory
This commit is contained in:
		| @@ -0,0 +1,7 @@ | ||||
| span.fancytree-node.todo .fancytree-title { | ||||
|     color: red !important; | ||||
| } | ||||
|  | ||||
| span.fancytree-node.done .fancytree-title { | ||||
|     color: green !important; | ||||
| } | ||||
| @@ -0,0 +1,63 @@ | ||||
| if (!["task", "location", "tag", "todoDate", "doneDate"].includes(api.originEntity.name)) { | ||||
|     return; | ||||
| } | ||||
|  | ||||
| const tagRootNote = api.getNoteWithLabel('taskTagRoot'); | ||||
| const doneRootNote = api.getNoteWithLabel('taskDoneRoot'); | ||||
| const todoRootNote = api.getNoteWithLabel('taskTodoRoot'); | ||||
|  | ||||
| if (!tagRootNote || !doneRootNote || !todoRootNote) { | ||||
|     console.log("One of the tagRootNote, doneRootNote or todoRootNote does not exist"); | ||||
|     return; | ||||
| } | ||||
|  | ||||
| const note = api.originEntity.getNote(); | ||||
|  | ||||
| if (note.isDeleted) { | ||||
|     return; | ||||
| } | ||||
|      | ||||
| const attributes = note.getAttributes(); | ||||
|  | ||||
| const todoDate = note.getLabelValue('todoDate'); | ||||
| const doneDate = note.getLabelValue('doneDate'); | ||||
|  | ||||
| function isWithinExpectedRange(date) { | ||||
|     if (!date) { | ||||
|         return true; | ||||
|     } | ||||
|      | ||||
|     const year = parseInt(date.substr(0, 4)); | ||||
|      | ||||
|     return year >= 2010 && year < 2050; | ||||
| } | ||||
|  | ||||
| if (!isWithinExpectedRange(todoDate) || !isWithinExpectedRange(doneDate)) { | ||||
|     console.log(`One or both dates - ${todoDate}, ${doneDate} - is outside of expected range`); | ||||
|      | ||||
|     return; | ||||
| } | ||||
|  | ||||
| const isTaskDone = !!doneDate; | ||||
|  | ||||
| api.toggleNoteInParent(isTaskDone, note.noteId, doneRootNote.noteId); | ||||
| api.toggleNoteInParent(!isTaskDone, note.noteId, todoRootNote.noteId); | ||||
|  | ||||
| const location = note.getLabelValue('location'); | ||||
| const locationRootNote = api.getNoteWithLabel('taskLocationRoot'); | ||||
|  | ||||
| reconcileAssignments(note, locationRootNote, location ? [location] : [], 'taskLocationNote', isTaskDone); | ||||
|  | ||||
| const tags = attributes.filter(attr => attr.type === 'label' && attr.name === 'tag').map(attr => attr.value); | ||||
|  | ||||
| reconcileAssignments(note, tagRootNote, tags, 'taskTagNote', isTaskDone); | ||||
|  | ||||
| note.toggleLabel(isTaskDone, "cssClass", "done"); | ||||
|  | ||||
| const doneTargetNoteId = isTaskDone ?  api.getDayNote(doneDate).noteId : null; | ||||
| api.setNoteToParent(note.noteId, 'DONE', doneTargetNoteId); | ||||
|  | ||||
| note.toggleLabel(!isTaskDone, "cssClass", "todo"); | ||||
|  | ||||
| const todoTargetNoteId = (!isTaskDone && todoDate) ? api.getDayNote(todoDate).noteId : null; | ||||
| api.setNoteToParent(note.noteId, 'TODO', todoTargetNoteId); | ||||
| @@ -0,0 +1,25 @@ | ||||
| module.exports = function (note, categoryRootNote, assignedCategories, labelName, isTaskDone) { | ||||
|     const found = {}; | ||||
|      | ||||
|     for (const categoryNote of categoryRootNote.getChildNotes()) { | ||||
|         const label = categoryNote.getLabel(labelName); | ||||
|          | ||||
|         if (label) { | ||||
|             found[label.value] = !isTaskDone && assignedCategories.includes(label.value); | ||||
|  | ||||
|             api.toggleNoteInParent(found[label.value], note.noteId, categoryNote.noteId); | ||||
|         } | ||||
|     } | ||||
|      | ||||
|     if (!isTaskDone) { | ||||
|         for (const assignedCategory of assignedCategories) { | ||||
|             if (!found[assignedCategory]) { | ||||
|                 const categoryNote = api.createTextNote(categoryRootNote.noteId, assignedCategory, "").note; | ||||
|                  | ||||
|                 categoryNote.addLabel(labelName, assignedCategory); | ||||
|  | ||||
|                 api.ensureNoteIsPresentInParent(note.noteId, categoryNote.noteId); | ||||
|             } | ||||
|         } | ||||
|     } | ||||
| } | ||||
| @@ -0,0 +1,14 @@ | ||||
| // creating notes is backend (server) responsibility so we need to pass | ||||
| // the control there | ||||
| const taskNoteId = await api.runOnBackend(() => { | ||||
|     const todoRootNote = api.getNoteWithLabel('taskTodoRoot'); | ||||
|     const resp = api.createTextNote(todoRootNote.noteId, 'new task', ''); | ||||
|  | ||||
|     return resp.note.noteId; | ||||
| }); | ||||
|  | ||||
| // wait until the frontend is fully synced with the changes made on the backend above | ||||
| await api.waitUntilSynced(); | ||||
|  | ||||
| // we got an ID of newly created note and we want to immediatelly display it | ||||
| await api.activateNewNote(taskNoteId); | ||||
| @@ -0,0 +1,19 @@ | ||||
| <html> | ||||
|    | ||||
|   <head> | ||||
|     <meta charset="utf-8"> | ||||
|     <meta name="viewport" content="width=device-width, initial-scale=1"> | ||||
|     <link rel="stylesheet" href="../../../../../style.css"> | ||||
|     <base target="_parent"> | ||||
|     <title data-trilium-title>task template</title> | ||||
|   </head> | ||||
|    | ||||
|   <body> | ||||
|     <div class="content"> | ||||
|        <h1 data-trilium-h1>task template</h1> | ||||
|  | ||||
|       <div class="ck-content"></div> | ||||
|     </div> | ||||
|   </body> | ||||
|  | ||||
| </html> | ||||
		Reference in New Issue
	
	Block a user