Merge remote-tracking branch 'origin/master'

This commit is contained in:
zadam 2019-12-29 10:19:11 +01:00
commit 7db4859fb9
18 changed files with 56 additions and 33 deletions

Binary file not shown.

View File

@ -44,7 +44,10 @@ export async function showDialog() {
const note = await treeCache.getNote(change.noteId); const note = await treeCache.getNote(change.noteId);
const notePath = await treeService.getSomeNotePath(note); const notePath = await treeService.getSomeNotePath(note);
noteLink = await linkService.createNoteLinkWithPath(notePath, change.title); noteLink = await linkService.createNoteLink(notePath, {
title: change.title,
showNotePath: true
});
} }
changesListEl.append($('<li>') changesListEl.append($('<li>')

View File

@ -255,6 +255,8 @@ function registerEntrypoints() {
await treeService.expandToNote(note.noteId); await treeService.expandToNote(note.noteId);
await noteDetailService.openInTab(note.noteId, true); await noteDetailService.openInTab(note.noteId, true);
noteDetailService.focusAndSelectTitle();
}); });
keyboardActionService.setGlobalActionHandler("EditBranchPrefix", async () => { keyboardActionService.setGlobalActionHandler("EditBranchPrefix", async () => {

View File

@ -125,14 +125,14 @@ function FrontendScriptApi(startNote, currentNote, originEntity = null, tabConte
} }
/** /**
* Executes given anonymous function on the server. * Executes given anonymous function on the backend.
* Internally this serializes the anonymous function into string and sends it to backend via AJAX. * Internally this serializes the anonymous function into string and sends it to backend via AJAX.
* *
* @param {string} script - script to be executed on the backend * @param {string} script - script to be executed on the backend
* @param {Array.<?>} params - list of parameters to the anonymous function to be send to backend * @param {Array.<?>} params - list of parameters to the anonymous function to be send to backend
* @return {Promise<*>} return value of the executed function on the backend * @return {Promise<*>} return value of the executed function on the backend
*/ */
this.runOnServer = async (script, params = []) => { this.runOnBackend = async (script, params = []) => {
if (typeof script === "function") { if (typeof script === "function") {
script = script.toString(); script = script.toString();
} }
@ -159,6 +159,12 @@ function FrontendScriptApi(startNote, currentNote, originEntity = null, tabConte
} }
}; };
/**
* @deprecated new name of this API call is runOnBackend so use that
* @method
*/
this.runOnServer = this.runOnBackend;
/** /**
* This is a powerful search method - you can search by attributes and their values, e.g.: * This is a powerful search method - you can search by attributes and their values, e.g.:
* "@dateModified =* MONTH AND @log". See full documentation for all options at: https://github.com/zadam/trilium/wiki/Search * "@dateModified =* MONTH AND @log". See full documentation for all options at: https://github.com/zadam/trilium/wiki/Search

View File

@ -9,7 +9,11 @@ function getNotePathFromUrl(url) {
return notePathMatch === null ? null : notePathMatch[1]; return notePathMatch === null ? null : notePathMatch[1];
} }
async function createNoteLink(notePath, noteTitle = null, tooltip = true) { async function createNoteLink(notePath, options = {}) {
let noteTitle = options.title;
const showTooltip = options.showTooltip === undefined ? true : options.showTooltip;
const showNotePath = options.showNotePath === undefined ? false : options.showNotePath;
if (!noteTitle) { if (!noteTitle) {
const {noteId, parentNoteId} = treeUtils.getNoteIdAndParentIdFromNotePath(notePath); const {noteId, parentNoteId} = treeUtils.getNoteIdAndParentIdFromNotePath(notePath);
@ -22,30 +26,26 @@ async function createNoteLink(notePath, noteTitle = null, tooltip = true) {
}).attr('data-action', 'note') }).attr('data-action', 'note')
.attr('data-note-path', notePath); .attr('data-note-path', notePath);
if (!tooltip) { if (!showTooltip) {
$noteLink.addClass("no-tooltip-preview"); $noteLink.addClass("no-tooltip-preview");
} }
return $noteLink; const $container = $("<span>").append($noteLink);
}
async function createNoteLinkWithPath(notePath, noteTitle = null) { if (showNotePath) {
const $link = await createNoteLink(notePath, noteTitle); notePath = await treeService.resolveNotePath(notePath);
const $res = $("<span>").append($link);
if (notePath.includes("/")) {
const noteIds = notePath.split("/"); const noteIds = notePath.split("/");
noteIds.pop(); // remove last element noteIds.pop(); // remove last element
const parentNotePath = noteIds.join("/").trim(); const parentNotePath = noteIds.join("/").trim();
if (parentNotePath) { if (parentNotePath) {
$res.append($("<small>").text(" (" + await treeUtils.getNotePathTitle(parentNotePath) + ")")); $container.append($("<small>").text(" (" + await treeUtils.getNotePathTitle(parentNotePath) + ")"));
} }
} }
return $res; return $container;
} }
function getNotePathFromLink($link) { function getNotePathFromLink($link) {
@ -180,7 +180,6 @@ $(document).on('contextmenu', ".note-detail-render a", newTabContextMenu);
export default { export default {
getNotePathFromUrl, getNotePathFromUrl,
createNoteLink, createNoteLink,
createNoteLinkWithPath,
addLinkToEditor, addLinkToEditor,
addTextToEditor, addTextToEditor,
goToLink goToLink

View File

@ -88,7 +88,7 @@ export default class LinkMap {
.addClass("note-box") .addClass("note-box")
.prop("id", noteBoxId); .prop("id", noteBoxId);
linkService.createNoteLink(noteId, note.title).then($link => { linkService.createNoteLink(noteId, {title: note.title}).then($link => {
$link.on('click', e => { $link.on('click', e => {
try { try {
$link.tooltip('dispose'); $link.tooltip('dispose');

View File

@ -137,7 +137,7 @@ class NoteDetailBook {
.attr('data-note-id', childNote.noteId) .attr('data-note-id', childNote.noteId)
.css("flex-basis", ZOOMS[this.zoomLevel].width) .css("flex-basis", ZOOMS[this.zoomLevel].width)
.addClass("type-" + type) .addClass("type-" + type)
.append($('<h5 class="note-book-title">').append(await linkService.createNoteLink(childNotePath, null, false))) .append($('<h5 class="note-book-title">').append(await linkService.createNoteLink(childNotePath, {showTooltip: false})))
.append($('<div class="note-book-content">') .append($('<div class="note-book-content">')
.css("max-height", ZOOMS[this.zoomLevel].height) .css("max-height", ZOOMS[this.zoomLevel].height)
.append(await this.getNoteContent(type, childNote))); .append(await this.getNoteContent(type, childNote)));

View File

@ -39,8 +39,11 @@ class NoteDetailFile {
}); });
this.$uploadNewRevisionInput.on('change', async () => { this.$uploadNewRevisionInput.on('change', async () => {
const fileToUpload = this.$uploadNewRevisionInput[0].files[0]; // copy to allow reset below
this.$uploadNewRevisionInput.val('');
const formData = new FormData(); const formData = new FormData();
formData.append('upload', this.$uploadNewRevisionInput[0].files[0]); formData.append('upload', fileToUpload);
const result = await $.ajax({ const result = await $.ajax({
url: baseApiUrl + 'notes/' + this.ctx.note.noteId + '/file', url: baseApiUrl + 'notes/' + this.ctx.note.noteId + '/file',

View File

@ -48,8 +48,11 @@ class NoteDetailImage {
}); });
this.$uploadNewRevisionInput.on('change', async () => { this.$uploadNewRevisionInput.on('change', async () => {
const fileToUpload = this.$uploadNewRevisionInput[0].files[0]; // copy to allow reset below
this.$uploadNewRevisionInput.val('');
const formData = new FormData(); const formData = new FormData();
formData.append('upload', this.$uploadNewRevisionInput[0].files[0]); formData.append('upload', fileToUpload);
const result = await $.ajax({ const result = await $.ajax({
url: baseApiUrl + 'images/' + this.ctx.note.noteId, url: baseApiUrl + 'images/' + this.ctx.note.noteId,

View File

@ -494,7 +494,7 @@ class NoteDetailRelationMap {
} }
async createNoteBox(noteId, title, x, y) { async createNoteBox(noteId, title, x, y) {
const $link = await linkService.createNoteLink(noteId, title); const $link = await linkService.createNoteLink(noteId, {title});
$link.mousedown(e => { $link.mousedown(e => {
console.log(e); console.log(e);

View File

@ -11,8 +11,6 @@ import protectedSessionService from "./protected_session.js";
import optionsService from "./options.js"; import optionsService from "./options.js";
import linkService from "./link.js"; import linkService from "./link.js";
import Sidebar from "./sidebar.js"; import Sidebar from "./sidebar.js";
import libraryLoader from "./library_loader.js";
import noteAutocompleteService from "./note_autocomplete.js";
const $tabContentsContainer = $("#note-tab-container"); const $tabContentsContainer = $("#note-tab-container");
@ -291,6 +289,10 @@ class TabContext {
} }
getComponent() { getComponent() {
if (!this.components[this.type]) {
throw new Error("Could not find component for type: " + this.type);
}
return this.components[this.type]; return this.components[this.type];
} }
@ -377,7 +379,7 @@ class TabContext {
async addPath(notePath, isCurrent) { async addPath(notePath, isCurrent) {
const title = await treeUtils.getNotePathTitle(notePath); const title = await treeUtils.getNotePathTitle(notePath);
const noteLink = await linkService.createNoteLink(notePath, title); const noteLink = await linkService.createNoteLink(notePath, {title});
noteLink noteLink
.addClass("no-tooltip-preview") .addClass("no-tooltip-preview")

View File

@ -127,16 +127,16 @@ async function getNodeFromPath(notePath, expand = false, expandOpts = {}) {
// we expand only after hoisted note since before then nodes are not actually present in the tree // we expand only after hoisted note since before then nodes are not actually present in the tree
if (parentNode) { if (parentNode) {
checkFolderStatus(parentNode);
if (!parentNode.isLoaded()) { if (!parentNode.isLoaded()) {
await parentNode.load(); await parentNode.load();
} }
if (expand) { if (expand) {
parentNode.setExpanded(true, expandOpts); await parentNode.setExpanded(true, expandOpts);
} }
await checkFolderStatus(parentNode);
let foundChildNode = findChildNode(parentNode, childNoteId); let foundChildNode = findChildNode(parentNode, childNoteId);
if (!foundChildNode) { // note might be recently created so we'll force reload and try again if (!foundChildNode) { // note might be recently created so we'll force reload and try again

View File

@ -131,12 +131,15 @@ async function checkOutstandingSyncs() {
const { stats, initialized } = await $.get('api/sync/stats'); const { stats, initialized } = await $.get('api/sync/stats');
if (initialized) { if (initialized) {
window.location.replace("./"); const remote = require('electron').remote;
remote.app.relaunch();
remote.app.exit(0);
} }
else {
const totalOutstandingSyncs = stats.outstandingPushes + stats.outstandingPulls;
const totalOutstandingSyncs = stats.outstandingPushes + stats.outstandingPulls; $("#outstanding-syncs").html(totalOutstandingSyncs);
}
$("#outstanding-syncs").html(totalOutstandingSyncs);
} }
function showAlert(message) { function showAlert(message) {

View File

@ -45,7 +45,7 @@ class EditedNotesWidget extends StandardWidget {
$item.append($("<i>").text(editedNote.title + " (deleted)")); $item.append($("<i>").text(editedNote.title + " (deleted)"));
} }
else { else {
$item.append(editedNote.notePath ? await linkService.createNoteLinkWithPath(editedNote.notePath.join("/")) : editedNote.title); $item.append(editedNote.notePath ? await linkService.createNoteLink(editedNote.notePath.join("/"), {showNotePath: true}) : editedNote.title);
} }
$list.append($item); $list.append($item);

View File

@ -39,7 +39,7 @@ class SimilarNotesWidget extends StandardWidget {
} }
const $item = $("<li>") const $item = $("<li>")
.append(await linkService.createNoteLinkWithPath(similarNote.notePath.join("/"))); .append(await linkService.createNoteLink(similarNote.notePath.join("/"), {showNotePath: true}));
$list.append($item); $list.append($item);
} }

View File

@ -57,6 +57,7 @@ body {
} }
#left-pane { #left-pane {
height: 100%;
display: flex; display: flex;
flex-direction: column; flex-direction: column;
} }

View File

@ -105,6 +105,7 @@ span.fancytree-node.muted { opacity: 0.6; }
flex-direction: column; flex-direction: column;
flex-grow: 100; flex-grow: 100;
height: 100%; height: 100%;
width: 100%;
} }
.note-detail-component-wrapper { .note-detail-component-wrapper {

View File

@ -83,7 +83,7 @@ async function checkBasicAuth(req, res, next) {
const dbUsername = await optionService.getOption('username'); const dbUsername = await optionService.getOption('username');
if (dbUsername !== username || !await passwordEncryptionService.verifyPassword(password)) { if (dbUsername !== username || !await passwordEncryptionService.verifyPassword(password)) {
res.status(401).send("Not authorized"); res.status(401).send('Incorrect username and/or password');
} }
else { else {
next(); next();