You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

49 lines
1.2 KiB

const Controller = require('libflitter/controller/Controller')
/*
* Menu Controller
* -------------------------------------------------------------
* Put some description here!
*/
class Menu extends Controller {
static get services() {
return [...super.services, 'models']
}
async get_items(req, res) {
// Build the "My Tree" option
const root_page = await req.user.get_root_page()
const nodes = await this._build_menu_object(root_page)
const menu = []
menu.push({
id: 0,
name: 'My Info Tree',
children: nodes,
noDelete: true,
virtual: true,
expanded: true,
})
return res.api(menu)
}
async _build_menu_object(parent_node, arr= []) {
const children = await this.models.get('api:Page').find({UUID: {$in: parent_node.ChildPageIds}})
if ( children ) {
for ( const child of children ) {
arr.push({
id: child.UUID,
name: child.Name,
children: await this._build_menu_object(child),
})
}
}
return arr
}
}
module.exports = exports = Menu