feat: move page

This commit is contained in:
NGPixel
2019-10-13 19:59:50 -04:00
parent daa8174d7f
commit 62d1d7a1df
23 changed files with 451 additions and 99 deletions

View File

@@ -204,6 +204,8 @@ import { get, sync } from 'vuex-pathify'
import _ from 'lodash'
import Cookies from 'js-cookie'
import movePageMutation from 'gql/common/common-pages-mutation-move.gql'
/* global siteLangs */
export default {
@@ -342,8 +344,26 @@ export default {
pageMove () {
this.movePageModal = true
},
pageMoveRename ({ path, locale }) {
async pageMoveRename ({ path, locale }) {
this.$store.commit(`loadingStart`, 'page-move')
try {
const resp = await this.$apollo.mutate({
mutation: movePageMutation,
variables: {
id: this.$store.get('page/id'),
destinationLocale: locale,
destinationPath: path
}
})
if (_.get(resp, 'data.pages.move.responseResult.succeeded', false)) {
window.location.replace(`/${locale}/${path}`)
} else {
throw new Error(_.get(resp, 'data.pages.move.responseResult.message', this.$t('common:error.unexpected')))
}
} catch (err) {
this.$store.commit('pushGraphError', err)
this.$store.commit(`loadingStop`, 'page-move')
}
},
pageDelete () {
this.deletePageModal = true

View File

@@ -98,6 +98,8 @@ import _ from 'lodash'
import { get } from 'vuex-pathify'
import pageTreeQuery from 'gql/common/common-pages-query-tree.gql'
const localeSegmentRegex = /^[A-Z]{2}(-[A-Z]{2})?$/i
/* global siteLangs, siteConfig */
export default {
@@ -152,7 +154,22 @@ export default {
return _.sortBy(_.filter(this.pages, ['parent', _.head(this.currentNode) || 0]), ['title', 'path'])
},
isValidPath () {
return this.currentPath && this.currentPath.length > 2
if (!this.currentPath) {
return false
}
const firstSection = _.head(this.currentPath.split('/'))
if (firstSection.length <= 1) {
return false
} else if (localeSegmentRegex.test(firstSection)) {
return false
} else if (
_.some(['login', 'logout', 'register', 'verify', 'favicons', 'fonts', 'img', 'js', 'svg'], p => {
return p === firstSection
})) {
return false
} else {
return true
}
}
},
watch: {