history.vue 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. <template lang="pug">
  2. .container.is-fluid
  3. .columns.is-gapless
  4. .column.is-narrow.is-hidden-touch.sidebar
  5. aside.stickyscroll
  6. .sidebar-label
  7. span {{ $t('history.pastversions') }}
  8. ul.sidebar-menu
  9. li(v-for='item in versions')
  10. a.is-multiline(:title='item.dateFull', @click='changeCommit(item)', :class='{ "is-active": item.commit === current.commit }')
  11. span {{ item.dateCalendar }}
  12. span.is-small {{ item.commitAbbr }}
  13. .column
  14. .history
  15. .history-title {{ currentPath }}
  16. .history-info
  17. .columns
  18. .column.history-info-meta
  19. p
  20. i.nc-icon-outline.ui-1_calendar-check-62
  21. span {{ $t('history.timestamp') }}: #[strong {{ current.dateFull }}]
  22. p
  23. i.nc-icon-outline.i.nc-icon-outline.users_man-23
  24. span {{ $t('history.author') }}: #[strong {{ current.name }} &lt;{{ current.email }}&gt;]
  25. p
  26. i.nc-icon-outline.media-1_flash-21
  27. span {{ $t('history.commit') }}: #[strong {{ current.commit }}]
  28. .column.history-info-actions
  29. .button-group
  30. button.button.is-blue-grey(@click='compareWith')
  31. i.nc-icon-outline.design_path-intersect
  32. span {{ $t('history.comparewith') }}
  33. button.button.is-blue-grey(@click='view')
  34. i.nc-icon-outline.ui-1_eye-17
  35. span {{ $t('history.view') }}
  36. button.button.is-blue-grey(@click='revertToVersion')
  37. i.nc-icon-outline.arrows-4_undo-29
  38. span {{ $t('history.reverttoversion') }}
  39. toggle.is-dark(v-model='sidebyside', :desc='$t("history.sidebyside")')
  40. .history-diff#diff
  41. </template>
  42. <script>
  43. /* global wiki, Diff2HtmlUI */
  44. let diffui
  45. let diffuiIsReady = false
  46. export default {
  47. name: 'history',
  48. props: ['currentPath', 'historyData'],
  49. data() {
  50. return {
  51. versions: [],
  52. current: {},
  53. diffui: {},
  54. sidebyside: true
  55. }
  56. },
  57. watch: {
  58. sidebyside() {
  59. this.draw()
  60. }
  61. },
  62. methods: {
  63. compareWith() {
  64. this.$store.dispatch('alert', {
  65. style: 'purple',
  66. icon: 'objects_astronaut',
  67. msg: 'Sorry, this function is not available. Coming soon!'
  68. })
  69. },
  70. view() {
  71. this.$store.dispatch('alert', {
  72. style: 'purple',
  73. icon: 'objects_astronaut',
  74. msg: 'Sorry, this function is not available. Coming soon!'
  75. })
  76. },
  77. revertToVersion() {
  78. this.$store.dispatch('alert', {
  79. style: 'purple',
  80. icon: 'objects_astronaut',
  81. msg: 'Sorry, this function is not available. Coming soon!'
  82. })
  83. },
  84. draw() {
  85. if (diffuiIsReady) {
  86. diffui.draw('#diff', {
  87. inputFormat: 'diff',
  88. outputFormat: this.sidebyside ? 'side-by-side' : 'line-by-line',
  89. matching: 'words',
  90. synchronisedScroll: true
  91. })
  92. }
  93. },
  94. changeCommit(cm) {
  95. let self = this
  96. diffuiIsReady = false
  97. self.current = cm
  98. self.$http.post(wiki.siteRoot + '/hist', {
  99. path: self.currentPath,
  100. commit: cm.commit
  101. }).then(resp => {
  102. return resp.json()
  103. }).then(resp => {
  104. diffui = new Diff2HtmlUI({ diff: resp.diff })
  105. diffuiIsReady = true
  106. self.draw()
  107. }).catch(err => {
  108. console.log(err)
  109. self.$store.dispatch('alert', {
  110. style: 'red',
  111. icon: 'ui-2_square-remove-09',
  112. msg: 'Error: ' + err.body.error
  113. })
  114. })
  115. }
  116. },
  117. mounted() {
  118. this.versions = JSON.parse(this.historyData)
  119. this.changeCommit(this.versions[0])
  120. }
  121. }
  122. </script>