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.

125 lines
3.7 KiB

  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. let diffui
  44. let diffuiIsReady = false
  45. export default {
  46. name: 'history',
  47. props: ['currentPath', 'historyData'],
  48. data() {
  49. return {
  50. versions: [],
  51. current: {},
  52. diffui: {},
  53. sidebyside: true
  54. }
  55. },
  56. watch: {
  57. sidebyside() {
  58. this.draw()
  59. }
  60. },
  61. methods: {
  62. compareWith() {
  63. this.$store.dispatch('alert', {
  64. style: 'purple',
  65. icon: 'objects_astronaut',
  66. msg: 'Sorry, this function is not available. Coming soon!'
  67. })
  68. },
  69. view() {
  70. this.$store.dispatch('alert', {
  71. style: 'purple',
  72. icon: 'objects_astronaut',
  73. msg: 'Sorry, this function is not available. Coming soon!'
  74. })
  75. },
  76. revertToVersion() {
  77. this.$store.dispatch('alert', {
  78. style: 'purple',
  79. icon: 'objects_astronaut',
  80. msg: 'Sorry, this function is not available. Coming soon!'
  81. })
  82. },
  83. draw() {
  84. if (diffuiIsReady) {
  85. diffui.draw('#diff', {
  86. inputFormat: 'diff',
  87. outputFormat: this.sidebyside ? 'side-by-side' : 'line-by-line',
  88. matching: 'words',
  89. synchronisedScroll: true
  90. })
  91. }
  92. },
  93. changeCommit(cm) {
  94. let self = this
  95. diffuiIsReady = false
  96. self.current = cm
  97. self.$http.post(siteRoot + '/hist', {
  98. path: self.currentPath,
  99. commit: cm.commit
  100. }).then(resp => {
  101. return resp.json()
  102. }).then(resp => {
  103. diffui = new Diff2HtmlUI({ diff: resp.diff })
  104. diffuiIsReady = true
  105. self.draw()
  106. }).catch(err => {
  107. console.log(err)
  108. self.$store.dispatch('alert', {
  109. style: 'red',
  110. icon: 'ui-2_square-remove-09',
  111. msg: 'Error: ' + err.body.error
  112. })
  113. })
  114. }
  115. },
  116. mounted() {
  117. this.versions = JSON.parse(this.historyData)
  118. this.changeCommit(this.versions[0])
  119. }
  120. }
  121. </script>