2017-11-21 12:32:34 +00:00
|
|
|
<template>
|
|
|
|
<div v-if="user.authenticated">
|
2017-11-29 15:15:29 +00:00
|
|
|
<h1>{{ author.forename }} {{ author.lastname }}</h1>
|
2017-11-21 12:32:34 +00:00
|
|
|
|
|
|
|
<div class="ui info message" v-if="loading">
|
|
|
|
<icon name="refresh" spin></icon>
|
2017-11-22 14:13:33 +00:00
|
|
|
<span v-lang.general.loading></span>
|
2017-11-21 12:32:34 +00:00
|
|
|
</div>
|
|
|
|
|
2017-11-23 13:18:31 +00:00
|
|
|
<div v-if="!loading">
|
2017-11-21 12:32:34 +00:00
|
|
|
|
|
|
|
<router-link :to="{ name: 'author-edit', params: { id: authorID} }" class="ui teal labeled icon button" style="float: right;">
|
|
|
|
<i class="edit icon"></i>
|
2017-11-22 14:13:33 +00:00
|
|
|
<span v-lang.general.edit></span>
|
2017-11-21 12:32:34 +00:00
|
|
|
</router-link>
|
|
|
|
|
2017-11-24 10:54:52 +00:00
|
|
|
<list :infos="authorList"/>
|
2017-11-30 14:26:28 +00:00
|
|
|
|
|
|
|
<p class="grey">
|
|
|
|
<span v-lang.general.created="this.createdTime"></span><br/>
|
|
|
|
<span v-if="this.author.created !== this.author.updated" v-lang.general.lastEdit="this.editedTime"></span>
|
|
|
|
</p>
|
2017-11-21 12:32:34 +00:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script>
|
|
|
|
import auth from '../auth'
|
|
|
|
import {HTTP} from '../http-common'
|
|
|
|
|
|
|
|
export default {
|
|
|
|
name: 'Author',
|
|
|
|
data () {
|
|
|
|
return {
|
|
|
|
user: auth.user,
|
|
|
|
author: {},
|
2017-11-24 10:54:52 +00:00
|
|
|
authorID: this.$route.params.id,
|
2017-11-30 14:26:28 +00:00
|
|
|
authorList: [],
|
|
|
|
createdTime: {
|
|
|
|
date: '',
|
|
|
|
time: ''
|
|
|
|
},
|
|
|
|
editedTime: {
|
|
|
|
date: '',
|
|
|
|
time: ''
|
|
|
|
}
|
2017-11-21 12:32:34 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
created () {
|
|
|
|
this.loadAuthor()
|
2017-12-05 14:55:56 +00:00
|
|
|
|
|
|
|
// Set the title
|
|
|
|
document.title = this.translate('nav').authors
|
2017-11-21 12:32:34 +00:00
|
|
|
},
|
|
|
|
watch: {
|
|
|
|
// call again the method if the route changes
|
|
|
|
'$route': 'loadAuthor'
|
|
|
|
},
|
2017-12-05 14:55:56 +00:00
|
|
|
computed: {
|
|
|
|
langGeneral () {
|
|
|
|
return this.translate('general')
|
|
|
|
}
|
|
|
|
},
|
2017-11-21 12:32:34 +00:00
|
|
|
methods: {
|
|
|
|
loadAuthor () {
|
|
|
|
this.loading = true
|
|
|
|
this.author = {}
|
|
|
|
HTTP.get(`authors/` + this.authorID)
|
|
|
|
.then(response => {
|
|
|
|
this.author = response.data
|
2017-11-24 10:54:52 +00:00
|
|
|
|
|
|
|
// Make a list
|
|
|
|
this.authorList = [
|
|
|
|
{
|
|
|
|
header: this.translate('authors').forename,
|
2017-11-29 15:15:29 +00:00
|
|
|
content: this.author.forename
|
2017-11-24 10:54:52 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
header: this.translate('authors').lastname,
|
2017-11-29 15:15:29 +00:00
|
|
|
content: this.author.lastname
|
2017-11-24 10:54:52 +00:00
|
|
|
}
|
|
|
|
]
|
|
|
|
|
2017-11-30 14:26:28 +00:00
|
|
|
// Beautify the date
|
|
|
|
let c = new Date(this.author.created * 1000)
|
|
|
|
// c.setSeconds()
|
|
|
|
this.createdTime = {
|
|
|
|
date: ('0' + c.getDate()).slice(-2) + '.' + ('0' + (c.getMonth() + 1)).slice(-2) + '.' + c.getFullYear(),
|
|
|
|
time: ('0' + c.getHours()).slice(-2) + ':' + ('0' + c.getMinutes()).slice(-2)
|
|
|
|
}
|
|
|
|
|
|
|
|
let e = new Date(this.author.updated * 1000)
|
|
|
|
// e.setSeconds()
|
|
|
|
this.editedTime = {
|
|
|
|
date: ('0' + e.getDate()).slice(-2) + '.' + ('0' + (e.getMonth() + 1)).slice(-2) + '.' + e.getFullYear(),
|
|
|
|
time: ('0' + e.getHours()).slice(-2) + ':' + ('0' + e.getMinutes()).slice(-2)
|
|
|
|
}
|
|
|
|
|
2017-12-05 14:55:56 +00:00
|
|
|
// Set the title
|
|
|
|
document.title = this.author.forename + ' ' + this.author.lastname + ' | ' + this.translate('nav').authors
|
|
|
|
|
2017-11-21 12:32:34 +00:00
|
|
|
this.loading = false
|
|
|
|
})
|
|
|
|
.catch(e => {
|
|
|
|
this.loading = false
|
2017-11-23 13:18:31 +00:00
|
|
|
// Build the notification text from error response
|
2017-11-30 14:26:28 +00:00
|
|
|
console.log(e)
|
2017-11-23 13:18:31 +00:00
|
|
|
let err = e.message
|
2017-12-07 09:45:33 +00:00
|
|
|
if (e.response.data.message) {
|
|
|
|
err += '<br/>' + e.response.data.message
|
2017-11-23 13:18:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Fire a notification
|
|
|
|
this.$notify({
|
|
|
|
type: 'error',
|
|
|
|
title: this.langGeneral.error,
|
|
|
|
text: err
|
|
|
|
})
|
2017-11-21 12:32:34 +00:00
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
</script>
|