conflict.vue 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. <template lang="pug">
  2. v-dialog(
  3. v-model='isShown'
  4. max-width='700'
  5. )
  6. v-card
  7. .dialog-header.is-short.is-indigo
  8. v-icon.mr-2(color='white') mdi-alert
  9. span {{$t('editor:conflict.title')}}
  10. v-card-text.pt-4
  11. i18next.body-2(tag='div', path='editor:conflict.infoGeneric')
  12. strong(place='authorName') {{latest.authorName}}
  13. span(place='date', :title='$options.filters.moment(latest.updatedAt, `LLL`)') {{ latest.updatedAt | moment('from') }}.
  14. v-btn.mt-2(outlined, color='indigo', small, :href='`/` + latest.locale + `/` + latest.path', target='_blank')
  15. v-icon(left) mdi-open-in-new
  16. span {{$t('editor:conflict.viewLatestVersion')}}
  17. .body-2.mt-5: strong {{$t('editor:conflict.whatToDo')}}
  18. .body-2.mt-1 #[v-icon(color='indigo') mdi-alpha-l-box] {{$t('editor:conflict.whatToDoLocal')}}
  19. .body-2.mt-1 #[v-icon(color='indigo') mdi-alpha-r-box] {{$t('editor:conflict.whatToDoRemote')}}
  20. v-card-chin
  21. v-spacer
  22. v-btn(text, @click='close') {{$t('common:actions.cancel')}}
  23. v-btn.px-4(color='indigo', @click='useLocal', dark, :title='$t(`editor:conflict.useLocalHint`)')
  24. v-icon(left) mdi-alpha-l-box
  25. span {{$t('editor:conflict.useLocal')}}
  26. v-dialog(
  27. v-model='isRemoteConfirmDiagShown'
  28. width='500'
  29. )
  30. template(v-slot:activator='{ on }')
  31. v-btn.ml-3(color='indigo', dark, v-on='on', :title='$t(`editor:conflict.useRemoteHint`)')
  32. v-icon(left) mdi-alpha-r-box
  33. span {{$t('editor:conflict.useRemote')}}
  34. v-card
  35. .dialog-header.is-short.is-indigo
  36. v-icon.mr-3(color='white') mdi-alpha-r-box
  37. span {{$t('editor:conflict.overwrite.title')}}
  38. v-card-text.pa-4
  39. i18next.body-2(tag='div', path='editor:conflict.overwrite.description')
  40. strong(place='refEditsLost') {{$t('editor:conflict.overwrite.editsLost')}}
  41. v-card-chin
  42. v-spacer
  43. v-btn(outlined, color='indigo', @click='isRemoteConfirmDiagShown = false')
  44. v-icon(left) mdi-close
  45. span {{$t('common:actions.cancel')}}
  46. v-btn(@click='useRemote', color='indigo', dark)
  47. v-icon(left) mdi-check
  48. span {{$t('common:actions.confirm')}}
  49. </template>
  50. <script>
  51. import _ from 'lodash'
  52. import gql from 'graphql-tag'
  53. export default {
  54. props: {
  55. value: {
  56. type: Boolean,
  57. default: false
  58. }
  59. },
  60. data() {
  61. return {
  62. latest: {
  63. updatedAt: '',
  64. authorName: '',
  65. content: '',
  66. locale: '',
  67. path: ''
  68. },
  69. isRemoteConfirmDiagShown: false
  70. }
  71. },
  72. computed: {
  73. isShown: {
  74. get() { return this.value },
  75. set(val) { this.$emit('input', val) }
  76. }
  77. },
  78. methods: {
  79. close () {
  80. this.isShown = false
  81. },
  82. useLocal () {
  83. this.$store.set('editor/checkoutDateActive', this.latest.updatedAt)
  84. this.$root.$emit('resetEditorConflict')
  85. this.close()
  86. },
  87. useRemote () {
  88. this.$store.set('editor/checkoutDateActive', this.latest.updatedAt)
  89. this.$store.set('editor/content', this.latest.content)
  90. this.$root.$emit('overwriteEditorContent')
  91. this.$root.$emit('resetEditorConflict')
  92. this.close()
  93. }
  94. },
  95. async mounted () {
  96. let resp = await this.$apollo.query({
  97. query: gql`
  98. query ($id: Int!) {
  99. pages {
  100. conflictLatest(id: $id) {
  101. authorName
  102. locale
  103. path
  104. content
  105. updatedAt
  106. }
  107. }
  108. }
  109. `,
  110. fetchPolicy: 'network-only',
  111. variables: {
  112. id: this.$store.get('page/id')
  113. }
  114. })
  115. resp = _.get(resp, 'data.pages.conflictLatest', false)
  116. if (!resp) {
  117. return this.$store.commit('showNotification', {
  118. message: 'Failed to fetch latest version.',
  119. style: 'warning',
  120. icon: 'warning'
  121. })
  122. }
  123. this.latest = resp
  124. }
  125. }
  126. </script>