This commit is contained in:
parent
5a48f62ce2
commit
3a24e8a1b9
|
@ -27,7 +27,7 @@ export default {
|
||||||
|
|
||||||
// Redirect if nessecary
|
// Redirect if nessecary
|
||||||
if (redirect) {
|
if (redirect) {
|
||||||
router.go(redirect)
|
router.push({ name: redirect })
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.catch(e => {
|
.catch(e => {
|
||||||
|
|
|
@ -12,9 +12,9 @@
|
||||||
An error occured.
|
An error occured.
|
||||||
</div>
|
</div>
|
||||||
{{ error.message }}
|
{{ error.message }}
|
||||||
<template v-if="error.response">
|
<p v-if="error.response.data">
|
||||||
{{ error.response.Message }}
|
{{ error.response.data.Message }}
|
||||||
</template>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="ui positive message" v-if="success">
|
<div class="ui positive message" v-if="success">
|
||||||
|
@ -36,10 +36,6 @@
|
||||||
Refresh
|
Refresh
|
||||||
</button>
|
</button>
|
||||||
|
|
||||||
<pre>
|
|
||||||
{{allStatus}}
|
|
||||||
</pre>
|
|
||||||
|
|
||||||
<form id="search">
|
<form id="search">
|
||||||
<div class="ui icon input">
|
<div class="ui icon input">
|
||||||
<input placeholder="Search for anything..." type="text" v-model="searchQuery">
|
<input placeholder="Search for anything..." type="text" v-model="searchQuery">
|
||||||
|
@ -83,6 +79,7 @@
|
||||||
<script>
|
<script>
|
||||||
import auth from '../auth'
|
import auth from '../auth'
|
||||||
import {HTTP} from '../http-common'
|
import {HTTP} from '../http-common'
|
||||||
|
import router from '../router'
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
name: 'Home',
|
name: 'Home',
|
||||||
|
@ -92,7 +89,7 @@ export default {
|
||||||
booksTitle: 'Books Overview',
|
booksTitle: 'Books Overview',
|
||||||
books: [],
|
books: [],
|
||||||
searchQuery: '',
|
searchQuery: '',
|
||||||
gridColumns: ['Title', 'ISBN', 'Year', 'Price', 'Author', 'Publisher', 'Status'],
|
gridColumns: ['Title', 'ISBN', 'Year', 'Price', 'Author', 'Publisher', 'Quantity', 'Status'],
|
||||||
gridButtons: [
|
gridButtons: [
|
||||||
{
|
{
|
||||||
text: 'Delete',
|
text: 'Delete',
|
||||||
|
@ -158,6 +155,7 @@ export default {
|
||||||
Price: bs[b].Price + '€',
|
Price: bs[b].Price + '€',
|
||||||
Author: '',
|
Author: '',
|
||||||
Publisher: bs[b].PublisherFull.Name,
|
Publisher: bs[b].PublisherFull.Name,
|
||||||
|
Quantity: bs[b].Quantity,
|
||||||
Status: bs[b].Status
|
Status: bs[b].Status
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -205,7 +203,6 @@ export default {
|
||||||
opt.action(gridObject)
|
opt.action(gridObject)
|
||||||
},
|
},
|
||||||
deleteBook (obj) {
|
deleteBook (obj) {
|
||||||
console.log(obj.ID.content, 'delete')
|
|
||||||
HTTP.delete('books/' + obj.ID.content)
|
HTTP.delete('books/' + obj.ID.content)
|
||||||
.then(response => {
|
.then(response => {
|
||||||
console.log(response)
|
console.log(response)
|
||||||
|
@ -219,7 +216,7 @@ export default {
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
editBook (book) {
|
editBook (book) {
|
||||||
console.log(book, 'edit')
|
router.push({ name: 'book-edit', params: { id: book.ID.content } })
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -38,6 +38,10 @@
|
||||||
<label>Year</label>
|
<label>Year</label>
|
||||||
<input name="year" placeholder="Year" type="number" min="1800" v-model.number="book.Year">
|
<input name="year" placeholder="Year" type="number" min="1800" v-model.number="book.Year">
|
||||||
</div>
|
</div>
|
||||||
|
<div class="field">
|
||||||
|
<label>Quantity</label>
|
||||||
|
<input placeholder="Quantity" type="number" min="0" v-model.number="book.Quantity">
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="field" v-if="!addPublisherForm">
|
<div class="field" v-if="!addPublisherForm">
|
||||||
|
@ -111,12 +115,15 @@
|
||||||
error: '',
|
error: '',
|
||||||
success: '',
|
success: '',
|
||||||
loading: false,
|
loading: false,
|
||||||
|
bookID: this.$route.params.id,
|
||||||
|
edit: false,
|
||||||
book: {
|
book: {
|
||||||
Title: '',
|
Title: '',
|
||||||
Isbn: '',
|
Isbn: '',
|
||||||
Year: (new Date()).getFullYear(),
|
Year: (new Date()).getFullYear(),
|
||||||
Price: null,
|
Price: null,
|
||||||
Status: 0,
|
Status: 0,
|
||||||
|
Quantity: 0,
|
||||||
PublisherFull: {
|
PublisherFull: {
|
||||||
ID: 0,
|
ID: 0,
|
||||||
Name: ''
|
Name: ''
|
||||||
|
@ -133,9 +140,33 @@
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
created () {
|
created () {
|
||||||
|
this.loading = true
|
||||||
this.loadPublishers()
|
this.loadPublishers()
|
||||||
this.loadAuthors()
|
this.loadAuthors()
|
||||||
this.loadStatus()
|
this.loadStatus()
|
||||||
|
|
||||||
|
// Look if we're in edit mode and get the book infos if nessesary
|
||||||
|
if (this.bookID) {
|
||||||
|
HTTP.get('books/' + this.bookID)
|
||||||
|
.then(response => {
|
||||||
|
this.book = response.data
|
||||||
|
this.edit = true
|
||||||
|
|
||||||
|
// Loop through all authors and reverse them
|
||||||
|
let as = this.book.Authors
|
||||||
|
|
||||||
|
for (const i in as) {
|
||||||
|
this.book.Authors[i] = {
|
||||||
|
ID: as[i].ID,
|
||||||
|
Name: as[i].Forename + ' ' + as[i].Lastname
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.catch(e => {
|
||||||
|
this.error = e
|
||||||
|
})
|
||||||
|
}
|
||||||
|
this.loading = false
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
loadPublishers: function () {
|
loadPublishers: function () {
|
||||||
|
@ -224,16 +255,28 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
// Finally Send it
|
// Finally Send it
|
||||||
HTTP.put('books', {book: this.book})
|
// If we want to newly insert it, make a different request
|
||||||
.then(response => {
|
if (this.edit) {
|
||||||
this.loading = false
|
HTTP.put('books/' + this.book.ID, {book: this.book})
|
||||||
console.log(response)
|
.then(response => {
|
||||||
this.success = 'The book was successfully inserted!'
|
this.loading = false
|
||||||
})
|
this.success = 'The book was successfully updated!'
|
||||||
.catch(e => {
|
})
|
||||||
this.loading = false
|
.catch(e => {
|
||||||
this.error = e
|
this.loading = false
|
||||||
})
|
this.error = e
|
||||||
|
})
|
||||||
|
} else { // insert a new book
|
||||||
|
HTTP.put('books', {book: this.book})
|
||||||
|
.then(response => {
|
||||||
|
this.loading = false
|
||||||
|
this.success = 'The book was successfully inserted!'
|
||||||
|
})
|
||||||
|
.catch(e => {
|
||||||
|
this.loading = false
|
||||||
|
this.error = e
|
||||||
|
})
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -69,7 +69,7 @@
|
||||||
password: this.credentials.password
|
password: this.credentials.password
|
||||||
}
|
}
|
||||||
|
|
||||||
auth.login(this, credentials, '/home')
|
auth.login(this, credentials, 'home')
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,22 +11,27 @@ export default new Router({
|
||||||
routes: [
|
routes: [
|
||||||
{
|
{
|
||||||
path: '/home',
|
path: '/home',
|
||||||
name: 'Home',
|
name: 'home',
|
||||||
component: Home
|
component: Home
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
path: '/login',
|
path: '/login',
|
||||||
name: 'Login',
|
name: 'login',
|
||||||
component: Login
|
component: Login
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
path: '/books',
|
path: '/books',
|
||||||
name: 'Books',
|
name: 'books',
|
||||||
component: Books
|
component: Books
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
path: '/books/add',
|
path: '/books/add',
|
||||||
name: 'Add Book',
|
name: 'add-book',
|
||||||
|
component: BooksAddEdit
|
||||||
|
},
|
||||||
|
{
|
||||||
|
path: '/books/:id/edit',
|
||||||
|
name: 'book-edit',
|
||||||
component: BooksAddEdit
|
component: BooksAddEdit
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
|
|
|
@ -86,6 +86,7 @@ func RegisterRoutes(e *echo.Echo) {
|
||||||
// Manage Books
|
// Manage Books
|
||||||
a.PUT("/books", apiv1.BookAdd)
|
a.PUT("/books", apiv1.BookAdd)
|
||||||
a.DELETE("/books/:id", apiv1.BookDelete)
|
a.DELETE("/books/:id", apiv1.BookDelete)
|
||||||
|
a.POST("/books/:id", apiv1.BookDelete)
|
||||||
|
|
||||||
// Manage Authors
|
// Manage Authors
|
||||||
a.PUT("/authors", apiv1.AuthorAdd)
|
a.PUT("/authors", apiv1.AuthorAdd)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user