Add ability to fetch menu items for a virtual root
This commit is contained in:
parent
7f8f0a1dd7
commit
97b4bf662c
@ -12,6 +12,46 @@ class Menu extends Controller {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async get_items(req, res) {
|
async get_items(req, res) {
|
||||||
|
const virtual_root = req.query.virtualRootPageId
|
||||||
|
const Page = this.models.get('api:Page')
|
||||||
|
const page_only = req.query.type === 'page'
|
||||||
|
|
||||||
|
if ( !virtual_root ) {
|
||||||
|
return this.get_top_level_menu(req, res);
|
||||||
|
} else {
|
||||||
|
const root_page = await Page.findOne({ UUID: virtual_root })
|
||||||
|
if ( !root_page || !(await root_page.is_accessible_by(req.user, 'view')) ) {
|
||||||
|
return res.status(404)
|
||||||
|
.message('Invalid virtual root page ID.')
|
||||||
|
.api()
|
||||||
|
}
|
||||||
|
|
||||||
|
const nodes = await this._build_menu_object(root_page, [], page_only)
|
||||||
|
const menu = []
|
||||||
|
|
||||||
|
const virtual_page = {
|
||||||
|
id: root_page.UUID,
|
||||||
|
children: [...(await root_page.get_menu_items(page_only)), ...nodes],
|
||||||
|
name: root_page.is_shared() ? root_page.Name + ' ⁽ˢʰᵃʳᵉᵈ⁾' : root_page.Name,
|
||||||
|
shared: root_page.is_shared(),
|
||||||
|
type: PageType.Note,
|
||||||
|
};
|
||||||
|
|
||||||
|
menu.push({
|
||||||
|
id: 0,
|
||||||
|
name: 'Virtual Tree Root',
|
||||||
|
children: [virtual_page],
|
||||||
|
noDelete: true,
|
||||||
|
noChildren: true,
|
||||||
|
virtual: true,
|
||||||
|
type: PageType.Branch,
|
||||||
|
})
|
||||||
|
|
||||||
|
return res.api(menu)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async get_top_level_menu(req, res) {
|
||||||
const Page = this.models.get('api:Page')
|
const Page = this.models.get('api:Page')
|
||||||
const page_only = req.query.type === 'page'
|
const page_only = req.query.type === 'page'
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user