history.vue 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  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()
  31. i.nc-icon-outline.design_path-intersect
  32. span {{ $t('history.comparewith') }}
  33. button.button.is-blue-grey()
  34. i.nc-icon-outline.ui-1_eye-17
  35. span {{ $t('history.view') }}
  36. button.button.is-blue-grey()
  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. draw() {
  63. if (diffuiIsReady) {
  64. diffui.draw('#diff', {
  65. inputFormat: 'diff',
  66. outputFormat: this.sidebyside ? 'side-by-side' : 'line-by-line',
  67. matching: 'words',
  68. synchronisedScroll: true
  69. })
  70. }
  71. },
  72. changeCommit(cm) {
  73. let self = this
  74. diffuiIsReady = false
  75. self.current = cm
  76. self.$http.post(siteRoot + '/hist', {
  77. path: self.currentPath,
  78. commit: cm.commit
  79. }).then(resp => {
  80. return resp.json()
  81. }).then(resp => {
  82. diffui = new Diff2HtmlUI({ diff: resp.diff })
  83. diffuiIsReady = true
  84. self.draw()
  85. }).catch(err => {
  86. console.log(err)
  87. self.$store.dispatch('alert', {
  88. style: 'red',
  89. icon: 'square-cross',
  90. msg: 'Error: ' + err.body.error
  91. })
  92. })
  93. }
  94. },
  95. mounted() {
  96. this.versions = JSON.parse(this.historyData)
  97. this.changeCommit(this.versions[0])
  98. }
  99. }
  100. </script>