Skip to content

Commit

Permalink
feat: convert page
Browse files Browse the repository at this point in the history
  • Loading branch information
NGPixel committed Apr 2, 2021
1 parent d75c553 commit 26f1c0f
Show file tree
Hide file tree
Showing 10 changed files with 331 additions and 2 deletions.
14 changes: 13 additions & 1 deletion client/components/common/nav-header.vue
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,9 @@
v-list-item.pl-4(@click='pageSource', v-if='mode !== `source` && hasReadSourcePermission')
v-list-item-avatar(size='24', tile): v-icon(color='indigo') mdi-code-tags
v-list-item-title.body-2 {{$t('common:header.viewSource')}}
v-list-item.pl-4(@click='pageConvert', v-if='hasWritePagesPermission')
v-list-item-avatar(size='24', tile): v-icon(color='indigo') mdi-lightning-bolt
v-list-item-title.body-2 {{$t('common:header.convert')}}
v-list-item.pl-4(@click='pageDuplicate', v-if='hasWritePagesPermission')
v-list-item-avatar(size='24', tile): v-icon(color='indigo') mdi-content-duplicate
v-list-item-title.body-2 {{$t('common:header.duplicate')}}
Expand Down Expand Up @@ -237,6 +240,7 @@
page-selector(mode='move', v-model='movePageModal', :open-handler='pageMoveRename', :path='path', :locale='locale')
page-selector(mode='create', v-model='duplicateOpts.modal', :open-handler='pageDuplicateHandle', :path='duplicateOpts.path', :locale='duplicateOpts.locale')
page-delete(v-model='deletePageModal', v-if='path && path.length')
page-convert(v-model='convertPageModal', v-if='path && path.length')

.nav-header-dev(v-if='isDevMode')
v-icon mdi-alert
Expand All @@ -255,7 +259,8 @@ import movePageMutation from 'gql/common/common-pages-mutation-move.gql'
export default {
components: {
PageDelete: () => import('./page-delete.vue')
PageDelete: () => import('./page-delete.vue'),
PageConvert: () => import('./page-convert.vue')
},
props: {
dense: {
Expand All @@ -274,6 +279,7 @@ export default {
searchAdvMenuShown: false,
newPageModal: false,
movePageModal: false,
convertPageModal: false,
deletePageModal: false,
locales: siteLangs,
isDevMode: false,
Expand Down Expand Up @@ -354,6 +360,9 @@ export default {
this.$root.$on('pageMove', () => {
this.pageMove()
})
this.$root.$on('pageConvert', () => {
this.pageConvert()
})
this.$root.$on('pageDuplicate', () => {
this.pageDuplicate()
})
Expand Down Expand Up @@ -416,6 +425,9 @@ export default {
pageDuplicateHandle ({ locale, path }) {
window.location.assign(`/e/${locale}/${path}?from=${this.$store.get('page/id')}`)
},
pageConvert () {
this.convertPageModal = true
},
pageMove () {
this.movePageModal = true
},
Expand Down
122 changes: 122 additions & 0 deletions client/components/common/page-convert.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
<template lang='pug'>
v-dialog(
v-model='isShown'
max-width='550'
persistent
overlay-color='blue-grey darken-4'
overlay-opacity='.7'
)
v-card
.dialog-header.is-short.is-dark
v-icon.mr-2(color='white') mdi-lightning-bolt
span {{$t('common:page.convert')}}
v-card-text.pt-5
i18next.body-2(path='common:page.convertTitle', tag='div')
span.blue-grey--text.text--darken-2(place='title') {{pageTitle}}
v-select.mt-5(
:items=`[
{ value: 'markdown', text: 'Markdown' },
{ value: 'ckeditor', text: 'Visual Editor' },
{ value: 'code', text: 'Raw HTML' }
]`
outlined
dense
hide-details
v-model='newEditor'
)
.caption.mt-5 {{$t('common:page.convertSubtitle')}}
v-card-chin
v-spacer
v-btn(text, @click='discard', :disabled='loading') {{$t('common:actions.cancel')}}
v-btn.px-4(color='grey darken-3', @click='convertPage', :loading='loading').white--text {{$t('common:actions.convert')}}
</template>

<script>
import _ from 'lodash'
import { get } from 'vuex-pathify'
import gql from 'graphql-tag'
export default {
props: {
value: {
type: Boolean,
default: false
}
},
data() {
return {
loading: false,
newEditor: ''
}
},
computed: {
isShown: {
get() { return this.value },
set(val) { this.$emit('input', val) }
},
pageTitle: get('page/title'),
pagePath: get('page/path'),
pageLocale: get('page/locale'),
pageId: get('page/id'),
pageEditor: get('page/editor')
},
mounted () {
this.newEditor = this.pageEditor
},
methods: {
discard() {
this.isShown = false
},
async convertPage() {
this.loading = true
this.$store.commit(`loadingStart`, 'page-convert')
this.$nextTick(async () => {
try {
const resp = await this.$apollo.mutate({
mutation: gql`
mutation (
$id: Int!
$editor: String!
) {
pages {
convert(
id: $id
editor: $editor
) {
responseResult {
succeeded
errorCode
slug
message
}
}
}
}
`,
variables: {
id: this.pageId,
editor: this.newEditor
}
})
if (_.get(resp, 'data.pages.convert.responseResult.succeeded', false)) {
this.isShown = false
_.delay(() => {
window.location.assign(`/e/${this.pageLocale}/${this.pagePath}`)
}, 400)
} else {
throw new Error(_.get(resp, 'data.pages.convert.responseResult.message', this.$t('common:error.unexpected')))
}
} catch (err) {
this.$store.commit('pushGraphError', err)
}
this.$store.commit(`loadingStop`, 'page-convert')
this.loading = false
})
}
}
}
</script>

<style lang='scss'>
</style>
1 change: 1 addition & 0 deletions client/store/page.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ const state = {
tags: [],
title: '',
updatedAt: '',
editor: '',
mode: '',
scriptJs: '',
scriptCss: '',
Expand Down
22 changes: 21 additions & 1 deletion client/themes/default/components/page.vue
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,18 @@
)
v-icon(size='20') mdi-code-tags
span {{$t('common:header.viewSource')}}
v-tooltip(:right='$vuetify.rtl', :left='!$vuetify.rtl', v-if='hasWritePagesPermission')
template(v-slot:activator='{ on }')
v-btn(
fab
small
color='white'
light
v-on='on'
@click='pageConvert'
)
v-icon(size='20') mdi-lightning-bolt
span {{$t('common:header.convert')}}
v-tooltip(:right='$vuetify.rtl', :left='!$vuetify.rtl', v-if='hasWritePagesPermission')
template(v-slot:activator='{ on }')
v-btn(
Expand Down Expand Up @@ -314,7 +326,7 @@ import _ from 'lodash'
import ClipboardJS from 'clipboard'
import Vue from 'vue'
Vue.component('tabset', Tabset)
Vue.component('Tabset', Tabset)
Prism.plugins.autoloader.languages_path = '/_assets/js/prism/'
Prism.plugins.NormalizeWhitespace.setDefaults({
Expand Down Expand Up @@ -397,6 +409,10 @@ export default {
type: Number,
default: 0
},
editor: {
type: String,
default: ''
},
isPublished: {
type: Boolean,
default: false
Expand Down Expand Up @@ -516,6 +532,7 @@ export default {
this.$store.set('page/path', this.path)
this.$store.set('page/tags', this.tags)
this.$store.set('page/title', this.title)
this.$store.set('page/editor', this.editor)
this.$store.set('page/updatedAt', this.updatedAt)
if (this.effectivePermissions) {
this.$store.set('page/effectivePermissions', JSON.parse(Buffer.from(this.effectivePermissions, 'base64').toString()))
Expand Down Expand Up @@ -597,6 +614,9 @@ export default {
pageSource () {
this.$root.$emit('pageSource')
},
pageConvert () {
this.$root.$emit('pageConvert')
},
pageDuplicate () {
this.$root.$emit('pageDuplicate')
},
Expand Down
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
"@aoberoi/passport-slack": "1.0.5",
"@azure/storage-blob": "12.2.1",
"@exlinc/keycloak-passport": "1.0.2",
"@joplin/turndown-plugin-gfm": "1.0.27",
"@root/csr": "0.8.1",
"@root/keypairs": "0.10.1",
"@root/pem": "1.0.4",
Expand Down Expand Up @@ -176,6 +177,7 @@
"striptags": "3.1.1",
"subscriptions-transport-ws": "0.9.18",
"tar-fs": "2.1.0",
"turndown": "7.0.0",
"twemoji": "13.0.1",
"uslug": "1.0.4",
"uuid": "8.3.1",
Expand Down
16 changes: 16 additions & 0 deletions server/graph/resolvers/page.js
Original file line number Diff line number Diff line change
Expand Up @@ -398,6 +398,22 @@ module.exports = {
return graphHelper.generateError(err)
}
},
/**
* CONVERT PAGE
*/
async convert(obj, args, context) {
try {
await WIKI.models.pages.convertPage({
...args,
user: context.req.user
})
return {
responseResult: graphHelper.generateSuccess('Page has been converted.')
}
} catch (err) {
return graphHelper.generateError(err)
}
},
/**
* MOVE PAGE
*/
Expand Down
5 changes: 5 additions & 0 deletions server/graph/schemas/page.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,11 @@ type PageMutation {
title: String
): PageResponse @auth(requires: ["write:pages", "manage:pages", "manage:system"])

convert(
id: Int!
editor: String!
): DefaultResponse @auth(requires: ["write:pages", "manage:pages", "manage:system"])

move(
id: Int!
destinationPath: String!
Expand Down
Loading

0 comments on commit 26f1c0f

Please sign in to comment.