feat: visualize pages (dendograms)

This commit is contained in:
NGPixel
2020-01-05 15:04:16 -05:00
parent 4698afdaeb
commit 6920a35d80
10 changed files with 709 additions and 15 deletions

View File

@@ -137,8 +137,12 @@ module.exports = {
async tree (obj, args, context, info) {
let results = []
let conds = {
localeCode: args.locale,
parent: (args.parent < 1) ? null : args.parent
localeCode: args.locale
}
if (args.parent) {
conds.parent = (args.parent < 1) ? null : args.parent
} else if (args.path) {
// conds.parent = (args.parent < 1) ? null : args.parent
}
switch (args.mode) {
case 'FOLDERS':
@@ -162,6 +166,44 @@ module.exports = {
parent: r.parent || 0,
locale: r.localeCode
}))
},
/**
* FETCH PAGE LINKS
*/
async links (obj, args, context, info) {
let results = []
results = await WIKI.models.knex('pages')
.column({ id: 'pages.id' }, { path: 'pages.path' }, 'title', { link: 'pageLinks.path' }, { locale: 'pageLinks.localeCode' })
.fullOuterJoin('pageLinks', 'pages.id', 'pageLinks.pageId')
.where({
'pages.localeCode': args.locale
})
return _.reduce(results, (result, val) => {
// -> Check if user has access to source and linked page
if (
!WIKI.auth.checkAccess(context.req.user, ['read:pages'], { path: val.path, locale: args.locale }) ||
!WIKI.auth.checkAccess(context.req.user, ['read:pages'], { path: val.link, locale: val.locale })
) {
return result
}
const existingEntry = _.findIndex(result, ['id', val.id])
if (existingEntry >= 0) {
if (val.link) {
result[existingEntry].links.push(`${val.locale}/${val.link}`)
}
} else {
result.push({
id: val.id,
title: val.title,
path: `${args.locale}/${val.path}`,
links: val.link ? [`${val.locale}/${val.link}`] : []
})
}
return result
}, [])
}
},
PageMutation: {