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.

120 lines
3.2 KiB

  1. <template lang='pug'>
  2. v-dialog(
  3. v-model='isShown'
  4. max-width='550'
  5. persistent
  6. overlay-color='blue-grey darken-4'
  7. overlay-opacity='.7'
  8. )
  9. v-card
  10. .dialog-header.is-short.is-dark
  11. v-icon.mr-2(color='white') mdi-lightning-bolt
  12. span {{$t('common:page.convert')}}
  13. v-card-text.pt-5
  14. i18next.body-2(path='common:page.convertTitle', tag='div')
  15. span.blue-grey--text.text--darken-2(place='title') {{pageTitle}}
  16. v-select.mt-5(
  17. :items=`[
  18. { value: 'markdown', text: 'Markdown' },
  19. { value: 'ckeditor', text: 'Visual Editor' },
  20. { value: 'code', text: 'Raw HTML' }
  21. ]`
  22. outlined
  23. dense
  24. hide-details
  25. v-model='newEditor'
  26. )
  27. .caption.mt-5 {{$t('common:page.convertSubtitle')}}
  28. v-card-chin
  29. v-spacer
  30. v-btn(text, @click='discard', :disabled='loading') {{$t('common:actions.cancel')}}
  31. v-btn.px-4(color='grey darken-3', @click='convertPage', :loading='loading').white--text {{$t('common:actions.convert')}}
  32. </template>
  33. <script>
  34. import _ from 'lodash'
  35. import { get } from 'vuex-pathify'
  36. import gql from 'graphql-tag'
  37. export default {
  38. props: {
  39. value: {
  40. type: Boolean,
  41. default: false
  42. }
  43. },
  44. data() {
  45. return {
  46. loading: false,
  47. newEditor: ''
  48. }
  49. },
  50. computed: {
  51. isShown: {
  52. get() { return this.value },
  53. set(val) { this.$emit('input', val) }
  54. },
  55. pageTitle: get('page/title'),
  56. pagePath: get('page/path'),
  57. pageLocale: get('page/locale'),
  58. pageId: get('page/id'),
  59. pageEditor: get('page/editor')
  60. },
  61. mounted () {
  62. this.newEditor = this.pageEditor
  63. },
  64. methods: {
  65. discard() {
  66. this.isShown = false
  67. },
  68. async convertPage() {
  69. this.loading = true
  70. this.$store.commit(`loadingStart`, 'page-convert')
  71. this.$nextTick(async () => {
  72. try {
  73. const resp = await this.$apollo.mutate({
  74. mutation: gql`
  75. mutation (
  76. $id: Int!
  77. $editor: String!
  78. ) {
  79. pages {
  80. convert(
  81. id: $id
  82. editor: $editor
  83. ) {
  84. responseResult {
  85. succeeded
  86. errorCode
  87. slug
  88. message
  89. }
  90. }
  91. }
  92. }
  93. `,
  94. variables: {
  95. id: this.pageId,
  96. editor: this.newEditor
  97. }
  98. })
  99. if (_.get(resp, 'data.pages.convert.responseResult.succeeded', false)) {
  100. this.isShown = false
  101. window.location.assign(`/e/${this.pageLocale}/${this.pagePath}`)
  102. } else {
  103. throw new Error(_.get(resp, 'data.pages.convert.responseResult.message', this.$t('common:error.unexpected')))
  104. }
  105. } catch (err) {
  106. this.$store.commit('pushGraphError', err)
  107. }
  108. this.$store.commit(`loadingStop`, 'page-convert')
  109. this.loading = false
  110. })
  111. }
  112. }
  113. }
  114. </script>
  115. <style lang='scss'>
  116. </style>