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
sql console also doesn't create a normal note by default
zadam3893f663d0c8
diff --git a/TODO b/TODOindex 7cbedcc17b..1f29eaf87e 100644--- a/TODO+++ b/TODO@@ -1,4 +1,3 @@-- search should not require a note- all ribbon tabs should have assignable shortcut- new icon- green themediff --git a/src/public/app/services/frontend_script_api.js b/src/public/app/services/frontend_script_api.jsindex 31ee842c0d..973b2901a7 100644--- a/src/public/app/services/frontend_script_api.js+++ b/src/public/app/services/frontend_script_api.js@@ -121,7 +121,7 @@ function FrontendScriptApi(startNote, currentNote, originEntity = null, $containbutton.append($("<span>").text(opts.title));} else {button = $('<span class="button-widget icon-action bx" data-toggle="tooltip" title="" data-placement="right"></span>')- .addClass("bx bx-" + opts.icon);+ .addClass("bx bx-" + (opts.icon || "question-mark"));button.attr("title", opts.title);button.tooltip({html: true});diff --git a/src/public/app/services/resizer.js b/src/public/app/services/resizer.jsindex 7fae5cd9d7..72c90de6c8 100644--- a/src/public/app/services/resizer.js+++ b/src/public/app/services/resizer.js@@ -51,7 +51,7 @@ function setupRightPaneResizer() {}if (rightPaneVisible) {- leftInstance = Split(['#center-pane', '#right-pane'], {+ rightInstance = Split(['#center-pane', '#right-pane'], {sizes: [100 - rightPaneWidth, rightPaneWidth],gutterSize: 5,onDragEnd: sizes => options.save('rightPaneWidth', Math.round(sizes[1]))diff --git a/src/public/app/widgets/note_detail.js b/src/public/app/widgets/note_detail.jsindex 8e5ab9b878..fb40c87b45 100644--- a/src/public/app/widgets/note_detail.js+++ b/src/public/app/widgets/note_detail.js@@ -191,6 +191,7 @@ export default class NoteDetailWidget extends NoteContextAwareWidget {await this.refresh();const widget = this.getTypeWidget();+ await widget.initialized;widget.focus();}}diff --git a/src/public/app/widgets/ribbon_widgets/search_definition.js b/src/public/app/widgets/ribbon_widgets/search_definition.jsindex b3efb9cb34..fba6212bce 100644--- a/src/public/app/widgets/ribbon_widgets/search_definition.js+++ b/src/public/app/widgets/ribbon_widgets/search_definition.js@@ -275,8 +275,6 @@ export default class SearchDefinitionWidget extends NoteContextAwareWidget {await appContext.tabManager.getActiveContext().setNote(notePath);- console.log("notePath", notePath);-toastService.showMessage("Search note has been saved into " + await treeService.getNotePathTitle(notePath));});}diff --git a/src/public/app/widgets/type_widgets/editable_code.js b/src/public/app/widgets/type_widgets/editable_code.jsindex 9a9716d490..76ebab7f99 100644--- a/src/public/app/widgets/type_widgets/editable_code.js+++ b/src/public/app/widgets/type_widgets/editable_code.js@@ -1,6 +1,11 @@import libraryLoader from "../../services/library_loader.js";import TypeWidget from "./type_widget.js";import keyboardActionService from "../../services/keyboard_actions.js";+import server from "../../services/server.js";+import ws from "../../services/ws.js";+import appContext from "../../services/app_context.js";+import toastService from "../../services/toast.js";+import treeService from "../../services/tree.js";const TPL = `<div class="note-detail-code note-detail-printable">@@ -12,11 +17,17 @@ const TPL = `<div class="note-detail-code-editor"></div>- <div style="text-align: center">+ <div style="display: flex; justify-content: space-evenly;"><button data-trigger-command="runActiveNote"class="no-print execute-button btn btn-sm">Execute <kbd data-command="runActiveNote"></kbd></button>++ <button class="no-print save-to-note-button btn btn-sm">++ <span class="bx bx-save"></span>+ Save to note</kbd>+ </button></div></div>`;@@ -27,6 +38,16 @@ export default class EditableCodeTypeWidget extends TypeWidget {this.$widget = $(TPL);this.$editor = this.$widget.find('.note-detail-code-editor');this.$executeButton = this.$widget.find('.execute-button');+ this.$saveToNoteButton = this.$widget.find('.save-to-note-button');+ this.$saveToNoteButton.on('click', async () => {+ const {notePath} = await server.post("save-sql-console", {sqlConsoleNoteId: this.noteId});++ await ws.waitForMaxKnownEntityChangeId();++ await appContext.tabManager.getActiveContext().setNote(notePath);++ toastService.showMessage("SQL Console note has been saved into " + await treeService.getNotePathTitle(notePath));+ });keyboardActionService.setupActionsForElement('code-detail', this.$widget, this);@@ -71,6 +92,11 @@ export default class EditableCodeTypeWidget extends TypeWidget {|| note.mime === 'text/x-sqlite;schema=trilium');+ this.$saveToNoteButton.toggle(+ note.mime === 'text/x-sqlite;schema=trilium'+ && !note.getAllNotePaths().find(notePathArr => !notePathArr.includes("hidden"))+ );+const noteComplement = await this.noteContext.getNoteComplement();await this.spacedUpdate.allowUpdateWithoutChange(() => {@@ -103,6 +129,7 @@ export default class EditableCodeTypeWidget extends TypeWidget {}focus() {+ this.$editor.focus();this.codeEditor.focus();}diff --git a/src/routes/api/date_notes.js b/src/routes/api/date_notes.jsindex 499b4390ab..ad9b382dd7 100644--- a/src/routes/api/date_notes.js+++ b/src/routes/api/date_notes.js@@ -60,22 +60,27 @@ function getDateNotesForMonth(req) {AND attr.value LIKE '${month}%'`);}-function createSqlConsole() {+function saveSqlConsole(req) {+ const sqlConsoleNote = becca.getNote(req.body.sqlConsoleNoteId);const today = dateUtils.localNowDate();const sqlConsoleHome =attributeService.getNoteWithLabel('sqlConsoleHome')|| dateNoteService.getDateNote(today);+ return sqlConsoleNote.cloneTo(sqlConsoleHome.noteId);+}++function createSqlConsole() {const {note} = noteService.createNewNote({- parentNoteId: sqlConsoleHome.noteId,+ parentNoteId: getSqlConsoleRoot().noteId,title: 'SQL Console',content: "SELECT title, isDeleted, isProtected FROM notes WHERE noteId = ''\n\n\n\n",type: 'code',mime: 'text/x-sqlite;schema=trilium'});- note.setLabel("sqlConsole", today);+ note.setLabel("sqlConsole", dateUtils.localNowDate());return note;}@@ -116,6 +121,22 @@ function getSearchRoot() {return searchRoot;}+function getSqlConsoleRoot() {+ let sqlConsoleRoot = becca.getNote('sqlconsole');++ if (!sqlConsoleRoot) {+ sqlConsoleRoot = noteService.createNewNote({+ noteId: 'sqlconsole',+ title: 'SQL Console',+ type: 'text',+ content: '',+ parentNoteId: getHiddenRoot().noteId+ }).note;+ }++ return sqlConsoleRoot;+}+function saveSearchNote(req) {const searchNote = becca.getNote(req.body.searchNoteId);@@ -171,6 +192,7 @@ module.exports = {getYearNote,getDateNotesForMonth,createSqlConsole,+ saveSqlConsole,createSearchNote,saveSearchNote};diff --git a/src/routes/routes.js b/src/routes/routes.jsindex 3b71644df8..e091943a64 100644--- a/src/routes/routes.js+++ b/src/routes/routes.js@@ -211,6 +211,7 @@ function register(app) {apiRoute(GET, '/api/date-notes/year/:year', dateNotesRoute.getYearNote);apiRoute(GET, '/api/date-notes/notes-for-month/:month', dateNotesRoute.getDateNotesForMonth);apiRoute(POST, '/api/sql-console', dateNotesRoute.createSqlConsole);+ apiRoute(POST, '/api/save-sql-console', dateNotesRoute.saveSqlConsole);apiRoute(POST, '/api/search-note', dateNotesRoute.createSearchNote);apiRoute(POST, '/api/save-search-note', dateNotesRoute.saveSearchNote);