You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

93 lines
3.0 KiB

  1. <template lang='pug'>
  2. v-card
  3. v-toolbar(flat, color='primary', dark, dense)
  4. .subtitle-1 {{ $t('admin:utilities.contentTitle') }}
  5. v-card-text
  6. .subtitle-1.pb-3.pl-0.primary--text Migrate all pages to target locale
  7. .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.
  8. .body-2.red--text: strong This operation is destructive and cannot be reversed! Make sure you have proper backups!
  9. v-toolbar.radius-7.mt-5(flat, :color='$vuetify.theme.dark ? `grey darken-3-d5` : `grey lighten-4`', height='80')
  10. v-select(
  11. label='Source Locale'
  12. outlined
  13. hide-details
  14. :items='locales'
  15. item-text='name'
  16. item-value='code'
  17. v-model='sourceLocale'
  18. )
  19. v-icon.mx-3(large) mdi-chevron-right-box-outline
  20. v-select(
  21. label='Target Locale'
  22. outlined
  23. hide-details
  24. :items='locales'
  25. item-text='name'
  26. item-value='code'
  27. v-model='targetLocale'
  28. )
  29. .body-2.mt-5 Pages that are already in the target locale will not be touched. If a page already exists at the target, the source page will not be modified as it would create a conflict. If you want to overwrite the target page, you must first delete it.
  30. v-btn(outlined, color='primary', @click='migrateToLocale', :disabled='loading').ml-0.mt-3
  31. v-icon(left) mdi-gesture-double-tap
  32. span Proceed
  33. </template>
  34. <script>
  35. import _ from 'lodash'
  36. import utilityContentMigrateLocaleMutation from 'gql/admin/utilities/utilities-mutation-content-migratelocale.gql'
  37. /* global siteLangs, siteConfig */
  38. export default {
  39. data: () => {
  40. return {
  41. loading: false,
  42. sourceLocale: '',
  43. targetLocale: ''
  44. }
  45. },
  46. computed: {
  47. currentLocale () {
  48. return siteConfig.lang
  49. },
  50. locales () {
  51. return siteLangs
  52. }
  53. },
  54. methods: {
  55. async migrateToLocale() {
  56. this.loading = true
  57. this.$store.commit(`loadingStart`, 'admin-utilities-content-migratelocale')
  58. try {
  59. const respRaw = await this.$apollo.mutate({
  60. mutation: utilityContentMigrateLocaleMutation,
  61. variables: {
  62. sourceLocale: this.sourceLocale,
  63. targetLocale: this.targetLocale
  64. }
  65. })
  66. const resp = _.get(respRaw, 'data.pages.migrateToLocale.responseResult', {})
  67. if (resp.succeeded) {
  68. this.$store.commit('showNotification', {
  69. message: `Migrated ${_.get(respRaw, 'data.pages.migrateToLocale.count', 0)} page(s) to target locale successfully.`,
  70. style: 'success',
  71. icon: 'check'
  72. })
  73. } else {
  74. throw new Error(resp.message)
  75. }
  76. } catch (err) {
  77. this.$store.commit('pushGraphError', err)
  78. }
  79. this.$store.commit(`loadingStop`, 'admin-utilities-content-migratelocale')
  80. this.loading = false
  81. }
  82. }
  83. }
  84. </script>
  85. <style lang='scss'>
  86. </style>