feat: visualize pages (dendograms)
This commit is contained in:
@@ -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: {
|
||||
|
@@ -42,10 +42,16 @@ type PageQuery {
|
||||
tags: [PageTag]! @auth(requires: ["manage:system", "read:pages"])
|
||||
|
||||
tree(
|
||||
parent: Int!
|
||||
path: String
|
||||
parent: Int
|
||||
mode: PageTreeMode!
|
||||
locale: String!
|
||||
includeParents: Boolean
|
||||
): [PageTreeItem] @auth(requires: ["manage:system", "read:pages"])
|
||||
|
||||
links(
|
||||
locale: String!
|
||||
): [PageLinkItem] @auth(requires: ["manage:system", "read:pages"])
|
||||
}
|
||||
|
||||
# -----------------------------------------------
|
||||
@@ -209,6 +215,13 @@ type PageTreeItem {
|
||||
locale: String!
|
||||
}
|
||||
|
||||
type PageLinkItem {
|
||||
id: Int!
|
||||
path: String!
|
||||
title: String!
|
||||
links: [String]!
|
||||
}
|
||||
|
||||
enum PageOrderBy {
|
||||
CREATED
|
||||
ID
|
||||
|
Reference in New Issue
Block a user