mirror of
				https://github.com/zadam/trilium.git
				synced 2025-10-31 10:26:08 +01:00 
			
		
		
		
	sql console also doesn't create a normal note by default
This commit is contained in:
		
							
								
								
									
										1
									
								
								TODO
									
									
									
									
									
								
							
							
						
						
									
										1
									
								
								TODO
									
									
									
									
									
								
							| @@ -1,4 +1,3 @@ | ||||
| - search should not require a note | ||||
| - all ribbon tabs should have assignable shortcut | ||||
| - new icon | ||||
| - green theme | ||||
|   | ||||
| @@ -121,7 +121,7 @@ function FrontendScriptApi(startNote, currentNote, originEntity = null, $contain | ||||
|             button.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}); | ||||
|   | ||||
| @@ -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])) | ||||
|   | ||||
| @@ -191,6 +191,7 @@ export default class NoteDetailWidget extends NoteContextAwareWidget { | ||||
|             await this.refresh(); | ||||
|  | ||||
|             const widget = this.getTypeWidget(); | ||||
|             await widget.initialized; | ||||
|             widget.focus(); | ||||
|         } | ||||
|     } | ||||
|   | ||||
| @@ -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)); | ||||
|         }); | ||||
|     } | ||||
|   | ||||
| @@ -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(); | ||||
|     } | ||||
|  | ||||
|   | ||||
| @@ -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 | ||||
| }; | ||||
|   | ||||
| @@ -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); | ||||
|  | ||||
|   | ||||
		Reference in New Issue
	
	Block a user