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.

195 lines
6.3 KiB

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