Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
W
wiki-js
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
1
Issues
1
List
Board
Labels
Milestones
Merge Requests
1
Merge Requests
1
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Jacklull
wiki-js
Commits
ab463fca
Commit
ab463fca
authored
Sep 02, 2019
by
Nick
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat: tags on page fetch + pageLinks table schema
parent
efab00fa
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
102 additions
and
40 deletions
+102
-40
page.vue
client/themes/default/components/page.vue
+3
-3
2.0.0-beta.293.js
server/db/migrations-sqlite/2.0.0-beta.293.js
+13
-0
2.0.0-beta.293.js
server/db/migrations/2.0.0-beta.293.js
+19
-0
pages.js
server/models/pages.js
+66
-36
page.pug
server/views/page.pug
+1
-1
No files found.
client/themes/default/components/page.vue
View file @
ab463fca
...
...
@@ -77,11 +77,11 @@
label
color='teal lighten-5'
v-for='(tag, idx) in tags'
:href='`/t/` + tag.
slu
g'
:key='tag.
slu
g'
:href='`/t/` + tag.
ta
g'
:key='tag.
ta
g'
)
v-icon(color='teal', left, small) mdi-label
span.teal--text.text--darken-2
{{
tag
.
t
ext
}}
span.teal--text.text--darken-2
{{
tag
.
t
itle
}}
v-card.mb-5
.pa-5
...
...
server/db/migrations-sqlite/2.0.0-beta.293.js
0 → 100644
View file @
ab463fca
exports
.
up
=
knex
=>
{
return
knex
.
schema
.
createTable
(
'pageLinks'
,
table
=>
{
table
.
increments
(
'id'
).
primary
()
table
.
integer
(
'sourcePageId'
).
unsigned
().
references
(
'id'
).
inTable
(
'pages'
).
onDelete
(
'CASCADE'
)
table
.
integer
(
'targetPageId'
).
unsigned
().
references
(
'id'
).
inTable
(
'pages'
).
onDelete
(
'CASCADE'
)
})
}
exports
.
down
=
knex
=>
{
return
knex
.
schema
.
dropTableIfExists
(
'pageLinks'
)
}
server/db/migrations/2.0.0-beta.293.js
0 → 100644
View file @
ab463fca
/* global WIKI */
exports
.
up
=
knex
=>
{
const
dbCompat
=
{
charset
:
(
WIKI
.
config
.
db
.
type
===
`mysql`
||
WIKI
.
config
.
db
.
type
===
`mariadb`
)
}
return
knex
.
schema
.
createTable
(
'pageLinks'
,
table
=>
{
if
(
dbCompat
.
charset
)
{
table
.
charset
(
'utf8mb4'
)
}
table
.
increments
(
'id'
).
primary
()
table
.
integer
(
'sourcePageId'
).
unsigned
().
references
(
'id'
).
inTable
(
'pages'
).
onDelete
(
'CASCADE'
)
table
.
integer
(
'targetPageId'
).
unsigned
().
references
(
'id'
).
inTable
(
'pages'
).
onDelete
(
'CASCADE'
)
})
}
exports
.
down
=
knex
=>
{
return
knex
.
schema
.
dropTableIfExists
(
'pageLinks'
)
}
server/models/pages.js
View file @
ab463fca
...
...
@@ -63,6 +63,18 @@ module.exports = class Page extends Model {
to
:
'tags.id'
}
},
links
:
{
relation
:
Model
.
ManyToManyRelation
,
modelClass
:
Page
,
join
:
{
from
:
'pages.id'
,
through
:
{
from
:
'pageLinks.sourcePageId'
,
to
:
'pageLinks.targetPageId'
},
to
:
'pages.id'
}
},
author
:
{
relation
:
Model
.
BelongsToOneRelation
,
modelClass
:
require
(
'./users'
),
...
...
@@ -120,6 +132,12 @@ module.exports = class Page extends Model {
publishEndDate
:
'string'
,
publishStartDate
:
'string'
,
render
:
'string'
,
tags
:
[
{
tag
:
'string'
,
title
:
'string'
}
],
title
:
'string'
,
toc
:
'string'
,
updatedAt
:
'string'
...
...
@@ -349,42 +367,53 @@ module.exports = class Page extends Model {
static
async
getPageFromDb
(
opts
)
{
const
queryModeID
=
_
.
isNumber
(
opts
)
return
WIKI
.
models
.
pages
.
query
()
.
column
([
'pages.*'
,
{
authorName
:
'author.name'
,
authorEmail
:
'author.email'
,
creatorName
:
'creator.name'
,
creatorEmail
:
'creator.email'
}
])
.
joinRelation
(
'author'
)
.
joinRelation
(
'creator'
)
.
where
(
queryModeID
?
{
'pages.id'
:
opts
}
:
{
'pages.path'
:
opts
.
path
,
'pages.localeCode'
:
opts
.
locale
})
// .andWhere(builder => {
// if (queryModeID) return
// builder.where({
// 'pages.isPublished': true
// }).orWhere({
// 'pages.isPublished': false,
// 'pages.authorId': opts.userId
// })
// })
// .andWhere(builder => {
// if (queryModeID) return
// if (opts.isPrivate) {
// builder.where({ 'pages.isPrivate': true, 'pages.privateNS': opts.privateNS })
// } else {
// builder.where({ 'pages.isPrivate': false })
// }
// })
.
first
()
try
{
return
WIKI
.
models
.
pages
.
query
()
.
column
([
'pages.*'
,
{
authorName
:
'author.name'
,
authorEmail
:
'author.email'
,
creatorName
:
'creator.name'
,
creatorEmail
:
'creator.email'
}
])
.
joinRelation
(
'author'
)
.
joinRelation
(
'creator'
)
.
eagerAlgorithm
(
Model
.
JoinEagerAlgorithm
)
.
eager
(
'tags(selectTags)'
,
{
selectTags
:
builder
=>
{
builder
.
select
(
'tag'
,
'title'
)
}
})
.
where
(
queryModeID
?
{
'pages.id'
:
opts
}
:
{
'pages.path'
:
opts
.
path
,
'pages.localeCode'
:
opts
.
locale
})
// .andWhere(builder => {
// if (queryModeID) return
// builder.where({
// 'pages.isPublished': true
// }).orWhere({
// 'pages.isPublished': false,
// 'pages.authorId': opts.userId
// })
// })
// .andWhere(builder => {
// if (queryModeID) return
// if (opts.isPrivate) {
// builder.where({ 'pages.isPrivate': true, 'pages.privateNS': opts.privateNS })
// } else {
// builder.where({ 'pages.isPrivate': false })
// }
// })
.
first
()
}
catch
(
err
)
{
WIKI
.
logger
.
warn
(
err
)
throw
err
}
}
static
async
savePageToCache
(
page
)
{
...
...
@@ -402,6 +431,7 @@ module.exports = class Page extends Model {
publishEndDate
:
page
.
publishEndDate
,
publishStartDate
:
page
.
publishStartDate
,
render
:
page
.
render
,
tags
:
page
.
tags
.
map
(
t
=>
_
.
pick
(
t
,
[
'tag'
,
'title'
])),
title
:
page
.
title
,
toc
:
_
.
isString
(
page
.
toc
)
?
page
.
toc
:
JSON
.
stringify
(
page
.
toc
),
updatedAt
:
page
.
updatedAt
...
...
server/views/page.pug
View file @
ab463fca
...
...
@@ -13,7 +13,7 @@ block body
path=page.path
title=page.title
description=page.description
tags=page.tags
:
tags=page.tags
created-at=page.createdAt
updated-at=page.updatedAt
author-name=page.authorName
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment