editor.vue 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. <template lang="pug">
  2. .editor
  3. nav-header
  4. template(slot='actions')
  5. v-btn(outline, color='green', @click.native.stop='save')
  6. v-icon(color='green', left) check
  7. span.white--text(v-if='mode === "create"') {{ $t('common:actions.create') }}
  8. span.white--text(v-else) {{ $t('common:actions.save') }}
  9. v-btn.is-icon(outline, color='red').mx-0: v-icon(color='red') close
  10. v-btn(outline, color='blue', @click.native.stop='openModal(`properties`)', dark)
  11. v-icon(left) sort_by_alpha
  12. span.white--text {{ $t('editor:page') }}
  13. v-content
  14. editor-code
  15. component(:is='currentModal')
  16. v-dialog(v-model='dialogProgress', persistent, max-width='350')
  17. v-card(color='blue darken-3', dark)
  18. v-card-text.text-xs-center.py-4
  19. atom-spinner.is-inline(
  20. :animation-duration='1000'
  21. :size='60'
  22. color='#FFF'
  23. )
  24. .subheading {{ $t('editor:save.processing') }}
  25. .caption.blue--text.text--lighten-3 {{ $t('editor:save.pleaseWait') }}
  26. v-snackbar(
  27. :color='notification.style'
  28. bottom,
  29. right,
  30. multi-line,
  31. v-model='notificationState'
  32. )
  33. .text-xs-left
  34. v-icon.mr-3(dark) {{ notification.icon }}
  35. span {{ notification.message }}
  36. </template>
  37. <script>
  38. import _ from 'lodash'
  39. import { get, sync } from 'vuex-pathify'
  40. import { AtomSpinner } from 'epic-spinners'
  41. import createPageMutation from 'gql/editor/create.gql'
  42. import editorStore from '@/store/editor'
  43. /* global WIKI */
  44. WIKI.$store.registerModule('editor', editorStore)
  45. export default {
  46. components: {
  47. AtomSpinner,
  48. editorCode: () => import(/* webpackChunkName: "editor-code" */ './editor/editor-code.vue'),
  49. editorModalProperties: () => import(/* webpackChunkName: "editor" */ './editor/editor-modal-properties.vue')
  50. },
  51. data() {
  52. return {
  53. currentModal: '',
  54. dialogProgress: false
  55. }
  56. },
  57. computed: {
  58. mode: get('editor/mode'),
  59. notification: get('notification'),
  60. notificationState: sync('notification@isActive')
  61. },
  62. mounted() {
  63. if (this.mode === 'create') {
  64. _.delay(() => {
  65. this.openModal('properties')
  66. }, 500)
  67. }
  68. },
  69. methods: {
  70. openModal(name) {
  71. this.currentModal = `editorModal${_.startCase(name)}`
  72. },
  73. closeModal() {
  74. _.delay(() => {
  75. this.currentModal = ``
  76. }, 500)
  77. },
  78. showProgressDialog(textKey) {
  79. this.dialogProgress = true
  80. },
  81. hideProgressDialog() {
  82. this.dialogProgress = false
  83. },
  84. async save() {
  85. this.showProgressDialog('saving')
  86. if (this.$store.get('editor/mode') === 'create') {
  87. const resp = await this.$apollo.mutate({
  88. mutation: createPageMutation,
  89. variables: {
  90. description: this.$store.get('editor/description'),
  91. editor: 'markdown',
  92. locale: this.$store.get('editor/locale'),
  93. isPublished: this.$store.get('editor/isPublished'),
  94. path: this.$store.get('editor/path'),
  95. publishEndDate: this.$store.get('editor/publishEndDate'),
  96. publishStartDate: this.$store.get('editor/publishStartDate'),
  97. tags: this.$store.get('editor/tags'),
  98. title: this.$store.get('editor/title')
  99. }
  100. })
  101. if (_.get(resp, 'data.pages.create.responseResult.succeeded')) {
  102. this.$store.commit('showNotification', {
  103. message: this.$t('editor:save.success'),
  104. style: 'success',
  105. icon: 'check'
  106. })
  107. this.$store.set('editor/mode', 'update')
  108. } else {
  109. }
  110. } else {
  111. }
  112. this.hideProgressDialog()
  113. }
  114. }
  115. }
  116. </script>
  117. <style lang='scss'>
  118. .atom-spinner.is-inline {
  119. display: inline-block;
  120. }
  121. </style>