wikijs-fork/client/js/components/history.vue

128 lines
3.8 KiB
Vue
Raw Normal View History

<template lang="pug">
2017-07-04 04:52:37 +00:00
.container.is-fluid
.columns.is-gapless
.column.is-narrow.is-hidden-touch.sidebar
aside.stickyscroll
.sidebar-label
2017-07-06 04:10:41 +00:00
span {{ $t('history.pastversions') }}
2017-07-04 04:52:37 +00:00
ul.sidebar-menu
li(v-for='item in versions')
2017-07-06 04:10:41 +00:00
a.is-multiline(:title='item.dateFull', @click='changeCommit(item)', :class='{ "is-active": item.commit === current.commit }')
2017-07-04 04:52:37 +00:00
span {{ item.dateCalendar }}
span.is-small {{ item.commitAbbr }}
.column
.history
.history-title {{ currentPath }}
.history-info
.columns
.column.history-info-meta
p
i.nc-icon-outline.ui-1_calendar-check-62
2017-07-06 04:10:41 +00:00
span {{ $t('history.timestamp') }}: #[strong {{ current.dateFull }}]
2017-07-04 04:52:37 +00:00
p
i.nc-icon-outline.i.nc-icon-outline.users_man-23
2017-07-06 04:10:41 +00:00
span {{ $t('history.author') }}: #[strong {{ current.name }} &lt;{{ current.email }}&gt;]
2017-07-04 04:52:37 +00:00
p
i.nc-icon-outline.media-1_flash-21
2017-07-06 04:10:41 +00:00
span {{ $t('history.commit') }}: #[strong {{ current.commit }}]
2017-07-04 04:52:37 +00:00
.column.history-info-actions
.button-group
2017-07-08 21:33:09 +00:00
button.button.is-blue-grey(@click='compareWith')
2017-07-04 04:52:37 +00:00
i.nc-icon-outline.design_path-intersect
2017-07-06 04:10:41 +00:00
span {{ $t('history.comparewith') }}
2017-07-08 21:33:09 +00:00
button.button.is-blue-grey(@click='view')
2017-07-04 04:52:37 +00:00
i.nc-icon-outline.ui-1_eye-17
2017-07-06 04:10:41 +00:00
span {{ $t('history.view') }}
2017-07-08 21:33:09 +00:00
button.button.is-blue-grey(@click='revertToVersion')
2017-07-04 04:52:37 +00:00
i.nc-icon-outline.arrows-4_undo-29
2017-07-06 04:10:41 +00:00
span {{ $t('history.reverttoversion') }}
toggle.is-dark(v-model='sidebyside', :desc='$t("history.sidebyside")')
2017-07-04 04:52:37 +00:00
.history-diff#diff
2017-07-02 22:15:05 +00:00
</template>
<script>
2017-10-30 01:36:05 +00:00
/* global wiki, Diff2HtmlUI */
2017-07-02 22:15:05 +00:00
let diffui
2017-07-06 04:10:41 +00:00
let diffuiIsReady = false
export default {
name: 'history',
2017-07-04 04:52:37 +00:00
props: ['currentPath', 'historyData'],
data() {
return {
2017-07-04 04:52:37 +00:00
versions: [],
2017-07-06 04:10:41 +00:00
current: {},
2017-07-02 22:15:05 +00:00
diffui: {},
sidebyside: true
}
},
2017-07-04 04:52:37 +00:00
watch: {
sidebyside() {
this.draw()
}
},
methods: {
2017-07-08 21:33:09 +00:00
compareWith() {
this.$store.dispatch('alert', {
style: 'purple',
icon: 'objects_astronaut',
msg: 'Sorry, this function is not available. Coming soon!'
})
},
view() {
this.$store.dispatch('alert', {
style: 'purple',
icon: 'objects_astronaut',
msg: 'Sorry, this function is not available. Coming soon!'
})
},
revertToVersion() {
this.$store.dispatch('alert', {
style: 'purple',
icon: 'objects_astronaut',
msg: 'Sorry, this function is not available. Coming soon!'
})
},
2017-07-02 22:15:05 +00:00
draw() {
2017-07-06 04:10:41 +00:00
if (diffuiIsReady) {
diffui.draw('#diff', {
inputFormat: 'diff',
outputFormat: this.sidebyside ? 'side-by-side' : 'line-by-line',
matching: 'words',
synchronisedScroll: true
})
}
},
changeCommit(cm) {
let self = this
diffuiIsReady = false
self.current = cm
2017-10-30 01:36:05 +00:00
self.$http.post(wiki.siteRoot + '/hist', {
2017-07-06 04:10:41 +00:00
path: self.currentPath,
commit: cm.commit
}).then(resp => {
return resp.json()
}).then(resp => {
diffui = new Diff2HtmlUI({ diff: resp.diff })
diffuiIsReady = true
self.draw()
}).catch(err => {
console.log(err)
self.$store.dispatch('alert', {
style: 'red',
2017-07-08 21:33:09 +00:00
icon: 'ui-2_square-remove-09',
2017-07-06 04:10:41 +00:00
msg: 'Error: ' + err.body.error
})
})
}
},
mounted() {
2017-07-04 04:52:37 +00:00
this.versions = JSON.parse(this.historyData)
2017-07-06 04:10:41 +00:00
this.changeCommit(this.versions[0])
}
}
</script>