138 lines
3.9 KiB
Vue
138 lines
3.9 KiB
Vue
<template>
|
|
<div v-if="user.authenticated">
|
|
<h1>{{ book.Title }}</h1>
|
|
|
|
<div class="ui info message" v-if="loading">
|
|
<icon name="refresh" spin></icon>
|
|
<span v-lang.general.loading></span>
|
|
</div>
|
|
|
|
<div v-if="!loading">
|
|
|
|
<router-link :to="{ name: 'book-edit', params: { id: bookID} }" class="ui teal labeled icon button" style="float: right;">
|
|
<i class="edit icon"></i>
|
|
<span v-lang.general.edit></span>
|
|
</router-link>
|
|
|
|
<div class="ui list">
|
|
<div class="item">
|
|
<div class="header" v-lang.books.gridColumns.isbn></div>
|
|
{{ book.Isbn }}
|
|
</div>
|
|
<div class="item">
|
|
<div class="header" v-lang.books.gridColumns.year></div>
|
|
{{ book.Year }}
|
|
</div>
|
|
<div class="item">
|
|
<div class="header" v-lang.books.gridColumns.price></div>
|
|
{{ book.Price }}
|
|
</div>
|
|
<div class="item">
|
|
<div class="header" v-lang.books.gridColumns.status></div>
|
|
{{ book.Status }}
|
|
</div>
|
|
<div class="item">
|
|
<div class="header" v-lang.books.gridColumns.publisher></div>
|
|
<router-link :to="{ name: 'publisher-show', params: { id: book.PublisherFull.ID} }">
|
|
{{ book.PublisherFull.Name }}
|
|
</router-link>
|
|
</div>
|
|
<div class="item">
|
|
<div class="header" v-lang.books.gridColumns.authors></div>
|
|
<template v-for="(author, index) in book.Authors">
|
|
<router-link :to="{ name: 'author-show', params: { id: author.ID} }">
|
|
{{ author.Lastname }} {{ author.Lastname }}
|
|
</router-link>
|
|
<template v-if="book.Authors.length > (index + 1)">, </template>
|
|
</template>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</template>
|
|
|
|
<script>
|
|
import auth from '../auth'
|
|
import {HTTP} from '../http-common'
|
|
// import router from '../router'
|
|
|
|
export default {
|
|
name: 'Book',
|
|
data () {
|
|
return {
|
|
user: auth.user,
|
|
book: {},
|
|
allStatus: [],
|
|
bookID: this.$route.params.id
|
|
}
|
|
},
|
|
created () {
|
|
this.loadStatus()
|
|
this.loadBook()
|
|
},
|
|
watch: {
|
|
// call again the method if the route changes
|
|
'$route': 'loadBook'
|
|
},
|
|
methods: {
|
|
errorNotification (e) {
|
|
// Build the notification text from error response
|
|
let err = e.message
|
|
if (e.response.data) {
|
|
err += '<br/>' + e.response.data.Message
|
|
}
|
|
|
|
// Fire a notification
|
|
this.$notify({
|
|
type: 'error',
|
|
title: this.langGeneral.error,
|
|
text: err
|
|
})
|
|
},
|
|
loadBook () {
|
|
this.loading = true
|
|
this.book = {}
|
|
HTTP.get(`books/` + this.bookID)
|
|
.then(response => {
|
|
this.book = response.data
|
|
|
|
// Get all authors and concat them into one singe string
|
|
let authors = this.book.Authors
|
|
for (const au in authors) {
|
|
this.book.Author += authors[au].Forename + ' ' + authors[au].Lastname
|
|
if (authors.length > au + 1) {
|
|
this.book.Author += ', '
|
|
}
|
|
}
|
|
|
|
// Make Status a name, not an id
|
|
this.book.Status = this.getStatusByID(this.book.Status)
|
|
this.loading = false
|
|
})
|
|
.catch(e => {
|
|
this.loading = false
|
|
this.errorNotification(e)
|
|
})
|
|
},
|
|
loadStatus: function () {
|
|
HTTP.get('status')
|
|
.then(response => {
|
|
this.allStatus = response.data
|
|
})
|
|
.catch(e => {
|
|
this.errorNotification(e)
|
|
})
|
|
},
|
|
getStatusByID: function (id) {
|
|
// TODO: is there a better way to do this?
|
|
for (const i in this.allStatus) {
|
|
if (this.allStatus[i].ID === id) {
|
|
return this.allStatus[i].Name
|
|
}
|
|
}
|
|
return ''
|
|
}
|
|
}
|
|
}
|
|
</script>
|