mirror of
				https://github.com/zadam/trilium.git
				synced 2025-10-31 02:16:05 +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 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 { | export default { | ||||||
|     getTodayNote, |     getTodayNote, | ||||||
|     getDateNote, |     getDateNote, | ||||||
|     getMonthNote, |     getMonthNote, | ||||||
|     getYearNote |     getYearNote, | ||||||
|  |     createSqlConsole | ||||||
| } | } | ||||||
| @@ -1,5 +1,7 @@ | |||||||
| import Component from "../widgets/component.js"; | import Component from "../widgets/component.js"; | ||||||
| import appContext from "./app_context.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 { | export default class DialogCommandExecutor extends Component { | ||||||
|     jumpToNoteCommand() { |     jumpToNoteCommand() { | ||||||
| @@ -54,18 +56,22 @@ export default class DialogCommandExecutor extends Component { | |||||||
|     } |     } | ||||||
|  |  | ||||||
|     showOptionsCommand() { |     showOptionsCommand() { | ||||||
|         import("../dialogs/options.js").then(d => d.showDialog()) |         import("../dialogs/options.js").then(d => d.showDialog()); | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     showHelpCommand() { |     showHelpCommand() { | ||||||
|         import("../dialogs/help.js").then(d => d.showDialog()) |         import("../dialogs/help.js").then(d => d.showDialog()); | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     showSQLConsoleCommand() { |     async showSQLConsoleCommand() { | ||||||
|         import("../dialogs/sql_console.js").then(d => d.showDialog()) |         const sqlConsoleNote = await dateNoteService.createSqlConsole(); | ||||||
|  |  | ||||||
|  |         const tabContext = await appContext.tabManager.openTabWithNote(sqlConsoleNote.noteId, true); | ||||||
|  |  | ||||||
|  |         appContext.triggerCommand('focusOnDetail', {tabId: tabContext.tabId}); | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     showBackendLogCommand() { |     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 = {}) { | async function createNote(parentNoteId, options = {}) { | ||||||
|     options = Object.assign({ |     options = Object.assign({ | ||||||
|         activate: true, |         activate: true, | ||||||
|  |         focus: 'title', | ||||||
|         target: 'into' |         target: 'into' | ||||||
|     }, options); |     }, options); | ||||||
|  |  | ||||||
| @@ -39,7 +40,8 @@ async function createNote(parentNoteId, options = {}) { | |||||||
|         title: newNoteName, |         title: newNoteName, | ||||||
|         content: options.content || "", |         content: options.content || "", | ||||||
|         isProtected: options.isProtected, |         isProtected: options.isProtected, | ||||||
|         type: options.type |         type: options.type, | ||||||
|  |         mime: options.mime | ||||||
|     }); |     }); | ||||||
|  |  | ||||||
|     if (options.saveSelection && utils.isCKEditorInitialized()) { |     if (options.saveSelection && utils.isCKEditorInitialized()) { | ||||||
| @@ -48,13 +50,16 @@ async function createNote(parentNoteId, options = {}) { | |||||||
|     } |     } | ||||||
|  |  | ||||||
|     if (options.activate) { |     if (options.activate) { | ||||||
|         await ws.waitForMaxKnownSyncId(); |  | ||||||
|  |  | ||||||
|         const activeTabContext = appContext.tabManager.getActiveTabContext(); |         const activeTabContext = appContext.tabManager.getActiveTabContext(); | ||||||
|         await activeTabContext.setNote(note.noteId); |         await activeTabContext.setNote(note.noteId); | ||||||
|  |  | ||||||
|  |         if (options.focus === 'title') { | ||||||
|             appContext.triggerCommand('focusAndSelectTitle'); |             appContext.triggerCommand('focusAndSelectTitle'); | ||||||
|         } |         } | ||||||
|  |         else if (options.focus === 'content') { | ||||||
|  |             appContext.triggerCommand('focusOnDetail', {tabId: this.tabId}); | ||||||
|  |         } | ||||||
|  |     } | ||||||
|  |  | ||||||
|     return {note, branch}; |     return {note, branch}; | ||||||
| } | } | ||||||
|   | |||||||
| @@ -208,6 +208,8 @@ export default class TabManager extends Component { | |||||||
|                 notePath: tabContext.notePath // resolved note path |                 notePath: tabContext.notePath // resolved note path | ||||||
|             }); |             }); | ||||||
|         } |         } | ||||||
|  |  | ||||||
|  |         return tabContext; | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     async activateOrOpenNote(noteId) { |     async activateOrOpenNote(noteId) { | ||||||
|   | |||||||
| @@ -4,7 +4,6 @@ const TPL = ` | |||||||
| <table class="note-info-widget-table"> | <table class="note-info-widget-table"> | ||||||
|     <style> |     <style> | ||||||
|         .note-info-widget-table { |         .note-info-widget-table { | ||||||
|             table-layout: fixed;  |  | ||||||
|             width: 100%; |             width: 100%; | ||||||
|         }  |         }  | ||||||
|     |     | ||||||
| @@ -22,22 +21,24 @@ const TPL = ` | |||||||
|  |  | ||||||
|     <tr> |     <tr> | ||||||
|         <th>Note ID:</th> |         <th>Note ID:</th> | ||||||
|         <td colspan="3" class="note-info-note-id"></td> |         <td class="note-info-note-id"></td> | ||||||
|     </tr> |     </tr> | ||||||
|     <tr> |     <tr> | ||||||
|         <th>Created:</th> |         <th>Created:</th> | ||||||
|         <td colspan="3" class="note-info-date-created"></td> |         <td class="note-info-date-created"></td> | ||||||
|     </tr> |     </tr> | ||||||
|     <tr> |     <tr> | ||||||
|         <th>Modified:</th> |         <th>Modified:</th> | ||||||
|         <td colspan="3" class="note-info-date-modified"></td> |         <td class="note-info-date-modified"></td> | ||||||
|     </tr> |     </tr> | ||||||
|     <tr> |     <tr> | ||||||
|         <th>Type:</th> |         <th>Type:</th> | ||||||
|         <td class="note-info-type"></td> |         <td> | ||||||
|  |             <span class="note-info-type"></span>, | ||||||
|              |              | ||||||
|         <th>MIME:</th> |             MIME:  | ||||||
|         <td class="note-info-mime"></td> |             <span class="note-info-mime"></span> | ||||||
|  |         </td> | ||||||
|     </tr> |     </tr> | ||||||
| </table> | </table> | ||||||
| `; | `; | ||||||
|   | |||||||
| @@ -441,6 +441,9 @@ export default class NoteTreeWidget extends TabAwareWidget { | |||||||
|                 return "bx bx-note"; |                 return "bx bx-note"; | ||||||
|             } |             } | ||||||
|         } |         } | ||||||
|  |         else if (note.type === 'code' && note.mime.startsWith('text/x-sql')) { | ||||||
|  |             return "bx bx-data"; | ||||||
|  |         } | ||||||
|         else { |         else { | ||||||
|             return NOTE_TYPE_ICONS[note.type]; |             return NOTE_TYPE_ICONS[note.type]; | ||||||
|         } |         } | ||||||
|   | |||||||
| @@ -312,14 +312,10 @@ div.ui-tooltip { | |||||||
|  |  | ||||||
| .CodeMirror { | .CodeMirror { | ||||||
|     font-family: "Liberation Mono", "Lucida Console", monospace; |     font-family: "Liberation Mono", "Lucida Console", monospace; | ||||||
|     height: auto; |     height: 100%; | ||||||
|     background: inherit; |     background: inherit; | ||||||
| } | } | ||||||
|  |  | ||||||
| .CodeMirror-scroll { |  | ||||||
|     min-height: 500px; |  | ||||||
| } |  | ||||||
|  |  | ||||||
| .CodeMirror-gutters { | .CodeMirror-gutters { | ||||||
|     background-color: inherit !important; |     background-color: inherit !important; | ||||||
|     border-right: none; |     border-right: none; | ||||||
|   | |||||||
| @@ -2,6 +2,8 @@ | |||||||
|  |  | ||||||
| const dateNoteService = require('../../services/date_notes'); | const dateNoteService = require('../../services/date_notes'); | ||||||
| const sql = require('../../services/sql'); | const sql = require('../../services/sql'); | ||||||
|  | const dateUtils = require('../../services/date_utils'); | ||||||
|  | const noteService = require('../../services/notes'); | ||||||
|  |  | ||||||
| async function getDateNote(req) { | async function getDateNote(req) { | ||||||
|     return await dateNoteService.getDateNote(req.params.date); |     return await dateNoteService.getDateNote(req.params.date); | ||||||
| @@ -31,9 +33,28 @@ async function getDateNotesForMonth(req) { | |||||||
|             AND attr.value LIKE '${month}%'`); |             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 = { | module.exports = { | ||||||
|     getDateNote, |     getDateNote, | ||||||
|     getMonthNote, |     getMonthNote, | ||||||
|     getYearNote, |     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/month/:month', dateNotesRoute.getMonthNote); | ||||||
|     apiRoute(GET, '/api/date-notes/year/:year', dateNotesRoute.getYearNote); |     apiRoute(GET, '/api/date-notes/year/:year', dateNotesRoute.getYearNote); | ||||||
|     apiRoute(GET, '/api/date-notes/notes-for-month/:month', dateNotesRoute.getDateNotesForMonth); |     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(GET, '/api/images/:noteId/:filename', [auth.checkApiAuthOrElectron], imageRoute.returnImage); | ||||||
|     route(POST, '/api/images', [auth.checkApiAuthOrElectron, uploadMiddleware, csrfMiddleware], imageRoute.uploadImage, apiResultHandler); |     route(POST, '/api/images', [auth.checkApiAuthOrElectron, uploadMiddleware, csrfMiddleware], imageRoute.uploadImage, apiResultHandler); | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user