Commit 13517339 authored by TTS Kieu Tuan Anh's avatar TTS Kieu Tuan Anh

header

parents 6a0b13e8 28df8be7
<template> <template>
<div> <!-- <div>
<b-navbar toggleable="lg" type="dark" variant="info" style="background-color: #6f2ca6 !important"> <b-navbar toggleable="lg" type="dark" variant="info" style="background-color: #6f2ca6 !important">
<SideBar /> <SideBar />
<b-navbar-toggle target="nav-collapse"></b-navbar-toggle> <b-navbar-toggle target="nav-collapse"></b-navbar-toggle> -->
<b-collapse id="nav-collapse" is-nav> <!-- <b-collapse id="nav-collapse" is-nav>
<b-navbar-nav> <b-navbar-nav>
<b-nav-item href="/users">USER</b-nav-item> <b-nav-item href="/users">USER</b-nav-item>
<b-nav-item href="/categories">CATEGORY</b-nav-item> <b-nav-item href="/categories">CATEGORY</b-nav-item>
<b-nav-item href="/products">PRODUCT</b-nav-item> <b-nav-item href="/products">PRODUCT</b-nav-item>
<b-nav-item href="/posts">POST</b-nav-item> <b-nav-item href="/posts">POST</b-nav-item>
</b-navbar-nav> </b-navbar-nav> -->
<!-- Right aligned nav items --> <!-- Right aligned nav items -->
<b-navbar-nav class="ml-auto"> <!-- <b-navbar-nav class="ml-auto">
<b-nav-item-dropdown right> <b-nav-item-dropdown right> -->
<!-- Using 'button-content' slot --> <!-- Using 'button-content' slot -->
<template #button-content> <!-- <template #button-content>
<em>{{ $auth.$storage.getUniversal("userName") }}</em> <em>{{ $auth.$storage.getUniversal("userName") }}</em>
</template> </template>
<b-dropdown-item href="#">Profile</b-dropdown-item> <b-dropdown-item href="#">Profile</b-dropdown-item>
...@@ -26,15 +26,49 @@ ...@@ -26,15 +26,49 @@
</b-navbar-nav> </b-navbar-nav>
</b-collapse> </b-collapse>
</b-navbar> </b-navbar>
</div> -->
<div>
<v-toolbar
dark
prominent
src="https://cdn.vuetifyjs.com/images/backgrounds/vbanner.jpg"
>
<v-app-bar-nav-icon></v-app-bar-nav-icon>
<v-toolbar-title>
<v-btn href="/users">
<span>USER</span>
<v-icon>mdi-account</v-icon>
</v-btn>
<v-btn href="/categories">
<span>CATEGORY</span>
<v-icon>mdi-heart</v-icon>
</v-btn>
<v-btn href="/products">
<span>PRODUCT</span>
<v-icon> mdi-briefcase</v-icon>
</v-btn>
<v-btn href="/posts">
<span>POST</span>
<v-icon>mdi-newspaper</v-icon>
</v-btn>
</v-toolbar-title>
<v-spacer></v-spacer>
<v-btn icon @click="logout">
<v-icon>mdi-export</v-icon>
</v-btn>
</v-toolbar>
</div> </div>
</template> </template>
<script> <script>
import SideBar from '@/components/SideBar'
export default { export default {
components: {
SideBar
},
methods: { methods: {
logout () { logout () {
fetch('http://127.0.0.1:8000/api/logout', { fetch('http://127.0.0.1:8000/api/logout', {
......
...@@ -246,7 +246,11 @@ export default { ...@@ -246,7 +246,11 @@ export default {
}, },
getCategories() { getCategories() {
this.$axios this.$axios
.get('/categories/') .get("/categories/",{
headers: {
'Content-Type': 'application/json',
Authorization: `Bearer ${this.$auth.$storage.getUniversal("token")}`,
}})
.then((response) => (this.categories = response.data.data)) .then((response) => (this.categories = response.data.data))
.catch(function (error) { .catch(function (error) {
console.log(error) console.log(error)
...@@ -257,34 +261,37 @@ export default { ...@@ -257,34 +261,37 @@ export default {
const image = Array.from(set) const image = Array.from(set)
const self = this const self = this
this.$axios this.$axios
.post('/categories/', { .post('/categories/',
{
name: this.name, name: this.name,
ordering: this.ordering, ordering: this.ordering,
parent_id: this.parent_id, parent_id: this.parent_id,
images: image, images: image,
}, { },
{
headers: { headers: {
'Content-Type': 'multipart/form-data', "Content-Type": "multipart/form-data",
'Authorization': this.$auth.$storage.getUniversal('token') Authorization: `Bearer ${this.$auth.$storage.getUniversal("token")}`,
} },
}) }
.then(response => { )
this.$bvModal.hide('modal-create') .then(response => {
self.$toast.success('Category created successfully!', { this.$bvModal.hide('modal-create')
duration: 3000 self.$toast.success('Category created successfully!', {
}) duration: 3000
this.editedItem = response.data.data
console.log(this.editedItem)
this.categories.push(this.editedItem)
}) })
.catch(errors => { this.editedItem = response.data.data
this.$bvModal.hide('modal-create') console.log(this.editedItem)
console.log(errors.response.data.message) this.categories.push(this.editedItem)
this.message = errors.response.data.message })
self.$toast.error('something went wrong while trying create!', { .catch(errors => {
duration: 3000 this.$bvModal.hide('modal-create')
}) console.log(errors.response.data.message)
this.message = errors.response.data.message
self.$toast.error('something went wrong while trying create!',{
duration: 3000
}) })
})
}, },
fileSelected(event) { fileSelected(event) {
console.log(event) console.log(event)
...@@ -297,20 +304,26 @@ export default { ...@@ -297,20 +304,26 @@ export default {
deleteCategory(ID, index) { deleteCategory(ID, index) {
const self = this const self = this
this.editedIndex = this.categories.indexOf(index) this.editedIndex = this.categories.indexOf(index)
if (confirm('Do you really want to delete?')) { if(confirm("Do you really want to delete?")){
try { try{
this.$axios this.$axios
.delete(`/categories/${ID}`) .delete(`/categories/${ID}`,
.then(response => { {
this.categories.splice(this.editedIndex, 1) headers: {
self.$toast.success('Category deleted successfully!', { "Content-Type": "multipart/form-data",
duration: 3000 Authorization: `Bearer ${this.$auth.$storage.getUniversal("token")}`,
}) },
}) })
} catch (error) { .then(response => {
console.log(error) this.categories.splice(this.editedIndex, 1)
} self.$toast.success('Category deleted successfully!',{
duration: 3000
})
})
} catch(error){
console.log(error)
} }
}
}, },
getID(item) { getID(item) {
console.log(this.categories.indexOf(item)) console.log(this.categories.indexOf(item))
...@@ -333,29 +346,31 @@ export default { ...@@ -333,29 +346,31 @@ export default {
console.log(this.eName) console.log(this.eName)
console.log(this.eOrdering) console.log(this.eOrdering)
console.log(this?.eID) console.log(this?.eID)
try { try{
this.$axios this.$axios
.post(`categories/update/${this?.eID}`, { .post(`categories/update/${this?.eID}`,
{
name: this.eName, name: this.eName,
ordering: this.eOrdering, ordering: this.eOrdering,
parent_id: this.eParentId, parent_id: this.eParentId,
images: image images: image },
}, { {
headers: { headers: {
'Content-Type': 'multipart/form-data', "Content-Type": "multipart/form-data",
'Authorization': this.$auth.$storage.getUniversal('token') Authorization: `Bearer ${this.$auth.$storage.getUniversal("token")}`,
} }
}) }
.then(response => { )
self.$toast.success('User updated successfully!', { .then(response => {
duration: 3000 self.$toast.success('User updated successfully!',{
}) duration: 3000
console.log(response) })
this.editedItem = response.data.data console.log(response)
this.$bvModal.hide('modal-edit') this.editedItem = response.data.data
Object.assign(this.categories[this.editedIndex], this.editedItem) this.$bvModal.hide('modal-edit')
}) Object.assign(this.categories[this.editedIndex], this.editedItem)
} catch (error) { })
} catch(error){
console.log(error) console.log(error)
} }
} }
......
...@@ -268,7 +268,11 @@ export default { ...@@ -268,7 +268,11 @@ export default {
}, },
getCategories() { getCategories() {
this.$axios this.$axios
.get('/categories/') .get("/categories/",{
headers: {
'Content-Type': 'application/json',
Authorization: `Bearer ${this.$auth.$storage.getUniversal("token")}`,
}})
.then((response) => (this.categories = response.data.data)) .then((response) => (this.categories = response.data.data))
.catch(function (error) { .catch(function (error) {
console.log(error) console.log(error)
...@@ -276,7 +280,11 @@ export default { ...@@ -276,7 +280,11 @@ export default {
}, },
getposts() { getposts() {
this.$axios this.$axios
.get('/posts/') .get("/posts/",{
headers: {
'Content-Type': 'application/json',
Authorization: `Bearer ${this.$auth.$storage.getUniversal("token")}`,
}})
.then((response) => (this.posts = response.data.data)) .then((response) => (this.posts = response.data.data))
.catch(function (error) { .catch(function (error) {
console.log(error) console.log(error)
...@@ -296,8 +304,8 @@ export default { ...@@ -296,8 +304,8 @@ export default {
}, },
{ {
headers: { headers: {
'Content-Type': 'multipart/form-data', "Content-Type": "multipart/form-data",
Authorization: this.$auth.$storage.getUniversal('token'), Authorization: `Bearer ${this.$auth.$storage.getUniversal("token")}`,
}, },
} }
) )
...@@ -324,7 +332,11 @@ export default { ...@@ -324,7 +332,11 @@ export default {
this.editedIndex = this.posts.indexOf(index) this.editedIndex = this.posts.indexOf(index)
if (confirm('Do you really want to delete?')) { if (confirm('Do you really want to delete?')) {
this.$axios this.$axios
.delete(`/posts/${ID}`) .delete(`/posts/${ID}`,{
headers: {
'Content-Type': 'application/json',
Authorization: `Bearer ${this.$auth.$storage.getUniversal("token")}`,
}})
.then((response) => { .then((response) => {
this.posts.splice(this.editedIndex, 1) this.posts.splice(this.editedIndex, 1)
self.$toast.success('Post deleted successfully!', { self.$toast.success('Post deleted successfully!', {
...@@ -345,8 +357,8 @@ export default { ...@@ -345,8 +357,8 @@ export default {
const resp = await this.$axios.get(`/posts/${ID}`, { const resp = await this.$axios.get(`/posts/${ID}`, {
method: 'GET', method: 'GET',
headers: { headers: {
'Content-Type': 'multipart/form-data', "Content-Type": "multipart/form-data",
Authorization: this.$auth.$storage.getUniversal('token'), Authorization: `Bearer ${this.$auth.$storage.getUniversal("token")}`,
}, },
}) })
console.log(resp.data) console.log(resp.data)
...@@ -386,8 +398,8 @@ export default { ...@@ -386,8 +398,8 @@ export default {
}, },
{ {
headers: { headers: {
'Content-Type': 'multipart/form-data', "Content-Type": "multipart/form-data",
Authorization: this.$auth.$storage.getUniversal('token'), Authorization: `Bearer ${this.$auth.$storage.getUniversal("token")}`,
}, },
} }
) )
......
...@@ -481,7 +481,11 @@ export default { ...@@ -481,7 +481,11 @@ export default {
}, },
getCategories() { getCategories() {
this.$axios this.$axios
.get('/categories/') .get("/categories/",{
headers: {
'Content-Type': 'application/json',
Authorization: `Bearer ${this.$auth.$storage.getUniversal("token")}`,
}})
.then((response) => (this.categories = response.data.data)) .then((response) => (this.categories = response.data.data))
.catch(function (error) { .catch(function (error) {
console.log(error) console.log(error)
...@@ -489,7 +493,11 @@ export default { ...@@ -489,7 +493,11 @@ export default {
}, },
getProducts() { getProducts() {
this.$axios this.$axios
.get('/products/') .get("/products/",{
headers: {
'Content-Type': 'application/json',
Authorization: `Bearer ${this.$auth.$storage.getUniversal("token")}`,
}})
.then((response) => (this.products = response.data.data)) .then((response) => (this.products = response.data.data))
.catch(function (error) { .catch(function (error) {
console.log(error) console.log(error)
...@@ -510,7 +518,7 @@ export default { ...@@ -510,7 +518,7 @@ export default {
}, { }, {
headers: { headers: {
'Content-Type': 'multipart/form-data', 'Content-Type': 'multipart/form-data',
'Authorization': this.$auth.$storage.getUniversal('token') Authorization: `Bearer ${this.$auth.$storage.getUniversal("token")}`,
} }
}) })
.then(response => { .then(response => {
...@@ -537,7 +545,11 @@ export default { ...@@ -537,7 +545,11 @@ export default {
if(confirm('Do you really want to delete?')){ if(confirm('Do you really want to delete?')){
try{ try{
this.$axios this.$axios
.delete(`/products/${ID}`) .delete(`/products/${ID}`,{
headers: {
'Content-Type': 'application/json',
Authorization: `Bearer ${this.$auth.$storage.getUniversal("token")}`,
}})
.then(response => { .then(response => {
this.products.splice(this.editedIndex, 1) this.products.splice(this.editedIndex, 1)
self.$toast.success('Category deleted successfully!',{ self.$toast.success('Category deleted successfully!',{
...@@ -555,8 +567,8 @@ export default { ...@@ -555,8 +567,8 @@ export default {
const resp = await this.$axios.get(`/products/${ID}`, { const resp = await this.$axios.get(`/products/${ID}`, {
method: 'GET', method: 'GET',
headers: { headers: {
'Content-Type': 'multipart/form-data', "Content-Type": "multipart/form-data",
Authorization: this.$auth.$storage.getUniversal('token'), Authorization: `Bearer ${this.$auth.$storage.getUniversal("token")}`,
}, },
}) })
this.sName = resp.data.data.name this.sName = resp.data.data.name
...@@ -594,11 +606,12 @@ export default { ...@@ -594,11 +606,12 @@ export default {
images: this.eImages, images: this.eImages,
variants: this.eVariants, variants: this.eVariants,
}, { }, {
headers: { headers: {
'Content-Type': 'multipart/form-data', "Content-Type": "multipart/form-data",
'Authorization': this.$auth.$storage.getUniversal('token') Authorization: `Bearer ${this.$auth.$storage.getUniversal("token")}`,
}
} }
} ) )
.then(response => { .then(response => {
self.$toast.success('User updated successfully!',{ self.$toast.success('User updated successfully!',{
duration: 3000 duration: 3000
......
<template> <!-- <template>
<div style="background-color: #8fc2ff"> <div style="background-color: #8fc2ff">
<div class="container" style=" <div class="container" style="
display: flex; display: flex;
...@@ -57,7 +57,7 @@ export default { ...@@ -57,7 +57,7 @@ export default {
confirm_password: this.confirm_password, confirm_password: this.confirm_password,
}), }),
}) })
this.$router.push('/') this.$router.push("/login")
}, },
}, },
} }
...@@ -81,4 +81,4 @@ export default { ...@@ -81,4 +81,4 @@ export default {
justify-content: center; justify-content: center;
margin-left: 50px; margin-left: 50px;
} }
</style> </style> -->
...@@ -228,7 +228,12 @@ export default { ...@@ -228,7 +228,12 @@ export default {
}, },
getUsers() { getUsers() {
this.$axios this.$axios
.get('/users/') .get('/users/',{
headers: {
'Content-Type': 'application/json',
Authorization: `Bearer ${this.$auth.$storage.getUniversal("token")}`,
},
})
.then((response) => (this.users = response.data.data.data)) .then((response) => (this.users = response.data.data.data))
.catch(function (error) { .catch(function (error) {
console.log(error) console.log(error)
...@@ -237,53 +242,63 @@ export default { ...@@ -237,53 +242,63 @@ export default {
createUser() { createUser() {
const self = this const self = this
this.$axios this.$axios
.post('/users/', { .post('/users/',
headers: { {
'Content-Type': 'application/json'
},
email: this.email, email: this.email,
password: this.password, password: this.password,
name: this.name, name:this.name,
}) },
.then(response => { {
// $bvModal.hide('modal-login') headers: {
this.$bvModal.hide('modal-login') 'Content-Type': 'application/json',
self.$toast.success('User created successfully!', { Authorization: `Bearer ${this.$auth.$storage.getUniversal("token")}`,
duration: 3000 },
}) }
console.log(response) )
this.editedItem = response.data.data .then(response => {
console.log(this.editedItem) // $bvModal.hide('modal-login');
this.users.push(this.editedItem) this.$bvModal.hide('modal-login')
}) self.$toast.success('User created successfully!',{
.catch(errors => { duration: 3000
this.$bvModal.hide('modal-login') })
console.log(errors.response.data.message) console.log(response)
this.message = errors.response.data.message this.editedItem = response.data.data
self.$toast.error('something went wrong while trying create!', { console.log(this.editedItem)
duration: 3000 this.users.push(this.editedItem)
}) })
}) .catch(errors => {
this.$bvModal.hide('modal-login')
console.log(errors.response.data.message)
this.message = errors.response.data.message
self.$toast.error('something went wrong while trying create!',{
duration: 3000
})
})
}, },
deleteUser(userID, index) { deleteUser(userID, index) {
const self = this const self = this
this.editedIndex = this.users.indexOf(index) this.editedIndex = this.users.indexOf(index)
if (confirm('Do you really want to delete?')) { if(confirm("Do you really want to delete?")){
try { try{
this.$axios this.$axios
.delete(`/users/${userID}`) .delete(`/users/${userID}`,{
.then(response => { headers: {
console.log(response.data) 'Content-Type': 'application/json',
this.users.splice(this.editedIndex, 1) Authorization: `Bearer ${this.$auth.$storage.getUniversal("token")}`,
self.$toast.success('User deleted successfully!', { },
duration: 3000 })
}) .then(response => {
}) console.log(response.data)
} catch (error) { this.users.splice(this.editedIndex, 1)
console.log(error) self.$toast.success('User deleted successfully!',{
} duration: 3000
})
})
} catch(error){
console.log(error)
} }
}, }
},
editUser(user) { editUser(user) {
this.$bvModal.show('modal-edit') this.$bvModal.show('modal-edit')
this.eID = user.id this.eID = user.id
...@@ -297,23 +312,31 @@ export default { ...@@ -297,23 +312,31 @@ export default {
console.log(this.eName) console.log(this.eName)
console.log(this.eEmail) console.log(this.eEmail)
console.log(this?.eID) console.log(this?.eID)
try { try{
this.$axios this.$axios
.put(`/users/${this?.eID}`, { .put(`/users/${this?.eID}`,
email: this.eEmail, {
password: this.ePassword, email: this.eEmail,
name: this.eName, password: this.ePassword,
}) name:this.eName,
.then(response => { },
self.$toast.success('User updated successfully!', { {
duration: 3000 headers: {
}) 'Content-Type': 'application/json',
console.log(response) Authorization: `Bearer ${this.$auth.$storage.getUniversal("token")}`,
this.editedItem = response.data.data },
this.$bvModal.hide('modal-edit') }
Object.assign(this.users[this.editedIndex], this.editedItem) )
}) .then(response => {
} catch (error) { self.$toast.success('User updated successfully!',{
duration: 3000
})
console.log(response)
this.editedItem = response.data.data
this.$bvModal.hide('modal-edit')
Object.assign(this.users[this.editedIndex], this.editedItem)
})
} catch(error){
console.log(error) console.log(error)
} }
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment