Added pagination to books overview
This commit is contained in:
parent
e05b3ea630
commit
0c03bc6f04
|
@ -14,6 +14,7 @@
|
||||||
"axios": "^0.17.0",
|
"axios": "^0.17.0",
|
||||||
"vue": "^2.5.2",
|
"vue": "^2.5.2",
|
||||||
"vue-awesome": "^2.3.4",
|
"vue-awesome": "^2.3.4",
|
||||||
|
"vue-paginate": "^3.5.1",
|
||||||
"vue-resource": "^1.3.4",
|
"vue-resource": "^1.3.4",
|
||||||
"vue-router": "^3.0.1"
|
"vue-router": "^3.0.1"
|
||||||
},
|
},
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
import {HTTP} from '../http-common'
|
import {HTTP} from '../http-common'
|
||||||
import {router} from '../router'
|
import router from '../router'
|
||||||
// const API_URL = 'http://localhost:8082/api/v1/'
|
// const API_URL = 'http://localhost:8082/api/v1/'
|
||||||
// const LOGIN_URL = 'http://localhost:8082/login'
|
// const LOGIN_URL = 'http://localhost:8082/login'
|
||||||
|
|
||||||
|
|
|
@ -1,41 +1,43 @@
|
||||||
<template>
|
<template>
|
||||||
<div v-if="user.authenticated">
|
<div v-if="user.authenticated">
|
||||||
<h1>{{ booksTitle }}</h1>
|
<h1>{{ booksTitle }}</h1>
|
||||||
<form id="search">
|
<div class="ui info message" v-if="loading">
|
||||||
<div class="ui icon input">
|
<icon name="refresh" spin></icon>
|
||||||
<input placeholder="Search..." type="text" v-model="searchQuery">
|
Loading...
|
||||||
<i class="search icon"></i>
|
</div>
|
||||||
|
<div v-if="!loading">
|
||||||
|
<form id="search">
|
||||||
|
<div class="ui icon input">
|
||||||
|
<input placeholder="Search..." type="text" v-model="searchQuery">
|
||||||
|
<i class="search icon"></i>
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
|
<paginate
|
||||||
|
name="books"
|
||||||
|
:list="filteredData"
|
||||||
|
:per="25"
|
||||||
|
tag="div"
|
||||||
|
>
|
||||||
|
<grid
|
||||||
|
:data="paginated('books')"
|
||||||
|
:columns="gridColumns"
|
||||||
|
>
|
||||||
|
</grid>
|
||||||
|
</paginate>
|
||||||
|
<div class="pagination-container">
|
||||||
|
<paginate-links
|
||||||
|
tag="div"
|
||||||
|
for="books"
|
||||||
|
:hide-single-page="true"
|
||||||
|
:classes="{
|
||||||
|
'ul': ['ui', 'pagination', 'menu'],
|
||||||
|
'li': 'item',
|
||||||
|
'li a': 'pagination-link'
|
||||||
|
}"
|
||||||
|
>
|
||||||
|
</paginate-links>
|
||||||
</div>
|
</div>
|
||||||
</form>
|
</div>
|
||||||
<grid
|
|
||||||
:data="books"
|
|
||||||
:columns="gridColumns"
|
|
||||||
:filter-key="searchQuery">
|
|
||||||
</grid>
|
|
||||||
<!-- <table class="ui celled table">
|
|
||||||
<thead>
|
|
||||||
<tr>
|
|
||||||
<th><a @click="sortBy('Title')">Title</a></th>
|
|
||||||
<th>ISBN</th>
|
|
||||||
<th>Year</th>
|
|
||||||
<th>Price</th>
|
|
||||||
<th>Status</th>
|
|
||||||
<th>Publisher</th>
|
|
||||||
<th>Actions</th>
|
|
||||||
</tr>
|
|
||||||
</thead>
|
|
||||||
<tbody>
|
|
||||||
<tr v-for="book in books">
|
|
||||||
<td>{{ book.Title }}</td>
|
|
||||||
<td>{{ book.Isbn }}</td>
|
|
||||||
<td>{{ book.Year }}</td>
|
|
||||||
<td>{{ book.Price }}€</td>
|
|
||||||
<td>{{ book.Status }}</td>
|
|
||||||
<td>{{ book.PublisherFull.Name }}</td>
|
|
||||||
<td><a class="button">Do</a> </td>
|
|
||||||
</tr>
|
|
||||||
</tbody>
|
|
||||||
</table>-->
|
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
|
@ -51,37 +53,88 @@ export default {
|
||||||
booksTitle: 'Books Overview',
|
booksTitle: 'Books Overview',
|
||||||
books: [],
|
books: [],
|
||||||
searchQuery: '',
|
searchQuery: '',
|
||||||
gridColumns: ['Title', 'ISBN', 'Year', 'Price', 'Status', 'Publisher']
|
gridColumns: ['Title', 'ISBN', 'Year', 'Price', 'Status', 'Publisher'],
|
||||||
}
|
loading: false,
|
||||||
},
|
paginate: ['books']
|
||||||
methods: {
|
|
||||||
sortBy (sortKey) {
|
|
||||||
this.reverse = (this.sortKey === sortKey) ? !this.reverse : false
|
|
||||||
|
|
||||||
this.sortKey = sortKey
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
created () {
|
created () {
|
||||||
HTTP.get(`books`)
|
this.loadBooks()
|
||||||
.then(response => {
|
},
|
||||||
// this.books = response.data
|
watch: {
|
||||||
let bs = response.data
|
// call again the method if the route changes
|
||||||
let i = 0
|
'$route': 'loadBooks'
|
||||||
for (const b in bs) {
|
},
|
||||||
this.books[i] = {
|
computed: {
|
||||||
Title: bs[b].Title,
|
filteredData: function () {
|
||||||
ISBN: bs[b].Isbn,
|
var filterKey = this.searchQuery && this.searchQuery.toLowerCase()
|
||||||
Year: bs[b].Year,
|
var data = this.books
|
||||||
Price: bs[b].Price + '€',
|
if (filterKey) {
|
||||||
Status: bs[b].Status,
|
data = data.filter(function (row) {
|
||||||
Publisher: bs[b].PublisherFull.Name
|
return Object.keys(row).some(function (key) {
|
||||||
|
return String(row[key]).toLowerCase().indexOf(filterKey) > -1
|
||||||
|
})
|
||||||
|
})
|
||||||
|
}
|
||||||
|
return data
|
||||||
|
}
|
||||||
|
},
|
||||||
|
methods: {
|
||||||
|
loadBooks () {
|
||||||
|
this.loading = true
|
||||||
|
HTTP.get(`books`)
|
||||||
|
.then(response => {
|
||||||
|
let bs = response.data
|
||||||
|
let i = 0
|
||||||
|
for (const b in bs) {
|
||||||
|
this.books[i] = {
|
||||||
|
Title: bs[b].Title,
|
||||||
|
ISBN: bs[b].Isbn,
|
||||||
|
Year: bs[b].Year,
|
||||||
|
Price: bs[b].Price + '€',
|
||||||
|
Status: bs[b].Status,
|
||||||
|
Publisher: bs[b].PublisherFull.Name
|
||||||
|
}
|
||||||
|
i++
|
||||||
}
|
}
|
||||||
i++
|
this.loading = false
|
||||||
}
|
})
|
||||||
})
|
.catch(e => {
|
||||||
.catch(e => {
|
this.loading = false
|
||||||
this.errors.push(e)
|
this.errors.push(e)
|
||||||
})
|
})
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
</script>
|
</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>
|
||||||
|
|
|
@ -11,6 +11,9 @@ import Grid from './components/Grid'
|
||||||
import 'vue-awesome/icons'
|
import 'vue-awesome/icons'
|
||||||
import Icon from 'vue-awesome/components/Icon'
|
import Icon from 'vue-awesome/components/Icon'
|
||||||
|
|
||||||
|
// Paginate import
|
||||||
|
import VuePaginate from 'vue-paginate'
|
||||||
|
|
||||||
// Icons setup
|
// Icons setup
|
||||||
Vue.component('icon', Icon)
|
Vue.component('icon', Icon)
|
||||||
|
|
||||||
|
@ -20,6 +23,9 @@ auth.checkAuth()
|
||||||
// Register Grid component
|
// Register Grid component
|
||||||
Vue.component('grid', Grid)
|
Vue.component('grid', Grid)
|
||||||
|
|
||||||
|
// Paginate setup
|
||||||
|
Vue.use(VuePaginate)
|
||||||
|
|
||||||
/* eslint-disable no-new */
|
/* eslint-disable no-new */
|
||||||
new Vue({
|
new Vue({
|
||||||
el: '#app',
|
el: '#app',
|
||||||
|
|
Loading…
Reference in New Issue