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

@@ -24,6 +24,7 @@
v-card-text.pt-0
template(v-for='(pm, idx) in pmGroup.items')
v-checkbox.pt-0(
style='justify-content: space-between;'
:key='pm.permission'
:label='pm.permission'
:hint='pm.hint'
@@ -60,14 +61,14 @@ export default {
},
{
permission: 'write:pages',
hint: 'Can create new pages, as specified in the Page Rules',
hint: 'Can create / edit pages, as specified in the Page Rules',
warning: false,
restrictedForSystem: false,
disabled: false
},
{
permission: 'manage:pages',
hint: 'Can edit and move existing pages as specified in the Page Rules',
hint: 'Can move existing pages as specified in the Page Rules',
warning: false,
restrictedForSystem: false,
disabled: false

View File

@@ -105,7 +105,7 @@
v-icon(left) mdi-code-tags
span Source
v-divider.mx-2(vertical)
v-btn(color='primary', text, :href='`/h/` + page.locale + `/` + page.path')
v-btn(color='primary', text, :href='`/h/` + page.locale + `/` + page.path', disabled)
v-icon(left) mdi-history
span History
v-spacer

View File

@@ -3,6 +3,12 @@
v-toolbar(flat, color='primary', dark, dense)
.subtitle-1 {{ $t('admin:utilities.contentTitle') }}
v-card-text
.subtitle-1.pb-3.primary--text Rebuild Page Tree
.body-2 The virtual structure of your wiki is automatically inferred from all page paths. You can trigger a full rebuild of the tree if some virtual folders are missing or not valid anymore.
v-btn(outlined, color='primary', @click='rebuildTree', :disabled='loading').ml-0.mt-3
v-icon(left) mdi-gesture-double-tap
span Proceed
v-divider.my-5
.subtitle-1.pb-3.pl-0.primary--text Migrate all pages to target locale
.body-2 If you created content before selecting a different locale and activating the namespacing capabilities, you may want to transfer all content to the base locale.
.body-2.red--text: strong This operation is destructive and cannot be reversed! Make sure you have proper backups!
@@ -35,6 +41,7 @@
<script>
import _ from 'lodash'
import utilityContentMigrateLocaleMutation from 'gql/admin/utilities/utilities-mutation-content-migratelocale.gql'
import utilityContentRebuildTreeMutation from 'gql/admin/utilities/utilities-mutation-content-rebuildtree.gql'
/* global siteLangs, siteConfig */
@@ -55,7 +62,32 @@ export default {
}
},
methods: {
async migrateToLocale() {
async rebuildTree () {
this.loading = true
this.$store.commit(`loadingStart`, 'admin-utilities-content-rebuildtree')
try {
const respRaw = await this.$apollo.mutate({
mutation: utilityContentRebuildTreeMutation
})
const resp = _.get(respRaw, 'data.pages.rebuildTree.responseResult', {})
if (resp.succeeded) {
this.$store.commit('showNotification', {
message: 'Page Tree rebuilt successfully.',
style: 'success',
icon: 'check'
})
} else {
throw new Error(resp.message)
}
} catch (err) {
this.$store.commit('pushGraphError', err)
}
this.$store.commit(`loadingStop`, 'admin-utilities-content-rebuildtree')
this.loading = false
},
async migrateToLocale () {
this.loading = true
this.$store.commit(`loadingStart`, 'admin-utilities-content-migratelocale')

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: {

View File

@@ -249,6 +249,11 @@ export default {
style: 'success',
icon: 'check'
})
if (this.locale !== this.$store.get('page/locale') || this.path !== this.$store.get('page/path')) {
_.delay(() => {
window.location.replace(`/e/${this.$store.get('page/locale')}/${this.$store.get('page/path')}`)
}, 1000)
}
} else {
throw new Error(_.get(resp, 'responseResult.message'))
}

View File

@@ -52,7 +52,6 @@
:items='namespaces'
v-model='locale'
hide-details
:disabled='mode !== "create"'
)
v-flex(xs12, md10)
v-text-field(
@@ -63,7 +62,6 @@
:hint='$t(`editor:props.pathHint`)'
persistent-hint
@click:append='showPathSelector'
:disabled='mode !== "create"'
)
v-divider
v-card-text.grey.pt-5(:class='darkMode ? `darken-3-d5` : `lighten-4`')
@@ -219,7 +217,7 @@
inset
)
page-selector(mode='create', v-model='pageSelectorShown', :path='path', :locale='locale', :open-handler='setPath')
page-selector(:mode='pageSelectorMode', v-model='pageSelectorShown', :path='path', :locale='locale', :open-handler='setPath')
</template>
<script>
@@ -257,7 +255,10 @@ export default {
path: sync('page/path'),
isPublished: sync('page/isPublished'),
publishStartDate: sync('page/publishStartDate'),
publishEndDate: sync('page/publishEndDate')
publishEndDate: sync('page/publishEndDate'),
pageSelectorMode () {
return (this.mode === 'create') ? 'create' : 'move'
}
},
watch: {
value(newValue, oldValue) {