Add ability to fetch only page-type menu items
continuous-integration/drone/push Build is passing Details
continuous-integration/drone Build is passing Details

master
Garrett Mills 4 years ago
parent 22611612e5
commit 7bde7576d5
Signed by: garrettmills
GPG Key ID: D2BF5FBA8298F246

@ -12,10 +12,11 @@ class Menu extends Controller {
async get_items(req, res) {
const Page = this.models.get('api:Page')
const page_only = req.query.type === 'page'
// Build the "My Tree" option
const root_page = await req.user.get_root_page()
const nodes = await this._build_menu_object(root_page)
const nodes = await this._build_menu_object(root_page, [], page_only)
const menu = []
menu.push({
@ -83,7 +84,7 @@ class Menu extends Controller {
return res.api(menu)
}
async _build_menu_object(parent_node, arr= []) {
async _build_menu_object(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 ) {
@ -91,7 +92,7 @@ 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()), ...(await this._build_menu_object(child))],
children: [...(await child.get_menu_items(page_only)), ...(await this._build_menu_object(child, [], page_only))],
type: 'page',
})
}

@ -247,7 +247,9 @@ class Page extends VersionedModel {
await user.save()
}
async get_menu_items() {
async get_menu_items(page_only) {
if ( page_only ) return [];
// {
// id: child.UUID,
// name: child.is_shared() ? child.Name + ' ⁽ˢʰᵃʳᵉᵈ⁾' : child.Name,

Loading…
Cancel
Save