Add ability to fetch only page-type menu items
All checks were successful
continuous-integration/drone/push Build is passing
continuous-integration/drone Build is passing

This commit is contained in:
Garrett Mills 2020-11-16 09:58:44 -06:00
parent 22611612e5
commit 7bde7576d5
Signed by: garrettmills
GPG Key ID: D2BF5FBA8298F246
2 changed files with 7 additions and 4 deletions

View File

@ -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',
})
}

View File

@ -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,