|
|
|
@ -26,9 +26,21 @@ class Menu extends Controller {
|
|
|
|
|
.api()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const nodes = await this._build_menu_object(root_page, [], page_only)
|
|
|
|
|
const nodes = await this._build_menu_object(req.user, root_page, [], page_only)
|
|
|
|
|
const menu = []
|
|
|
|
|
|
|
|
|
|
if ( req.user.preferences?.bookmark_page_ids?.length ) {
|
|
|
|
|
menu.push({
|
|
|
|
|
id: 0,
|
|
|
|
|
name: 'My Bookmarks',
|
|
|
|
|
children: await this.get_bookmarks(req.user),
|
|
|
|
|
noDelete: true,
|
|
|
|
|
noChildren: true,
|
|
|
|
|
virtual: true,
|
|
|
|
|
type: PageType.Branch,
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const virtual_page = {
|
|
|
|
|
id: root_page.UUID,
|
|
|
|
|
children: [...(await root_page.get_menu_items(page_only)), ...nodes],
|
|
|
|
@ -57,9 +69,21 @@ class Menu extends Controller {
|
|
|
|
|
|
|
|
|
|
// Build the "My Tree" option
|
|
|
|
|
const root_page = await req.user.get_root_page()
|
|
|
|
|
const nodes = await this._build_menu_object(root_page, [], page_only)
|
|
|
|
|
const nodes = await this._build_menu_object(req.user, root_page, [], page_only)
|
|
|
|
|
const menu = []
|
|
|
|
|
|
|
|
|
|
if ( req.user.preferences?.bookmark_page_ids?.length ) {
|
|
|
|
|
menu.push({
|
|
|
|
|
id: 0,
|
|
|
|
|
name: 'My Bookmarks',
|
|
|
|
|
children: await this.get_bookmarks(req.user),
|
|
|
|
|
noDelete: true,
|
|
|
|
|
noChildren: true,
|
|
|
|
|
virtual: true,
|
|
|
|
|
type: PageType.Branch,
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
menu.push({
|
|
|
|
|
id: 0,
|
|
|
|
|
name: 'My Info Tree',
|
|
|
|
@ -82,6 +106,7 @@ class Menu extends Controller {
|
|
|
|
|
children: await this._build_secure_menu_object(tree, req.user),
|
|
|
|
|
level: await tree.access_level_for(req.user),
|
|
|
|
|
type: tree.PageType || PageType.Note,
|
|
|
|
|
bookmark: (req.user.preferences.bookmark_page_ids || []).includes(tree.UUID),
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -96,6 +121,7 @@ class Menu extends Controller {
|
|
|
|
|
children: await this._build_secure_menu_object(tree, req.user),
|
|
|
|
|
level: await tree.access_level_for(req.user),
|
|
|
|
|
type: tree.PageType || PageType.Note,
|
|
|
|
|
bookmark: (req.user.preferences.bookmark_page_ids || []).includes(tree.UUID),
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -110,6 +136,7 @@ class Menu extends Controller {
|
|
|
|
|
children: await this._build_secure_menu_object(tree, req.user),
|
|
|
|
|
level: await tree.access_level_for(req.user),
|
|
|
|
|
type: tree.PageType || PageType.Note,
|
|
|
|
|
bookmark: (req.user.preferences.bookmark_page_ids || []).includes(tree.UUID),
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -126,6 +153,24 @@ class Menu extends Controller {
|
|
|
|
|
return res.api(menu)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
async get_bookmarks(user) {
|
|
|
|
|
const pages = await user.get_bookmarked_pages()
|
|
|
|
|
const items = []
|
|
|
|
|
|
|
|
|
|
for ( const page of pages ) {
|
|
|
|
|
items.push({
|
|
|
|
|
id: page.UUID,
|
|
|
|
|
name: page.is_shared() ? page.Name + ' ⁽ˢʰᵃʳᵉᵈ⁾' : page.Name,
|
|
|
|
|
shared: page.is_shared(),
|
|
|
|
|
bookmark: true,
|
|
|
|
|
type: page.PageType || PageType.Note,
|
|
|
|
|
children: [],
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return items
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
async move_node(req, res, next) {
|
|
|
|
|
const Page = this.models.get('api:Page');
|
|
|
|
|
|
|
|
|
@ -181,7 +226,7 @@ class Menu extends Controller {
|
|
|
|
|
return res.api();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
async _build_menu_object(parent_node, arr= [], page_only = false) {
|
|
|
|
|
async _build_menu_object(user, parent_node, arr= [], page_only = false) {
|
|
|
|
|
const children = await this.models.get('api:Page').find({UUID: {$in: parent_node.ChildPageIds}})
|
|
|
|
|
if ( children ) {
|
|
|
|
|
for ( const child of children ) {
|
|
|
|
@ -189,8 +234,9 @@ class Menu extends Controller {
|
|
|
|
|
id: child.UUID,
|
|
|
|
|
name: child.is_shared() ? child.Name + ' ⁽ˢʰᵃʳᵉᵈ⁾' : child.Name,
|
|
|
|
|
shared: child.is_shared(),
|
|
|
|
|
children: [...(await child.get_menu_items(page_only)), ...(await this._build_menu_object(child, [], page_only))],
|
|
|
|
|
children: [...(await child.get_menu_items(page_only)), ...(await this._build_menu_object(user, child, [], page_only))],
|
|
|
|
|
type: child.PageType || PageType.Note,
|
|
|
|
|
bookmark: (user.preferences.bookmark_page_ids || []).includes(child.UUID),
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
@ -209,6 +255,7 @@ class Menu extends Controller {
|
|
|
|
|
children: await this._build_secure_menu_object(child, user),
|
|
|
|
|
level: await child.access_level_for(user),
|
|
|
|
|
type: child.PageType || PageType.Note,
|
|
|
|
|
bookmark: (user.preferences.bookmark_page_ids || []).includes(child.UUID),
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|