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
|
||||
|
@@ -4,7 +4,7 @@ const crypto = require('crypto')
|
||||
const path = require('path')
|
||||
|
||||
const localeSegmentRegex = /^[A-Z]{2}(-[A-Z]{2})?$/i
|
||||
const localeFolderRegex = /^([a-z]{2}(?:-[a-z]{2})?)\/?(.*)/i
|
||||
const localeFolderRegex = /^([a-z]{2}(?:-[a-z]{2})?\/)?(.*)/i
|
||||
|
||||
const contentToExt = {
|
||||
markdown: 'md',
|
||||
@@ -125,7 +125,7 @@ module.exports = {
|
||||
const result = localeFolderRegex.exec(meta.path)
|
||||
if (result[1]) {
|
||||
meta = {
|
||||
locale: result[1],
|
||||
locale: result[1].replace('/', ''),
|
||||
path: result[2]
|
||||
}
|
||||
}
|
||||
|
@@ -72,7 +72,8 @@ module.exports = {
|
||||
},
|
||||
|
||||
async processPage ({ user, fullPath, relPath, contentType, moduleName }) {
|
||||
const contentPath = pageHelper.getPagePath(relPath)
|
||||
const normalizedRelPath = relPath.replace(/\\/g, '/')
|
||||
const contentPath = pageHelper.getPagePath(normalizedRelPath)
|
||||
const itemContents = await fs.readFile(path.join(fullPath, relPath), 'utf8')
|
||||
const pageData = WIKI.models.pages.parseMetadata(itemContents, contentType)
|
||||
const currentPage = await WIKI.models.pages.getPageFromDb({
|
||||
@@ -82,7 +83,7 @@ module.exports = {
|
||||
const newTags = !_.isNil(pageData.tags) ? _.get(pageData, 'tags', '').split(', ') : false
|
||||
if (currentPage) {
|
||||
// Already in the DB, can mark as modified
|
||||
WIKI.logger.info(`(STORAGE/${moduleName}) Page marked as modified: ${relPath}`)
|
||||
WIKI.logger.info(`(STORAGE/${moduleName}) Page marked as modified: ${normalizedRelPath}`)
|
||||
await WIKI.models.pages.updatePage({
|
||||
id: currentPage.id,
|
||||
title: _.get(pageData, 'title', currentPage.title),
|
||||
@@ -96,7 +97,7 @@ module.exports = {
|
||||
})
|
||||
} else {
|
||||
// Not in the DB, can mark as new
|
||||
WIKI.logger.info(`(STORAGE/${moduleName}) Page marked as new: ${relPath}`)
|
||||
WIKI.logger.info(`(STORAGE/${moduleName}) Page marked as new: ${normalizedRelPath}`)
|
||||
const pageEditor = await WIKI.models.editors.getDefaultEditor(contentType)
|
||||
await WIKI.models.pages.createPage({
|
||||
path: contentPath.path,
|
||||
|
Reference in New Issue
Block a user