2017-11-21 10:16:07 +00:00
|
|
|
<template>
|
|
|
|
<div v-if="user.authenticated">
|
2017-11-22 14:13:33 +00:00
|
|
|
<h1 v-lang.authors.title></h1>
|
2017-11-21 10:16:07 +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 10:16:07 +00:00
|
|
|
</div>
|
|
|
|
|
2017-11-23 13:18:31 +00:00
|
|
|
<div v-if="!loading">
|
2017-11-21 10:16:07 +00:00
|
|
|
|
|
|
|
<router-link to="/authors/add" class="ui green labeled icon button" style="float: right;">
|
|
|
|
<i class="plus icon"></i>
|
2017-11-22 14:13:33 +00:00
|
|
|
<span v-lang.authors.newAuthor></span>
|
2017-11-21 10:16:07 +00:00
|
|
|
</router-link>
|
|
|
|
|
2017-11-21 10:38:52 +00:00
|
|
|
<button @click="loadAuthors()" class="ui teal labeled icon button" style="float: right;">
|
2017-11-21 10:16:07 +00:00
|
|
|
<i class="refresh icon"></i>
|
2017-11-22 14:13:33 +00:00
|
|
|
<span v-lang.general.refresh></span>
|
2017-11-21 10:16:07 +00:00
|
|
|
</button>
|
|
|
|
|
|
|
|
<form id="search">
|
|
|
|
<div class="ui icon input">
|
2017-11-22 14:13:33 +00:00
|
|
|
<input :placeholder="langGeneral.search" type="text" v-model="searchQuery" v-focus>
|
2017-11-21 10:16:07 +00:00
|
|
|
<i class="search icon"></i>
|
|
|
|
</div>
|
|
|
|
</form>
|
|
|
|
<paginate
|
|
|
|
name="authors"
|
|
|
|
:list="filteredData"
|
|
|
|
:per="35"
|
|
|
|
tag="div"
|
|
|
|
>
|
|
|
|
<grid
|
|
|
|
:data="paginated('authors')"
|
|
|
|
:columns="gridColumns"
|
|
|
|
:buttons="gridButtons"
|
|
|
|
:btnclick="gridBtnClicked"
|
|
|
|
>
|
|
|
|
</grid>
|
|
|
|
</paginate>
|
|
|
|
<div class="pagination-container">
|
|
|
|
<paginate-links
|
|
|
|
tag="div"
|
|
|
|
for="authors"
|
|
|
|
:hide-single-page="true"
|
|
|
|
:classes="{
|
|
|
|
'ul': ['ui', 'pagination', 'menu'],
|
|
|
|
'li': 'item',
|
|
|
|
'li a': 'pagination-link'
|
|
|
|
}"
|
|
|
|
>
|
|
|
|
</paginate-links>
|
2017-11-22 14:28:55 +00:00
|
|
|
<div v-if="$refs.paginator" v-lang.general.searchResultCount="$refs.paginator.pageItemsCount"></div>
|
2017-11-21 10:16:07 +00:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<modal
|
|
|
|
v-if="showModal"
|
|
|
|
@close="showModal = false"
|
|
|
|
v-on:submit="deleteBtnSuccess()">
|
2017-11-22 14:13:33 +00:00
|
|
|
<span slot="header" v-lang.authors.deleteHeader></span>
|
|
|
|
<p slot="text" v-lang.authors.deleteMsg></p>
|
2017-11-21 10:16:07 +00:00
|
|
|
</modal>
|
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script>
|
|
|
|
import auth from '../auth'
|
|
|
|
import {HTTP} from '../http-common'
|
|
|
|
import router from '../router'
|
|
|
|
|
|
|
|
export default {
|
|
|
|
name: 'Authors',
|
|
|
|
data () {
|
|
|
|
return {
|
|
|
|
user: auth.user,
|
|
|
|
authors: [],
|
|
|
|
searchQuery: '',
|
2017-11-22 14:13:33 +00:00
|
|
|
gridColumns: [],
|
2017-11-21 10:16:07 +00:00
|
|
|
gridButtons: [
|
|
|
|
{
|
2017-11-22 14:28:55 +00:00
|
|
|
text: '',
|
2017-11-21 10:16:07 +00:00
|
|
|
icon: 'trash',
|
2017-11-21 10:49:52 +00:00
|
|
|
action: this.DeleteAuthor,
|
2017-11-21 10:16:07 +00:00
|
|
|
css: 'ui red icon button'
|
|
|
|
},
|
|
|
|
{
|
|
|
|
text: '',
|
|
|
|
icon: 'edit',
|
|
|
|
action: this.editauthor,
|
|
|
|
css: 'ui blue icon button'
|
|
|
|
}
|
|
|
|
],
|
|
|
|
loading: false,
|
|
|
|
paginate: ['authors'],
|
|
|
|
allStatus: [],
|
|
|
|
showModal: false
|
|
|
|
}
|
|
|
|
},
|
|
|
|
created () {
|
|
|
|
this.loadAuthors()
|
2017-11-22 14:13:33 +00:00
|
|
|
|
|
|
|
this.gridButtons[0].text = this.translate('general').delete
|
|
|
|
this.gridColumns = [this.translate('general').name]
|
2017-12-05 14:55:56 +00:00
|
|
|
|
|
|
|
// Set the title
|
|
|
|
document.title = this.translate('nav').authors
|
2017-11-21 10:16:07 +00:00
|
|
|
},
|
|
|
|
watch: {
|
|
|
|
// call again the method if the route changes
|
|
|
|
'$route': 'loadAuthors'
|
|
|
|
},
|
|
|
|
computed: {
|
|
|
|
filteredData: function () {
|
2017-11-29 13:51:51 +00:00
|
|
|
let filterKey = this.searchQuery && this.searchQuery.toLowerCase()
|
|
|
|
let data = this.authors
|
2017-11-21 10:16:07 +00:00
|
|
|
if (filterKey) {
|
|
|
|
data = data.filter(function (row) {
|
|
|
|
return Object.keys(row).some(function (key) {
|
|
|
|
if (row[key].content) {
|
|
|
|
return String(row[key].content).toLowerCase().indexOf(filterKey) > -1
|
|
|
|
} else {
|
|
|
|
return String(row[key]).toLowerCase().indexOf(filterKey) > -1
|
|
|
|
}
|
|
|
|
})
|
|
|
|
})
|
|
|
|
}
|
|
|
|
return data
|
2017-11-22 14:13:33 +00:00
|
|
|
},
|
|
|
|
langGeneral () {
|
|
|
|
return this.translate('general')
|
2017-11-21 10:16:07 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
methods: {
|
2017-11-23 13:18:31 +00:00
|
|
|
errorNotification (e) {
|
|
|
|
// Build the notification text from error response
|
|
|
|
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 10:16:07 +00:00
|
|
|
loadAuthors () {
|
|
|
|
this.loading = true
|
|
|
|
this.authors = []
|
|
|
|
HTTP.get(`authors`)
|
|
|
|
.then(response => {
|
|
|
|
let bs = response.data
|
|
|
|
let i = 0
|
|
|
|
|
|
|
|
// Loop throught the data we got from our API and prepare an array to display all authors
|
|
|
|
for (const b in bs) {
|
|
|
|
this.authors[i] = {
|
2017-11-29 15:15:29 +00:00
|
|
|
id: {content: bs[b].id, hide: true}, // Don't show the ID
|
|
|
|
name: {content: bs[b].forename + ' ' + bs[b].lastname, link: '/authors/' + bs[b].id} // Add a link to the element
|
2017-11-21 10:16:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// increment dat shit
|
|
|
|
i++
|
|
|
|
}
|
2017-11-23 13:18:31 +00:00
|
|
|
|
2017-11-21 10:16:07 +00:00
|
|
|
this.loading = false
|
|
|
|
})
|
|
|
|
.catch(e => {
|
|
|
|
this.loading = false
|
2017-11-23 13:18:31 +00:00
|
|
|
this.errorNotification(e)
|
2017-11-21 10:16:07 +00:00
|
|
|
})
|
|
|
|
},
|
|
|
|
gridBtnClicked (opt, gridObject) {
|
|
|
|
opt.action(gridObject)
|
|
|
|
},
|
|
|
|
deleteBtnSuccess () { // Event helper function
|
|
|
|
this.$emit('delete-submit')
|
|
|
|
},
|
2017-11-21 10:49:52 +00:00
|
|
|
DeleteAuthor (obj) {
|
2017-11-21 10:16:07 +00:00
|
|
|
this.showModal = true
|
|
|
|
this.$on('delete-submit', function () {
|
2017-11-28 11:27:00 +00:00
|
|
|
// Prevent deleting already deleted authors
|
|
|
|
if (obj) {
|
2017-11-29 15:15:29 +00:00
|
|
|
HTTP.delete('authors/' + obj.id.content)
|
2017-11-28 11:27:00 +00:00
|
|
|
.then(response => {
|
2017-12-07 09:45:33 +00:00
|
|
|
if (response.status === 200 && response.data.message === 'success') {
|
2017-11-28 11:27:00 +00:00
|
|
|
// Fire a notification
|
|
|
|
this.$notify({
|
|
|
|
type: 'success',
|
|
|
|
title: this.langGeneral.success,
|
|
|
|
text: this.translate('authors').deleteSuccess
|
|
|
|
})
|
|
|
|
this.loadAuthors()
|
|
|
|
}
|
|
|
|
})
|
|
|
|
.catch(e => {
|
|
|
|
this.errorNotification(e)
|
2017-11-21 10:49:52 +00:00
|
|
|
this.loadAuthors()
|
2017-11-28 11:27:00 +00:00
|
|
|
})
|
|
|
|
}
|
|
|
|
obj = null
|
2017-11-21 10:16:07 +00:00
|
|
|
this.showModal = false
|
|
|
|
})
|
|
|
|
},
|
|
|
|
editauthor (author) {
|
2017-11-29 15:15:29 +00:00
|
|
|
router.push({ name: 'author-edit', params: { id: author.id.content } })
|
2017-11-21 10:16:07 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
</script>
|
|
|
|
|
|
|
|
<style>
|
|
|
|
a.pagination-link{
|
|
|
|
margin: -5px -1.14286em -18px;
|
|
|
|
display: block;
|
|
|
|
position: absolute;
|
|
|
|
cursor: pointer;
|
|
|
|
padding: 0.928571em 1.14286em;
|
|
|
|
color: rgba(0,0,0,.87);
|
|
|
|
|
|
|
|
-webkit-transition: background-color 200ms; /* Safari */
|
|
|
|
transition: background-color 200ms;
|
|
|
|
}
|
|
|
|
|
|
|
|
a.pagination-link:hover{
|
|
|
|
background: rgba(0,0,0,.02);
|
|
|
|
}
|
|
|
|
|
|
|
|
.pagination{
|
|
|
|
padding: 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
.pagination-container{
|
|
|
|
margin-top: 1rem;
|
|
|
|
text-align: center;
|
|
|
|
}
|
|
|
|
|
|
|
|
#search{
|
|
|
|
margin-bottom: 1rem;
|
|
|
|
}
|
|
|
|
</style>
|