2018-03-25 23:09:17 +08:00
|
|
|
import utils from './utils.js';
|
2017-11-05 07:28:49 +08:00
|
|
|
|
2018-03-25 23:09:17 +08:00
|
|
|
const $tree = $("#tree");
|
2017-09-10 00:06:15 +08:00
|
|
|
|
2018-03-25 23:09:17 +08:00
|
|
|
function getParentProtectedStatus(node) {
|
|
|
|
return utils.isTopLevelNode(node) ? 0 : node.getParent().data.isProtected;
|
|
|
|
}
|
2017-10-02 11:07:32 +08:00
|
|
|
|
2018-03-25 23:09:17 +08:00
|
|
|
function getNodeByKey(key) {
|
|
|
|
return $tree.fancytree('getNodeByKey', key);
|
|
|
|
}
|
2017-10-02 11:07:32 +08:00
|
|
|
|
2018-03-25 23:09:17 +08:00
|
|
|
function getNoteIdFromNotePath(notePath) {
|
|
|
|
const path = notePath.split("/");
|
2017-09-19 08:48:02 +08:00
|
|
|
|
2018-03-25 23:09:17 +08:00
|
|
|
return path[path.length - 1];
|
|
|
|
}
|
2017-11-19 21:47:22 +08:00
|
|
|
|
2018-03-25 23:09:17 +08:00
|
|
|
function getNotePath(node) {
|
|
|
|
const path = [];
|
2017-11-19 21:47:22 +08:00
|
|
|
|
2018-03-25 23:09:17 +08:00
|
|
|
while (node && !utils.isRootNode(node)) {
|
|
|
|
if (node.data.noteId) {
|
|
|
|
path.push(node.data.noteId);
|
2017-11-19 21:47:22 +08:00
|
|
|
}
|
|
|
|
|
2018-03-25 23:09:17 +08:00
|
|
|
node = node.getParent();
|
2017-11-19 21:47:22 +08:00
|
|
|
}
|
|
|
|
|
2018-03-25 23:09:17 +08:00
|
|
|
return path.reverse().join("/");
|
|
|
|
}
|
|
|
|
|
|
|
|
export default {
|
|
|
|
getParentProtectedStatus,
|
|
|
|
getNodeByKey,
|
|
|
|
getNotePath,
|
|
|
|
getNoteIdFromNotePath,
|
|
|
|
};
|