2018-12-29 17:04:59 +08:00
|
|
|
import treeService from "./services/tree.js";
|
|
|
|
import noteDetailService from "./services/note_detail.js";
|
|
|
|
import dragAndDropSetup from "./services/drag_and_drop.js";
|
|
|
|
import treeCache from "./services/tree_cache.js";
|
|
|
|
import treeBuilder from "./services/tree_builder.js";
|
|
|
|
import contextMenuWidget from "./services/context_menu.js";
|
|
|
|
import ContextMenuItemsContainer from "./services/context_menu_items_container.js";
|
|
|
|
import treeChangesService from "./services/branches.js";
|
|
|
|
import utils from "./services/utils.js";
|
|
|
|
import treeUtils from "./services/tree_utils.js";
|
2018-12-24 05:28:57 +08:00
|
|
|
|
2018-12-29 02:47:02 +08:00
|
|
|
const $leftPane = $("#left-pane");
|
2018-12-24 17:10:36 +08:00
|
|
|
const $tree = $("#tree");
|
2018-12-25 01:39:31 +08:00
|
|
|
const $detail = $("#detail");
|
2018-12-25 03:38:38 +08:00
|
|
|
const $closeDetailButton = $("#close-detail-button");
|
2018-12-25 01:39:31 +08:00
|
|
|
|
2018-12-25 03:38:38 +08:00
|
|
|
function togglePanes() {
|
2018-12-29 02:47:02 +08:00
|
|
|
if (!$leftPane.is(":visible") || !$detail.is(":visible")) {
|
2018-12-25 03:38:38 +08:00
|
|
|
$detail.toggleClass("d-none");
|
2018-12-29 02:47:02 +08:00
|
|
|
$leftPane.toggleClass("d-none");
|
2018-12-25 03:38:38 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-12-31 05:36:39 +08:00
|
|
|
function showDetailPane() {
|
|
|
|
if (!$detail.is(":visible")) {
|
|
|
|
$detail.removeClass("d-none");
|
|
|
|
$leftPane.addClass("d-none");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
$closeDetailButton.click(() => {
|
|
|
|
// no page is opened
|
|
|
|
document.location.hash = '-';
|
2018-12-24 17:10:36 +08:00
|
|
|
|
2018-12-31 05:36:39 +08:00
|
|
|
togglePanes();
|
|
|
|
});
|
2018-12-29 17:19:28 +08:00
|
|
|
|
2018-12-24 17:10:36 +08:00
|
|
|
async function showTree() {
|
|
|
|
const tree = await treeService.loadTree();
|
|
|
|
|
|
|
|
$tree.fancytree({
|
|
|
|
autoScroll: true,
|
|
|
|
extensions: ["dnd5", "clones"],
|
|
|
|
source: tree,
|
|
|
|
scrollParent: $tree,
|
|
|
|
minExpandLevel: 2, // root can't be collapsed
|
|
|
|
activate: (event, data) => {
|
|
|
|
const node = data.node;
|
|
|
|
const noteId = node.data.noteId;
|
|
|
|
|
2018-12-28 05:36:11 +08:00
|
|
|
treeService.clearSelectedNodes();
|
|
|
|
|
2018-12-24 17:10:36 +08:00
|
|
|
treeService.setCurrentNotePathToHash(node);
|
2018-12-29 17:19:28 +08:00
|
|
|
|
2018-12-31 05:36:39 +08:00
|
|
|
showDetailPane();
|
2018-12-24 17:10:36 +08:00
|
|
|
|
|
|
|
noteDetailService.switchToNote(noteId, true);
|
|
|
|
},
|
|
|
|
expand: (event, data) => treeService.setExpandedToServer(data.node.data.branchId, true),
|
|
|
|
collapse: (event, data) => treeService.setExpandedToServer(data.node.data.branchId, false),
|
|
|
|
init: (event, data) => treeService.treeInitialized(), // don't collapse to short form
|
|
|
|
dnd5: dragAndDropSetup,
|
|
|
|
lazyLoad: function(event, data) {
|
|
|
|
const noteId = data.node.data.noteId;
|
|
|
|
|
|
|
|
data.result = treeCache.getNote(noteId).then(note => treeBuilder.prepareBranch(note));
|
|
|
|
},
|
|
|
|
clones: {
|
|
|
|
highlightActiveClones: true
|
|
|
|
}
|
|
|
|
});
|
2018-12-29 05:05:04 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
$("#note-menu-button").click(async e => {
|
|
|
|
const node = treeService.getCurrentNode();
|
|
|
|
const branch = await treeCache.getBranch(node.data.branchId);
|
|
|
|
const note = await treeCache.getNote(node.data.noteId);
|
|
|
|
const parentNote = await treeCache.getNote(branch.parentNoteId);
|
|
|
|
const isNotRoot = note.noteId !== 'root';
|
|
|
|
|
|
|
|
const itemsContainer = new ContextMenuItemsContainer([
|
2018-12-29 17:04:59 +08:00
|
|
|
{title: "Insert note after", cmd: "insertNoteAfter", uiIcon: "plus"},
|
|
|
|
{title: "Insert child note", cmd: "insertChildNote", uiIcon: "plus"},
|
|
|
|
{title: "Delete this note", cmd: "delete", uiIcon: "trash"}
|
2018-12-29 05:05:04 +08:00
|
|
|
]);
|
|
|
|
|
2018-12-29 17:04:59 +08:00
|
|
|
itemsContainer.enableItem("insertNoteAfter", isNotRoot && parentNote.type !== 'search');
|
|
|
|
itemsContainer.enableItem("insertChildNote", note.type !== 'search');
|
2018-12-29 05:05:04 +08:00
|
|
|
itemsContainer.enableItem("delete", isNotRoot && parentNote.type !== 'search');
|
2018-12-29 17:04:59 +08:00
|
|
|
|
2018-12-29 06:57:11 +08:00
|
|
|
contextMenuWidget.initContextMenu(e, itemsContainer, (event, cmd) => {
|
2018-12-29 17:04:59 +08:00
|
|
|
if (cmd === "insertNoteAfter") {
|
|
|
|
const parentNoteId = node.data.parentNoteId;
|
|
|
|
const isProtected = treeUtils.getParentProtectedStatus(node);
|
|
|
|
|
|
|
|
treeService.createNote(node, parentNoteId, 'after', isProtected);
|
|
|
|
}
|
|
|
|
else if (cmd === "insertChildNote") {
|
|
|
|
treeService.createNote(node, node.data.noteId, 'into');
|
|
|
|
}
|
|
|
|
else if (cmd === "delete") {
|
2018-12-29 06:57:11 +08:00
|
|
|
treeChangesService.deleteNodes([node]);
|
2018-12-24 17:10:36 +08:00
|
|
|
|
2018-12-29 06:57:11 +08:00
|
|
|
// move to the tree
|
|
|
|
togglePanes();
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
throw new Error("Unrecognized command " + cmd);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
2018-12-29 05:05:04 +08:00
|
|
|
|
2018-12-29 16:13:52 +08:00
|
|
|
$("#switch-to-desktop-button").click(() => {
|
|
|
|
utils.setCookie('trilium-device', 'desktop');
|
2018-12-29 05:05:04 +08:00
|
|
|
|
2018-12-29 16:13:52 +08:00
|
|
|
utils.reloadApp();
|
|
|
|
});
|
2018-12-29 07:09:16 +08:00
|
|
|
|
2018-12-29 16:13:52 +08:00
|
|
|
$("#log-out-button").click(() => {
|
|
|
|
$("#logout-form").submit();
|
2018-12-29 06:57:11 +08:00
|
|
|
});
|
2018-12-24 17:10:36 +08:00
|
|
|
|
2018-12-31 05:36:39 +08:00
|
|
|
// this is done so that startNotePath is not used
|
|
|
|
if (!document.location.hash) {
|
|
|
|
document.location.hash = '-';
|
|
|
|
}
|
|
|
|
|
2018-12-24 17:10:36 +08:00
|
|
|
showTree();
|