mirror of
https://github.com/zadam/trilium.git
synced 2025-06-06 18:08:33 +02:00
sql console also doesn't create a normal note by default
This commit is contained in:
parent
a0de3c97a5
commit
3893f663d0
1
TODO
1
TODO
@ -1,4 +1,3 @@
|
|||||||
- search should not require a note
|
|
||||||
- all ribbon tabs should have assignable shortcut
|
- all ribbon tabs should have assignable shortcut
|
||||||
- new icon
|
- new icon
|
||||||
- green theme
|
- green theme
|
||||||
|
@ -121,7 +121,7 @@ function FrontendScriptApi(startNote, currentNote, originEntity = null, $contain
|
|||||||
button.append($("<span>").text(opts.title));
|
button.append($("<span>").text(opts.title));
|
||||||
} else {
|
} else {
|
||||||
button = $('<span class="button-widget icon-action bx" data-toggle="tooltip" title="" data-placement="right"></span>')
|
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.attr("title", opts.title);
|
||||||
button.tooltip({html: true});
|
button.tooltip({html: true});
|
||||||
|
@ -51,7 +51,7 @@ function setupRightPaneResizer() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (rightPaneVisible) {
|
if (rightPaneVisible) {
|
||||||
leftInstance = Split(['#center-pane', '#right-pane'], {
|
rightInstance = Split(['#center-pane', '#right-pane'], {
|
||||||
sizes: [100 - rightPaneWidth, rightPaneWidth],
|
sizes: [100 - rightPaneWidth, rightPaneWidth],
|
||||||
gutterSize: 5,
|
gutterSize: 5,
|
||||||
onDragEnd: sizes => options.save('rightPaneWidth', Math.round(sizes[1]))
|
onDragEnd: sizes => options.save('rightPaneWidth', Math.round(sizes[1]))
|
||||||
|
@ -191,6 +191,7 @@ export default class NoteDetailWidget extends NoteContextAwareWidget {
|
|||||||
await this.refresh();
|
await this.refresh();
|
||||||
|
|
||||||
const widget = this.getTypeWidget();
|
const widget = this.getTypeWidget();
|
||||||
|
await widget.initialized;
|
||||||
widget.focus();
|
widget.focus();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -275,8 +275,6 @@ export default class SearchDefinitionWidget extends NoteContextAwareWidget {
|
|||||||
|
|
||||||
await appContext.tabManager.getActiveContext().setNote(notePath);
|
await appContext.tabManager.getActiveContext().setNote(notePath);
|
||||||
|
|
||||||
console.log("notePath", notePath);
|
|
||||||
|
|
||||||
toastService.showMessage("Search note has been saved into " + await treeService.getNotePathTitle(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 libraryLoader from "../../services/library_loader.js";
|
||||||
import TypeWidget from "./type_widget.js";
|
import TypeWidget from "./type_widget.js";
|
||||||
import keyboardActionService from "../../services/keyboard_actions.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 = `
|
const TPL = `
|
||||||
<div class="note-detail-code note-detail-printable">
|
<div class="note-detail-code note-detail-printable">
|
||||||
@ -12,11 +17,17 @@ const TPL = `
|
|||||||
|
|
||||||
<div class="note-detail-code-editor"></div>
|
<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"
|
<button data-trigger-command="runActiveNote"
|
||||||
class="no-print execute-button btn btn-sm">
|
class="no-print execute-button btn btn-sm">
|
||||||
Execute <kbd data-command="runActiveNote"></kbd>
|
Execute <kbd data-command="runActiveNote"></kbd>
|
||||||
</button>
|
</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>
|
||||||
</div>`;
|
</div>`;
|
||||||
|
|
||||||
@ -27,6 +38,16 @@ export default class EditableCodeTypeWidget extends TypeWidget {
|
|||||||
this.$widget = $(TPL);
|
this.$widget = $(TPL);
|
||||||
this.$editor = this.$widget.find('.note-detail-code-editor');
|
this.$editor = this.$widget.find('.note-detail-code-editor');
|
||||||
this.$executeButton = this.$widget.find('.execute-button');
|
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);
|
keyboardActionService.setupActionsForElement('code-detail', this.$widget, this);
|
||||||
|
|
||||||
@ -71,6 +92,11 @@ export default class EditableCodeTypeWidget extends TypeWidget {
|
|||||||
|| note.mime === 'text/x-sqlite;schema=trilium'
|
|| 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();
|
const noteComplement = await this.noteContext.getNoteComplement();
|
||||||
|
|
||||||
await this.spacedUpdate.allowUpdateWithoutChange(() => {
|
await this.spacedUpdate.allowUpdateWithoutChange(() => {
|
||||||
@ -103,6 +129,7 @@ export default class EditableCodeTypeWidget extends TypeWidget {
|
|||||||
}
|
}
|
||||||
|
|
||||||
focus() {
|
focus() {
|
||||||
|
this.$editor.focus();
|
||||||
this.codeEditor.focus();
|
this.codeEditor.focus();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -60,22 +60,27 @@ function getDateNotesForMonth(req) {
|
|||||||
AND attr.value LIKE '${month}%'`);
|
AND attr.value LIKE '${month}%'`);
|
||||||
}
|
}
|
||||||
|
|
||||||
function createSqlConsole() {
|
function saveSqlConsole(req) {
|
||||||
|
const sqlConsoleNote = becca.getNote(req.body.sqlConsoleNoteId);
|
||||||
const today = dateUtils.localNowDate();
|
const today = dateUtils.localNowDate();
|
||||||
|
|
||||||
const sqlConsoleHome =
|
const sqlConsoleHome =
|
||||||
attributeService.getNoteWithLabel('sqlConsoleHome')
|
attributeService.getNoteWithLabel('sqlConsoleHome')
|
||||||
|| dateNoteService.getDateNote(today);
|
|| dateNoteService.getDateNote(today);
|
||||||
|
|
||||||
|
return sqlConsoleNote.cloneTo(sqlConsoleHome.noteId);
|
||||||
|
}
|
||||||
|
|
||||||
|
function createSqlConsole() {
|
||||||
const {note} = noteService.createNewNote({
|
const {note} = noteService.createNewNote({
|
||||||
parentNoteId: sqlConsoleHome.noteId,
|
parentNoteId: getSqlConsoleRoot().noteId,
|
||||||
title: 'SQL Console',
|
title: 'SQL Console',
|
||||||
content: "SELECT title, isDeleted, isProtected FROM notes WHERE noteId = ''\n\n\n\n",
|
content: "SELECT title, isDeleted, isProtected FROM notes WHERE noteId = ''\n\n\n\n",
|
||||||
type: 'code',
|
type: 'code',
|
||||||
mime: 'text/x-sqlite;schema=trilium'
|
mime: 'text/x-sqlite;schema=trilium'
|
||||||
});
|
});
|
||||||
|
|
||||||
note.setLabel("sqlConsole", today);
|
note.setLabel("sqlConsole", dateUtils.localNowDate());
|
||||||
|
|
||||||
return note;
|
return note;
|
||||||
}
|
}
|
||||||
@ -116,6 +121,22 @@ function getSearchRoot() {
|
|||||||
return searchRoot;
|
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) {
|
function saveSearchNote(req) {
|
||||||
const searchNote = becca.getNote(req.body.searchNoteId);
|
const searchNote = becca.getNote(req.body.searchNoteId);
|
||||||
|
|
||||||
@ -171,6 +192,7 @@ module.exports = {
|
|||||||
getYearNote,
|
getYearNote,
|
||||||
getDateNotesForMonth,
|
getDateNotesForMonth,
|
||||||
createSqlConsole,
|
createSqlConsole,
|
||||||
|
saveSqlConsole,
|
||||||
createSearchNote,
|
createSearchNote,
|
||||||
saveSearchNote
|
saveSearchNote
|
||||||
};
|
};
|
||||||
|
@ -211,6 +211,7 @@ function register(app) {
|
|||||||
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);
|
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/search-note', dateNotesRoute.createSearchNote);
|
||||||
apiRoute(POST, '/api/save-search-note', dateNotesRoute.saveSearchNote);
|
apiRoute(POST, '/api/save-search-note', dateNotesRoute.saveSearchNote);
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user