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
bind global menu item "Open SQL console" to the logic to create such a note
zadamd20415c979a6
diff --git a/src/public/app/services/date_notes.js b/src/public/app/services/date_notes.jsindex e5d6faf6b6..5a1a88ca0a 100644--- a/src/public/app/services/date_notes.js+++ b/src/public/app/services/date_notes.js@@ -27,9 +27,17 @@ async function getYearNote(year) {return await treeCache.getNote(note.noteId);}+/** @return {NoteShort} */+async function createSqlConsole() {+ const note = await server.post('sql-console');++ return await treeCache.getNote(note.noteId);+}+export default {getTodayNote,getDateNote,getMonthNote,- getYearNote+ getYearNote,+ createSqlConsole}\ No newline at end of filediff --git a/src/public/app/services/dialog_command_executor.js b/src/public/app/services/dialog_command_executor.jsindex dda83c95ad..084eabccf2 100644--- a/src/public/app/services/dialog_command_executor.js+++ b/src/public/app/services/dialog_command_executor.js@@ -1,5 +1,7 @@import Component from "../widgets/component.js";import appContext from "./app_context.js";+import dateNoteService from "../services/date_notes.js";+import noteCreateService from "../services/note_create.js";export default class DialogCommandExecutor extends Component {jumpToNoteCommand() {@@ -54,18 +56,22 @@ export default class DialogCommandExecutor extends Component {}showOptionsCommand() {- import("../dialogs/options.js").then(d => d.showDialog())+ import("../dialogs/options.js").then(d => d.showDialog());}showHelpCommand() {- import("../dialogs/help.js").then(d => d.showDialog())+ import("../dialogs/help.js").then(d => d.showDialog());}- showSQLConsoleCommand() {- import("../dialogs/sql_console.js").then(d => d.showDialog())+ async showSQLConsoleCommand() {+ const sqlConsoleNote = await dateNoteService.createSqlConsole();++ const tabContext = await appContext.tabManager.openTabWithNote(sqlConsoleNote.noteId, true);++ appContext.triggerCommand('focusOnDetail', {tabId: tabContext.tabId});}showBackendLogCommand() {- import("../dialogs/backend_log.js").then(d => d.showDialog())+ import("../dialogs/backend_log.js").then(d => d.showDialog());}}\ No newline at end of filediff --git a/src/public/app/services/note_create.js b/src/public/app/services/note_create.jsindex 353bc7a36a..152c234d99 100644--- a/src/public/app/services/note_create.js+++ b/src/public/app/services/note_create.js@@ -16,6 +16,7 @@ async function createNewTopLevelNote() {async function createNote(parentNoteId, options = {}) {options = Object.assign({activate: true,+ focus: 'title',target: 'into'}, options);@@ -39,7 +40,8 @@ async function createNote(parentNoteId, options = {}) {title: newNoteName,content: options.content || "",isProtected: options.isProtected,- type: options.type+ type: options.type,+ mime: options.mime});if (options.saveSelection && utils.isCKEditorInitialized()) {@@ -48,12 +50,15 @@ async function createNote(parentNoteId, options = {}) {}if (options.activate) {- await ws.waitForMaxKnownSyncId();-const activeTabContext = appContext.tabManager.getActiveTabContext();await activeTabContext.setNote(note.noteId);- appContext.triggerCommand('focusAndSelectTitle');+ if (options.focus === 'title') {+ appContext.triggerCommand('focusAndSelectTitle');+ }+ else if (options.focus === 'content') {+ appContext.triggerCommand('focusOnDetail', {tabId: this.tabId});+ }}return {note, branch};diff --git a/src/public/app/services/tab_manager.js b/src/public/app/services/tab_manager.jsindex 5463e295c7..b15470f4c8 100644--- a/src/public/app/services/tab_manager.js+++ b/src/public/app/services/tab_manager.js@@ -208,6 +208,8 @@ export default class TabManager extends Component {notePath: tabContext.notePath // resolved note path});}++ return tabContext;}async activateOrOpenNote(noteId) {diff --git a/src/public/app/widgets/collapsible_widgets/note_info.js b/src/public/app/widgets/collapsible_widgets/note_info.jsindex e0cb8aaac4..a228370060 100644--- a/src/public/app/widgets/collapsible_widgets/note_info.js+++ b/src/public/app/widgets/collapsible_widgets/note_info.js@@ -4,7 +4,6 @@ const TPL = `<table class="note-info-widget-table"><style>.note-info-widget-table {- table-layout: fixed;width: 100%;}@@ -22,22 +21,24 @@ const TPL = `<tr><th>Note ID:</th>- <td colspan="3" class="note-info-note-id"></td>+ <td class="note-info-note-id"></td></tr><tr><th>Created:</th>- <td colspan="3" class="note-info-date-created"></td>+ <td class="note-info-date-created"></td></tr><tr><th>Modified:</th>- <td colspan="3" class="note-info-date-modified"></td>+ <td class="note-info-date-modified"></td></tr><tr><th>Type:</th>- <td class="note-info-type"></td>-- <th>MIME:</th>- <td class="note-info-mime"></td>+ <td>+ <span class="note-info-type"></span>,++ MIME:+ <span class="note-info-mime"></span>+ </td></tr></table>`;diff --git a/src/public/app/widgets/note_tree.js b/src/public/app/widgets/note_tree.jsindex 5c4cc4ae52..4b6f0ebd27 100644--- a/src/public/app/widgets/note_tree.js+++ b/src/public/app/widgets/note_tree.js@@ -441,6 +441,9 @@ export default class NoteTreeWidget extends TabAwareWidget {return "bx bx-note";}}+ else if (note.type === 'code' && note.mime.startsWith('text/x-sql')) {+ return "bx bx-data";+ }else {return NOTE_TYPE_ICONS[note.type];}diff --git a/src/public/stylesheets/style.css b/src/public/stylesheets/style.cssindex ad4bc65ddb..bebb0ab636 100644--- a/src/public/stylesheets/style.css+++ b/src/public/stylesheets/style.css@@ -312,14 +312,10 @@ div.ui-tooltip {.CodeMirror {font-family: "Liberation Mono", "Lucida Console", monospace;- height: auto;+ height: 100%;background: inherit;}-.CodeMirror-scroll {- min-height: 500px;-}-.CodeMirror-gutters {background-color: inherit !important;border-right: none;diff --git a/src/routes/api/date_notes.js b/src/routes/api/date_notes.jsindex 5584f6eb8f..aae557773e 100644--- a/src/routes/api/date_notes.js+++ b/src/routes/api/date_notes.js@@ -2,6 +2,8 @@const dateNoteService = require('../../services/date_notes');const sql = require('../../services/sql');+const dateUtils = require('../../services/date_utils');+const noteService = require('../../services/notes');async function getDateNote(req) {return await dateNoteService.getDateNote(req.params.date);@@ -31,9 +33,28 @@ async function getDateNotesForMonth(req) {AND attr.value LIKE '${month}%'`);}+async function createSqlConsole() {+ const today = dateUtils.localNowDate();++ const todayNote = await dateNoteService.getDateNote(today);++ const {note} = await noteService.createNewNote({+ parentNoteId: todayNote.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'+ });++ await note.setLabel("sqlConsole", today);++ return note;+}+module.exports = {getDateNote,getMonthNote,getYearNote,- getDateNotesForMonth+ getDateNotesForMonth,+ createSqlConsole};\ No newline at end of filediff --git a/src/routes/routes.js b/src/routes/routes.jsindex 1de0a7e29a..6cbead5c34 100644--- a/src/routes/routes.js+++ b/src/routes/routes.js@@ -181,6 +181,7 @@ function register(app) {apiRoute(GET, '/api/date-notes/month/:month', dateNotesRoute.getMonthNote);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);route(GET, '/api/images/:noteId/:filename', [auth.checkApiAuthOrElectron], imageRoute.returnImage);route(POST, '/api/images', [auth.checkApiAuthOrElectron, uploadMiddleware, csrfMiddleware], imageRoute.uploadImage, apiResultHandler);