mirror of
				https://github.com/zadam/trilium.git
				synced 2025-10-31 02:16:05 +01:00 
			
		
		
		
	add API to add plugin buttons, fixes
This commit is contained in:
		
							
								
								
									
										21
									
								
								src/public/javascripts/api.js
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										21
									
								
								src/public/javascripts/api.js
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,21 @@ | |||||||
|  | const api = (function() { | ||||||
|  |     const pluginButtonsEl = $("#plugin-buttons"); | ||||||
|  |  | ||||||
|  |     async function activateNote(notePath) { | ||||||
|  |         await noteTree.activateNode(notePath); | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     function addButtonToToolbar(buttonId, button) { | ||||||
|  |         $("#" + buttonId).remove(); | ||||||
|  |  | ||||||
|  |         button.attr('id', buttonId); | ||||||
|  |  | ||||||
|  |         pluginButtonsEl.append(button); | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |  | ||||||
|  |     return { | ||||||
|  |         addButtonToToolbar, | ||||||
|  |         activateNote | ||||||
|  |     } | ||||||
|  | })(); | ||||||
| @@ -116,5 +116,6 @@ async function stopWatch(what, func) { | |||||||
| } | } | ||||||
|  |  | ||||||
| function executeScript(script) { | function executeScript(script) { | ||||||
|     eval("(async function() {" + script + "})()"); |     // last \r\n is necessary if script contains line comment on its last line | ||||||
|  |     eval("(async function() {" + script + "\r\n})()"); | ||||||
| } | } | ||||||
| @@ -190,11 +190,6 @@ div.ui-tooltip { | |||||||
|     float: right; |     float: right; | ||||||
| } | } | ||||||
|  |  | ||||||
| #note-id-display { |  | ||||||
|     color: lightgrey; |  | ||||||
|     margin-left: 10px; |  | ||||||
| } |  | ||||||
|  |  | ||||||
| #note-source { | #note-source { | ||||||
|     height: 98%; |     height: 98%; | ||||||
|     width: 100%; |     width: 100%; | ||||||
| @@ -245,6 +240,7 @@ div.ui-tooltip { | |||||||
|     right: 10px; |     right: 10px; | ||||||
|     bottom: 5px; |     bottom: 5px; | ||||||
|     z-index: 1000; |     z-index: 1000; | ||||||
|  |     color: lightgrey; | ||||||
| } | } | ||||||
|  |  | ||||||
| #note-type-dropdown { | #note-type-dropdown { | ||||||
|   | |||||||
| @@ -19,11 +19,12 @@ router.post('/exec', auth.checkApiAuth, wrap(async (req, res, next) => { | |||||||
|  |  | ||||||
| router.get('/startup', auth.checkApiAuth, wrap(async (req, res, next) => { | router.get('/startup', auth.checkApiAuth, wrap(async (req, res, next) => { | ||||||
|     const noteIds = await attributes.getNoteIdsWithAttribute("run_on_startup"); |     const noteIds = await attributes.getNoteIdsWithAttribute("run_on_startup"); | ||||||
|  |     const repository = new Repository(req); | ||||||
|  |  | ||||||
|     const scripts = []; |     const scripts = []; | ||||||
|  |  | ||||||
|     for (const noteId of noteIds) { |     for (const noteId of noteIds) { | ||||||
|         scripts.push(await getNoteWithSubtreeScript(noteId, req)); |         scripts.push(await getNoteWithSubtreeScript(noteId, repository)); | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     res.send(scripts); |     res.send(scripts); | ||||||
| @@ -41,10 +42,10 @@ router.get('/subtree/:noteId', auth.checkApiAuth, wrap(async (req, res, next) => | |||||||
|     res.send(subTreeScripts + noteScript); |     res.send(subTreeScripts + noteScript); | ||||||
| })); | })); | ||||||
|  |  | ||||||
| async function getNoteWithSubtreeScript(noteId, req) { | async function getNoteWithSubtreeScript(noteId, repository) { | ||||||
|     const noteScript = (await notes.getNoteById(noteId, req)).content; |     const noteScript = (await repository.getNote(noteId)).content; | ||||||
|  |  | ||||||
|     const subTreeScripts = await getSubTreeScripts(noteId, [noteId], req); |     const subTreeScripts = await getSubTreeScripts(noteId, [noteId], repository); | ||||||
|  |  | ||||||
|     return subTreeScripts + noteScript; |     return subTreeScripts + noteScript; | ||||||
| } | } | ||||||
|   | |||||||
							
								
								
									
										11
									
								
								src/scripts/today.js
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										11
									
								
								src/scripts/today.js
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,11 @@ | |||||||
|  | api.addButtonToToolbar('go-today', $('<button class="btn btn-xs" onclick="goToday();"><span class="ui-icon ui-icon-calendar"></span> Today</button>')); | ||||||
|  |  | ||||||
|  | window.goToday = async function() { | ||||||
|  |     const todayDateStr = formatDateISO(new Date()); | ||||||
|  |  | ||||||
|  |     const todayNoteId = await server.exec([todayDateStr], async todayDateStr => { | ||||||
|  |         return await this.getDateNoteId(todayDateStr); | ||||||
|  |     }); | ||||||
|  |  | ||||||
|  |     api.activateNote(todayNoteId); | ||||||
|  | }; | ||||||
| @@ -65,6 +65,8 @@ | |||||||
|                 }); |                 }); | ||||||
|             } |             } | ||||||
|  |  | ||||||
|  |             data.sort((a, b) => a.date < b.date ? -1 : +1); | ||||||
|  |  | ||||||
|             return data; |             return data; | ||||||
|         }); |         }); | ||||||
|  |  | ||||||
|   | |||||||
| @@ -5,32 +5,6 @@ const sync_table = require('./sync_table'); | |||||||
| const attributes = require('./attributes'); | const attributes = require('./attributes'); | ||||||
| const protected_session = require('./protected_session'); | const protected_session = require('./protected_session'); | ||||||
|  |  | ||||||
| async function updateJsonNote(noteId, data) { |  | ||||||
|     const ret = await createNewNote(noteId, { |  | ||||||
|         title: name, |  | ||||||
|         content: JSON.stringify(data), |  | ||||||
|         target: 'into', |  | ||||||
|         isProtected: false, |  | ||||||
|         type: 'code', |  | ||||||
|         mime: 'application/json' |  | ||||||
|     }); |  | ||||||
|  |  | ||||||
|     return ret.noteId; |  | ||||||
| } |  | ||||||
|  |  | ||||||
| async function createNewJsonNote(parentNoteId, name, payload) { |  | ||||||
|     const ret = await createNewNote(parentNoteId, { |  | ||||||
|         title: name, |  | ||||||
|         content: JSON.stringify(payload), |  | ||||||
|         target: 'into', |  | ||||||
|         isProtected: false, |  | ||||||
|         type: 'code', |  | ||||||
|         mime: 'application/json' |  | ||||||
|     }); |  | ||||||
|  |  | ||||||
|     return ret.noteId; |  | ||||||
| } |  | ||||||
|  |  | ||||||
| async function createNewNote(parentNoteId, noteOpts, dataKey, sourceId) { | async function createNewNote(parentNoteId, noteOpts, dataKey, sourceId) { | ||||||
|     const noteId = utils.newNoteId(); |     const noteId = utils.newNoteId(); | ||||||
|     const noteTreeId = utils.newNoteTreeId(); |     const noteTreeId = utils.newNoteTreeId(); | ||||||
|   | |||||||
| @@ -20,12 +20,18 @@ | |||||||
|           <button class="btn btn-xs" onclick="eventLog.showDialog();">Event log</button> |           <button class="btn btn-xs" onclick="eventLog.showDialog();">Event log</button> | ||||||
|         </div> |         </div> | ||||||
|  |  | ||||||
|  |         <div id="plugin-buttons"> | ||||||
|  |         </div> | ||||||
|  |  | ||||||
|         <div> |         <div> | ||||||
|           <button class="btn btn-xs" onclick="syncNow();" title="Number of outstanding changes to be pushed to server"> |           <button class="btn btn-xs" onclick="syncNow();" title="Number of outstanding changes to be pushed to server"> | ||||||
|  |             <span class="ui-icon ui-icon-refresh"></span> | ||||||
|  |  | ||||||
|             Sync now (<span id="changes-to-push-count">0</span>) |             Sync now (<span id="changes-to-push-count">0</span>) | ||||||
|           </button> |           </button> | ||||||
|  |  | ||||||
|           <button class="btn btn-xs" onclick="settings.showDialog();">Settings</button> |           <button class="btn btn-xs" onclick="settings.showDialog();"> | ||||||
|  |             <span class="ui-icon ui-icon-gear"></span> Settings</button> | ||||||
|  |  | ||||||
|           <form action="logout" id="logout-button" method="POST" style="display: inline;"> |           <form action="logout" id="logout-button" method="POST" style="display: inline;"> | ||||||
|             <input type="submit" class="btn btn-xs" value="Logout"> |             <input type="submit" class="btn btn-xs" value="Logout"> | ||||||
| @@ -492,7 +498,7 @@ | |||||||
|     <script src="javascripts/link.js"></script> |     <script src="javascripts/link.js"></script> | ||||||
|     <script src="javascripts/sync.js"></script> |     <script src="javascripts/sync.js"></script> | ||||||
|     <script src="javascripts/messaging.js"></script> |     <script src="javascripts/messaging.js"></script> | ||||||
|  |     <script src="javascripts/api.js"></script> | ||||||
|  |  | ||||||
|     <script type="text/javascript"> |     <script type="text/javascript"> | ||||||
|       // we hide container initally because otherwise it is rendered first without CSS and then flickers into |       // we hide container initally because otherwise it is rendered first without CSS and then flickers into | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user