mirror of
https://github.com/zadam/trilium.git
synced 2025-03-01 14:22:32 +01:00
renamed currentNote to activeNote to be consistent with frontend API
This commit is contained in:
parent
0d0464549f
commit
ef40c66344
@ -49,7 +49,7 @@ window.glob.noteChanged = noteDetailService.noteChanged;
|
|||||||
window.glob.refreshTree = treeService.reload;
|
window.glob.refreshTree = treeService.reload;
|
||||||
|
|
||||||
// required for ESLint plugin
|
// required for ESLint plugin
|
||||||
window.glob.getCurrentNote = noteDetailService.getCurrentNote;
|
window.glob.getActiveNote = noteDetailService.getActiveNote;
|
||||||
window.glob.requireLibrary = libraryLoader.requireLibrary;
|
window.glob.requireLibrary = libraryLoader.requireLibrary;
|
||||||
window.glob.ESLINT = libraryLoader.ESLINT;
|
window.glob.ESLINT = libraryLoader.ESLINT;
|
||||||
|
|
||||||
|
@ -27,7 +27,7 @@ function setLinkType(linkType) {
|
|||||||
async function showDialog() {
|
async function showDialog() {
|
||||||
glob.activeDialog = $dialog;
|
glob.activeDialog = $dialog;
|
||||||
|
|
||||||
if (noteDetailService.getCurrentNoteType() === 'text') {
|
if (noteDetailService.getActiveNoteType() === 'text') {
|
||||||
$linkTypeHtml.prop('disabled', false);
|
$linkTypeHtml.prop('disabled', false);
|
||||||
|
|
||||||
setLinkType('html');
|
setLinkType('html');
|
||||||
@ -99,14 +99,14 @@ $form.submit(() => {
|
|||||||
else if (linkType === 'selected-to-current') {
|
else if (linkType === 'selected-to-current') {
|
||||||
const prefix = $clonePrefix.val();
|
const prefix = $clonePrefix.val();
|
||||||
|
|
||||||
cloningService.cloneNoteTo(noteId, noteDetailService.getCurrentNoteId(), prefix);
|
cloningService.cloneNoteTo(noteId, noteDetailService.getActiveNoteId(), prefix);
|
||||||
|
|
||||||
$dialog.modal('hide');
|
$dialog.modal('hide');
|
||||||
}
|
}
|
||||||
else if (linkType === 'current-to-selected') {
|
else if (linkType === 'current-to-selected') {
|
||||||
const prefix = $clonePrefix.val();
|
const prefix = $clonePrefix.val();
|
||||||
|
|
||||||
cloningService.cloneNoteTo(noteDetailService.getCurrentNoteId(), noteId, prefix);
|
cloningService.cloneNoteTo(noteDetailService.getActiveNoteId(), noteId, prefix);
|
||||||
|
|
||||||
$dialog.modal('hide');
|
$dialog.modal('hide');
|
||||||
}
|
}
|
||||||
|
@ -90,7 +90,7 @@ function AttributesModel() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
this.loadAttributes = async function() {
|
this.loadAttributes = async function() {
|
||||||
const noteId = noteDetailService.getCurrentNoteId();
|
const noteId = noteDetailService.getActiveNoteId();
|
||||||
|
|
||||||
const attributes = await server.get('notes/' + noteId + '/attributes');
|
const attributes = await server.get('notes/' + noteId + '/attributes');
|
||||||
|
|
||||||
@ -136,7 +136,7 @@ function AttributesModel() {
|
|||||||
|
|
||||||
self.updateAttributePositions();
|
self.updateAttributePositions();
|
||||||
|
|
||||||
const noteId = noteDetailService.getCurrentNoteId();
|
const noteId = noteDetailService.getActiveNoteId();
|
||||||
|
|
||||||
const attributesToSave = self.ownedAttributes()
|
const attributesToSave = self.ownedAttributes()
|
||||||
.map(attribute => attribute())
|
.map(attribute => attribute())
|
||||||
|
@ -13,13 +13,13 @@ function showDialog() {
|
|||||||
|
|
||||||
$dialog.modal();
|
$dialog.modal();
|
||||||
|
|
||||||
const currentNote = noteDetailService.getCurrentNote();
|
const activeNote = noteDetailService.getActiveNote();
|
||||||
|
|
||||||
$noteId.text(currentNote.noteId);
|
$noteId.text(activeNote.noteId);
|
||||||
$utcDateCreated.text(currentNote.utcDateCreated);
|
$utcDateCreated.text(activeNote.utcDateCreated);
|
||||||
$utcDateModified.text(currentNote.utcDateModified);
|
$utcDateModified.text(activeNote.utcDateModified);
|
||||||
$type.text(currentNote.type);
|
$type.text(activeNote.type);
|
||||||
$mime.text(currentNote.mime);
|
$mime.text(activeNote.mime);
|
||||||
}
|
}
|
||||||
|
|
||||||
$okButton.click(() => $dialog.modal('hide'));
|
$okButton.click(() => $dialog.modal('hide'));
|
||||||
|
@ -11,7 +11,7 @@ let revisionItems = [];
|
|||||||
let note;
|
let note;
|
||||||
|
|
||||||
async function showCurrentNoteRevisions() {
|
async function showCurrentNoteRevisions() {
|
||||||
await showNoteRevisionsDialog(noteDetailService.getCurrentNoteId());
|
await showNoteRevisionsDialog(noteDetailService.getActiveNoteId());
|
||||||
}
|
}
|
||||||
|
|
||||||
async function showNoteRevisionsDialog(noteId, noteRevisionId) {
|
async function showNoteRevisionsDialog(noteId, noteRevisionId) {
|
||||||
@ -22,7 +22,7 @@ async function showNoteRevisionsDialog(noteId, noteRevisionId) {
|
|||||||
$list.empty();
|
$list.empty();
|
||||||
$content.empty();
|
$content.empty();
|
||||||
|
|
||||||
note = noteDetailService.getCurrentNote();
|
note = noteDetailService.getActiveNote();
|
||||||
revisionItems = await server.get('notes/' + noteId + '/revisions');
|
revisionItems = await server.get('notes/' + noteId + '/revisions');
|
||||||
|
|
||||||
for (const item of revisionItems) {
|
for (const item of revisionItems) {
|
||||||
|
@ -8,7 +8,7 @@ function showDialog() {
|
|||||||
|
|
||||||
$dialog.modal();
|
$dialog.modal();
|
||||||
|
|
||||||
const noteText = noteDetailService.getCurrentNote().noteContent.content;
|
const noteText = noteDetailService.getActiveNote().noteContent.content;
|
||||||
|
|
||||||
$noteSource.text(formatHtml(noteText));
|
$noteSource.text(formatHtml(noteText));
|
||||||
}
|
}
|
||||||
|
@ -18,7 +18,7 @@ function invalidateAttributes() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function reloadAttributes() {
|
function reloadAttributes() {
|
||||||
attributePromise = server.get('notes/' + noteDetailService.getCurrentNoteId() + '/attributes');
|
attributePromise = server.get('notes/' + noteDetailService.getActiveNoteId() + '/attributes');
|
||||||
}
|
}
|
||||||
|
|
||||||
async function refreshAttributes() {
|
async function refreshAttributes() {
|
||||||
@ -40,7 +40,7 @@ async function showAttributes() {
|
|||||||
$attributeList.hide();
|
$attributeList.hide();
|
||||||
$attributeListInner.empty();
|
$attributeListInner.empty();
|
||||||
|
|
||||||
const note = noteDetailService.getCurrentNote();
|
const note = noteDetailService.getActiveNote();
|
||||||
|
|
||||||
const attributes = await attributePromise;
|
const attributes = await attributePromise;
|
||||||
|
|
||||||
@ -283,7 +283,7 @@ async function promotedAttributeChanged(event) {
|
|||||||
value = $attr.val();
|
value = $attr.val();
|
||||||
}
|
}
|
||||||
|
|
||||||
const result = await server.put("notes/" + noteDetailService.getCurrentNoteId() + "/attribute", {
|
const result = await server.put("notes/" + noteDetailService.getActiveNoteId() + "/attribute", {
|
||||||
attributeId: $attr.prop("attribute-id"),
|
attributeId: $attr.prop("attribute-id"),
|
||||||
type: $attr.prop("attribute-type"),
|
type: $attr.prop("attribute-type"),
|
||||||
name: $attr.prop("attribute-name"),
|
name: $attr.prop("attribute-name"),
|
||||||
|
@ -202,13 +202,13 @@ function FrontendScriptApi(startNote, currentNote, originEntity = null) {
|
|||||||
* @method
|
* @method
|
||||||
* @returns {string} content of active note (loaded into right pane)
|
* @returns {string} content of active note (loaded into right pane)
|
||||||
*/
|
*/
|
||||||
this.getActiveNoteContent = noteDetailService.getCurrentNoteContent;
|
this.getActiveNoteContent = noteDetailService.getActiveNoteContent;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @method
|
* @method
|
||||||
* @returns {NoteFull} active note (loaded into right pane)
|
* @returns {NoteFull} active note (loaded into right pane)
|
||||||
*/
|
*/
|
||||||
this.getActiveNote = noteDetailService.getCurrentNote;
|
this.getActiveNote = noteDetailService.getActiveNote;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This method checks whether user navigated away from the note from which the scripts has been started.
|
* This method checks whether user navigated away from the note from which the scripts has been started.
|
||||||
@ -220,7 +220,7 @@ function FrontendScriptApi(startNote, currentNote, originEntity = null) {
|
|||||||
* @return {boolean} returns true if the original note is still loaded, false if user switched to another
|
* @return {boolean} returns true if the original note is still loaded, false if user switched to another
|
||||||
*/
|
*/
|
||||||
this.isNoteStillActive = () => {
|
this.isNoteStillActive = () => {
|
||||||
return this.originEntity.noteId === noteDetailService.getCurrentNoteId();
|
return this.originEntity.noteId === noteDetailService.getActiveNoteId();
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -8,7 +8,7 @@ const SELECTED_PATH_KEY = "data-note-path";
|
|||||||
async function autocompleteSource(term, cb) {
|
async function autocompleteSource(term, cb) {
|
||||||
const result = await server.get('autocomplete'
|
const result = await server.get('autocomplete'
|
||||||
+ '?query=' + encodeURIComponent(term)
|
+ '?query=' + encodeURIComponent(term)
|
||||||
+ '¤tNoteId=' + noteDetailService.getCurrentNoteId());
|
+ '&activeNoteId=' + noteDetailService.getActiveNoteId());
|
||||||
|
|
||||||
if (result.length === 0) {
|
if (result.length === 0) {
|
||||||
result.push({
|
result.push({
|
||||||
|
@ -32,7 +32,7 @@ const $scriptArea = $("#note-detail-script-area");
|
|||||||
const $savedIndicator = $("#saved-indicator");
|
const $savedIndicator = $("#saved-indicator");
|
||||||
const $body = $("body");
|
const $body = $("body");
|
||||||
|
|
||||||
let currentNote = null;
|
let activeNote = null;
|
||||||
|
|
||||||
let noteChangeDisabled = false;
|
let noteChangeDisabled = false;
|
||||||
|
|
||||||
@ -52,7 +52,7 @@ const components = {
|
|||||||
|
|
||||||
function getComponent(type) {
|
function getComponent(type) {
|
||||||
if (!type) {
|
if (!type) {
|
||||||
type = getCurrentNote().type;
|
type = getActiveNote().type;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (components[type]) {
|
if (components[type]) {
|
||||||
@ -63,18 +63,18 @@ function getComponent(type) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function getCurrentNote() {
|
function getActiveNote() {
|
||||||
return currentNote;
|
return activeNote;
|
||||||
}
|
}
|
||||||
|
|
||||||
function getCurrentNoteId() {
|
function getActiveNoteId() {
|
||||||
return currentNote ? currentNote.noteId : null;
|
return activeNote ? activeNote.noteId : null;
|
||||||
}
|
}
|
||||||
|
|
||||||
function getCurrentNoteType() {
|
function getActiveNoteType() {
|
||||||
const currentNote = getCurrentNote();
|
const activeNote = getActiveNote();
|
||||||
|
|
||||||
return currentNote ? currentNote.type : null;
|
return activeNote ? activeNote.type : null;
|
||||||
}
|
}
|
||||||
|
|
||||||
function noteChanged() {
|
function noteChanged() {
|
||||||
@ -90,18 +90,18 @@ function noteChanged() {
|
|||||||
async function reload() {
|
async function reload() {
|
||||||
// no saving here
|
// no saving here
|
||||||
|
|
||||||
await loadNoteDetail(getCurrentNoteId());
|
await loadNoteDetail(getActiveNoteId());
|
||||||
}
|
}
|
||||||
|
|
||||||
async function switchToNote(noteId) {
|
async function switchToNote(noteId) {
|
||||||
if (getCurrentNoteId() !== noteId) {
|
if (getActiveNoteId() !== noteId) {
|
||||||
await saveNoteIfChanged();
|
await saveNoteIfChanged();
|
||||||
|
|
||||||
await loadNoteDetail(noteId);
|
await loadNoteDetail(noteId);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function getCurrentNoteContent() {
|
function getActiveNoteContent() {
|
||||||
return getComponent().getContent();
|
return getComponent().getContent();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -110,7 +110,7 @@ function onNoteChange(func) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async function saveNote() {
|
async function saveNote() {
|
||||||
const note = getCurrentNote();
|
const note = getActiveNote();
|
||||||
|
|
||||||
if (note.isProtected && !protectedSessionHolder.isProtectedSessionAvailable()) {
|
if (note.isProtected && !protectedSessionHolder.isProtectedSessionAvailable()) {
|
||||||
return;
|
return;
|
||||||
@ -119,7 +119,7 @@ async function saveNote() {
|
|||||||
note.title = $noteTitle.val();
|
note.title = $noteTitle.val();
|
||||||
|
|
||||||
if (note.noteContent != null) { // might be null for file/image
|
if (note.noteContent != null) { // might be null for file/image
|
||||||
note.noteContent.content = getCurrentNoteContent(note);
|
note.noteContent.content = getActiveNoteContent(note);
|
||||||
}
|
}
|
||||||
|
|
||||||
// it's important to set the flag back to false immediatelly after retrieving title and content
|
// it's important to set the flag back to false immediatelly after retrieving title and content
|
||||||
@ -137,7 +137,7 @@ async function saveNote() {
|
|||||||
$savedIndicator.fadeIn();
|
$savedIndicator.fadeIn();
|
||||||
|
|
||||||
// run async
|
// run async
|
||||||
bundleService.executeRelationBundles(getCurrentNote(), 'runOnNoteChange');
|
bundleService.executeRelationBundles(getActiveNote(), 'runOnNoteChange');
|
||||||
}
|
}
|
||||||
|
|
||||||
async function saveNoteIfChanged() {
|
async function saveNoteIfChanged() {
|
||||||
@ -150,11 +150,11 @@ async function saveNoteIfChanged() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function updateNoteView() {
|
function updateNoteView() {
|
||||||
$noteDetailWrapper.toggleClass("protected", currentNote.isProtected);
|
$noteDetailWrapper.toggleClass("protected", activeNote.isProtected);
|
||||||
$protectButton.toggleClass("active", currentNote.isProtected);
|
$protectButton.toggleClass("active", activeNote.isProtected);
|
||||||
$protectButton.prop("disabled", currentNote.isProtected);
|
$protectButton.prop("disabled", activeNote.isProtected);
|
||||||
$unprotectButton.toggleClass("active", !currentNote.isProtected);
|
$unprotectButton.toggleClass("active", !activeNote.isProtected);
|
||||||
$unprotectButton.prop("disabled", !currentNote.isProtected || !protectedSessionHolder.isProtectedSessionAvailable());
|
$unprotectButton.prop("disabled", !activeNote.isProtected || !protectedSessionHolder.isProtectedSessionAvailable());
|
||||||
|
|
||||||
for (const clazz of Array.from($body[0].classList)) { // create copy to safely iterate over while removing classes
|
for (const clazz of Array.from($body[0].classList)) { // create copy to safely iterate over while removing classes
|
||||||
if (clazz.startsWith("type-") || clazz.startsWith("mime-")) {
|
if (clazz.startsWith("type-") || clazz.startsWith("mime-")) {
|
||||||
@ -162,14 +162,14 @@ function updateNoteView() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$body.addClass(utils.getNoteTypeClass(currentNote.type));
|
$body.addClass(utils.getNoteTypeClass(activeNote.type));
|
||||||
$body.addClass(utils.getMimeTypeClass(currentNote.mime));
|
$body.addClass(utils.getMimeTypeClass(activeNote.mime));
|
||||||
}
|
}
|
||||||
|
|
||||||
async function handleProtectedSession() {
|
async function handleProtectedSession() {
|
||||||
const newSessionCreated = await protectedSessionService.ensureProtectedSession(currentNote.isProtected, false);
|
const newSessionCreated = await protectedSessionService.ensureProtectedSession(activeNote.isProtected, false);
|
||||||
|
|
||||||
if (currentNote.isProtected) {
|
if (activeNote.isProtected) {
|
||||||
protectedSessionHolder.touchProtectedSession();
|
protectedSessionHolder.touchProtectedSession();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -192,8 +192,8 @@ async function loadNoteDetail(noteId) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// only now that we're in sync with tree active node we will switch currentNote
|
// only now that we're in sync with tree active node we will switch activeNote
|
||||||
currentNote = loadedNote;
|
activeNote = loadedNote;
|
||||||
|
|
||||||
if (utils.isDesktop()) {
|
if (utils.isDesktop()) {
|
||||||
// needs to happen after loading the note itself because it references current noteId
|
// needs to happen after loading the note itself because it references current noteId
|
||||||
@ -211,15 +211,15 @@ async function loadNoteDetail(noteId) {
|
|||||||
noteChangeDisabled = true;
|
noteChangeDisabled = true;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
$noteTitle.val(currentNote.title);
|
$noteTitle.val(activeNote.title);
|
||||||
|
|
||||||
if (utils.isDesktop()) {
|
if (utils.isDesktop()) {
|
||||||
noteTypeService.setNoteType(currentNote.type);
|
noteTypeService.setNoteType(activeNote.type);
|
||||||
noteTypeService.setNoteMime(currentNote.mime);
|
noteTypeService.setNoteMime(activeNote.mime);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (const componentType in components) {
|
for (const componentType in components) {
|
||||||
if (componentType !== currentNote.type) {
|
if (componentType !== activeNote.type) {
|
||||||
components[componentType].cleanup();
|
components[componentType].cleanup();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -234,7 +234,7 @@ async function loadNoteDetail(noteId) {
|
|||||||
|
|
||||||
$noteTitle.removeAttr("readonly"); // this can be set by protected session service
|
$noteTitle.removeAttr("readonly"); // this can be set by protected session service
|
||||||
|
|
||||||
await getComponent(currentNote.type).show();
|
await getComponent(activeNote.type).show();
|
||||||
}
|
}
|
||||||
finally {
|
finally {
|
||||||
noteChangeDisabled = false;
|
noteChangeDisabled = false;
|
||||||
@ -243,13 +243,13 @@ async function loadNoteDetail(noteId) {
|
|||||||
treeService.setBranchBackgroundBasedOnProtectedStatus(noteId);
|
treeService.setBranchBackgroundBasedOnProtectedStatus(noteId);
|
||||||
|
|
||||||
// after loading new note make sure editor is scrolled to the top
|
// after loading new note make sure editor is scrolled to the top
|
||||||
getComponent(currentNote.type).scrollToTop();
|
getComponent(activeNote.type).scrollToTop();
|
||||||
|
|
||||||
fireDetailLoaded();
|
fireDetailLoaded();
|
||||||
|
|
||||||
$scriptArea.empty();
|
$scriptArea.empty();
|
||||||
|
|
||||||
await bundleService.executeRelationBundles(getCurrentNote(), 'runOnNoteView');
|
await bundleService.executeRelationBundles(getActiveNote(), 'runOnNoteView');
|
||||||
|
|
||||||
if (utils.isDesktop()) {
|
if (utils.isDesktop()) {
|
||||||
await attributeService.showAttributes();
|
await attributeService.showAttributes();
|
||||||
@ -259,7 +259,7 @@ async function loadNoteDetail(noteId) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async function showChildrenOverview() {
|
async function showChildrenOverview() {
|
||||||
const note = getCurrentNote();
|
const note = getActiveNote();
|
||||||
const attributes = await attributeService.getAttributes();
|
const attributes = await attributeService.getAttributes();
|
||||||
const hideChildrenOverview = attributes.some(attr => attr.type === 'label' && attr.name === 'hideChildrenOverview')
|
const hideChildrenOverview = attributes.some(attr => attr.type === 'label' && attr.name === 'hideChildrenOverview')
|
||||||
|| note.type === 'relation-map'
|
|| note.type === 'relation-map'
|
||||||
@ -273,7 +273,7 @@ async function showChildrenOverview() {
|
|||||||
|
|
||||||
$childrenOverview.empty();
|
$childrenOverview.empty();
|
||||||
|
|
||||||
const notePath = treeService.getCurrentNotePath();
|
const notePath = treeService.getActiveNotePath();
|
||||||
|
|
||||||
for (const childBranch of await note.getChildBranches()) {
|
for (const childBranch of await note.getChildBranches()) {
|
||||||
const link = $('<a>', {
|
const link = $('<a>', {
|
||||||
@ -317,7 +317,7 @@ function addDetailLoadedListener(noteId, callback) {
|
|||||||
|
|
||||||
function fireDetailLoaded() {
|
function fireDetailLoaded() {
|
||||||
for (const {noteId, callback} of detailLoadedListeners) {
|
for (const {noteId, callback} of detailLoadedListeners) {
|
||||||
if (noteId === currentNote.noteId) {
|
if (noteId === activeNote.noteId) {
|
||||||
callback();
|
callback();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -327,7 +327,7 @@ function fireDetailLoaded() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
messagingService.subscribeToSyncMessages(syncData => {
|
messagingService.subscribeToSyncMessages(syncData => {
|
||||||
if (syncData.some(sync => sync.entityName === 'notes' && sync.entityId === getCurrentNoteId())) {
|
if (syncData.some(sync => sync.entityName === 'notes' && sync.entityId === getActiveNoteId())) {
|
||||||
infoService.showMessage('Reloading note because of background changes');
|
infoService.showMessage('Reloading note because of background changes');
|
||||||
|
|
||||||
reload();
|
reload();
|
||||||
@ -339,7 +339,7 @@ $noteDetailWrapper.on("dragover", e => e.preventDefault());
|
|||||||
$noteDetailWrapper.on("dragleave", e => e.preventDefault());
|
$noteDetailWrapper.on("dragleave", e => e.preventDefault());
|
||||||
|
|
||||||
$noteDetailWrapper.on("drop", e => {
|
$noteDetailWrapper.on("drop", e => {
|
||||||
importDialog.uploadFiles(getCurrentNoteId(), e.originalEvent.dataTransfer.files, {
|
importDialog.uploadFiles(getActiveNoteId(), e.originalEvent.dataTransfer.files, {
|
||||||
safeImport: true,
|
safeImport: true,
|
||||||
shrinkImages: true,
|
shrinkImages: true,
|
||||||
textImportedAsText: true,
|
textImportedAsText: true,
|
||||||
@ -354,7 +354,7 @@ $(document).ready(() => {
|
|||||||
|
|
||||||
const title = $noteTitle.val();
|
const title = $noteTitle.val();
|
||||||
|
|
||||||
treeService.setNoteTitle(getCurrentNoteId(), title);
|
treeService.setNoteTitle(getActiveNoteId(), title);
|
||||||
});
|
});
|
||||||
|
|
||||||
noteDetailText.focus();
|
noteDetailText.focus();
|
||||||
@ -371,10 +371,10 @@ export default {
|
|||||||
switchToNote,
|
switchToNote,
|
||||||
updateNoteView,
|
updateNoteView,
|
||||||
loadNote,
|
loadNote,
|
||||||
getCurrentNote,
|
getActiveNote,
|
||||||
getCurrentNoteContent,
|
getActiveNoteContent,
|
||||||
getCurrentNoteType,
|
getActiveNoteType,
|
||||||
getCurrentNoteId,
|
getActiveNoteId,
|
||||||
focusOnTitle,
|
focusOnTitle,
|
||||||
focusAndSelectTitle,
|
focusAndSelectTitle,
|
||||||
saveNote,
|
saveNote,
|
||||||
|
@ -44,14 +44,14 @@ async function show() {
|
|||||||
|
|
||||||
$component.show();
|
$component.show();
|
||||||
|
|
||||||
const currentNote = noteDetailService.getCurrentNote();
|
const activeNote = noteDetailService.getActiveNote();
|
||||||
|
|
||||||
// this needs to happen after the element is shown, otherwise the editor won't be refreshed
|
// this needs to happen after the element is shown, otherwise the editor won't be refreshed
|
||||||
// CodeMirror breaks pretty badly on null so even though it shouldn't happen (guarded by consistency check)
|
// CodeMirror breaks pretty badly on null so even though it shouldn't happen (guarded by consistency check)
|
||||||
// we provide fallback
|
// we provide fallback
|
||||||
codeEditor.setValue(currentNote.noteContent.content || "");
|
codeEditor.setValue(activeNote.noteContent.content || "");
|
||||||
|
|
||||||
const info = CodeMirror.findModeByMIME(currentNote.mime);
|
const info = CodeMirror.findModeByMIME(activeNote.mime);
|
||||||
|
|
||||||
if (info) {
|
if (info) {
|
||||||
codeEditor.setOption("mode", info.mime);
|
codeEditor.setOption("mode", info.mime);
|
||||||
@ -71,21 +71,21 @@ function focus() {
|
|||||||
|
|
||||||
async function executeCurrentNote() {
|
async function executeCurrentNote() {
|
||||||
// ctrl+enter is also used elsewhere so make sure we're running only when appropriate
|
// ctrl+enter is also used elsewhere so make sure we're running only when appropriate
|
||||||
if (noteDetailService.getCurrentNoteType() !== 'code') {
|
if (noteDetailService.getActiveNoteType() !== 'code') {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// make sure note is saved so we load latest changes
|
// make sure note is saved so we load latest changes
|
||||||
await noteDetailService.saveNoteIfChanged();
|
await noteDetailService.saveNoteIfChanged();
|
||||||
|
|
||||||
const currentNote = noteDetailService.getCurrentNote();
|
const activeNote = noteDetailService.getActiveNote();
|
||||||
|
|
||||||
if (currentNote.mime.endsWith("env=frontend")) {
|
if (activeNote.mime.endsWith("env=frontend")) {
|
||||||
await bundleService.getAndExecuteBundle(noteDetailService.getCurrentNoteId());
|
await bundleService.getAndExecuteBundle(noteDetailService.getActiveNoteId());
|
||||||
}
|
}
|
||||||
|
|
||||||
if (currentNote.mime.endsWith("env=backend")) {
|
if (activeNote.mime.endsWith("env=backend")) {
|
||||||
await server.post('script/run/' + noteDetailService.getCurrentNoteId());
|
await server.post('script/run/' + noteDetailService.getActiveNoteId());
|
||||||
}
|
}
|
||||||
|
|
||||||
infoService.showMessage("Note executed");
|
infoService.showMessage("Note executed");
|
||||||
|
@ -15,21 +15,21 @@ const $downloadButton = $("#file-download");
|
|||||||
const $openButton = $("#file-open");
|
const $openButton = $("#file-open");
|
||||||
|
|
||||||
async function show() {
|
async function show() {
|
||||||
const currentNote = noteDetailService.getCurrentNote();
|
const activeNote = noteDetailService.getActiveNote();
|
||||||
|
|
||||||
const attributes = await server.get('notes/' + currentNote.noteId + '/attributes');
|
const attributes = await server.get('notes/' + activeNote.noteId + '/attributes');
|
||||||
const attributeMap = utils.toObject(attributes, l => [l.name, l.value]);
|
const attributeMap = utils.toObject(attributes, l => [l.name, l.value]);
|
||||||
|
|
||||||
$component.show();
|
$component.show();
|
||||||
|
|
||||||
$fileNoteId.text(currentNote.noteId);
|
$fileNoteId.text(activeNote.noteId);
|
||||||
$fileName.text(attributeMap.originalFileName || "?");
|
$fileName.text(attributeMap.originalFileName || "?");
|
||||||
$fileSize.text((attributeMap.fileSize || "?") + " bytes");
|
$fileSize.text((attributeMap.fileSize || "?") + " bytes");
|
||||||
$fileType.text(currentNote.mime);
|
$fileType.text(activeNote.mime);
|
||||||
|
|
||||||
if (currentNote.noteContent && currentNote.noteContent.content) {
|
if (activeNote.noteContent && activeNote.noteContent.content) {
|
||||||
$previewRow.show();
|
$previewRow.show();
|
||||||
$previewContent.text(currentNote.noteContent.content);
|
$previewContent.text(activeNote.noteContent.content);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
$previewRow.hide();
|
$previewRow.hide();
|
||||||
@ -51,7 +51,7 @@ $openButton.click(() => {
|
|||||||
|
|
||||||
function getFileUrl() {
|
function getFileUrl() {
|
||||||
// electron needs absolute URL so we extract current host, port, protocol
|
// electron needs absolute URL so we extract current host, port, protocol
|
||||||
return utils.getHost() + "/api/notes/" + noteDetailService.getCurrentNoteId();
|
return utils.getHost() + "/api/notes/" + noteDetailService.getActiveNoteId();
|
||||||
}
|
}
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
|
@ -15,18 +15,18 @@ const $fileType = $("#image-filetype");
|
|||||||
const $fileSize = $("#image-filesize");
|
const $fileSize = $("#image-filesize");
|
||||||
|
|
||||||
async function show() {
|
async function show() {
|
||||||
const currentNote = noteDetailService.getCurrentNote();
|
const activeNote = noteDetailService.getActiveNote();
|
||||||
|
|
||||||
const attributes = await server.get('notes/' + currentNote.noteId + '/attributes');
|
const attributes = await server.get('notes/' + activeNote.noteId + '/attributes');
|
||||||
const attributeMap = utils.toObject(attributes, l => [l.name, l.value]);
|
const attributeMap = utils.toObject(attributes, l => [l.name, l.value]);
|
||||||
|
|
||||||
$component.show();
|
$component.show();
|
||||||
|
|
||||||
$fileName.text(attributeMap.originalFileName || "?");
|
$fileName.text(attributeMap.originalFileName || "?");
|
||||||
$fileSize.text((attributeMap.fileSize || "?") + " bytes");
|
$fileSize.text((attributeMap.fileSize || "?") + " bytes");
|
||||||
$fileType.text(currentNote.mime);
|
$fileType.text(activeNote.mime);
|
||||||
|
|
||||||
$imageView.prop("src", `api/images/${currentNote.noteId}/${currentNote.title}`);
|
$imageView.prop("src", `api/images/${activeNote.noteId}/${activeNote.title}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
$imageDownloadButton.click(() => utils.download(getFileUrl()));
|
$imageDownloadButton.click(() => utils.download(getFileUrl()));
|
||||||
@ -62,7 +62,7 @@ $copyToClipboardButton.click(() => {
|
|||||||
|
|
||||||
function getFileUrl() {
|
function getFileUrl() {
|
||||||
// electron needs absolute URL so we extract current host, port, protocol
|
// electron needs absolute URL so we extract current host, port, protocol
|
||||||
return utils.getHost() + "/api/notes/" + noteDetailService.getCurrentNoteId() + "/download";
|
return utils.getHost() + "/api/notes/" + noteDetailService.getActiveNoteId() + "/download";
|
||||||
}
|
}
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
|
@ -79,7 +79,7 @@ const linkOverlays = [
|
|||||||
];
|
];
|
||||||
|
|
||||||
function loadMapData() {
|
function loadMapData() {
|
||||||
const currentNote = noteDetailService.getCurrentNote();
|
const activeNote = noteDetailService.getActiveNote();
|
||||||
mapData = {
|
mapData = {
|
||||||
notes: [],
|
notes: [],
|
||||||
// it is important to have this exact value here so that initial transform is same as this
|
// it is important to have this exact value here so that initial transform is same as this
|
||||||
@ -93,9 +93,9 @@ function loadMapData() {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
if (currentNote.noteContent.content) {
|
if (activeNote.noteContent.content) {
|
||||||
try {
|
try {
|
||||||
mapData = JSON.parse(currentNote.noteContent.content);
|
mapData = JSON.parse(activeNote.noteContent.content);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.log("Could not parse content: ", e);
|
console.log("Could not parse content: ", e);
|
||||||
}
|
}
|
||||||
@ -507,7 +507,7 @@ $createChildNote.click(async () => {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const {note} = await server.post(`notes/${noteDetailService.getCurrentNoteId()}/children`, {
|
const {note} = await server.post(`notes/${noteDetailService.getActiveNoteId()}/children`, {
|
||||||
title,
|
title,
|
||||||
target: 'into'
|
target: 'into'
|
||||||
});
|
});
|
||||||
|
@ -26,7 +26,7 @@ async function render() {
|
|||||||
|
|
||||||
$noteDetailRenderContent.append(bundle.html);
|
$noteDetailRenderContent.append(bundle.html);
|
||||||
|
|
||||||
await bundleService.executeBundle(bundle, noteDetailService.getCurrentNote());
|
await bundleService.executeBundle(bundle, noteDetailService.getActiveNote());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -9,10 +9,10 @@ const $refreshButton = $('#note-detail-search-refresh-results-button');
|
|||||||
function show() {
|
function show() {
|
||||||
$component.show();
|
$component.show();
|
||||||
|
|
||||||
console.log(noteDetailService.getCurrentNote());
|
console.log(noteDetailService.getActiveNote());
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const json = JSON.parse(noteDetailService.getCurrentNote().noteContent.content);
|
const json = JSON.parse(noteDetailService.getActiveNote().noteContent.content);
|
||||||
|
|
||||||
$searchString.val(json.searchString);
|
$searchString.val(json.searchString);
|
||||||
}
|
}
|
||||||
|
@ -31,7 +31,7 @@ async function show() {
|
|||||||
|
|
||||||
$component.show();
|
$component.show();
|
||||||
|
|
||||||
textEditor.setData(noteDetailService.getCurrentNote().noteContent.content);
|
textEditor.setData(noteDetailService.getActiveNote().noteContent.content);
|
||||||
}
|
}
|
||||||
|
|
||||||
function getContent() {
|
function getContent() {
|
||||||
|
@ -97,7 +97,7 @@ function NoteTypeModel() {
|
|||||||
};
|
};
|
||||||
|
|
||||||
async function save() {
|
async function save() {
|
||||||
const note = noteDetailService.getCurrentNote();
|
const note = noteDetailService.getActiveNote();
|
||||||
|
|
||||||
await server.put('notes/' + note.noteId
|
await server.put('notes/' + note.noteId
|
||||||
+ '/type/' + encodeURIComponent(self.type())
|
+ '/type/' + encodeURIComponent(self.type())
|
||||||
@ -112,7 +112,7 @@ function NoteTypeModel() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function confirmChangeIfContent() {
|
function confirmChangeIfContent() {
|
||||||
if (!noteDetailService.getCurrentNoteContent()) {
|
if (!noteDetailService.getActiveNoteContent()) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -112,13 +112,13 @@ async function enterProtectedSessionOnServer(password) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async function protectNoteAndSendToServer() {
|
async function protectNoteAndSendToServer() {
|
||||||
if (noteDetailService.getCurrentNote().isProtected) {
|
if (noteDetailService.getActiveNote().isProtected) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
await ensureProtectedSession(true, true);
|
await ensureProtectedSession(true, true);
|
||||||
|
|
||||||
const note = noteDetailService.getCurrentNote();
|
const note = noteDetailService.getActiveNote();
|
||||||
note.isProtected = true;
|
note.isProtected = true;
|
||||||
|
|
||||||
await noteDetailService.saveNote(note);
|
await noteDetailService.saveNote(note);
|
||||||
@ -129,10 +129,10 @@ async function protectNoteAndSendToServer() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async function unprotectNoteAndSendToServer() {
|
async function unprotectNoteAndSendToServer() {
|
||||||
const currentNote = noteDetailService.getCurrentNote();
|
const activeNote = noteDetailService.getActiveNote();
|
||||||
|
|
||||||
if (!currentNote.isProtected) {
|
if (!activeNote.isProtected) {
|
||||||
infoService.showAndLogError(`Note ${currentNote.noteId} is not protected`);
|
infoService.showAndLogError(`Note ${activeNote.noteId} is not protected`);
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -146,11 +146,11 @@ async function unprotectNoteAndSendToServer() {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
currentNote.isProtected = false;
|
activeNote.isProtected = false;
|
||||||
|
|
||||||
await noteDetailService.saveNote(currentNote);
|
await noteDetailService.saveNote(activeNote);
|
||||||
|
|
||||||
treeService.setProtected(currentNote.noteId, currentNote.isProtected);
|
treeService.setProtected(activeNote.noteId, activeNote.isProtected);
|
||||||
|
|
||||||
noteDetailService.updateNoteView();
|
noteDetailService.updateNoteView();
|
||||||
}
|
}
|
||||||
|
@ -39,7 +39,7 @@ function getCurrentNode() {
|
|||||||
return $tree.fancytree("getActiveNode");
|
return $tree.fancytree("getActiveNode");
|
||||||
}
|
}
|
||||||
|
|
||||||
function getCurrentNotePath() {
|
function getActiveNotePath() {
|
||||||
const node = getCurrentNode();
|
const node = getCurrentNode();
|
||||||
|
|
||||||
return treeUtils.getNotePath(node);
|
return treeUtils.getNotePath(node);
|
||||||
@ -330,7 +330,7 @@ async function setExpandedToServer(branchId, isExpanded) {
|
|||||||
function addRecentNote(branchId, notePath) {
|
function addRecentNote(branchId, notePath) {
|
||||||
setTimeout(async () => {
|
setTimeout(async () => {
|
||||||
// we include the note into recent list only if the user stayed on the note at least 5 seconds
|
// we include the note into recent list only if the user stayed on the note at least 5 seconds
|
||||||
if (notePath && notePath === getCurrentNotePath()) {
|
if (notePath && notePath === getActiveNotePath()) {
|
||||||
await server.post('recent-notes', { branchId, notePath });
|
await server.post('recent-notes', { branchId, notePath });
|
||||||
}
|
}
|
||||||
}, 1500);
|
}, 1500);
|
||||||
@ -339,12 +339,12 @@ function addRecentNote(branchId, notePath) {
|
|||||||
function setCurrentNotePathToHash(node) {
|
function setCurrentNotePathToHash(node) {
|
||||||
utils.assertArguments(node);
|
utils.assertArguments(node);
|
||||||
|
|
||||||
const currentNotePath = treeUtils.getNotePath(node);
|
const activeNotePath = treeUtils.getNotePath(node);
|
||||||
const currentBranchId = node.data.branchId;
|
const currentBranchId = node.data.branchId;
|
||||||
|
|
||||||
document.location.hash = currentNotePath;
|
document.location.hash = activeNotePath;
|
||||||
|
|
||||||
addRecentNote(currentBranchId, currentNotePath);
|
addRecentNote(currentBranchId, activeNotePath);
|
||||||
}
|
}
|
||||||
|
|
||||||
function getSelectedNodes(stopOnParents = false) {
|
function getSelectedNodes(stopOnParents = false) {
|
||||||
@ -563,7 +563,7 @@ async function createNote(node, parentNoteId, target, isProtected, saveSelection
|
|||||||
isProtected = false;
|
isProtected = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (noteDetailService.getCurrentNoteType() !== 'text') {
|
if (noteDetailService.getActiveNoteType() !== 'text') {
|
||||||
saveSelection = false;
|
saveSelection = false;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
@ -714,7 +714,7 @@ $(window).bind('hashchange', function() {
|
|||||||
if (isNotePathInAddress()) {
|
if (isNotePathInAddress()) {
|
||||||
const notePath = getHashValueFromAddress();
|
const notePath = getHashValueFromAddress();
|
||||||
|
|
||||||
if (notePath !== '-' && getCurrentNotePath() !== notePath) {
|
if (notePath !== '-' && getActiveNotePath() !== notePath) {
|
||||||
console.debug("Switching to " + notePath + " because of hash change");
|
console.debug("Switching to " + notePath + " because of hash change");
|
||||||
|
|
||||||
activateNote(notePath);
|
activateNote(notePath);
|
||||||
@ -738,7 +738,7 @@ export default {
|
|||||||
activateNote,
|
activateNote,
|
||||||
getFocusedNode,
|
getFocusedNode,
|
||||||
getCurrentNode,
|
getCurrentNode,
|
||||||
getCurrentNotePath,
|
getActiveNotePath,
|
||||||
setCurrentNotePathToHash,
|
setCurrentNotePathToHash,
|
||||||
setNoteTitle,
|
setNoteTitle,
|
||||||
setPrefix,
|
setPrefix,
|
||||||
|
@ -8,14 +8,14 @@ const optionService = require('../../services/options');
|
|||||||
|
|
||||||
async function getAutocomplete(req) {
|
async function getAutocomplete(req) {
|
||||||
const query = req.query.query;
|
const query = req.query.query;
|
||||||
const currentNoteId = req.query.currentNoteId || 'none';
|
const activeNoteId = req.query.activeNoteId || 'none';
|
||||||
|
|
||||||
let results;
|
let results;
|
||||||
|
|
||||||
const timestampStarted = Date.now();
|
const timestampStarted = Date.now();
|
||||||
|
|
||||||
if (query.trim().length === 0) {
|
if (query.trim().length === 0) {
|
||||||
results = await getRecentNotes(currentNoteId);
|
results = await getRecentNotes(activeNoteId);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
results = await noteCacheService.findNotes(query);
|
results = await noteCacheService.findNotes(query);
|
||||||
@ -30,7 +30,7 @@ async function getAutocomplete(req) {
|
|||||||
return results;
|
return results;
|
||||||
}
|
}
|
||||||
|
|
||||||
async function getRecentNotes(currentNoteId) {
|
async function getRecentNotes(activeNoteId) {
|
||||||
let extraCondition = '';
|
let extraCondition = '';
|
||||||
|
|
||||||
const hoistedNoteId = await optionService.getOption('hoistedNoteId');
|
const hoistedNoteId = await optionService.getOption('hoistedNoteId');
|
||||||
@ -51,7 +51,7 @@ async function getRecentNotes(currentNoteId) {
|
|||||||
${extraCondition}
|
${extraCondition}
|
||||||
ORDER BY
|
ORDER BY
|
||||||
utcDateCreated DESC
|
utcDateCreated DESC
|
||||||
LIMIT 200`, [currentNoteId]);
|
LIMIT 200`, [activeNoteId]);
|
||||||
|
|
||||||
return recentNotes.map(rn => {
|
return recentNotes.map(rn => {
|
||||||
const title = noteCacheService.getNoteTitleForPath(rn.notePath.split('/'));
|
const title = noteCacheService.getNoteTitleForPath(rn.notePath.split('/'));
|
||||||
|
@ -22,7 +22,7 @@ const appInfo = require('./app_info');
|
|||||||
function BackendScriptApi(currentNote, apiParams) {
|
function BackendScriptApi(currentNote, apiParams) {
|
||||||
/** @property {Note} note where script started executing */
|
/** @property {Note} note where script started executing */
|
||||||
this.startNote = apiParams.startNote;
|
this.startNote = apiParams.startNote;
|
||||||
/** @property {Note} note where script is currently executing */
|
/** @property {Note} note where script is currently executing. Don't mix this up with concept of active note */
|
||||||
this.currentNote = currentNote;
|
this.currentNote = currentNote;
|
||||||
/** @property {Entity} entity whose event triggered this executions */
|
/** @property {Entity} entity whose event triggered this executions */
|
||||||
this.originEntity = apiParams.originEntity;
|
this.originEntity = apiParams.originEntity;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user