Build your personal knowledge base with Trilium Notes
TypeScript electronelectron-appknowledge-baseknowledge-graphknowledge-managementknowledge-management-graphlocal-firstnote-managmentnote-takernote-takingnotebooknotesnotes-apppersonal-knowledge-basepersonal-wikiscriptableself-hostedself-hostingwiki
add API to add plugin buttons, fixes
azivner5bffba4e2ff6
diff --git a/src/public/javascripts/api.js b/src/public/javascripts/api.jsnew file mode 100644index 0000000000..941187d2b7--- /dev/null+++ b/src/public/javascripts/api.js@@ -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+ }+})();\ No newline at end of filediff --git a/src/public/javascripts/utils.js b/src/public/javascripts/utils.jsindex e5ff83f88b..9e1ae2e5bb 100644--- a/src/public/javascripts/utils.js+++ b/src/public/javascripts/utils.js@@ -116,5 +116,6 @@ async function stopWatch(what, func) {}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})()");}\ No newline at end of filediff --git a/src/public/stylesheets/style.css b/src/public/stylesheets/style.cssindex db8901b7e5..876cfca950 100644--- a/src/public/stylesheets/style.css+++ b/src/public/stylesheets/style.css@@ -190,11 +190,6 @@ div.ui-tooltip {float: right;}-#note-id-display {- color: lightgrey;- margin-left: 10px;-}-#note-source {height: 98%;width: 100%;@@ -245,6 +240,7 @@ div.ui-tooltip {right: 10px;bottom: 5px;z-index: 1000;+ color: lightgrey;}#note-type-dropdown {diff --git a/src/routes/api/script.js b/src/routes/api/script.jsindex 376aaaa978..85042a30e6 100644--- a/src/routes/api/script.js+++ b/src/routes/api/script.js@@ -19,11 +19,12 @@ router.post('/exec', 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 repository = new Repository(req);const scripts = [];for (const noteId of noteIds) {- scripts.push(await getNoteWithSubtreeScript(noteId, req));+ scripts.push(await getNoteWithSubtreeScript(noteId, repository));}res.send(scripts);@@ -41,10 +42,10 @@ router.get('/subtree/:noteId', auth.checkApiAuth, wrap(async (req, res, next) =>res.send(subTreeScripts + noteScript);}));-async function getNoteWithSubtreeScript(noteId, req) {- const noteScript = (await notes.getNoteById(noteId, req)).content;+async function getNoteWithSubtreeScript(noteId, repository) {+ const noteScript = (await repository.getNote(noteId)).content;- const subTreeScripts = await getSubTreeScripts(noteId, [noteId], req);+ const subTreeScripts = await getSubTreeScripts(noteId, [noteId], repository);return subTreeScripts + noteScript;}diff --git a/src/scripts/today.js b/src/scripts/today.jsnew file mode 100644index 0000000000..f348cc70db--- /dev/null+++ b/src/scripts/today.js@@ -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);+};\ No newline at end of filediff --git a/src/scripts/weight.html b/src/scripts/weight.htmlindex 59ec0e79f3..57fcbd9add 100644--- a/src/scripts/weight.html+++ b/src/scripts/weight.html@@ -65,6 +65,8 @@});}+ data.sort((a, b) => a.date < b.date ? -1 : +1);+return data;});diff --git a/src/services/notes.js b/src/services/notes.jsindex 38b1cf797c..c8e695dab4 100644--- a/src/services/notes.js+++ b/src/services/notes.js@@ -5,32 +5,6 @@ const sync_table = require('./sync_table');const attributes = require('./attributes');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) {const noteId = utils.newNoteId();const noteTreeId = utils.newNoteTreeId();diff --git a/src/views/index.ejs b/src/views/index.ejsindex 18db3ac052..9ccd021e38 100644--- a/src/views/index.ejs+++ b/src/views/index.ejs@@ -20,12 +20,18 @@<button class="btn btn-xs" onclick="eventLog.showDialog();">Event log</button></div>+ <div id="plugin-buttons">+ </div>+<div><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>)</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;"><input type="submit" class="btn btn-xs" value="Logout">@@ -492,7 +498,7 @@<script src="javascripts/link.js"></script><script src="javascripts/sync.js"></script><script src="javascripts/messaging.js"></script>-+ <script src="javascripts/api.js"></script><script type="text/javascript">// we hide container initally because otherwise it is rendered first without CSS and then flickers into