Commit 04d79a95 authored by esatakpunar's avatar esatakpunar

products add and edit properties

parent 20fea156
...@@ -68,9 +68,7 @@ export default { ...@@ -68,9 +68,7 @@ export default {
</template> </template>
<template v-slot:[`item.actions`]="{ item }"> <template v-slot:[`item.actions`]="{ item }">
<v-icon small class="mr-2" @click="editItem(item)"> <v-icon small class="mr-2"> mdi-pencil </v-icon>
mdi-pencil
</v-icon>
<v-icon small @click="deleteCustomer([item.id])"> mdi-delete </v-icon> <v-icon small @click="deleteCustomer([item.id])"> mdi-delete </v-icon>
</template> </template>
</v-data-table> </v-data-table>
......
...@@ -11,6 +11,7 @@ export default { ...@@ -11,6 +11,7 @@ export default {
computed: { computed: {
...mapGetters("products", [ ...mapGetters("products", [
"headers", "headers",
"dialogHeaders",
"productList", "productList",
"singleExpand", "singleExpand",
"expanded", "expanded",
...@@ -26,7 +27,8 @@ export default { ...@@ -26,7 +27,8 @@ export default {
"closeDialog", "closeDialog",
"deleteProduct", "deleteProduct",
"deleteMultiProduct", "deleteMultiProduct",
"addProduct", "saveProduct",
"editProduct",
]), ]),
}, },
created() { created() {
...@@ -55,70 +57,68 @@ export default { ...@@ -55,70 +57,68 @@ export default {
<v-toolbar-title>Products</v-toolbar-title> <v-toolbar-title>Products</v-toolbar-title>
<v-divider class="mx-4" inset vertical></v-divider> <v-divider class="mx-4" inset vertical></v-divider>
<v-dialog v-model="dialog" max-width="750px"> <v-btn
<template v-slot:activator="{ on, attrs }"> large
<v-btn icon
large color="success"
icon class="white--text"
color="success" @click="editProduct()"
class="ml-4" >
v-bind="attrs"
v-on="on"
>
<v-icon>add</v-icon>
</v-btn>
</template>
<v-card>
<v-card-title>
<span class="text-h5">Add Product</span>
</v-card-title>
<v-card-text>
<v-container>
<v-row>
<template v-for="header in headers">
<v-flex
xs12
sm6
md4
pa-4
:key="header.value"
v-if="!(header.value === 'actions')"
>
<v-text-field
v-model="editedItem[header.value]"
:label="header.text"
></v-text-field>
</v-flex>
</template>
</v-row>
</v-container>
</v-card-text>
<v-card-actions>
<v-spacer></v-spacer>
<v-btn color="blue darken-1" text> Cancel </v-btn>
<v-btn color="blue darken-1" text @click="addProduct()">
Save
</v-btn>
</v-card-actions>
</v-card>
</v-dialog>
<!-- <v-btn large icon color="success" class="white--text ml-2">
<v-icon>add</v-icon> <v-icon>add</v-icon>
</v-btn> --> </v-btn>
<v-btn <v-btn
large large
icon icon
color="red" color="red"
class="white--text ml-2" class="white--text"
@click="deleteMultiProduct(selected)" @click="deleteMultiProduct(selected)"
> >
<v-dialog v-model="dialog" max-width="500px">
<template v-slot:activator="{}"> </template>
<v-card>
<v-card-title>
<span class="headline"></span>
</v-card-title>
<v-card-text>
<v-container grid-list-md>
<v-layout wrap>
<template v-for="header in dialogHeaders">
<v-flex
xs12
sm6
md4
:key="header.value"
v-if="!(header.value === 'actions')"
>
<v-text-field
v-model="editedItem[header.value]"
:label="header.text"
></v-text-field>
</v-flex>
</template>
</v-layout>
</v-container>
</v-card-text>
<v-card-actions>
<v-spacer></v-spacer>
<template>
<v-btn color="blue darken-1" @click="closeDialog()"
>Cancel</v-btn
>
<v-btn color="blue darken-1" @click="saveProduct()">
Save</v-btn
>
</template>
</v-card-actions>
</v-card>
</v-dialog>
<v-icon>delete</v-icon> <v-icon>delete</v-icon>
</v-btn> </v-btn>
<v-spacer></v-spacer> <v-spacer></v-spacer>
<v-switch <v-switch
v-model="singleExpand" v-model="singleExpand"
label="Single expand" label="Single expand"
...@@ -133,7 +133,7 @@ export default { ...@@ -133,7 +133,7 @@ export default {
</template> </template>
<template v-slot:[`item.actions`]="{ item }"> <template v-slot:[`item.actions`]="{ item }">
<v-icon small class="mr-2" @click="editItem(item)"> <v-icon small class="mr-2" @click="editProduct(item)">
mdi-pencil mdi-pencil
</v-icon> </v-icon>
<v-icon small @click="deleteProduct([item.id])"> mdi-delete </v-icon> <v-icon small @click="deleteProduct([item.id])"> mdi-delete </v-icon>
......
...@@ -31,6 +31,7 @@ export default { ...@@ -31,6 +31,7 @@ export default {
console.log(e); console.log(e);
}); });
}); });
this.itemList = [];
}, },
deleteMultiProduct({ dispatch }, items) { deleteMultiProduct({ dispatch }, items) {
const itemList = []; const itemList = [];
...@@ -40,16 +41,31 @@ export default { ...@@ -40,16 +41,31 @@ export default {
console.log(itemList); console.log(itemList);
dispatch("deleteProduct", itemList); dispatch("deleteProduct", itemList);
}, },
addProduct({ getters, dispatch }) {
const config = { saveProduct({ getters, dispatch }) {
if (!getters.editedItem.image) {
getters.editedItem.image =
"https://upload.wikimedia.org/wikipedia/commons/7/70/Solid_white.svg";
}
const postConfig = {
method: "post", method: "post",
url: `http://localhost:3000/products/`, url: `http://localhost:3000/products/`,
data: { products: getters.editedItem }, data: getters.editedItem,
};
const putConfig = {
method: "put",
url: `http://localhost:3000/products/${getters.editedItem.id}`,
data: getters.editedItem,
}; };
axios(config).then(() => { axios(!getters.editedItem.id ? postConfig : putConfig).then(() => {
console.log("TESET");
dispatch("fetchProductData"); dispatch("fetchProductData");
}); });
dispatch("closeDialog"); dispatch("closeDialog");
}, },
editProduct({ commit, getters }, item) {
commit("setEditedIndex", getters.productList.indexOf(item));
commit("setEditedItem", Object.assign({}, item));
commit("setDialog", true);
},
}; };
...@@ -16,6 +16,23 @@ export default { ...@@ -16,6 +16,23 @@ export default {
{ text: "Actions", value: "actions", sortable: false }, { text: "Actions", value: "actions", sortable: false },
]; ];
}, },
dialogHeaders() {
return [
{
text: "Product Name",
align: "left",
value: "productName",
type: "text",
},
{ text: "Type", value: "type", type: "text" },
{ text: "Product Material", value: "productMaterial", type: "text" },
{ text: "Department", value: "department", type: "text" },
{ text: "Color", value: "color", type: "text" },
{ text: "Price", value: "price", type: "text" },
{ text: "Image", value: "image", type: "text" },
{ text: "Product Description", value: "productDescription" },
];
},
productList(state) { productList(state) {
return state.productList; return state.productList;
}, },
......
...@@ -8,4 +8,10 @@ export default { ...@@ -8,4 +8,10 @@ export default {
setDialog(state, value) { setDialog(state, value) {
state.dialog = value; state.dialog = value;
}, },
setEditedIndex(state, index) {
state.editedIndex = index;
},
setEditedItem(state, item) {
state.editedItem = item;
},
}; };
This source diff could not be displayed because it is too large. You can view the blob instead.
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