editor.vue 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  1. <template lang="pug">
  2. .editor
  3. nav-header(dense)
  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(outline, color='red').mx-0
  10. v-icon(color='red', left) close
  11. span.white--text {{ $t('common:actions.discard') }}
  12. v-btn(outline, color='blue', @click.native.stop='openModal(`properties`)', dark)
  13. v-icon(left) sort_by_alpha
  14. span.white--text {{ $t('editor:page') }}
  15. v-content
  16. editor-code
  17. component(:is='currentModal')
  18. v-dialog(v-model='dialogProgress', persistent, max-width='350')
  19. v-card(color='blue darken-3', dark)
  20. v-card-text.text-xs-center.py-4
  21. atom-spinner.is-inline(
  22. :animation-duration='1000'
  23. :size='60'
  24. color='#FFF'
  25. )
  26. .subheading {{ $t('editor:save.processing') }}
  27. .caption.blue--text.text--lighten-3 {{ $t('editor:save.pleaseWait') }}
  28. v-snackbar(
  29. :color='notification.style'
  30. bottom,
  31. right,
  32. multi-line,
  33. v-model='notificationState'
  34. )
  35. .text-xs-left
  36. v-icon.mr-3(dark) {{ notification.icon }}
  37. span {{ notification.message }}
  38. </template>
  39. <script>
  40. import _ from 'lodash'
  41. import { get, sync } from 'vuex-pathify'
  42. import { AtomSpinner } from 'epic-spinners'
  43. import createPageMutation from 'gql/editor/create.gql'
  44. import updatePageMutation from 'gql/editor/update.gql'
  45. import editorStore from '@/store/editor'
  46. /* global WIKI */
  47. WIKI.$store.registerModule('editor', editorStore)
  48. export default {
  49. components: {
  50. AtomSpinner,
  51. editorCode: () => import(/* webpackChunkName: "editor-code" */ './editor/editor-code.vue'),
  52. editorModalProperties: () => import(/* webpackChunkName: "editor" */ './editor/editor-modal-properties.vue')
  53. },
  54. data() {
  55. return {
  56. currentModal: '',
  57. dialogProgress: false
  58. }
  59. },
  60. computed: {
  61. mode: get('editor/mode'),
  62. notification: get('notification'),
  63. notificationState: sync('notification@isActive')
  64. },
  65. mounted() {
  66. if (this.mode === 'create') {
  67. _.delay(() => {
  68. this.openModal('properties')
  69. }, 500)
  70. }
  71. },
  72. methods: {
  73. openModal(name) {
  74. this.currentModal = `editorModal${_.startCase(name)}`
  75. },
  76. closeModal() {
  77. _.delay(() => {
  78. this.currentModal = ``
  79. }, 500)
  80. },
  81. showProgressDialog(textKey) {
  82. this.dialogProgress = true
  83. },
  84. hideProgressDialog() {
  85. this.dialogProgress = false
  86. },
  87. async save() {
  88. this.showProgressDialog('saving')
  89. try {
  90. if (this.$store.get('editor/mode') === 'create') {
  91. // --------------------------------------------
  92. // -> CREATE PAGE
  93. // --------------------------------------------
  94. let resp = await this.$apollo.mutate({
  95. mutation: createPageMutation,
  96. variables: {
  97. content: this.$store.get('editor/content'),
  98. description: this.$store.get('editor/description'),
  99. editor: 'markdown',
  100. locale: this.$store.get('editor/locale'),
  101. isPrivate: false,
  102. isPublished: this.$store.get('editor/isPublished'),
  103. path: this.$store.get('editor/path'),
  104. publishEndDate: this.$store.get('editor/publishEndDate'),
  105. publishStartDate: this.$store.get('editor/publishStartDate'),
  106. tags: this.$store.get('editor/tags'),
  107. title: this.$store.get('editor/title')
  108. }
  109. })
  110. resp = _.get(resp, 'data.pages.create', {})
  111. if (_.get(resp, 'responseResult.succeeded')) {
  112. this.$store.commit('showNotification', {
  113. message: this.$t('editor:save.success'),
  114. style: 'success',
  115. icon: 'check'
  116. })
  117. this.$store.set('editor/id', _.get(resp, 'page.id'))
  118. this.$store.set('editor/mode', 'update')
  119. } else {
  120. throw new Error(_.get(resp, 'responseResult.message'))
  121. }
  122. } else {
  123. // --------------------------------------------
  124. // -> UPDATE EXISTING PAGE
  125. // --------------------------------------------
  126. let resp = await this.$apollo.mutate({
  127. mutation: updatePageMutation,
  128. variables: {
  129. id: this.$store.get('editor/id'),
  130. content: this.$store.get('editor/content'),
  131. description: this.$store.get('editor/description'),
  132. editor: 'markdown',
  133. locale: this.$store.get('editor/locale'),
  134. isPrivate: false,
  135. isPublished: this.$store.get('editor/isPublished'),
  136. path: this.$store.get('editor/path'),
  137. publishEndDate: this.$store.get('editor/publishEndDate'),
  138. publishStartDate: this.$store.get('editor/publishStartDate'),
  139. tags: this.$store.get('editor/tags'),
  140. title: this.$store.get('editor/title')
  141. }
  142. })
  143. resp = _.get(resp, 'data.pages.update', {})
  144. if (_.get(resp, 'responseResult.succeeded')) {
  145. this.$store.commit('showNotification', {
  146. message: this.$t('editor:save.success'),
  147. style: 'success',
  148. icon: 'check'
  149. })
  150. } else {
  151. throw new Error(_.get(resp, 'responseResult.message'))
  152. }
  153. }
  154. } catch (err) {
  155. this.$store.commit('showNotification', {
  156. message: err.message,
  157. style: 'error',
  158. icon: 'warning'
  159. })
  160. }
  161. this.hideProgressDialog()
  162. }
  163. }
  164. }
  165. </script>
  166. <style lang='scss'>
  167. .atom-spinner.is-inline {
  168. display: inline-block;
  169. }
  170. </style>