Site > Versions > Active latest and keep active

This commit is contained in:
brunosimon
2017-08-29 19:48:52 +01:00
parent 2530f6ba5a
commit f2ca2ac277
7 changed files with 51 additions and 13 deletions
+1 -1
View File
@@ -3,6 +3,6 @@
File
{{ content.path.directory }} {{ content.name }}
</header>
<versions :content="content.versions"></versions>
<versions :file="content" :content="content.versions"></versions>
<viewer></viewer>
</div>
-8
View File
@@ -5,13 +5,5 @@ export default
props:
{
content: { type: Object }
},
methods:
{
onClick()
{
this.$store.commit('setVersion', this.content)
}
}
}
+2
View File
@@ -0,0 +1,2 @@
.version
display block
+1 -1
View File
@@ -1,3 +1,3 @@
<a href="#" class="version" @click.prevent="onClick">
<a href="#" class="version">
{{ content.date }}
</a>
+43 -1
View File
@@ -11,13 +11,15 @@ export default
props:
{
content: { type: Array }
content: { type: Array },
file: { type: Object }
},
computed:
{
versions()
{
// console.log('uh')
const versions = this.content.sort((versionA, versionB) =>
{
const dateA = new Date(versionA.date)
@@ -28,5 +30,45 @@ export default
return versions
}
},
watch:
{
versions: 'onVersionsUpdate',
file: 'onFileUpdate'
},
created()
{
this.keepLatest = false
},
mounted()
{
this.$store.commit('setVersion', this.versions[0])
},
methods:
{
onVersionsUpdate()
{
if(this.keepLatest)
{
this.$store.commit('setVersion', this.versions[0])
}
},
onFileUpdate()
{
this.keepLatest = true
this.$store.commit('setVersion', this.versions[0])
},
onVersionClick(version, index)
{
this.keepLatest = index === 0
this.$store.commit('setVersion', version)
}
}
}
+1 -1
View File
@@ -1,3 +1,3 @@
<div class="versions">
<version v-for="version of versions" :content="version"></version>
<version v-for="(version, key) of versions" :content="version" @click.native.prevent="onVersionClick(version, key)"></version>
</div>
+3 -1
View File
@@ -35,9 +35,11 @@ export default {
{
const file = state.tree.getFile(data)
if(file)
if(!state.current || state.current.data.id !== file.data.id)
{
state.current = file
// console.log(state.current.data.versions.length)
// state.currentVersion = state.current.data.versions[state.current.data.versions.length - 1]
}
},