Commit 6cc35af0 authored by esatakpunar's avatar esatakpunar

datatable setLoading added

parent 32f09e5c
...@@ -16,6 +16,7 @@ export default { ...@@ -16,6 +16,7 @@ export default {
"customerList", "customerList",
"filteredCustomerList", "filteredCustomerList",
"dialog", "dialog",
"loading",
"dialogHeaders", "dialogHeaders",
"editedItem", "editedItem",
"editedIndex", "editedIndex",
...@@ -53,6 +54,7 @@ export default { ...@@ -53,6 +54,7 @@ export default {
v-model="selected" v-model="selected"
:headers="headers" :headers="headers"
:items="customerList" :items="customerList"
:loading="loading"
show-select show-select
class="evation-1" class="evation-1"
> >
...@@ -170,7 +172,7 @@ export default { ...@@ -170,7 +172,7 @@ export default {
</template> </template>
<template v-slot:[`item.image`]="{ item }"> <template v-slot:[`item.image`]="{ item }">
<img width="75" :src="`${item.image}`" /> <img width="75" :src="`${item.image}`" v-if="item.image" />
</template> </template>
<template v-slot:[`item.actions`]="{ item }"> <template v-slot:[`item.actions`]="{ item }">
......
...@@ -8,13 +8,14 @@ export default { ...@@ -8,13 +8,14 @@ export default {
} else if (data.filterColumn) { } else if (data.filterColumn) {
query = data.filterColumn + "_like=" + data.searchInput; query = data.filterColumn + "_like=" + data.searchInput;
} }
commit("setLoading", true);
axios axios
.get(`http://localhost:3000/customers?${query}`) .get(`http://localhost:3000/customers?${query}`)
.then((response) => { .then((response) => {
commit("setCustomerList", response.data); commit("setCustomerList", response.data);
dispatch("filterCustomer", { searchInput: "" }); dispatch("filterCustomer", { searchInput: "" });
commit("setLoading", false);
}) })
.catch((e) => { .catch((e) => {
console.log(e); console.log(e);
...@@ -28,13 +29,15 @@ export default { ...@@ -28,13 +29,15 @@ export default {
closeDialog({ commit }) { closeDialog({ commit }) {
commit("setDialog", false); commit("setDialog", false);
}, },
deleteCustomer({ dispatch }, idList) { deleteCustomer({ dispatch, commit }, idList) {
confirm("Are you sure you want to delete this item?") && confirm("Are you sure you want to delete this item?") &&
idList.forEach((id) => { idList.forEach((id) => {
commit("setLoading", true);
axios axios
.delete(`http://localhost:3000/customers/${id}`) .delete(`http://localhost:3000/customers/${id}`)
.then(() => { .then(() => {
dispatch("fetchCustomerData"); dispatch("fetchCustomerData");
commit("setLoading", false);
}) })
.catch((e) => { .catch((e) => {
console.log(e); console.log(e);
...@@ -49,7 +52,7 @@ export default { ...@@ -49,7 +52,7 @@ export default {
dispatch("deleteCustomer", itemList); dispatch("deleteCustomer", itemList);
}, },
saveCustomer({ getters, dispatch }) { saveCustomer({ getters, dispatch, commit }) {
const postConfig = { const postConfig = {
method: "post", method: "post",
url: `http://localhost:3000/customers/`, url: `http://localhost:3000/customers/`,
...@@ -61,9 +64,10 @@ export default { ...@@ -61,9 +64,10 @@ export default {
url: `http://localhost:3000/customers/${getters.editedItem.id}`, url: `http://localhost:3000/customers/${getters.editedItem.id}`,
data: getters.editedItem, data: getters.editedItem,
}; };
commit("setLoading", true);
axios(!getters.editedItem.id ? postConfig : putConfig).then(() => { axios(!getters.editedItem.id ? postConfig : putConfig).then(() => {
dispatch("fetchCustomerData"); dispatch("fetchCustomerData");
commit("setLoading", false);
}); });
dispatch("closeDialog"); dispatch("closeDialog");
}, },
......
...@@ -43,6 +43,9 @@ export default { ...@@ -43,6 +43,9 @@ export default {
dialog(state) { dialog(state) {
return state.dialog; return state.dialog;
}, },
loading(state) {
return state.loading;
},
filteredCustomerList(state) { filteredCustomerList(state) {
return state.filteredCustomerList; return state.filteredCustomerList;
}, },
......
...@@ -11,6 +11,10 @@ export default { ...@@ -11,6 +11,10 @@ export default {
setDialog(state, value) { setDialog(state, value) {
state.dialog = value; state.dialog = value;
}, },
setLoading(state, value) {
state.loading = value;
console.log(value);
},
setfilteredCustomerList(state, data) { setfilteredCustomerList(state, data) {
state.filteredCustomerList = data; state.filteredCustomerList = data;
}, },
......
...@@ -4,4 +4,5 @@ export default () => ({ ...@@ -4,4 +4,5 @@ export default () => ({
editedIndex: -1, editedIndex: -1,
editedItem: {}, editedItem: {},
dialog: false, dialog: false,
loading: false,
}); });
...@@ -19,6 +19,7 @@ export default { ...@@ -19,6 +19,7 @@ export default {
"singleExpand", "singleExpand",
"expanded", "expanded",
"dialog", "dialog",
"loading",
"editedItem", "editedItem",
"editedIndex", "editedIndex",
]), ]),
...@@ -55,6 +56,7 @@ export default { ...@@ -55,6 +56,7 @@ export default {
v-model="selected" v-model="selected"
:headers="headers" :headers="headers"
:items="productList" :items="productList"
:loading="loading"
:single-expand="singleExpand" :single-expand="singleExpand"
:expanded.sync="expanded" :expanded.sync="expanded"
show-select show-select
......
...@@ -8,12 +8,13 @@ export default { ...@@ -8,12 +8,13 @@ export default {
} else if (data.filterColumn) { } else if (data.filterColumn) {
query = data.filterColumn + "_like=" + data.searchInput; query = data.filterColumn + "_like=" + data.searchInput;
} }
commit("setLoading", true);
axios axios
.get(`http://localhost:3000/products?${query}`) .get(`http://localhost:3000/products?${query}`)
.then((response) => { .then((response) => {
commit("setProductList", response.data); commit("setProductList", response.data);
dispatch("filterProduct", { searchInput: "" }); dispatch("filterProduct", { searchInput: "" });
commit("setLoading", false);
}) })
.catch((e) => { .catch((e) => {
console.log(e); console.log(e);
...@@ -28,13 +29,16 @@ export default { ...@@ -28,13 +29,16 @@ export default {
commit("setDialog", false); commit("setDialog", false);
}, },
deleteProduct({ dispatch }, idList) { deleteProduct({ dispatch, commit }, idList) {
confirm("Are you sure you want to delete this item?") && confirm("Are you sure you want to delete this item?") &&
idList.forEach((id) => { idList.forEach((id) => {
commit("setLoading", true);
axios axios
.delete(`http://localhost:3000/products/${id}`) .delete(`http://localhost:3000/products/${id}`)
.then(() => { .then(() => {
dispatch("fetchProductData"); dispatch("fetchProductData");
commit("setLoading", false);
}) })
.catch((e) => { .catch((e) => {
console.log(e); console.log(e);
...@@ -51,7 +55,7 @@ export default { ...@@ -51,7 +55,7 @@ export default {
dispatch("deleteProduct", itemList); dispatch("deleteProduct", itemList);
}, },
saveProduct({ getters, dispatch }) { saveProduct({ getters, dispatch, commit }) {
const postConfig = { const postConfig = {
method: "post", method: "post",
url: `http://localhost:3000/products/`, url: `http://localhost:3000/products/`,
...@@ -63,9 +67,11 @@ export default { ...@@ -63,9 +67,11 @@ export default {
url: `http://localhost:3000/products/${getters.editedItem.id}`, url: `http://localhost:3000/products/${getters.editedItem.id}`,
data: getters.editedItem, data: getters.editedItem,
}; };
commit("setLoading", true);
axios(!getters.editedItem.id ? postConfig : putConfig).then(() => { axios(!getters.editedItem.id ? postConfig : putConfig).then(() => {
dispatch("fetchProductData"); dispatch("fetchProductData");
commit("setLoading", false);
}); });
dispatch("closeDialog"); dispatch("closeDialog");
}, },
......
...@@ -53,6 +53,9 @@ export default { ...@@ -53,6 +53,9 @@ export default {
dialog(state) { dialog(state) {
return state.dialog; return state.dialog;
}, },
loading(state) {
return state.loading;
},
filteredProductList(state) { filteredProductList(state) {
return state.filteredProductList; return state.filteredProductList;
}, },
......
...@@ -8,6 +8,10 @@ export default { ...@@ -8,6 +8,10 @@ export default {
setDialog(state, value) { setDialog(state, value) {
state.dialog = value; state.dialog = value;
}, },
setLoading(state, value) {
state.loading = value;
console.log(value);
},
setEditedIndex(state, index) { setEditedIndex(state, index) {
state.editedIndex = index; state.editedIndex = index;
}, },
......
...@@ -6,4 +6,5 @@ export default () => ({ ...@@ -6,4 +6,5 @@ export default () => ({
editedIndex: -1, editedIndex: -1,
editedItem: {}, editedItem: {},
dialog: false, dialog: false,
loading: false,
}); });
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