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

add CRUD category

parent ef2d4838
...@@ -28,8 +28,7 @@ export default { ...@@ -28,8 +28,7 @@ export default {
], ],
// Plugins to run before rendering page: https://go.nuxtjs.dev/config-plugins // Plugins to run before rendering page: https://go.nuxtjs.dev/config-plugins
plugins: [ plugins: ['~/plugins/axios.js'],
],
// Auto import components: https://go.nuxtjs.dev/config-components // Auto import components: https://go.nuxtjs.dev/config-components
components: true, components: true,
...@@ -57,6 +56,7 @@ export default { ...@@ -57,6 +56,7 @@ export default {
debug: process.env.DEBUG || false, debug: process.env.DEBUG || false,
proxyHeaders: false, proxyHeaders: false,
credentials: false, credentials: false,
}, },
auth: { auth: {
...@@ -79,5 +79,6 @@ export default { ...@@ -79,5 +79,6 @@ export default {
} }
} }
] ]
}, },
} }
...@@ -35,7 +35,7 @@ ...@@ -35,7 +35,7 @@
<input <input
type="text" type="text"
class="form-control mb-2" class="form-control mb-2"
placeholder="password" placeholder="Ordering"
v-model="ordering" v-model="ordering"
required required
/> />
...@@ -56,6 +56,50 @@ ...@@ -56,6 +56,50 @@
<button @click="createCategory" v-b-modal.modal-close_visit class="btn btn-success btn-sm m-1">Submit</button> <button @click="createCategory" v-b-modal.modal-close_visit class="btn btn-success btn-sm m-1">Submit</button>
</template> </template>
</b-modal> </b-modal>
<!-- edit-modal -->
<b-modal id="modal-edit" title="Edit Category" class="modal fade" >
<p class="my-4">
<form >
<label>Name :</label>
<input
type="text"
class="form-control mb-2"
placeholder="name"
v-model="eName"
max="255"
min="1"
/>
<label>Parent ID :</label>
<input
type="text"
class="form-control mb-2"
placeholder="Parent ID"
v-model="eParent_id"
/>
<label>Ordering :</label>
<input
type="text"
class="form-control mb-2"
placeholder="Ordering"
v-model="eOrdering"
/>
<!-- <b-form-select v-model="selected" :options="options"></b-form-select> -->
<label>Image :</label>
<b-form-file
v-model="eImage"
:state="Boolean(eImage)"
placeholder="Choose a image or drop it here..."
drop-placeholder="Drop file here..."
></b-form-file>
</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="updateCategory(this?.eID)" v-b-modal.modal-close_visit class="btn btn-success btn-sm m-1">Submit</button>
</template>
</b-modal>
<div> <div>
<v-data-table <v-data-table
...@@ -143,8 +187,8 @@ ...@@ -143,8 +187,8 @@
</v-toolbar> </v-toolbar>
</template> </template>
<template v-slot:item.actions="{ item }"> <template v-slot:item.actions="{ item }">
<v-icon small class="mr-2" @click=" editUser(item.id);" :id ="item.id"> mdi-pencil </v-icon> <v-icon small class="mr-2" @click=" editCategory(item.id)" :id ="item.id"> mdi-pencil </v-icon>
<v-icon small @click="deleteUser(item.id)" :id ="item.id"> mdi-delete </v-icon> <v-icon small @click="deleteCategory(item.id,item)" :id ="item.id"> mdi-delete </v-icon>
</template> </template>
<template v-slot:no-data> <template v-slot:no-data>
<v-btn color="primary" @click="initialize"> Reset </v-btn> <v-btn color="primary" @click="initialize"> Reset </v-btn>
...@@ -204,9 +248,10 @@ export default { ...@@ -204,9 +248,10 @@ export default {
], ],
categories: [], categories: [],
eID: '', eID: '',
eEmail:'',
eName:'', eName:'',
ePassword:'', eOrdering:'',
eParent_id:'',
eImage: null,
message: [], message: [],
editedIndex: -1, editedIndex: -1,
editedItem: { editedItem: {
...@@ -305,7 +350,7 @@ export default { ...@@ -305,7 +350,7 @@ export default {
}, { }, {
headers: { headers: {
"Content-Type": "multipart/form-data", "Content-Type": "multipart/form-data",
"Authorization": "bearer " + this.$auth.$storage.getUniversal("token") "Authorization": this.$auth.$storage.getUniversal("token")
} }
}) })
.then(response => { .then(response => {
...@@ -329,37 +374,50 @@ export default { ...@@ -329,37 +374,50 @@ export default {
this.url = URL.createObjectURL(file); this.url = URL.createObjectURL(file);
this.image = file; this.image = file;
console.log(file) console.log(file)
console.log(this.image)
}, },
deleteUser(userID) { deleteCategory(ID,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{
axios axios
.delete(`http://127.0.0.1:8000/api/categories/${userID}`) .delete(`http://127.0.0.1:8000/api/categories/${ID}`)
.then(response => {
this.categories.splice(this.editedIndex, 1);
})
} catch(error){ } catch(error){
console.log(error) console.log(error)
} }
} }
}, },
getID(item) {
editUser(userID) { console.log(this.categories.indexOf(item))
},
editCategory(userID) {
this.$bvModal.show('modal-edit'); this.$bvModal.show('modal-edit');
this.eID = userID; this.eID = userID;
console.log(this?.eID); console.log(this?.eID);
console.log(this.eName);
}, },
updateUser(userID) { updateCategory(userID) {
const self = this const self = this
console.log(this.eName); console.log(this.eName);
console.log(this.eEmail); console.log(this.eOrdering);
console.log(this?.eID); console.log(this?.eID);
try{ try{
axios axios
.put(`http://127.0.0.1:8000/api/categories/${this?.eID}`,{ .post(`http://127.0.0.1:8000/api/categories/update/${this?.eID}`,{
name: this.eName,
email: this.eEmail, ordering: this.eOrdering,
password: this.ePassword, parent_id: this.eParent_id,
name:this.eName,} ) image: this.eImage }, {
headers: {
"Content-Type": "multipart/form-data",
"Authorization": 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
......
...@@ -94,6 +94,7 @@ export default { ...@@ -94,6 +94,7 @@ export default {
body: JSON.stringify({ body: JSON.stringify({
email: this.email, email: this.email,
password: this.password, password: this.password,
status: this.status,
}), }),
}).then((response) => { }).then((response) => {
return response.json(); return response.json();
......
...@@ -78,6 +78,7 @@ export default { ...@@ -78,6 +78,7 @@ export default {
method: "POST", method: "POST",
headers: { headers: {
"Content-Type": "application/json", "Content-Type": "application/json",
Accept: "application/json",
}, },
body: JSON.stringify({ body: JSON.stringify({
name: this.name, name: this.name,
......
export default ({ $axios}) => {
$axios.onRequest(config => {
config.headers.common['Content-Type'] = 'multipart/form-data';
});
}
\ No newline at end of file
import { LocalScheme } from '~auth/runtime'
export default class CustomScheme extends LocalScheme {
// Override `fetchUser` method of `local` scheme
async fetchUser (endpoint) {
// Token is required but not available
if (!this.check().valid) {
return
}
// User endpoint is disabled.
if (!this.options.endpoints.user) {
this.$auth.setUser({})
return
}
// Try to fetch user and then set
return this.$auth.requestWith(
this.name,
endpoint,
this.options.endpoints.user
).then((response) => {
const user = getProp(response.data, this.options.user.property)
// Transform the user object
const customUser = {
...user,
fullName: user.firstName + ' ' + user.lastName,
roles: ['user']
}
// Set the custom user
// The `customUser` object will be accessible through `this.$auth.user`
// Like `this.$auth.user.fullName` or `this.$auth.user.roles`
this.$auth.setUser(customUser)
return response
}).catch((error) => {
this.$auth.callOnError(error, { method: 'fetchUser' })
})
}
}
\ No newline at end of file
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