parent
617a77b809
commit
85e0af2e9d
@ -0,0 +1,36 @@
|
||||
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) {
|
||||
const root_page = await req.user.get_root_page()
|
||||
const nodes = await this._build_menu_object(root_page)
|
||||
return res.api(nodes)
|
||||
}
|
||||
|
||||
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
|
Loading…
Reference in new issue