small refactorings

This commit is contained in:
zadam 2019-10-20 13:09:00 +02:00
parent 2305ad7405
commit 358fd13c8d
7 changed files with 44 additions and 25 deletions

6
.idea/jsLibraryMappings.xml generated Normal file
View File

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="JavaScriptLibraryMappings">
<file url="PROJECT" libraries="{@types/jquery}" />
</component>
</project>

6
package-lock.json generated
View File

@ -13037,9 +13037,9 @@
}
},
"ws": {
"version": "7.1.2",
"resolved": "https://registry.npmjs.org/ws/-/ws-7.1.2.tgz",
"integrity": "sha512-gftXq3XI81cJCgkUiAVixA0raD9IVmXqsylCrjRygw4+UOOGzPoxnQ6r/CnVL9i+mDncJo94tSkyrtuuQVBmrg==",
"version": "7.2.0",
"resolved": "https://registry.npmjs.org/ws/-/ws-7.2.0.tgz",
"integrity": "sha512-+SqNqFbwTm/0DC18KYzIsMTnEWpLwJsiasW/O17la4iDRRIO9uaHbvKiAS3AHgTiuuWerK/brj4O6MYZkei9xg==",
"requires": {
"async-limiter": "^1.0.0"
}

View File

@ -74,7 +74,7 @@
"turndown": "5.0.3",
"turndown-plugin-gfm": "1.0.2",
"unescape": "1.0.1",
"ws": "7.1.2",
"ws": "7.2.0",
"xml2js": "0.4.22"
},
"devDependencies": {

View File

@ -90,6 +90,7 @@ async function activateOrOpenNote(noteId) {
});
}
/** @return {TabContext[]} */
function getTabContexts() {
return tabContexts;
}
@ -119,12 +120,14 @@ function getActiveTabNote() {
return activeContext ? activeContext.note : null;
}
/** @return {string|null} */
function getActiveTabNoteId() {
const activeNote = getActiveTabNote();
return activeNote ? activeNote.noteId : null;
}
/** @return {string|null} */
function getActiveTabNoteType() {
const activeNote = getActiveTabNote();

View File

@ -25,19 +25,26 @@ const $scrollToActiveNoteButton = $("#scroll-to-active-note-button");
let setFrontendAsLoaded;
const frontendLoaded = new Promise(resolve => { setFrontendAsLoaded = resolve; });
// focused & not active node can happen during multiselection where the node is selected but not activated
// (its content is not displayed in the detail)
/**
* focused & not active node can happen during multiselection where the node is selected but not activated
* (its content is not displayed in the detail)
* @return {FancytreeNode|null}
*/
function getFocusedNode() {
const tree = $tree.fancytree("getTree");
return tree.getFocusNode();
}
// note that if you want to access data like noteId or isProtected, you need to go into "data" property
/**
* note that if you want to access data like noteId or isProtected, you need to go into "data" property
* @return {FancytreeNode|null}
*/
function getActiveNode() {
return $tree.fancytree("getActiveNode");
}
/** @return {FancytreeNode[]} */
async function getNodesByBranchId(branchId) {
utils.assertArguments(branchId);
@ -46,6 +53,7 @@ async function getNodesByBranchId(branchId) {
return getNodesByNoteId(branch.noteId).filter(node => node.data.branchId === branchId);
}
/** @return {FancytreeNode[]} */
function getNodesByNoteId(noteId) {
utils.assertArguments(noteId);
@ -76,10 +84,12 @@ async function setNodeTitleWithPrefix(node) {
node.setTitle(utils.escapeHtml(title));
}
/** @return {FancytreeNode} */
async function expandToNote(notePath, expandOpts) {
return await getNodeFromPath(notePath, true, expandOpts);
}
/** @return {FancytreeNode} */
function findChildNode(parentNode, childNoteId) {
let foundChildNode = null;
@ -89,13 +99,16 @@ function findChildNode(parentNode, childNoteId) {
break;
}
}
return foundChildNode;
}
/** @return {FancytreeNode} */
async function getNodeFromPath(notePath, expand = false, expandOpts = {}) {
utils.assertArguments(notePath);
const hoistedNoteId = await hoistedNoteService.getHoistedNoteId();
/** @var {FancytreeNode} */
let parentNode = null;
const runPath = await getRunPath(notePath);
@ -145,6 +158,7 @@ async function getNodeFromPath(notePath, expand = false, expandOpts = {}) {
return parentNode;
}
/** @return {FancytreeNode} */
async function activateNote(notePath, noteLoadedListener) {
utils.assertArguments(notePath);
@ -190,6 +204,7 @@ async function activateNote(notePath, noteLoadedListener) {
/**
* Accepts notePath which might or might not be valid and returns an existing path as close to the original
* notePath as possible.
* @return {string|null}
*/
async function resolveNotePath(notePath) {
const runPath = await getRunPath(notePath);
@ -200,6 +215,8 @@ async function resolveNotePath(notePath) {
/**
* 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.
*
* @return {string[]}
*/
async function getRunPath(notePath) {
utils.assertArguments(notePath);
@ -313,10 +330,12 @@ async function setExpandedToServer(branchId, isExpanded) {
await server.put('branches/' + branchId + '/expanded/' + expandedNum);
}
/** @return {FancytreeNode[]} */
function getSelectedNodes(stopOnParents = false) {
return getTree().getSelectedNodes(stopOnParents);
}
/** @return {FancytreeNode[]} */
function getSelectedOrActiveNodes(node) {
let notes = getSelectedNodes(true);
@ -506,6 +525,7 @@ function initFancyTree(tree) {
});
}
/** @return {Fancytree} */
function getTree() {
return $tree.fancytree('getTree');
}
@ -759,27 +779,17 @@ ws.subscribeToMessages(message => {
});
ws.subscribeToOutsideSyncMessages(syncData => {
const noteIdsToRefresh = [];
const noteIdsToRefresh = new Set();
for (const sync of syncData.filter(sync => sync.entityName === 'branches')) {
if (!noteIdsToRefresh.includes(sync.parentNoteId)) {
noteIdsToRefresh.push(sync.parentNoteId);
}
}
// this has the problem that the former parentNoteId might not be invalidated
// and the former location of the branch/note won't be removed.
syncData.filter(sync => sync.entityName === 'branches').forEach(sync => noteIdsToRefresh.add(sync.parentNoteId));
for (const sync of syncData.filter(sync => sync.entityName === 'notes')) {
if (!noteIdsToRefresh.includes(sync.noteId)) {
noteIdsToRefresh.push(sync.noteId);
}
}
syncData.filter(sync => sync.entityName === 'notes').forEach(sync => noteIdsToRefresh.add(sync.noteId));
for (const sync of syncData.filter(sync => sync.entityName === 'note_reordering')) {
if (!noteIdsToRefresh.includes(sync.entityId)) {
noteIdsToRefresh.push(sync.entityId);
}
}
syncData.filter(sync => sync.entityName === 'note_reordering').forEach(sync => noteIdsToRefresh.add(sync.entityId));
reloadNotes(noteIdsToRefresh);
reloadNotes(Array.from(noteIdsToRefresh));
});
utils.bindGlobalShortcut('ctrl+o', async () => {

View File

@ -1,4 +1,3 @@
import noteDetailService from "./note_detail.js";
import utils from "./utils.js";
import Branch from "../entities/branch.js";
import server from "./server.js";

View File

@ -9,5 +9,6 @@
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="library" name="@types/jquery" level="application" />
</component>
</module>