Merge branch 'master' into stable

This commit is contained in:
azivner
2017-12-20 19:52:17 -05:00
28 changed files with 330 additions and 118 deletions

View File

@@ -88,7 +88,7 @@ const contextMenu = (function() {
const node = $.ui.fancytree.getNode(ui.target);
if (ui.cmd === "insertNoteHere") {
const parentNoteId = node.data.note_pid;
const parentNoteId = node.data.parent_note_id;
const isProtected = treeUtils.getParentProtectedStatus(node);
noteTree.createNote(node, parentNoteId, 'after', isProtected);

View File

@@ -154,6 +154,7 @@ settings.addModule((async function () {
settings.addModule((async function () {
const forceFullSyncButton = $("#force-full-sync-button");
const fillSyncRowsButton = $("#fill-sync-rows-button");
forceFullSyncButton.click(async () => {
await server.post('sync/force-full-sync');
@@ -161,6 +162,12 @@ settings.addModule((async function () {
showMessage("Full sync triggered");
});
fillSyncRowsButton.click(async () => {
await server.post('sync/fill-sync-rows');
showMessage("Sync rows filled successfully");
});
return {};
})());

View File

@@ -20,15 +20,22 @@ const sqlConsole = (function() {
async function execute() {
const sqlQuery = queryEl.val();
const results = await server.post("sql/execute", {
const result = await server.post("sql/execute", {
query: sqlQuery
});
if (!result.success) {
showError(result.error);
return;
}
const rows = result.rows;
resultHeadEl.empty();
resultBodyEl.empty();
if (results.length > 0) {
const result = results[0];
if (rows.length > 0) {
const result = rows[0];
const rowEl = $("<tr>");
for (const key in result) {
@@ -38,7 +45,7 @@ const sqlConsole = (function() {
resultHeadEl.append(rowEl);
}
for (const result of results) {
for (const result of rows) {
const rowEl = $("<tr>");
for (const key in result) {

View File

@@ -2,7 +2,6 @@
const messaging = (function() {
const changesToPushCountEl = $("#changes-to-push-count");
let ws = null;
function logError(message) {
console.log(now(), message); // needs to be separate from .trace()
@@ -21,12 +20,15 @@ const messaging = (function() {
if (message.type === 'sync') {
lastPingTs = new Date().getTime();
const syncData = message.data.filter(sync => sync.source_id !== glob.sourceId);
if (syncData.length > 0) {
console.log(now(), "Sync data: ", message);
if (message.data.length > 0) {
console.log(now(), "Sync data: ", message.data);
lastSyncId = message.data[message.data.length - 1].id;
}
const syncData = message.data.filter(sync => sync.source_id !== glob.sourceId);
if (syncData.some(sync => sync.entity_name === 'notes_tree')) {
console.log(now(), "Reloading tree because of background changes");
@@ -59,17 +61,20 @@ const messaging = (function() {
const protocol = document.location.protocol === 'https:' ? 'wss' : 'ws';
// use wss for secure messaging
ws = new WebSocket(protocol + "://" + location.host);
const ws = new WebSocket(protocol + "://" + location.host);
ws.onopen = event => console.log(now(), "Connected to server with WebSocket");
ws.onmessage = messageHandler;
ws.onclose = function(){
// Try to reconnect in 5 seconds
setTimeout(() => connectWebSocket(), 5000);
};
return ws;
}
connectWebSocket();
const ws = connectWebSocket();
let lastSyncId = glob.maxSyncIdAtLoad;
let lastPingTs = new Date().getTime();
let connectionBrokenNotification = null;
@@ -92,7 +97,12 @@ const messaging = (function() {
showMessage("Re-connected to server");
}
}, 3000);
ws.send(JSON.stringify({
type: 'ping',
lastSyncId: lastSyncId
}));
}, 1000);
return {
logError

View File

@@ -132,7 +132,7 @@ const noteTree = (function() {
delete note.note_title; // this should not be used. Use noteIdToTitle instead
setParentChildRelation(note.note_tree_id, note.note_pid, note.note_id);
setParentChildRelation(note.note_tree_id, note.parent_note_id, note.note_id);
}
return prepareNoteTreeInner('root');
@@ -171,7 +171,7 @@ const noteTree = (function() {
const node = {
note_id: noteTree.note_id,
note_pid: noteTree.note_pid,
parent_note_id: noteTree.parent_note_id,
note_tree_id: noteTree.note_tree_id,
is_protected: noteTree.is_protected,
prefix: noteTree.prefix,
@@ -207,7 +207,7 @@ const noteTree = (function() {
//console.log(now(), "Run path: ", runPath);
for (const childNoteId of runPath) {
const node = getNodesByNoteId(childNoteId).find(node => node.data.note_pid === parentNoteId);
const node = getNodesByNoteId(childNoteId).find(node => node.data.parent_note_id === parentNoteId);
if (childNoteId === noteId) {
await node.setActive();
@@ -334,6 +334,10 @@ const noteTree = (function() {
while (cur !== 'root') {
path.push(cur);
if (!childToParents[cur]) {
throwError("Can't find parents for " + cur);
}
cur = childToParents[cur][0];
}
@@ -505,12 +509,16 @@ const noteTree = (function() {
await getTree().reload(notes);
}
function getNotePathFromAddress() {
return document.location.hash.substr(1); // strip initial #
}
function loadTree() {
return server.get('tree').then(resp => {
startNotePath = resp.start_note_path;
if (document.location.hash) {
startNotePath = document.location.hash.substr(1); // strip initial #
startNotePath = getNotePathFromAddress();
}
return prepareNoteTree(resp.notes);
@@ -610,7 +618,7 @@ const noteTree = (function() {
const newNode = {
title: newNoteName,
note_id: result.note_id,
note_pid: parentNoteId,
parent_note_id: parentNoteId,
refKey: result.note_id,
note_tree_id: result.note_tree_id,
is_protected: isProtected,
@@ -642,7 +650,7 @@ const noteTree = (function() {
console.log("pressed O");
const node = getCurrentNode();
const parentNoteId = node.data.note_pid;
const parentNoteId = node.data.parent_note_id;
const isProtected = treeUtils.getParentProtectedStatus(node);
createNote(node, parentNoteId, 'after', isProtected);
@@ -668,6 +676,26 @@ const noteTree = (function() {
$(document).bind('keydown', 'ctrl+.', scrollToCurrentNote);
$(window).bind('hashchange', function() {
const notePath = getNotePathFromAddress();
activateNode(notePath);
});
if (isElectron()) {
$(document).bind('keydown', 'alt+left', e => {
window.history.back();
e.preventDefault();
});
$(document).bind('keydown', 'alt+right', e => {
window.history.forward();
e.preventDefault();
});
}
return {
reload,
collapseTree,

View File

@@ -96,13 +96,13 @@ const treeChanges = (function() {
}
function changeNode(node, func) {
noteTree.removeParentChildRelation(node.data.note_pid, node.data.note_id);
noteTree.removeParentChildRelation(node.data.parent_note_id, node.data.note_id);
func(node);
node.data.note_pid = node.getParent() === null ? 'root' : node.getParent().data.note_id;
node.data.parent_note_id = node.getParent() === null ? 'root' : node.getParent().data.note_id;
noteTree.setParentChildRelation(node.data.note_tree_id, node.data.note_pid, node.data.note_id);
noteTree.setParentChildRelation(node.data.note_tree_id, node.data.parent_note_id, node.data.note_id);
noteTree.setCurrentNotePathToHash(node);
}