mirror of
https://github.com/TriliumNext/Notes.git
synced 2025-07-28 18:42:28 +08:00
client-ts: Port services/hoisted_note.js
This commit is contained in:
parent
e872e88376
commit
f1896c3f5f
@ -1,7 +1,8 @@
|
|||||||
import appContext from "../components/app_context.js";
|
import appContext from "../components/app_context.js";
|
||||||
import treeService from "./tree.js";
|
import treeService, { Node } from "./tree.js";
|
||||||
import dialogService from "./dialog.js";
|
import dialogService from "./dialog.js";
|
||||||
import froca from "./froca.js";
|
import froca from "./froca.js";
|
||||||
|
import NoteContext from "../components/note_context.js";
|
||||||
|
|
||||||
function getHoistedNoteId() {
|
function getHoistedNoteId() {
|
||||||
const activeNoteContext = appContext.tabManager.getActiveContext();
|
const activeNoteContext = appContext.tabManager.getActiveContext();
|
||||||
@ -17,11 +18,11 @@ async function unhoist() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function isTopLevelNode(node) {
|
function isTopLevelNode(node: Node) {
|
||||||
return isHoistedNode(node.getParent());
|
return isHoistedNode(node.getParent());
|
||||||
}
|
}
|
||||||
|
|
||||||
function isHoistedNode(node) {
|
function isHoistedNode(node: Node) {
|
||||||
// even though check for 'root' should not be necessary, we keep it just in case
|
// even though check for 'root' should not be necessary, we keep it just in case
|
||||||
return node.data.noteId === "root"
|
return node.data.noteId === "root"
|
||||||
|| node.data.noteId === getHoistedNoteId();
|
|| node.data.noteId === getHoistedNoteId();
|
||||||
@ -35,10 +36,10 @@ async function isHoistedInHiddenSubtree() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const hoistedNote = await froca.getNote(hoistedNoteId);
|
const hoistedNote = await froca.getNote(hoistedNoteId);
|
||||||
return hoistedNote.isHiddenCompletely();
|
return hoistedNote?.isHiddenCompletely();
|
||||||
}
|
}
|
||||||
|
|
||||||
async function checkNoteAccess(notePath, noteContext) {
|
async function checkNoteAccess(notePath: string, noteContext: NoteContext) {
|
||||||
const resolvedNotePath = await treeService.resolveNotePath(notePath, noteContext.hoistedNoteId);
|
const resolvedNotePath = await treeService.resolveNotePath(notePath, noteContext.hoistedNoteId);
|
||||||
|
|
||||||
if (!resolvedNotePath) {
|
if (!resolvedNotePath) {
|
||||||
@ -49,11 +50,15 @@ async function checkNoteAccess(notePath, noteContext) {
|
|||||||
const hoistedNoteId = noteContext.hoistedNoteId;
|
const hoistedNoteId = noteContext.hoistedNoteId;
|
||||||
|
|
||||||
if (!resolvedNotePath.includes(hoistedNoteId) && (!resolvedNotePath.includes('_hidden') || resolvedNotePath.includes('_lbBookmarks'))) {
|
if (!resolvedNotePath.includes(hoistedNoteId) && (!resolvedNotePath.includes('_hidden') || resolvedNotePath.includes('_lbBookmarks'))) {
|
||||||
const requestedNote = await froca.getNote(treeService.getNoteIdFromUrl(resolvedNotePath));
|
const noteId = treeService.getNoteIdFromUrl(resolvedNotePath);
|
||||||
|
if (!noteId) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
const requestedNote = await froca.getNote(noteId);
|
||||||
const hoistedNote = await froca.getNote(hoistedNoteId);
|
const hoistedNote = await froca.getNote(hoistedNoteId);
|
||||||
|
|
||||||
if ((!hoistedNote.hasAncestor('_hidden') || resolvedNotePath.includes('_lbBookmarks'))
|
if ((!hoistedNote?.hasAncestor('_hidden') || resolvedNotePath.includes('_lbBookmarks'))
|
||||||
&& !await dialogService.confirm(`Requested note '${requestedNote.title}' is outside of hoisted note '${hoistedNote.title}' subtree and you must unhoist to access the note. Do you want to proceed with unhoisting?`)) {
|
&& !await dialogService.confirm(`Requested note '${requestedNote?.title}' is outside of hoisted note '${hoistedNote?.title}' subtree and you must unhoist to access the note. Do you want to proceed with unhoisting?`)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
Loading…
x
Reference in New Issue
Block a user