|
|
|
|
@ -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();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|