Include child nodes in menu tree (Noded/frontend#17)
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
Garrett Mills 2020-10-13 09:58:36 -05:00
parent 604753b3ff
commit 2a5e3419e8
Signed by: garrettmills
GPG Key ID: D2BF5FBA8298F246
2 changed files with 54 additions and 1 deletions

View File

@ -24,6 +24,7 @@ class Menu extends Controller {
children: nodes, children: nodes,
noDelete: true, noDelete: true,
virtual: true, virtual: true,
type: 'branch',
}) })
// Get view only shared trees // Get view only shared trees
@ -36,6 +37,7 @@ class Menu extends Controller {
name: tree.Name, name: tree.Name,
children: await this._build_secure_menu_object(tree, req.user), children: await this._build_secure_menu_object(tree, req.user),
level: await tree.access_level_for(req.user), level: await tree.access_level_for(req.user),
type: 'page',
}) })
} }
@ -49,6 +51,7 @@ class Menu extends Controller {
name: tree.Name, name: tree.Name,
children: await this._build_secure_menu_object(tree, req.user), children: await this._build_secure_menu_object(tree, req.user),
level: await tree.access_level_for(req.user), level: await tree.access_level_for(req.user),
type: 'page',
}) })
} }
@ -62,6 +65,7 @@ class Menu extends Controller {
name: tree.Name, name: tree.Name,
children: await this._build_secure_menu_object(tree, req.user), children: await this._build_secure_menu_object(tree, req.user),
level: await tree.access_level_for(req.user), level: await tree.access_level_for(req.user),
type: 'page',
}) })
} }
@ -71,6 +75,7 @@ class Menu extends Controller {
children: [...view_only_nodes, ...update_nodes, ...manage_nodes], children: [...view_only_nodes, ...update_nodes, ...manage_nodes],
noDelete: true, noDelete: true,
virtual: true, virtual: true,
type: 'branch',
}) })
return res.api(menu) return res.api(menu)
@ -84,7 +89,8 @@ class Menu extends Controller {
id: child.UUID, id: child.UUID,
name: child.is_shared() ? child.Name + ' ⁽ˢʰᵃʳᵉᵈ⁾' : child.Name, name: child.is_shared() ? child.Name + ' ⁽ˢʰᵃʳᵉᵈ⁾' : child.Name,
shared: child.is_shared(), shared: child.is_shared(),
children: await this._build_menu_object(child), children: [...(await child.get_menu_items()), ...(await this._build_menu_object(child))],
type: 'page',
}) })
} }
} }
@ -102,6 +108,7 @@ class Menu extends Controller {
name: child.Name, name: child.Name,
children: await this._build_secure_menu_object(child, user), children: await this._build_secure_menu_object(child, user),
level: await child.access_level_for(user), level: await child.access_level_for(user),
type: 'page',
}) })
} }
} }

View File

@ -221,6 +221,52 @@ class Page extends Model {
await user.save() await user.save()
} }
async get_menu_items() {
// {
// id: child.UUID,
// name: child.is_shared() ? child.Name + ' ⁽ˢʰᵃʳᵉᵈ⁾' : child.Name,
// shared: child.is_shared(),
// children: await this._build_menu_object(child),
// type: 'page',
// }
// Databases & Code Snips
const children = []
const Database = this.models.get('api:db:Database')
const dbs = await Database.find({
Active: true,
PageId: this.UUID,
})
for ( const db of dbs ) {
children.push({
id: db.PageId,
node_id: db.NodeId,
children: [],
type: 'db',
name: db.Name,
})
}
const Codium = this.models.get('api:Codium')
const codiums = await Codium.find({
PageId: this.UUID,
})
for ( const codium of codiums ) {
children.push({
id: codium.PageId,
node_id: codium.NodeId,
children: [],
type: 'code',
name: codium.code.slice(0, 25) + (codium.code.length > 25 ? '...' : ''),
})
}
return children
}
} }
module.exports = exports = Page; module.exports = exports = Page;