Commit ee8f9bac authored by vietanh-0511's avatar vietanh-0511

Merge branch 'dev' of...

Merge branch 'dev' of https://gitlab.kiaisoft.com/kiaisoft.anh.tran2/kiaisoft_tuananh_nuxt into feature/user-login
parents 5a873b10 ef3630f7
<template> <template>
<div> <div>
<b-navbar toggleable="lg" type="dark" variant="info" style="background-color: #6f2ca6 !important"> <v-toolbar
<SideBar /> dark
prominent
<b-navbar-toggle target="nav-collapse"></b-navbar-toggle> src="https://cdn.vuetifyjs.com/images/backgrounds/vbanner.jpg"
>
<b-collapse id="nav-collapse" is-nav> <v-app-bar-nav-icon />
<b-navbar-nav>
<b-nav-item href="/users">USER</b-nav-item> <v-toolbar-title>
<b-nav-item href="/categories">CATEGORY</b-nav-item> <v-btn href="/users">
<b-nav-item href="/products">PRODUCT</b-nav-item> <span>USER</span>
<b-nav-item href="/posts">POST</b-nav-item> <v-icon dense>mdi-account</v-icon>
</b-navbar-nav> </v-btn>
<!-- Right aligned nav items --> <v-btn href="/categories">
<b-navbar-nav class="ml-auto"> <span>CATEGORY</span>
<b-nav-item-dropdown right> <v-icon dense>mdi-heart</v-icon>
<!-- Using 'button-content' slot --> </v-btn>
<template #button-content>
<em>{{ $auth.$storage.getUniversal("userName") }}</em> <v-btn href="/products">
</template> <span>PRODUCT</span>
<b-dropdown-item href="#">Profile</b-dropdown-item> <v-icon dense> mdi-briefcase</v-icon>
<b-dropdown-item href="#" @click="logout">Sign Out</b-dropdown-item> </v-btn>
</b-nav-item-dropdown>
</b-navbar-nav> <v-btn href="/posts">
</b-collapse> <span>POST</span>
</b-navbar> <v-icon dense>mdi-newspaper</v-icon>
</v-btn>
</v-toolbar-title>
<v-spacer />
<v-toolbar-title>{{ $auth.$storage.getUniversal("userName") }}</v-toolbar-title>
<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> -->
<template> <template>
<v-app>
<div> <div>
<div />
<div> <div>
<v-breadcrumbs :items="items">
<template #divider>
<v-icon>mdi-chevron-right</v-icon>
</template>
</v-breadcrumbs>
</div> </div>
<b-breadcrumb>
<b-breadcrumb-item href="/home">
<b-icon icon="house-fill" scale="1.25" shift-v="1.25" aria-hidden="true"></b-icon>
Home
</b-breadcrumb-item>
<b-breadcrumb-item href="/home/users">User</b-breadcrumb-item>
</b-breadcrumb>
<div style="float: right"> <div style="float: right">
<b-button v-b-modal.modal-login class="text-white">New User</b-button> <v-dialog
<!-- modal create user --> v-model="dialog1"
<b-modal id="modal-login" title="Create User" class="modal fade"> persistent
<Notification :message="error" v-if="error" /> max-width="600px"
<p class="my-4"> @submit.prevent="createUser"
<form @submit.prevent="createUser"> >
<label>Name :</label> <template #activator="{ on, attrs }">
<input type="text" class="form-control mb-2" placeholder="name" v-model="name" max="255" min="1" required /> <v-btn
<label>Email :</label> color="primary"
<input type="email" class="form-control mb-2" placeholder="Email" v-model="email" required /> dark
<label>Password :</label> v-bind="attrs"
<input type="password" class="form-control mb-2" placeholder="password" v-model="password" required /> v-on="on"
</form> >
</p> New USER
<template #modal-footer> </v-btn>
<button v-b-modal.modal-close_visit @click="$bvModal.hide('modal-login')"
class="btn btn-danger btn-sm m-1">Close</button>
<button @click="createUser" v-b-modal.modal-close_visit class="btn btn-success btn-sm m-1">Submit</button>
</template>
</b-modal>
<!-- modal edit user -->
<b-modal id="modal-edit" title="Edit User" class="modal fade">
<p class="my-4">
<form @submit.prevent="">
<label>Name :</label>
<input type="text" class="form-control mb-2" placeholder="name" v-model="eName" max="255" min="1" required />
<label>Email :</label>
<input type="email" class="form-control mb-2" placeholder="Email" v-model="eEmail" required />
<label>Password :</label>
<input type="password" class="form-control mb-2" placeholder="password" v-model="ePassword" required />
</form>
</p>
<template #modal-footer>
<button v-b-modal.modal-close_visit @click="$bvModal.hide('modal-edit')"
class="btn btn-danger btn-sm m-1">Close</button>
<button @click="updateUser(this?.eID)" v-b-modal.modal-close_visit
class="btn btn-success btn-sm m-1">Submit</button>
</template> </template>
</b-modal> <v-card>
<v-card-title>
<span class="text-h5">User Profile</span>
</v-card-title>
<v-card-text>
<v-container>
<v-row>
<v-col
cols="12"
sm="6"
md="4"
>
<v-text-field
v-model="name"
label="Legal name*"
required
/>
</v-col>
<v-col cols="12">
<v-text-field
v-model="email"
label="Email*"
required
/>
</v-col>
<v-col cols="12">
<v-text-field
v-model="password"
label="Password*"
type="password"
required
/>
</v-col>
</v-row>
</v-container>
<small>*indicates required field</small>
</v-card-text>
<v-card-actions>
<v-spacer />
<v-btn
color="blue darken-1"
text
@click="dialog1 = false"
>
Close
</v-btn>
<v-btn
color="blue darken-1"
text
type="submit"
@click="dialog1 = false; createUser();"
>
Save
</v-btn>
</v-card-actions>
</v-card>
</v-dialog>
</div> </div>
<!-- modal-create -->
<v-dialog
v-model="dialog2"
persistent
max-width="600px"
>
<v-card>
<v-card-title>
<span class="text-h5">User Edit</span>
</v-card-title>
<v-card-text>
<v-container>
<v-row>
<v-col
cols="12"
sm="6"
md="4"
>
<v-text-field
v-model="eName"
label="Legal name*"
required
/>
</v-col>
<v-col cols="12">
<v-text-field
v-model="eEmail"
label="Email*"
required
/>
</v-col>
<v-col cols="12">
<v-text-field
v-model="ePassword"
label="Password*"
type="password"
required
/>
</v-col>
</v-row>
</v-container>
<small>*indicates required field</small>
</v-card-text>
<v-card-actions>
<v-spacer />
<v-btn
color="blue darken-1"
text
@click="dialog2 = false"
>
Close
</v-btn>
<v-btn
color="blue darken-1"
text
type="submit"
@click="dialog2 = false; updateUser();"
>
Save
</v-btn>
</v-card-actions>
</v-card>
</v-dialog>
<v-data-table :headers="headers" :items="users" sort-by="calories" class="elevation-1"> <v-data-table :headers="headers" :items="users" sort-by="calories" class="elevation-1">
<template v-slot:top> <template #top>
<v-toolbar flat> <v-toolbar flat>
<v-toolbar-title>User Manage</v-toolbar-title> <v-toolbar-title>User Manage</v-toolbar-title>
<v-divider class="mx-4" inset vertical></v-divider> <v-divider class="mx-4" inset vertical />
<v-spacer></v-spacer> <v-spacer />
<v-dialog v-model="dialog" max-width="500px">
<template v-slot:activator="{ on, attrs }">
<!-- modal create user -->
</template>
<v-card>
<v-card-title>
<span class="text-h5">{{ formTitle }}</span>
</v-card-title>
<v-card-text>
<v-container>
<v-row>
<v-col cols="12" sm="6" md="4">
<v-text-field v-model="editedItem.name" label="name"></v-text-field>
</v-col>
<v-col cols="12" sm="6" md="4">
<v-text-field v-model="editedItem.id" label="id"></v-text-field>
</v-col>
<v-col cols="12" sm="6" md="4">
<v-text-field v-model="editedItem.email" label="email"></v-text-field>
</v-col>
<v-col cols="12" sm="6" md="4">
<v-text-field v-model="editedItem.created_at" label="created_at"></v-text-field>
</v-col>
<v-col cols="12" sm="6" md="4">
<v-text-field v-model="editedItem.updated_at" label="updated_at"></v-text-field>
</v-col>
</v-row>
</v-container>
</v-card-text>
<v-card-actions>
<v-spacer></v-spacer>
<v-btn color="blue darken-1" text @click="close">
Cancel
</v-btn>
<v-btn color="blue darken-1" text @click="save"> Save </v-btn>
</v-card-actions>
</v-card>
</v-dialog>
<v-dialog v-model="dialogDelete" max-width="500px">
<v-card>
<v-card-title class="text-h5">Are you sure you want to delete this item?</v-card-title>
<v-card-actions>
<v-spacer></v-spacer>
<v-btn color="blue darken-1" text @click="closeDelete">Cancel</v-btn>
<v-btn color="blue darken-1" text @click="deleteItemConfirm">OK</v-btn>
<v-spacer></v-spacer>
</v-card-actions>
</v-card>
</v-dialog>
</v-toolbar> </v-toolbar>
</template> </template>
<template v-slot:item.actions="{ item }"> <template #item.actions="{ item }">
<v-icon small class="mr-2" @click="editUser(item)" :id="item.id"> mdi-pencil </v-icon> <v-icon :id="item.id" small class="mr-2" @click="dialog2 = true; editUser(item);">
<v-icon small @click="deleteUser(item.id, item)" :id="item.id"> mdi-delete </v-icon> mdi-pencil
</v-icon>
<v-icon :id="item.id" small @click="deleteUser(item.id, item)">
mdi-delete
</v-icon>
</template> </template>
<template v-slot:no-data> <template #no-data>
<v-btn color="primary" @click="initialize"> Reset </v-btn> <v-btn color="primary" @click="initialize">
Reset
</v-btn>
</template> </template>
</v-data-table> </v-data-table>
</div> </div>
</v-app>
</template> </template>
<script> <script>
export default { export default {
...@@ -127,21 +182,35 @@ export default { ...@@ -127,21 +182,35 @@ export default {
name: '', name: '',
password: '', password: '',
error: '', error: '',
dialog: false, dialog1: false,
dialog2: false,
dialogDelete: false, dialogDelete: false,
headers: [ headers: [
{ {
text: 'Name', text: 'Name',
align: 'start', align: 'start',
sortable: false, sortable: false,
value: 'name', value: 'name'
}, },
{ text: 'id', value: 'id' }, { text: 'id', value: 'id' },
{ text: 'email', value: 'email' }, { text: 'email', value: 'email' },
{ text: 'status', value: 'id', sortable: false }, { text: 'status', value: 'id', sortable: false },
{ text: 'created_at', value: 'created_at' }, { text: 'created_at', value: 'created_at' },
{ text: 'updated_at', value: 'updated_at' }, { text: 'updated_at', value: 'updated_at' },
{ text: 'Actions', value: 'actions', sortable: false }, { text: 'Actions', value: 'actions', sortable: false }
],
items: [
{
icon: 'mdi-home',
text: 'Home',
disabled: false,
href: '/home'
},
{
text: 'User',
disabled: false,
href: '/users'
}
], ],
users: [], users: [],
eIndex: [], eIndex: [],
...@@ -156,7 +225,7 @@ export default { ...@@ -156,7 +225,7 @@ export default {
id: '', id: '',
email: '', email: '',
created_at: '', created_at: '',
updated_at: '', updated_at: ''
}, },
defaultItem: { defaultItem: {
name: '', name: '',
...@@ -164,61 +233,61 @@ export default { ...@@ -164,61 +233,61 @@ export default {
email: '', email: '',
status: '', status: '',
created_at: '', created_at: '',
updated_at: '', updated_at: ''
}, }
} }
}, },
computed: { computed: {
formTitle() { formTitle () {
return this.editedIndex === -1 ? 'New Item' : 'Edit Item' return this.editedIndex === -1 ? 'New Item' : 'Edit Item'
}, }
}, },
watch: { watch: {
dialog(val) { dialog (val) {
val || this.close() val || this.close()
}, },
dialogDelete(val) { dialogDelete (val) {
val || this.closeDelete() val || this.closeDelete()
}, }
}, },
created() { created () {
this.initialize() this.initialize()
this.getUsers() this.getUsers()
}, },
methods: { methods: {
initialize() { initialize () {
this.users = [], this.users = []
this.editedItem = {} this.editedItem = {}
}, },
editItem(item) { editItem (item) {
this.editedIndex = this.users.indexOf(item) this.editedIndex = this.users.indexOf(item)
this.editedItem = Object.assign({}, item) this.editedItem = Object.assign({}, item)
this.dialog = true this.dialog = true
}, },
deleteItem(item) { deleteItem (item) {
this.editedIndex = this.users.indexOf(item) this.editedIndex = this.users.indexOf(item)
this.editedItem = Object.assign({}, item) this.editedItem = Object.assign({}, item)
this.dialogDelete = true this.dialogDelete = true
}, },
deleteItemConfirm() { deleteItemConfirm () {
this.users.splice(this.editedIndex, 1) this.users.splice(this.editedIndex, 1)
this.closeDelete() this.closeDelete()
}, },
close() { close () {
this.dialog = false this.dialog = false
this.$nextTick(() => { this.$nextTick(() => {
this.editedItem = Object.assign({}, this.defaultItem) this.editedItem = Object.assign({}, this.defaultItem)
this.editedIndex = -1 this.editedIndex = -1
}) })
}, },
closeDelete() { closeDelete () {
this.dialogDelete = false this.dialogDelete = false
this.$nextTick(() => { this.$nextTick(() => {
this.editedItem = Object.assign({}, this.defaultItem) this.editedItem = Object.assign({}, this.defaultItem)
this.editedIndex = -1 this.editedIndex = -1
}) })
}, },
save() { save () {
if (this.editedIndex > -1) { if (this.editedIndex > -1) {
Object.assign(this.users[this.editedIndex], this.editedItem) Object.assign(this.users[this.editedIndex], this.editedItem)
} else { } else {
...@@ -226,28 +295,34 @@ export default { ...@@ -226,28 +295,34 @@ export default {
} }
this.close() this.close()
}, },
getUsers() { getUsers () {
this.$axios this.$axios
.get('/users/') .get('/users/', {
.then((response) => (this.users = response.data.data.data)) headers: {
'Content-Type': 'application/json',
Authorization: `Bearer ${this.$auth.$storage.getUniversal('token')}`
}
})
.then(response => (this.users = response.data.data.data))
.catch(function (error) { .catch(function (error) {
console.log(error) console.log(error)
}) })
}, },
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 => { headers: {
// $bvModal.hide('modal-login') 'Content-Type': 'application/json',
this.$bvModal.hide('modal-login') Authorization: `Bearer ${this.$auth.$storage.getUniversal('token')}`
}
}
)
.then((response) => {
self.$toast.success('User created successfully!', { self.$toast.success('User created successfully!', {
duration: 3000 duration: 3000
}) })
...@@ -256,7 +331,7 @@ export default { ...@@ -256,7 +331,7 @@ export default {
console.log(this.editedItem) console.log(this.editedItem)
this.users.push(this.editedItem) this.users.push(this.editedItem)
}) })
.catch(errors => { .catch((errors) => {
this.$bvModal.hide('modal-login') this.$bvModal.hide('modal-login')
console.log(errors.response.data.message) console.log(errors.response.data.message)
this.message = errors.response.data.message this.message = errors.response.data.message
...@@ -265,14 +340,14 @@ export default { ...@@ -265,14 +340,14 @@ export default {
}) })
}) })
}, },
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 => { .then((response) => {
console.log(response.data) console.log(response.data)
this.users.splice(this.editedIndex, 1) this.users.splice(this.editedIndex, 1)
self.$toast.success('User deleted successfully!', { self.$toast.success('User deleted successfully!', {
...@@ -284,39 +359,47 @@ export default { ...@@ -284,39 +359,47 @@ export default {
} }
} }
}, },
editUser(user) { editUser (user) {
this.$bvModal.show('modal-edit')
this.eID = user.id this.eID = user.id
this.eEmail = user.email this.eEmail = user.email
this.eName = user.name this.eName = user.name
this.editedIndex = this.users.indexOf(user) this.editedIndex = this.users.indexOf(user)
console.log(this?.eID) console.log(this?.eID)
}, },
updateUser(userID) { updateUser (userID) {
const self = this const self = this
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 { this.$axios
this.$axios .put(`/users/${this?.eID}`,
.put(`/users/${this?.eID}`, { {
email: this.eEmail, email: this.eEmail,
password: this.ePassword, password: this.ePassword,
name: this.eName, name: this.eName
},
{
headers: {
'Content-Type': 'application/json',
Authorization: `Bearer ${this.$auth.$storage.getUniversal('token')}`
}
}
)
.then((response) => {
self.$toast.success('User updated successfully!', {
duration: 3000
}) })
.then(response => { console.log(response)
self.$toast.success('User updated successfully!', { this.editedItem = response.data.data
duration: 3000 Object.assign(this.users[this.editedIndex], this.editedItem)
}) })
console.log(response) .catch((error) => {
this.editedItem = response.data.data console.log(error)
this.$bvModal.hide('modal-edit') self.$toast.error('something went wrong while trying update!', {
Object.assign(this.users[this.editedIndex], this.editedItem) duration: 3000
}) })
} catch (error) { })
console.log(error)
}
} }
}, }
} }
</script> </script>
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