2018-03-26 01:41:29 +08:00
|
|
|
import contextMenuService from './context_menu.js';
|
2018-03-25 23:09:17 +08:00
|
|
|
import dragAndDropSetup from './drag_and_drop.js';
|
2018-03-26 01:41:29 +08:00
|
|
|
import linkService from './link.js';
|
|
|
|
import messagingService from './messaging.js';
|
|
|
|
import noteDetailService from './note_detail.js';
|
2018-03-26 09:16:57 +08:00
|
|
|
import protectedSessionHolder from './protected_session_holder.js';
|
2018-03-26 01:41:29 +08:00
|
|
|
import treeChangesService from './tree_changes.js';
|
2018-03-25 23:09:17 +08:00
|
|
|
import treeUtils from './tree_utils.js';
|
|
|
|
import utils from './utils.js';
|
|
|
|
import server from './server.js';
|
2018-03-26 01:41:29 +08:00
|
|
|
import recentNotesDialog from '../dialogs/recent_notes.js';
|
2018-03-26 07:49:33 +08:00
|
|
|
import editTreePrefixDialog from '../dialogs/edit_tree_prefix.js';
|
2018-03-26 00:29:00 +08:00
|
|
|
import treeCache from './tree_cache.js';
|
2018-03-26 09:29:35 +08:00
|
|
|
import infoService from "./info.js";
|
2018-03-26 11:25:17 +08:00
|
|
|
import Branch from '../entities/branch.js';
|
2017-11-22 09:04:06 +08:00
|
|
|
|
2018-03-25 23:09:17 +08:00
|
|
|
const $tree = $("#tree");
|
|
|
|
const $parentList = $("#parent-list");
|
|
|
|
const $parentListList = $("#parent-list-inner");
|
|
|
|
const $createTopLevelNoteButton = $("#create-top-level-note-button");
|
|
|
|
const $collapseTreeButton = $("#collapse-tree-button");
|
|
|
|
const $scrollToCurrentNoteButton = $("#scroll-to-current-note-button");
|
2018-02-25 10:23:04 +08:00
|
|
|
|
2018-03-25 23:09:17 +08:00
|
|
|
let startNotePath = null;
|
2018-03-13 08:00:19 +08:00
|
|
|
|
2018-03-25 23:09:17 +08:00
|
|
|
// note that if you want to access data like noteId or isProtected, you need to go into "data" property
|
|
|
|
function getCurrentNode() {
|
|
|
|
return $tree.fancytree("getActiveNode");
|
|
|
|
}
|
2017-11-24 09:12:39 +08:00
|
|
|
|
2018-03-25 23:09:17 +08:00
|
|
|
function getCurrentNotePath() {
|
|
|
|
const node = getCurrentNode();
|
2017-12-24 00:02:38 +08:00
|
|
|
|
2018-03-25 23:09:17 +08:00
|
|
|
return treeUtils.getNotePath(node);
|
|
|
|
}
|
2017-11-28 23:17:30 +08:00
|
|
|
|
2018-03-26 02:49:20 +08:00
|
|
|
async function getNodesByBranchId(branchId) {
|
2018-03-25 23:09:17 +08:00
|
|
|
utils.assertArguments(branchId);
|
2017-11-28 23:17:30 +08:00
|
|
|
|
2018-03-26 02:49:20 +08:00
|
|
|
const branch = await treeCache.getBranch(branchId);
|
2017-12-24 00:02:38 +08:00
|
|
|
|
2018-03-25 23:09:17 +08:00
|
|
|
return getNodesByNoteId(branch.noteId).filter(node => node.data.branchId === branchId);
|
|
|
|
}
|
2017-11-24 09:12:39 +08:00
|
|
|
|
2018-03-25 23:09:17 +08:00
|
|
|
function getNodesByNoteId(noteId) {
|
|
|
|
utils.assertArguments(noteId);
|
2017-12-24 00:02:38 +08:00
|
|
|
|
2018-03-25 23:09:17 +08:00
|
|
|
const list = getTree().getNodesByRef(noteId);
|
|
|
|
return list ? list : []; // if no nodes with this refKey are found, fancy tree returns null
|
|
|
|
}
|
2017-11-28 23:17:30 +08:00
|
|
|
|
2018-03-26 02:49:20 +08:00
|
|
|
async function setPrefix(branchId, prefix) {
|
2018-03-25 23:09:17 +08:00
|
|
|
utils.assertArguments(branchId);
|
2017-11-28 23:17:30 +08:00
|
|
|
|
2018-03-26 02:49:20 +08:00
|
|
|
const branch = await treeCache.getBranch(branchId);
|
2018-03-13 11:14:09 +08:00
|
|
|
|
2018-03-26 02:49:20 +08:00
|
|
|
branch.prefix = prefix;
|
|
|
|
|
|
|
|
for (const node of await getNodesByBranchId(branchId)) {
|
|
|
|
await setNodeTitleWithPrefix(node);
|
|
|
|
}
|
2018-03-25 23:09:17 +08:00
|
|
|
}
|
2018-03-13 11:14:09 +08:00
|
|
|
|
2018-03-26 02:49:20 +08:00
|
|
|
async function setNodeTitleWithPrefix(node) {
|
2018-03-27 09:50:47 +08:00
|
|
|
const noteTitle = await treeUtils.getNoteTitle(node.data.noteId);
|
2018-03-26 02:49:20 +08:00
|
|
|
const branch = await treeCache.getBranch(node.data.branchId);
|
2018-03-13 11:14:09 +08:00
|
|
|
|
2018-03-25 23:09:17 +08:00
|
|
|
const prefix = branch.prefix;
|
2017-11-28 23:17:30 +08:00
|
|
|
|
2018-03-25 23:09:17 +08:00
|
|
|
const title = (prefix ? (prefix + " - ") : "") + noteTitle;
|
2017-12-24 00:02:38 +08:00
|
|
|
|
2018-03-25 23:09:17 +08:00
|
|
|
node.setTitle(utils.escapeHtml(title));
|
|
|
|
}
|
2018-03-25 22:06:14 +08:00
|
|
|
|
2018-03-25 23:09:17 +08:00
|
|
|
async function prepareBranch(noteRows, branchRows) {
|
|
|
|
utils.assertArguments(noteRows);
|
2017-11-18 10:31:54 +08:00
|
|
|
|
2018-03-26 00:29:00 +08:00
|
|
|
treeCache.load(noteRows, branchRows);
|
2017-12-24 00:02:38 +08:00
|
|
|
|
2018-03-26 02:49:20 +08:00
|
|
|
return await prepareBranchInner(await treeCache.getNote('root'));
|
2018-03-25 23:09:17 +08:00
|
|
|
}
|
2017-11-24 09:12:39 +08:00
|
|
|
|
2018-03-25 23:09:17 +08:00
|
|
|
async function getExtraClasses(note) {
|
|
|
|
utils.assertArguments(note);
|
2017-11-24 09:12:39 +08:00
|
|
|
|
2018-03-25 23:09:17 +08:00
|
|
|
const extraClasses = [];
|
2017-11-24 09:12:39 +08:00
|
|
|
|
2018-03-25 23:09:17 +08:00
|
|
|
if (note.isProtected) {
|
|
|
|
extraClasses.push("protected");
|
|
|
|
}
|
2018-01-27 11:32:44 +08:00
|
|
|
|
2018-03-25 23:09:17 +08:00
|
|
|
if ((await note.getParentNotes()).length > 1) {
|
|
|
|
extraClasses.push("multiple-parents");
|
2017-11-24 09:12:39 +08:00
|
|
|
}
|
|
|
|
|
2018-03-25 23:09:17 +08:00
|
|
|
extraClasses.push(note.type);
|
2017-12-24 00:02:38 +08:00
|
|
|
|
2018-03-25 23:09:17 +08:00
|
|
|
return extraClasses.join(" ");
|
|
|
|
}
|
2018-03-25 08:41:27 +08:00
|
|
|
|
2018-03-25 23:09:17 +08:00
|
|
|
async function prepareBranchInner(parentNote) {
|
|
|
|
utils.assertArguments(parentNote);
|
2017-11-20 05:43:49 +08:00
|
|
|
|
2018-03-25 23:09:17 +08:00
|
|
|
const childBranches = await parentNote.getChildBranches();
|
2017-11-18 10:31:54 +08:00
|
|
|
|
2018-03-25 23:09:17 +08:00
|
|
|
if (!childBranches) {
|
2018-03-26 01:41:29 +08:00
|
|
|
messagingService.logError(`No children for ${parentNote}. This shouldn't happen.`);
|
2018-03-25 23:09:17 +08:00
|
|
|
return;
|
|
|
|
}
|
2017-12-29 08:00:31 +08:00
|
|
|
|
2018-03-25 23:09:17 +08:00
|
|
|
const noteList = [];
|
|
|
|
|
|
|
|
for (const branch of childBranches) {
|
|
|
|
const note = await branch.getNote();
|
|
|
|
const title = (branch.prefix ? (branch.prefix + " - ") : "") + note.title;
|
|
|
|
|
|
|
|
const node = {
|
|
|
|
noteId: note.noteId,
|
|
|
|
parentNoteId: branch.parentNoteId,
|
|
|
|
branchId: branch.branchId,
|
|
|
|
isProtected: note.isProtected,
|
|
|
|
title: utils.escapeHtml(title),
|
|
|
|
extraClasses: await getExtraClasses(note),
|
|
|
|
refKey: note.noteId,
|
|
|
|
expanded: note.type !== 'search' && branch.isExpanded
|
|
|
|
};
|
2017-11-24 09:12:39 +08:00
|
|
|
|
2018-03-25 23:09:17 +08:00
|
|
|
const hasChildren = (await note.getChildNotes()).length > 0;
|
2018-03-13 11:14:09 +08:00
|
|
|
|
2018-03-25 23:09:17 +08:00
|
|
|
if (hasChildren || note.type === 'search') {
|
|
|
|
node.folder = true;
|
2017-11-18 10:31:54 +08:00
|
|
|
|
2018-03-25 23:09:17 +08:00
|
|
|
if (node.expanded && note.type !== 'search') {
|
|
|
|
node.children = await prepareBranchInner(note);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
node.lazy = true;
|
2017-11-05 07:28:49 +08:00
|
|
|
}
|
|
|
|
}
|
2017-11-18 10:31:54 +08:00
|
|
|
|
2018-03-25 23:09:17 +08:00
|
|
|
noteList.push(node);
|
2017-11-05 07:28:49 +08:00
|
|
|
}
|
|
|
|
|
2018-03-25 23:09:17 +08:00
|
|
|
return noteList;
|
|
|
|
}
|
2017-12-24 00:02:38 +08:00
|
|
|
|
2018-03-25 23:09:17 +08:00
|
|
|
async function expandToNote(notePath, expandOpts) {
|
|
|
|
utils.assertArguments(notePath);
|
2017-12-24 01:19:15 +08:00
|
|
|
|
2018-03-25 23:09:17 +08:00
|
|
|
const runPath = await getRunPath(notePath);
|
2017-12-04 06:46:56 +08:00
|
|
|
|
2018-03-25 23:09:17 +08:00
|
|
|
const noteId = treeUtils.getNoteIdFromNotePath(notePath);
|
2017-12-04 06:46:56 +08:00
|
|
|
|
2018-03-25 23:09:17 +08:00
|
|
|
let parentNoteId = 'root';
|
2017-12-04 06:46:56 +08:00
|
|
|
|
2018-03-25 23:09:17 +08:00
|
|
|
for (const childNoteId of runPath) {
|
|
|
|
const node = getNodesByNoteId(childNoteId).find(node => node.data.parentNoteId === parentNoteId);
|
2017-12-04 06:46:56 +08:00
|
|
|
|
2018-03-25 23:09:17 +08:00
|
|
|
if (childNoteId === noteId) {
|
|
|
|
return node;
|
2017-12-04 06:46:56 +08:00
|
|
|
}
|
2018-03-25 23:09:17 +08:00
|
|
|
else {
|
|
|
|
await node.setExpanded(true, expandOpts);
|
|
|
|
}
|
|
|
|
|
|
|
|
parentNoteId = childNoteId;
|
2018-01-16 09:54:22 +08:00
|
|
|
}
|
2018-03-25 23:09:17 +08:00
|
|
|
}
|
2018-01-16 09:54:22 +08:00
|
|
|
|
2018-03-25 23:09:17 +08:00
|
|
|
async function activateNode(notePath) {
|
|
|
|
utils.assertArguments(notePath);
|
2018-01-16 09:54:22 +08:00
|
|
|
|
2018-03-25 23:09:17 +08:00
|
|
|
const node = await expandToNote(notePath);
|
2018-01-16 09:54:22 +08:00
|
|
|
|
2018-03-25 23:09:17 +08:00
|
|
|
await node.setActive();
|
2018-01-02 07:53:52 +08:00
|
|
|
|
2018-03-25 23:09:17 +08:00
|
|
|
clearSelectedNodes();
|
|
|
|
}
|
2017-12-04 06:46:56 +08:00
|
|
|
|
2018-03-25 23:09:17 +08:00
|
|
|
/**
|
|
|
|
* Accepts notePath and tries to resolve it. Part of the path might not be valid because of note moving (which causes
|
|
|
|
* path change) or other corruption, in that case this will try to get some other valid path to the correct note.
|
|
|
|
*/
|
|
|
|
async function getRunPath(notePath) {
|
|
|
|
utils.assertArguments(notePath);
|
2017-12-24 00:02:38 +08:00
|
|
|
|
2018-03-25 23:09:17 +08:00
|
|
|
const path = notePath.split("/").reverse();
|
|
|
|
path.push('root');
|
2017-11-19 21:47:22 +08:00
|
|
|
|
2018-03-25 23:09:17 +08:00
|
|
|
const effectivePath = [];
|
|
|
|
let childNoteId = null;
|
|
|
|
let i = 0;
|
2017-11-20 07:16:50 +08:00
|
|
|
|
2018-03-25 23:09:17 +08:00
|
|
|
while (true) {
|
|
|
|
if (i >= path.length) {
|
|
|
|
break;
|
|
|
|
}
|
2017-11-30 13:02:32 +08:00
|
|
|
|
2018-03-25 23:09:17 +08:00
|
|
|
const parentNoteId = path[i++];
|
2017-11-20 00:28:46 +08:00
|
|
|
|
2018-03-25 23:09:17 +08:00
|
|
|
if (childNoteId !== null) {
|
2018-03-26 02:49:20 +08:00
|
|
|
const child = await treeCache.getNote(childNoteId);
|
2018-03-25 23:09:17 +08:00
|
|
|
const parents = await child.getParentNotes();
|
2017-11-20 00:28:46 +08:00
|
|
|
|
2018-03-25 23:09:17 +08:00
|
|
|
if (!parents) {
|
2018-03-26 01:41:29 +08:00
|
|
|
messagingService.logError("No parents found for " + childNoteId);
|
2018-03-25 23:09:17 +08:00
|
|
|
return;
|
|
|
|
}
|
2017-11-27 10:00:42 +08:00
|
|
|
|
2018-03-25 23:09:17 +08:00
|
|
|
if (!parents.some(p => p.noteId === parentNoteId)) {
|
|
|
|
console.log(utils.now(), "Did not find parent " + parentNoteId + " for child " + childNoteId);
|
2017-11-20 00:28:46 +08:00
|
|
|
|
2018-03-25 23:09:17 +08:00
|
|
|
if (parents.length > 0) {
|
|
|
|
console.log(utils.now(), "Available parents:", parents);
|
2017-12-24 00:02:38 +08:00
|
|
|
|
2018-03-25 23:09:17 +08:00
|
|
|
const someNotePath = await getSomeNotePath(parents[0]);
|
2017-12-24 01:19:15 +08:00
|
|
|
|
2018-03-25 23:09:17 +08:00
|
|
|
if (someNotePath) { // in case it's root the path may be empty
|
|
|
|
const pathToRoot = someNotePath.split("/").reverse();
|
2017-11-20 07:16:50 +08:00
|
|
|
|
2018-03-25 23:09:17 +08:00
|
|
|
for (const noteId of pathToRoot) {
|
|
|
|
effectivePath.push(noteId);
|
2017-11-30 13:02:32 +08:00
|
|
|
}
|
2017-11-20 00:28:46 +08:00
|
|
|
}
|
2017-11-19 21:47:22 +08:00
|
|
|
|
2018-03-25 23:09:17 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
else {
|
2018-03-26 01:41:29 +08:00
|
|
|
messagingService.logError("No parents, can't activate node.");
|
2018-03-25 23:09:17 +08:00
|
|
|
return;
|
|
|
|
}
|
2017-11-19 21:47:22 +08:00
|
|
|
}
|
|
|
|
}
|
2017-12-04 06:46:56 +08:00
|
|
|
|
2018-03-25 23:09:17 +08:00
|
|
|
if (parentNoteId === 'root') {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
effectivePath.push(parentNoteId);
|
|
|
|
childNoteId = parentNoteId;
|
|
|
|
}
|
2017-11-19 21:47:22 +08:00
|
|
|
}
|
|
|
|
|
2018-03-25 23:09:17 +08:00
|
|
|
return effectivePath.reverse();
|
|
|
|
}
|
2017-12-24 00:02:38 +08:00
|
|
|
|
2018-03-25 23:09:17 +08:00
|
|
|
async function showParentList(noteId, node) {
|
|
|
|
utils.assertArguments(noteId, node);
|
2017-11-22 09:04:06 +08:00
|
|
|
|
2018-03-26 02:49:20 +08:00
|
|
|
const note = await treeCache.getNote(noteId);
|
2018-03-25 23:09:17 +08:00
|
|
|
const parents = await note.getParentNotes();
|
2017-11-23 12:16:54 +08:00
|
|
|
|
2018-03-25 23:09:17 +08:00
|
|
|
if (!parents.length) {
|
2018-03-26 09:29:35 +08:00
|
|
|
infoService.throwError("Can't find parents for noteId=" + noteId);
|
2018-03-25 23:09:17 +08:00
|
|
|
}
|
2017-11-22 09:04:06 +08:00
|
|
|
|
2018-03-25 23:09:17 +08:00
|
|
|
if (parents.length <= 1) {
|
|
|
|
$parentList.hide();
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
$parentList.show();
|
|
|
|
$parentListList.empty();
|
2017-11-22 09:04:06 +08:00
|
|
|
|
2018-03-25 23:09:17 +08:00
|
|
|
for (const parentNote of parents) {
|
|
|
|
const parentNotePath = await getSomeNotePath(parentNote);
|
|
|
|
// this is to avoid having root notes leading '/'
|
|
|
|
const notePath = parentNotePath ? (parentNotePath + '/' + noteId) : noteId;
|
2018-03-27 09:50:47 +08:00
|
|
|
const title = await treeUtils.getNotePathTitle(notePath);
|
2017-11-22 09:04:06 +08:00
|
|
|
|
2018-03-25 23:09:17 +08:00
|
|
|
let item;
|
2017-11-22 09:04:06 +08:00
|
|
|
|
2018-03-25 23:09:17 +08:00
|
|
|
if (node.getParent().data.noteId === parentNote.noteId) {
|
|
|
|
item = $("<span/>").attr("title", "Current note").append(title);
|
2017-11-22 09:04:06 +08:00
|
|
|
}
|
2018-03-25 23:09:17 +08:00
|
|
|
else {
|
2018-03-26 01:41:29 +08:00
|
|
|
item = linkService.createNoteLink(notePath, title);
|
2018-03-25 23:09:17 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
$parentListList.append($("<li/>").append(item));
|
2017-11-22 09:04:06 +08:00
|
|
|
}
|
|
|
|
}
|
2018-03-25 23:09:17 +08:00
|
|
|
}
|
2017-11-22 09:04:06 +08:00
|
|
|
|
2018-03-25 23:09:17 +08:00
|
|
|
async function getSomeNotePath(note) {
|
|
|
|
utils.assertArguments(note);
|
2017-11-22 09:04:06 +08:00
|
|
|
|
2018-03-25 23:09:17 +08:00
|
|
|
const path = [];
|
2017-11-22 09:04:06 +08:00
|
|
|
|
2018-03-25 23:09:17 +08:00
|
|
|
let cur = note;
|
2017-11-22 09:04:06 +08:00
|
|
|
|
2018-03-25 23:09:17 +08:00
|
|
|
while (cur.noteId !== 'root') {
|
|
|
|
path.push(cur.noteId);
|
2018-03-25 11:00:12 +08:00
|
|
|
|
2018-03-25 23:09:17 +08:00
|
|
|
const parents = await cur.getParentNotes();
|
2017-12-20 10:40:48 +08:00
|
|
|
|
2018-03-25 23:09:17 +08:00
|
|
|
if (!parents.length) {
|
2018-03-26 09:29:35 +08:00
|
|
|
infoService.throwError("Can't find parents for " + cur);
|
2017-11-22 09:04:06 +08:00
|
|
|
}
|
|
|
|
|
2018-03-25 23:09:17 +08:00
|
|
|
cur = parents[0];
|
2017-11-22 09:04:06 +08:00
|
|
|
}
|
|
|
|
|
2018-03-25 23:09:17 +08:00
|
|
|
return path.reverse().join('/');
|
|
|
|
}
|
2017-11-05 07:28:49 +08:00
|
|
|
|
2018-03-25 23:09:17 +08:00
|
|
|
async function setExpandedToServer(branchId, isExpanded) {
|
|
|
|
utils.assertArguments(branchId);
|
2017-11-05 07:28:49 +08:00
|
|
|
|
2018-03-25 23:09:17 +08:00
|
|
|
const expandedNum = isExpanded ? 1 : 0;
|
2017-12-24 00:02:38 +08:00
|
|
|
|
2018-03-25 23:09:17 +08:00
|
|
|
await server.put('tree/' + branchId + '/expanded/' + expandedNum);
|
|
|
|
}
|
2017-11-20 07:16:50 +08:00
|
|
|
|
2018-03-25 23:09:17 +08:00
|
|
|
function setCurrentNotePathToHash(node) {
|
|
|
|
utils.assertArguments(node);
|
2017-11-20 07:16:50 +08:00
|
|
|
|
2018-03-25 23:09:17 +08:00
|
|
|
const currentNotePath = treeUtils.getNotePath(node);
|
|
|
|
const currentBranchId = node.data.branchId;
|
2017-11-20 07:16:50 +08:00
|
|
|
|
2018-03-25 23:09:17 +08:00
|
|
|
document.location.hash = currentNotePath;
|
2018-01-02 06:59:59 +08:00
|
|
|
|
2018-03-26 01:41:29 +08:00
|
|
|
recentNotesDialog.addRecentNote(currentBranchId, currentNotePath);
|
2018-03-25 23:09:17 +08:00
|
|
|
}
|
2018-01-02 06:59:59 +08:00
|
|
|
|
2018-03-25 23:09:17 +08:00
|
|
|
function getSelectedNodes(stopOnParents = false) {
|
|
|
|
return getTree().getSelectedNodes(stopOnParents);
|
|
|
|
}
|
2018-01-02 07:53:52 +08:00
|
|
|
|
2018-03-25 23:09:17 +08:00
|
|
|
function clearSelectedNodes() {
|
|
|
|
for (const selectedNode of getSelectedNodes()) {
|
|
|
|
selectedNode.setSelected(false);
|
2018-01-02 06:59:59 +08:00
|
|
|
}
|
|
|
|
|
2018-03-25 23:09:17 +08:00
|
|
|
const currentNode = getCurrentNode();
|
2017-12-24 00:02:38 +08:00
|
|
|
|
2018-03-25 23:09:17 +08:00
|
|
|
if (currentNode) {
|
|
|
|
currentNode.setSelected(true);
|
|
|
|
}
|
|
|
|
}
|
2017-11-05 07:28:49 +08:00
|
|
|
|
2018-03-26 02:49:20 +08:00
|
|
|
async function treeInitialized() {
|
|
|
|
const noteId = treeUtils.getNoteIdFromNotePath(startNotePath);
|
|
|
|
|
2018-03-26 10:37:02 +08:00
|
|
|
if (!await treeCache.getNote(noteId)) {
|
2018-03-26 02:49:20 +08:00
|
|
|
// note doesn't exist so don't try to activate it
|
|
|
|
startNotePath = null;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (startNotePath) {
|
|
|
|
activateNode(startNotePath);
|
|
|
|
|
|
|
|
// looks like this this doesn't work when triggered immediatelly after activating node
|
|
|
|
// so waiting a second helps
|
|
|
|
setTimeout(scrollToCurrentNote, 1000);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-03-25 23:09:17 +08:00
|
|
|
function initFancyTree(branch) {
|
|
|
|
utils.assertArguments(branch);
|
2018-01-02 07:29:06 +08:00
|
|
|
|
2018-03-25 23:09:17 +08:00
|
|
|
const keybindings = {
|
|
|
|
"del": node => {
|
2018-03-26 01:41:29 +08:00
|
|
|
treeChangesService.deleteNodes(getSelectedNodes(true));
|
2018-03-25 23:09:17 +08:00
|
|
|
},
|
|
|
|
"ctrl+up": node => {
|
|
|
|
const beforeNode = node.getPrevSibling();
|
2018-01-02 07:29:06 +08:00
|
|
|
|
2018-03-25 23:09:17 +08:00
|
|
|
if (beforeNode !== null) {
|
2018-03-26 01:41:29 +08:00
|
|
|
treeChangesService.moveBeforeNode([node], beforeNode);
|
2018-03-25 23:09:17 +08:00
|
|
|
}
|
2017-11-05 07:28:49 +08:00
|
|
|
|
2018-03-25 23:09:17 +08:00
|
|
|
return false;
|
|
|
|
},
|
|
|
|
"ctrl+down": node => {
|
|
|
|
let afterNode = node.getNextSibling();
|
|
|
|
if (afterNode !== null) {
|
2018-03-26 01:41:29 +08:00
|
|
|
treeChangesService.moveAfterNode([node], afterNode);
|
2018-03-25 23:09:17 +08:00
|
|
|
}
|
2018-01-02 07:29:06 +08:00
|
|
|
|
2018-03-25 23:09:17 +08:00
|
|
|
return false;
|
|
|
|
},
|
|
|
|
"ctrl+left": node => {
|
2018-03-26 01:41:29 +08:00
|
|
|
treeChangesService.moveNodeUpInHierarchy(node);
|
2018-01-02 06:59:59 +08:00
|
|
|
|
2018-03-25 23:09:17 +08:00
|
|
|
return false;
|
|
|
|
},
|
|
|
|
"ctrl+right": node => {
|
|
|
|
let toNode = node.getPrevSibling();
|
2018-01-02 06:59:59 +08:00
|
|
|
|
2018-03-25 23:09:17 +08:00
|
|
|
if (toNode !== null) {
|
2018-03-26 01:41:29 +08:00
|
|
|
treeChangesService.moveToNode([node], toNode);
|
2018-03-25 23:09:17 +08:00
|
|
|
}
|
2018-01-02 07:29:06 +08:00
|
|
|
|
2018-03-25 23:09:17 +08:00
|
|
|
return false;
|
|
|
|
},
|
|
|
|
"shift+up": node => {
|
|
|
|
node.navigate($.ui.keyCode.UP, true).then(() => {
|
|
|
|
const currentNode = getCurrentNode();
|
2018-01-02 06:59:59 +08:00
|
|
|
|
2018-03-25 23:09:17 +08:00
|
|
|
if (currentNode.isSelected()) {
|
|
|
|
node.setSelected(false);
|
|
|
|
}
|
2018-01-02 06:59:59 +08:00
|
|
|
|
2018-03-25 23:09:17 +08:00
|
|
|
currentNode.setSelected(true);
|
|
|
|
});
|
2018-01-02 07:29:06 +08:00
|
|
|
|
2018-03-25 23:09:17 +08:00
|
|
|
return false;
|
|
|
|
},
|
|
|
|
"shift+down": node => {
|
|
|
|
node.navigate($.ui.keyCode.DOWN, true).then(() => {
|
|
|
|
const currentNode = getCurrentNode();
|
2018-01-14 12:03:17 +08:00
|
|
|
|
2018-03-25 23:09:17 +08:00
|
|
|
if (currentNode.isSelected()) {
|
|
|
|
node.setSelected(false);
|
2018-01-02 07:11:23 +08:00
|
|
|
}
|
|
|
|
|
2018-03-25 23:09:17 +08:00
|
|
|
currentNode.setSelected(true);
|
|
|
|
});
|
2017-12-28 10:12:54 +08:00
|
|
|
|
2018-03-25 23:09:17 +08:00
|
|
|
return false;
|
|
|
|
},
|
|
|
|
"f2": node => {
|
2018-03-26 07:49:33 +08:00
|
|
|
editTreePrefixDialog.showDialog(node);
|
2018-03-25 23:09:17 +08:00
|
|
|
},
|
|
|
|
"alt+-": node => {
|
|
|
|
collapseTree(node);
|
|
|
|
},
|
|
|
|
"alt+s": node => {
|
|
|
|
sortAlphabetically(node.data.noteId);
|
|
|
|
|
|
|
|
return false;
|
|
|
|
},
|
|
|
|
"ctrl+a": node => {
|
|
|
|
for (const child of node.getParent().getChildren()) {
|
|
|
|
child.setSelected(true);
|
|
|
|
}
|
2017-12-28 10:12:54 +08:00
|
|
|
|
2018-03-25 23:09:17 +08:00
|
|
|
return false;
|
|
|
|
},
|
|
|
|
"ctrl+c": () => {
|
2018-03-26 01:41:29 +08:00
|
|
|
contextMenuService.copy(getSelectedNodes());
|
2018-03-25 23:09:17 +08:00
|
|
|
|
|
|
|
return false;
|
|
|
|
},
|
|
|
|
"ctrl+x": () => {
|
2018-03-26 01:41:29 +08:00
|
|
|
contextMenuService.cut(getSelectedNodes());
|
2018-03-25 23:09:17 +08:00
|
|
|
|
|
|
|
return false;
|
|
|
|
},
|
|
|
|
"ctrl+v": node => {
|
2018-03-26 01:41:29 +08:00
|
|
|
contextMenuService.pasteInto(node);
|
2018-03-25 23:09:17 +08:00
|
|
|
|
|
|
|
return false;
|
|
|
|
},
|
|
|
|
"return": node => {
|
2018-03-26 01:41:29 +08:00
|
|
|
noteDetailService.focus();
|
2018-03-25 23:09:17 +08:00
|
|
|
|
|
|
|
return false;
|
|
|
|
},
|
|
|
|
"backspace": node => {
|
|
|
|
if (!utils.isTopLevelNode(node)) {
|
2018-03-26 08:18:08 +08:00
|
|
|
node.getParent().setActive().then(clearSelectedNodes);
|
2018-03-25 23:09:17 +08:00
|
|
|
}
|
|
|
|
},
|
|
|
|
// code below shouldn't be necessary normally, however there's some problem with interaction with context menu plugin
|
|
|
|
// after opening context menu, standard shortcuts don't work, but they are detected here
|
|
|
|
// so we essentially takeover the standard handling with our implementation.
|
|
|
|
"left": node => {
|
2018-03-26 08:18:08 +08:00
|
|
|
node.navigate($.ui.keyCode.LEFT, true).then(clearSelectedNodes);
|
2018-03-25 23:09:17 +08:00
|
|
|
|
|
|
|
return false;
|
|
|
|
},
|
|
|
|
"right": node => {
|
2018-03-26 08:18:08 +08:00
|
|
|
node.navigate($.ui.keyCode.RIGHT, true).then(clearSelectedNodes);
|
2018-03-25 23:09:17 +08:00
|
|
|
|
|
|
|
return false;
|
|
|
|
},
|
|
|
|
"up": node => {
|
2018-03-26 08:18:08 +08:00
|
|
|
node.navigate($.ui.keyCode.UP, true).then(clearSelectedNodes);
|
2018-03-25 23:09:17 +08:00
|
|
|
|
|
|
|
return false;
|
|
|
|
},
|
|
|
|
"down": node => {
|
2018-03-26 08:18:08 +08:00
|
|
|
node.navigate($.ui.keyCode.DOWN, true).then(clearSelectedNodes);
|
2018-03-25 23:09:17 +08:00
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
};
|
2018-01-23 11:14:03 +08:00
|
|
|
|
2018-03-25 23:09:17 +08:00
|
|
|
$tree.fancytree({
|
|
|
|
autoScroll: true,
|
|
|
|
keyboard: false, // we takover keyboard handling in the hotkeys plugin
|
|
|
|
extensions: ["hotkeys", "filter", "dnd", "clones"],
|
|
|
|
source: branch,
|
|
|
|
scrollParent: $("#tree"),
|
|
|
|
click: (event, data) => {
|
|
|
|
const targetType = data.targetType;
|
|
|
|
const node = data.node;
|
|
|
|
|
|
|
|
if (targetType === 'title' || targetType === 'icon') {
|
|
|
|
if (!event.ctrlKey) {
|
|
|
|
node.setActive();
|
|
|
|
node.setSelected(true);
|
|
|
|
|
|
|
|
clearSelectedNodes();
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
node.setSelected(!node.isSelected());
|
2018-01-04 11:49:53 +08:00
|
|
|
}
|
2017-12-26 10:47:32 +08:00
|
|
|
|
|
|
|
return false;
|
2018-03-25 23:09:17 +08:00
|
|
|
}
|
|
|
|
},
|
|
|
|
activate: (event, data) => {
|
|
|
|
const node = data.node.data;
|
|
|
|
|
|
|
|
setCurrentNotePathToHash(data.node);
|
|
|
|
|
2018-03-26 01:41:29 +08:00
|
|
|
noteDetailService.switchToNote(node.noteId);
|
2018-03-25 23:09:17 +08:00
|
|
|
|
|
|
|
showParentList(node.noteId, data.node);
|
|
|
|
},
|
|
|
|
expand: (event, data) => {
|
|
|
|
setExpandedToServer(data.node.data.branchId, true);
|
|
|
|
},
|
|
|
|
collapse: (event, data) => {
|
|
|
|
setExpandedToServer(data.node.data.branchId, false);
|
|
|
|
},
|
|
|
|
init: (event, data) => {
|
2018-03-26 02:49:20 +08:00
|
|
|
treeInitialized();
|
2018-03-25 23:09:17 +08:00
|
|
|
},
|
|
|
|
hotkeys: {
|
|
|
|
keydown: keybindings
|
|
|
|
},
|
|
|
|
filter: {
|
|
|
|
autoApply: true, // Re-apply last filter if lazy data is loaded
|
|
|
|
autoExpand: true, // Expand all branches that contain matches while filtered
|
|
|
|
counter: false, // Show a badge with number of matching child nodes near parent icons
|
|
|
|
fuzzy: false, // Match single characters in order, e.g. 'fb' will match 'FooBar'
|
|
|
|
hideExpandedCounter: true, // Hide counter badge if parent is expanded
|
|
|
|
hideExpanders: false, // Hide expanders if all child nodes are hidden by filter
|
|
|
|
highlight: true, // Highlight matches by wrapping inside <mark> tags
|
|
|
|
leavesOnly: false, // Match end nodes only
|
|
|
|
nodata: true, // Display a 'no data' status node if result is empty
|
|
|
|
mode: "hide" // Grayout unmatched nodes (pass "hide" to remove unmatched node instead)
|
|
|
|
},
|
|
|
|
dnd: dragAndDropSetup,
|
2018-03-26 07:49:33 +08:00
|
|
|
lazyLoad: function(event, data) {
|
2018-03-25 23:09:17 +08:00
|
|
|
const noteId = data.node.data.noteId;
|
2018-03-26 10:37:02 +08:00
|
|
|
data.result = treeCache.getNote(noteId).then(note => {
|
2018-03-26 07:49:33 +08:00
|
|
|
if (note.type === 'search') {
|
|
|
|
return loadSearchNote(noteId);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
return prepareBranchInner(note);
|
|
|
|
}
|
|
|
|
});
|
2018-03-25 23:09:17 +08:00
|
|
|
},
|
|
|
|
clones: {
|
|
|
|
highlightActiveClones: true
|
|
|
|
}
|
|
|
|
});
|
2017-11-05 07:28:49 +08:00
|
|
|
|
2018-03-26 01:41:29 +08:00
|
|
|
$tree.contextmenu(contextMenuService.contextMenuSettings);
|
2018-03-25 23:09:17 +08:00
|
|
|
}
|
2018-01-02 06:59:59 +08:00
|
|
|
|
2018-03-25 23:09:17 +08:00
|
|
|
async function loadSearchNote(searchNoteId) {
|
2018-03-26 11:25:17 +08:00
|
|
|
const searchNote = await noteDetailService.loadNote(searchNoteId);
|
|
|
|
const noteIds = await server.get('search/' + encodeURIComponent(searchNote.jsonContent.searchString));
|
2017-11-05 07:28:49 +08:00
|
|
|
|
2018-03-25 23:09:17 +08:00
|
|
|
for (const noteId of noteIds) {
|
2018-03-26 11:25:17 +08:00
|
|
|
const branch = new Branch(treeCache, {
|
|
|
|
branchId: "virt" + utils.randomString(10),
|
2018-03-25 23:09:17 +08:00
|
|
|
noteId: noteId,
|
|
|
|
parentNoteId: searchNoteId,
|
|
|
|
prefix: '',
|
|
|
|
virtual: true
|
|
|
|
});
|
2018-03-26 11:25:17 +08:00
|
|
|
|
|
|
|
treeCache.addBranch(branch);
|
2017-11-05 07:28:49 +08:00
|
|
|
}
|
|
|
|
|
2018-03-26 11:25:17 +08:00
|
|
|
return await prepareBranchInner(searchNote);
|
2018-03-25 23:09:17 +08:00
|
|
|
}
|
2018-03-13 11:14:09 +08:00
|
|
|
|
2018-03-25 23:09:17 +08:00
|
|
|
function getTree() {
|
|
|
|
return $tree.fancytree('getTree');
|
|
|
|
}
|
2018-03-13 11:14:09 +08:00
|
|
|
|
2018-03-25 23:09:17 +08:00
|
|
|
async function reload() {
|
|
|
|
const notes = await loadTree();
|
2018-03-13 11:14:09 +08:00
|
|
|
|
2018-03-25 23:09:17 +08:00
|
|
|
// this will also reload the note content
|
|
|
|
await getTree().reload(notes);
|
|
|
|
}
|
2018-03-13 11:27:21 +08:00
|
|
|
|
2018-03-25 23:09:17 +08:00
|
|
|
function getNotePathFromAddress() {
|
|
|
|
return document.location.hash.substr(1); // strip initial #
|
|
|
|
}
|
2018-03-13 11:27:21 +08:00
|
|
|
|
2018-03-25 23:09:17 +08:00
|
|
|
async function loadTree() {
|
|
|
|
const resp = await server.get('tree');
|
|
|
|
startNotePath = resp.start_note_path;
|
2018-03-26 10:56:23 +08:00
|
|
|
window.glob.instanceName = resp.instanceName;
|
2018-03-13 11:14:09 +08:00
|
|
|
|
2018-03-25 23:09:17 +08:00
|
|
|
if (document.location.hash) {
|
|
|
|
startNotePath = getNotePathFromAddress();
|
2017-11-23 08:58:56 +08:00
|
|
|
}
|
|
|
|
|
2018-03-25 23:09:17 +08:00
|
|
|
return await prepareBranch(resp.notes, resp.branches);
|
|
|
|
}
|
2017-11-05 22:52:28 +08:00
|
|
|
|
2018-03-25 23:09:17 +08:00
|
|
|
$(() => loadTree().then(branch => initFancyTree(branch)));
|
2017-11-05 22:52:28 +08:00
|
|
|
|
2018-03-25 23:09:17 +08:00
|
|
|
function collapseTree(node = null) {
|
|
|
|
if (!node) {
|
|
|
|
node = $tree.fancytree("getRootNode");
|
2017-12-20 08:31:02 +08:00
|
|
|
}
|
|
|
|
|
2018-03-25 23:09:17 +08:00
|
|
|
node.setExpanded(false);
|
2017-11-05 07:28:49 +08:00
|
|
|
|
2018-03-25 23:09:17 +08:00
|
|
|
node.visit(node => node.setExpanded(false));
|
|
|
|
}
|
2017-11-05 07:28:49 +08:00
|
|
|
|
2018-03-25 23:09:17 +08:00
|
|
|
function scrollToCurrentNote() {
|
|
|
|
const node = getCurrentNode();
|
2017-12-26 23:00:08 +08:00
|
|
|
|
2018-03-25 23:09:17 +08:00
|
|
|
if (node) {
|
|
|
|
node.makeVisible({scrollIntoView: true});
|
2017-12-26 23:00:08 +08:00
|
|
|
|
2018-03-25 23:09:17 +08:00
|
|
|
node.setFocus();
|
2017-11-05 07:28:49 +08:00
|
|
|
}
|
2018-03-25 23:09:17 +08:00
|
|
|
}
|
2017-11-05 07:28:49 +08:00
|
|
|
|
2018-03-25 23:09:17 +08:00
|
|
|
function setBranchBackgroundBasedOnProtectedStatus(noteId) {
|
|
|
|
getNodesByNoteId(noteId).map(node => node.toggleClass("protected", !!node.data.isProtected));
|
|
|
|
}
|
2017-11-05 07:28:49 +08:00
|
|
|
|
2018-03-25 23:09:17 +08:00
|
|
|
function setProtected(noteId, isProtected) {
|
|
|
|
getNodesByNoteId(noteId).map(node => node.data.isProtected = isProtected);
|
2017-11-05 07:28:49 +08:00
|
|
|
|
2018-03-25 23:09:17 +08:00
|
|
|
setBranchBackgroundBasedOnProtectedStatus(noteId);
|
|
|
|
}
|
2017-11-05 07:28:49 +08:00
|
|
|
|
2018-03-26 02:49:20 +08:00
|
|
|
async function setNoteTitle(noteId, title) {
|
2018-03-25 23:09:17 +08:00
|
|
|
utils.assertArguments(noteId);
|
2017-11-23 08:58:56 +08:00
|
|
|
|
2018-03-26 10:37:02 +08:00
|
|
|
const note = await treeCache.getNote(noteId);
|
|
|
|
|
|
|
|
note.title = title;
|
2017-11-23 12:16:54 +08:00
|
|
|
|
2018-03-26 02:49:20 +08:00
|
|
|
for (const clone of getNodesByNoteId(noteId)) {
|
|
|
|
await setNodeTitleWithPrefix(clone);
|
|
|
|
}
|
2018-03-25 23:09:17 +08:00
|
|
|
}
|
2017-11-23 12:16:54 +08:00
|
|
|
|
2018-03-25 23:09:17 +08:00
|
|
|
async function createNewTopLevelNote() {
|
|
|
|
const rootNode = $tree.fancytree("getRootNode");
|
2017-12-24 00:02:38 +08:00
|
|
|
|
2018-03-25 23:09:17 +08:00
|
|
|
await createNote(rootNode, "root", "into");
|
|
|
|
}
|
2017-11-23 12:16:54 +08:00
|
|
|
|
2018-03-25 23:09:17 +08:00
|
|
|
async function createNote(node, parentNoteId, target, isProtected) {
|
|
|
|
utils.assertArguments(node, parentNoteId, target);
|
2017-11-23 12:16:54 +08:00
|
|
|
|
2018-03-25 23:09:17 +08:00
|
|
|
// if isProtected isn't available (user didn't enter password yet), then note is created as unencrypted
|
|
|
|
// but this is quite weird since user doesn't see WHERE the note is being created so it shouldn't occur often
|
2018-03-26 09:16:57 +08:00
|
|
|
if (!isProtected || !protectedSessionHolder.isProtectedSessionAvailable()) {
|
2018-03-25 23:09:17 +08:00
|
|
|
isProtected = false;
|
|
|
|
}
|
2017-11-23 12:16:54 +08:00
|
|
|
|
2018-03-25 23:09:17 +08:00
|
|
|
const newNoteName = "new note";
|
2018-03-25 12:20:55 +08:00
|
|
|
|
2018-03-25 23:09:17 +08:00
|
|
|
const result = await server.post('notes/' + parentNoteId + '/children', {
|
|
|
|
title: newNoteName,
|
|
|
|
target: target,
|
|
|
|
target_branchId: node.data.branchId,
|
|
|
|
isProtected: isProtected
|
|
|
|
});
|
2018-03-25 12:20:55 +08:00
|
|
|
|
2018-03-25 23:09:17 +08:00
|
|
|
const note = new NoteShort(treeCache, {
|
|
|
|
noteId: result.noteId,
|
|
|
|
title: result.title,
|
|
|
|
isProtected: result.isProtected,
|
|
|
|
type: result.type,
|
|
|
|
mime: result.mime
|
|
|
|
});
|
2018-01-28 23:37:43 +08:00
|
|
|
|
2018-03-25 23:09:17 +08:00
|
|
|
const branch = new Branch(treeCache, result);
|
2018-01-28 23:37:43 +08:00
|
|
|
|
2018-03-25 23:09:17 +08:00
|
|
|
treeCache.add(note, branch);
|
2017-11-23 12:16:54 +08:00
|
|
|
|
2018-03-26 01:41:29 +08:00
|
|
|
noteDetailService.newNoteCreated();
|
2018-01-17 12:22:13 +08:00
|
|
|
|
2018-03-25 23:09:17 +08:00
|
|
|
const newNode = {
|
|
|
|
title: newNoteName,
|
|
|
|
noteId: result.noteId,
|
|
|
|
parentNoteId: parentNoteId,
|
|
|
|
refKey: result.noteId,
|
|
|
|
branchId: result.branchId,
|
|
|
|
isProtected: isProtected,
|
|
|
|
extraClasses: await getExtraClasses(note)
|
|
|
|
};
|
2017-11-23 12:16:54 +08:00
|
|
|
|
2018-03-25 23:09:17 +08:00
|
|
|
if (target === 'after') {
|
|
|
|
await node.appendSibling(newNode).setActive(true);
|
|
|
|
}
|
|
|
|
else if (target === 'into') {
|
|
|
|
if (!node.getChildren() && node.isFolder()) {
|
|
|
|
await node.setExpanded();
|
2017-11-23 12:16:54 +08:00
|
|
|
}
|
2018-01-17 12:22:13 +08:00
|
|
|
else {
|
2018-03-25 23:09:17 +08:00
|
|
|
node.addChildren(newNode);
|
2018-01-17 12:22:13 +08:00
|
|
|
}
|
2017-11-23 12:16:54 +08:00
|
|
|
|
2018-03-25 23:09:17 +08:00
|
|
|
await node.getLastChild().setActive(true);
|
2018-02-14 12:25:28 +08:00
|
|
|
|
2018-03-25 23:09:17 +08:00
|
|
|
node.folder = true;
|
|
|
|
node.renderTitle();
|
2017-11-23 12:16:54 +08:00
|
|
|
}
|
2018-03-25 23:09:17 +08:00
|
|
|
else {
|
2018-03-26 09:29:35 +08:00
|
|
|
infoService.throwError("Unrecognized target: " + target);
|
2018-01-14 06:00:40 +08:00
|
|
|
}
|
|
|
|
|
2018-03-25 23:09:17 +08:00
|
|
|
clearSelectedNodes(); // to unmark previously active node
|
2018-02-13 12:53:00 +08:00
|
|
|
|
2018-03-26 09:29:35 +08:00
|
|
|
infoService.showMessage("Created!");
|
2018-03-25 23:09:17 +08:00
|
|
|
}
|
2018-02-25 10:23:04 +08:00
|
|
|
|
2018-03-25 23:09:17 +08:00
|
|
|
async function sortAlphabetically(noteId) {
|
|
|
|
await server.put('notes/' + noteId + '/sort');
|
2018-03-14 07:31:07 +08:00
|
|
|
|
2018-03-25 23:09:17 +08:00
|
|
|
await reload();
|
|
|
|
}
|
2017-12-19 12:41:13 +08:00
|
|
|
|
2018-03-26 09:16:57 +08:00
|
|
|
messagingService.subscribeToMessages(syncData => {
|
|
|
|
if (syncData.some(sync => sync.entityName === 'branches')
|
|
|
|
|| syncData.some(sync => sync.entityName === 'notes')) {
|
|
|
|
|
|
|
|
console.log(utils.now(), "Reloading tree because of background changes");
|
|
|
|
|
|
|
|
reload();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2018-03-26 10:37:02 +08:00
|
|
|
utils.bindShortcut('ctrl+o', () => {
|
2018-03-25 23:09:17 +08:00
|
|
|
const node = getCurrentNode();
|
|
|
|
const parentNoteId = node.data.parentNoteId;
|
|
|
|
const isProtected = treeUtils.getParentProtectedStatus(node);
|
2017-12-19 12:41:13 +08:00
|
|
|
|
2018-03-25 23:09:17 +08:00
|
|
|
createNote(node, parentNoteId, 'after', isProtected);
|
|
|
|
});
|
2017-12-19 12:41:13 +08:00
|
|
|
|
2018-03-26 10:37:02 +08:00
|
|
|
utils.bindShortcut('ctrl+p', () => {
|
2018-03-25 23:09:17 +08:00
|
|
|
const node = getCurrentNode();
|
2017-12-19 12:41:13 +08:00
|
|
|
|
2018-03-25 23:09:17 +08:00
|
|
|
createNote(node, node.data.noteId, 'into', node.data.isProtected);
|
|
|
|
});
|
2017-12-18 05:56:30 +08:00
|
|
|
|
2018-03-26 10:37:02 +08:00
|
|
|
utils.bindShortcut('ctrl+del', () => {
|
2018-03-25 23:09:17 +08:00
|
|
|
const node = getCurrentNode();
|
2017-12-20 08:31:02 +08:00
|
|
|
|
2018-03-26 01:41:29 +08:00
|
|
|
treeChangesService.deleteNodes([node]);
|
2018-03-25 23:09:17 +08:00
|
|
|
});
|
2017-12-20 08:31:02 +08:00
|
|
|
|
2018-03-26 10:37:02 +08:00
|
|
|
utils.bindShortcut('ctrl+.', scrollToCurrentNote);
|
2017-12-20 08:54:55 +08:00
|
|
|
|
2018-03-25 23:09:17 +08:00
|
|
|
$(window).bind('hashchange', function() {
|
|
|
|
const notePath = getNotePathFromAddress();
|
2017-12-20 08:54:55 +08:00
|
|
|
|
2018-03-25 23:09:17 +08:00
|
|
|
if (getCurrentNotePath() !== notePath) {
|
|
|
|
console.log("Switching to " + notePath + " because of hash change");
|
2017-12-20 08:54:55 +08:00
|
|
|
|
2018-03-25 23:09:17 +08:00
|
|
|
activateNode(notePath);
|
2017-12-20 08:54:55 +08:00
|
|
|
}
|
2018-03-25 23:09:17 +08:00
|
|
|
});
|
2017-12-20 08:54:55 +08:00
|
|
|
|
2018-03-27 10:11:45 +08:00
|
|
|
utils.bindShortcut('alt+c', () => collapseTree()); // don't use shortened form since collapseTree() accepts argument
|
|
|
|
|
2018-03-25 23:09:17 +08:00
|
|
|
$createTopLevelNoteButton.click(createNewTopLevelNote);
|
|
|
|
$collapseTreeButton.click(collapseTree);
|
|
|
|
$scrollToCurrentNoteButton.click(scrollToCurrentNote);
|
|
|
|
|
|
|
|
export default {
|
|
|
|
reload,
|
|
|
|
collapseTree,
|
|
|
|
scrollToCurrentNote,
|
|
|
|
setBranchBackgroundBasedOnProtectedStatus,
|
|
|
|
setProtected,
|
|
|
|
expandToNote,
|
|
|
|
activateNode,
|
2018-03-27 09:50:47 +08:00
|
|
|
getCurrentNode,
|
2018-03-25 23:09:17 +08:00
|
|
|
getCurrentNotePath,
|
|
|
|
setCurrentNotePathToHash,
|
|
|
|
setNoteTitle,
|
2018-03-27 09:50:47 +08:00
|
|
|
setPrefix,
|
2018-03-25 23:09:17 +08:00
|
|
|
createNewTopLevelNote,
|
|
|
|
createNote,
|
|
|
|
getSelectedNodes,
|
2018-03-26 10:56:23 +08:00
|
|
|
sortAlphabetically
|
2018-03-25 23:09:17 +08:00
|
|
|
};
|