mirror of
				https://github.com/zadam/trilium.git
				synced 2025-10-31 18:36:30 +01:00 
			
		
		
		
	bind global menu item "Open SQL console" to the logic to create such a note
This commit is contained in:
		| @@ -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 | ||||
| } | ||||
| @@ -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()); | ||||
|     } | ||||
| } | ||||
| @@ -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}; | ||||
|   | ||||
| @@ -208,6 +208,8 @@ export default class TabManager extends Component { | ||||
|                 notePath: tabContext.notePath // resolved note path | ||||
|             }); | ||||
|         } | ||||
|  | ||||
|         return tabContext; | ||||
|     } | ||||
|  | ||||
|     async activateOrOpenNote(noteId) { | ||||
|   | ||||
| @@ -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> | ||||
| `; | ||||
|   | ||||
| @@ -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]; | ||||
|         } | ||||
|   | ||||
| @@ -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; | ||||
|   | ||||
| @@ -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 | ||||
| }; | ||||
| @@ -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); | ||||
|   | ||||
		Reference in New Issue
	
	Block a user