Commit 96471290 authored by Nicolas Giard's avatar Nicolas Giard

feat: page history pagination + dark mode fix

parent 78ba895e
...@@ -5,48 +5,49 @@ ...@@ -5,48 +5,49 @@
v-toolbar(color='primary', dark) v-toolbar(color='primary', dark)
.subheading Viewing history of page #[strong /{{path}}] .subheading Viewing history of page #[strong /{{path}}]
v-spacer v-spacer
.caption.blue--text.text--lighten-3 ID {{pageId}} .caption.blue--text.text--lighten-3.mr-4 Trail Length: {{total}}
.caption.blue--text.text--lighten-3 ID: {{pageId}}
v-btn.ml-4(depressed, color='blue darken-1', @click='goLive') Return to Live Version v-btn.ml-4(depressed, color='blue darken-1', @click='goLive') Return to Live Version
v-container(fluid, grid-list-xl) v-container(fluid, grid-list-xl)
v-layout(row, wrap) v-layout(row, wrap)
v-flex(xs4) v-flex(xs4)
v-chip.ma-0.grey--text.text--darken-2( v-chip.ma-0(
label label
small small
color='grey lighten-2' :color='darkMode ? `grey darken-2` : `grey lighten-2`'
:class='darkMode ? `grey--text text--lighten-2` : `grey--text text--darken-2`'
) )
span Live span Live
v-timeline( v-timeline(
dense dense
) )
v-timeline-item( v-timeline-item.pb-2(
v-for='ph in trail' v-for='(ph, idx) in trail'
:key='ph.versionId' :key='ph.versionId'
:small='ph.actionType === `edit`' :small='ph.actionType === `edit`'
fill-dot fill-dot
:color='trailColor(ph.actionType)' :color='trailColor(ph.actionType)'
:icon='trailIcon(ph.actionType)' :icon='trailIcon(ph.actionType)'
:class='idx >= trail.length - 1 ? `pb-4` : `pb-2`'
) )
v-card.radius-7(flat, :class='trailBgColor(ph.actionType)') v-card.radius-7(flat, :class='trailBgColor(ph.actionType)')
v-toolbar(flat, :color='trailBgColor(ph.actionType)') v-toolbar(flat, :color='trailBgColor(ph.actionType)', height='40')
v-chip.ml-0.mr-3( v-chip.ml-0.mr-3(
v-if='diffSource === ph.versionId' v-if='diffSource === ph.versionId'
label
small small
color='pink' color='pink'
) )
.caption.white--text Source .caption.white--text Source
v-chip.ml-0.mr-3( v-chip.ml-0.mr-3(
v-if='diffTarget === ph.versionId' v-if='diffTarget === ph.versionId'
label
small small
color='pink' color='pink'
) )
.caption.white--text Target .caption.white--text Target
.caption(v-if='ph.actionType === `edit`') Edited by {{ ph.authorName }} .caption(v-if='ph.actionType === `edit`') Edited by #[strong {{ ph.authorName }}]
.caption(v-else-if='ph.actionType === `move`') Moved from #[strong {{ph.valueBefore}}] to #[strong {{ph.valueAfter}}] by {{ ph.authorName }} .caption(v-else-if='ph.actionType === `move`') Moved from #[strong {{ph.valueBefore}}] to #[strong {{ph.valueAfter}}] by #[strong {{ ph.authorName }}]
.caption(v-else-if='ph.actionType === `initial`') Created by {{ ph.authorName }} .caption(v-else-if='ph.actionType === `initial`') Created by #[strong {{ ph.authorName }}]
.caption(v-else) Unknown Action by {{ ph.authorName }} .caption(v-else) Unknown Action by #[strong {{ ph.authorName }}]
v-spacer v-spacer
.caption {{ ph.createdAt | moment('calendar') }} .caption {{ ph.createdAt | moment('calendar') }}
v-menu(offset-x, left) v-menu(offset-x, left)
...@@ -76,20 +77,30 @@ ...@@ -76,20 +77,30 @@
v-list-tile-avatar: v-icon call_split v-list-tile-avatar: v-icon call_split
v-list-tile-title Branch off from here v-list-tile-title Branch off from here
v-chip.ma-0.grey--text.text--darken-2( v-btn.ma-0.radius-7(
v-if='total > trail.length'
block
color='grey darken-2'
@click='loadMore'
)
.caption.white--text Load More...
v-chip.ma-0(
v-else
label label
small small
color='grey lighten-2' :color='darkMode ? `grey darken-2` : `grey lighten-2`'
:class='darkMode ? `grey--text text--lighten-2` : `grey--text text--darken-2`'
) End of history trail ) End of history trail
v-flex(xs8) v-flex(xs8)
v-card.radius-7 v-card.radius-7
v-card-text v-card-text
v-card.grey.lighten-4.radius-7(flat) v-card.grey.radius-7(flat, :class='darkMode ? `darken-2` : `lighten-4`')
v-card-text v-card-text
.subheading Page Title .subheading Page Title
.caption Some page description .caption Some page description
.mt-3(v-html='diffHTML') v-card.mt-3(light, v-html='diffHTML')
nav-footer nav-footer
</template> </template>
...@@ -129,7 +140,8 @@ export default { ...@@ -129,7 +140,8 @@ export default {
trail: [], trail: [],
diffSource: 0, diffSource: 0,
diffTarget: 0, diffTarget: 0,
offset: 0 offsetPage: 0,
total: 0
} }
}, },
computed: { computed: {
...@@ -173,6 +185,28 @@ export default { ...@@ -173,6 +185,28 @@ export default {
setDiffTarget(versionId) { setDiffTarget(versionId) {
this.diffTarget = versionId this.diffTarget = versionId
}, },
loadMore() {
this.offsetPage++
this.$apollo.queries.trail.fetchMore({
variables: {
id: this.pageId,
offsetPage: this.offsetPage,
offsetSize: 25
},
updateQuery: (previousResult, { fetchMoreResult }) => {
return {
pages: {
history: {
total: previousResult.pages.history.total,
trail: [...previousResult.pages.history.trail, ...fetchMoreResult.pages.history.trail],
__typename: previousResult.pages.history.__typename
},
__typename: previousResult.pages.__typename
}
}
}
})
},
trailColor(actionType) { trailColor(actionType) {
switch (actionType) { switch (actionType) {
case 'edit': case 'edit':
...@@ -200,11 +234,11 @@ export default { ...@@ -200,11 +234,11 @@ export default {
trailBgColor(actionType) { trailBgColor(actionType) {
switch (actionType) { switch (actionType) {
case 'move': case 'move':
return 'purple lighten-5' return this.darkMode ? 'purple' : 'purple lighten-5'
case 'initial': case 'initial':
return 'teal lighten-5' return this.darkMode ? 'teal darken-3' : 'teal lighten-5'
default: default:
return 'grey lighten-3' return this.darkMode ? 'grey darken-3' : 'grey lighten-3'
} }
} }
}, },
...@@ -214,10 +248,15 @@ export default { ...@@ -214,10 +248,15 @@ export default {
variables() { variables() {
return { return {
id: this.pageId, id: this.pageId,
offset: 0 offsetPage: 0,
offsetSize: 25
} }
}, },
update: (data) => data.pages.history, manual: true,
result({ data, loading, networkStatus }) {
this.total = data.pages.history.total
this.trail = data.pages.history.trail
},
watchLoading (isLoading) { watchLoading (isLoading) {
this.$store.commit(`loading${isLoading ? 'Start' : 'Stop'}`, 'history-trail-refresh') this.$store.commit(`loading${isLoading ? 'Start' : 'Stop'}`, 'history-trail-refresh')
} }
......
query($id: Int!, $offset: Int) { query($id: Int!, $offsetPage: Int, $offsetSize: Int) {
pages { pages {
history(id:$id, offset:$offset) { history(id:$id, offsetPage:$offsetPage, offsetSize:$offsetSize) {
trail {
versionId versionId
authorId authorId
authorName authorName
...@@ -9,5 +10,7 @@ query($id: Int!, $offset: Int) { ...@@ -9,5 +10,7 @@ query($id: Int!, $offset: Int) {
valueAfter valueAfter
createdAt createdAt
} }
total
}
} }
} }
...@@ -13,7 +13,8 @@ module.exports = { ...@@ -13,7 +13,8 @@ module.exports = {
async history(obj, args, context, info) { async history(obj, args, context, info) {
return WIKI.models.pageHistory.getHistory({ return WIKI.models.pageHistory.getHistory({
pageId: args.id, pageId: args.id,
offset: args.offset || 0 offsetPage: args.offsetPage || 0,
offsetSize: args.offsetSize || 100
}) })
}, },
async list(obj, args, context, info) { async list(obj, args, context, info) {
......
...@@ -17,8 +17,9 @@ extend type Mutation { ...@@ -17,8 +17,9 @@ extend type Mutation {
type PageQuery { type PageQuery {
history( history(
id: Int! id: Int!
offset: Int offsetPage: Int
): [PageHistory] offsetSize: Int
): PageHistoryResult
list( list(
filter: String filter: String
...@@ -107,3 +108,8 @@ type PageHistory { ...@@ -107,3 +108,8 @@ type PageHistory {
valueAfter: String valueAfter: String
createdAt: Date! createdAt: Date!
} }
type PageHistoryResult {
trail: [PageHistory]
total: Int!
}
...@@ -103,7 +103,7 @@ module.exports = class PageHistory extends Model { ...@@ -103,7 +103,7 @@ module.exports = class PageHistory extends Model {
}) })
} }
static async getHistory({ pageId, offset = 0 }) { static async getHistory({ pageId, offsetPage = 0, offsetSize = 100 }) {
const history = await WIKI.models.pageHistory.query() const history = await WIKI.models.pageHistory.query()
.column([ .column([
'pageHistory.id', 'pageHistory.id',
...@@ -118,18 +118,40 @@ module.exports = class PageHistory extends Model { ...@@ -118,18 +118,40 @@ module.exports = class PageHistory extends Model {
.where({ .where({
'pageHistory.pageId': pageId 'pageHistory.pageId': pageId
}) })
.orderBy('pageHistory.createdAt', 'asc') .orderBy('pageHistory.createdAt', 'desc')
.offset(offset) .page(offsetPage, offsetSize)
.limit(20)
let prevPh = null let prevPh = null
const upperLimit = (offsetPage + 1) * offsetSize
return _.reduce(history, (res, ph) => { if (history.total >= upperLimit) {
prevPh = await WIKI.models.pageHistory.query()
.column([
'pageHistory.id',
'pageHistory.path',
'pageHistory.authorId',
'pageHistory.createdAt',
{
authorName: 'author.name'
}
])
.joinRelation('author')
.where({
'pageHistory.pageId': pageId
})
.orderBy('pageHistory.createdAt', 'desc')
.offset((offsetPage + 1) * offsetSize)
.limit(1)
.first()
}
return {
trail: _.reduce(_.reverse(history.results), (res, ph) => {
let actionType = 'edit' let actionType = 'edit'
let valueBefore = null let valueBefore = null
let valueAfter = null let valueAfter = null
if (!prevPh && offset === 0) { if (!prevPh && history.total < upperLimit) {
actionType = 'initial' actionType = 'initial'
} else if (_.get(prevPh, 'path', '') !== ph.path) { } else if (_.get(prevPh, 'path', '') !== ph.path) {
actionType = 'move' actionType = 'move'
...@@ -149,6 +171,8 @@ module.exports = class PageHistory extends Model { ...@@ -149,6 +171,8 @@ module.exports = class PageHistory extends Model {
prevPh = ph prevPh = ph
return res return res
}, []) }, []),
total: history.total
}
} }
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment