Commit 589c8c7a authored by esatakpunar's avatar esatakpunar

filter propertied added

parent 5dd075d3
...@@ -6,16 +6,25 @@ export default { ...@@ -6,16 +6,25 @@ export default {
data() { data() {
return { return {
selected: [], selected: [],
column: "all",
search: "",
}; };
}, },
computed: { computed: {
...mapGetters("customers", [ ...mapGetters("customers", [
"headers", "headers",
"customerList", "customerList",
"filteredCustomerList",
"dialog", "dialog",
"dialogHeaders",
"editedItem", "editedItem",
"editedIndex", "editedIndex",
]), ]),
indexofColumn() {
return this.dialogHeaders.findIndex(
(header) => this.column == header.value
);
},
}, },
methods: { methods: {
...mapActions("customers", [ ...mapActions("customers", [
...@@ -24,10 +33,13 @@ export default { ...@@ -24,10 +33,13 @@ export default {
"closeDialog", "closeDialog",
"deleteCustomer", "deleteCustomer",
"deleteMultiCustomer", "deleteMultiCustomer",
"saveCustomer",
"editCustomer",
"filterCustomer",
]), ]),
}, },
created() { created() {
this.fetchCustomerData(); this.fetchCustomerData({ searchInput: "", filterColumn: "id" });
}, },
}; };
</script> </script>
...@@ -49,18 +61,112 @@ export default { ...@@ -49,18 +61,112 @@ export default {
<v-toolbar-title>Customers</v-toolbar-title> <v-toolbar-title>Customers</v-toolbar-title>
<v-divider class="mx-4" inset vertical></v-divider> <v-divider class="mx-4" inset vertical></v-divider>
<v-btn
large
icon
color="success"
class="white--text"
@click="editCustomer()"
>
<v-icon>add</v-icon>
</v-btn>
<v-btn <v-btn
large large
icon icon
color="red" color="red"
class="white--text ml-2" class="white--text"
@click="deleteMultiCustomer(selected)" @click="deleteMultiCustomer(selected)"
> >
<v-icon>delete</v-icon> <v-icon>delete</v-icon>
</v-btn> </v-btn>
<v-btn
icon
large
color="blue-grey"
class="white--text"
@click="fetchCustomerData"
>
<v-icon>refresh</v-icon>
</v-btn>
<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' ||
header.value === 'all'
)
"
>
<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="saveCustomer()">
Save</v-btn
>
</template>
</v-card-actions>
</v-card>
</v-dialog>
<v-spacer></v-spacer> <v-spacer></v-spacer>
</v-toolbar> </v-toolbar>
<v-toolbar flat>
<v-select
label="Header Name"
v-model="column"
:items="dialogHeaders"
item-text="text"
item-value="value"
class="mt-5"
></v-select>
<v-text-field
:type="headers[indexofColumn].type"
label="Search"
v-model="search"
single-line
outline
hide-details
class="ml-4"
></v-text-field>
<v-btn
@click="
fetchCustomerData({
searchInput: search,
filterColumn: column,
})
"
class="ml-4"
large
>Search
</v-btn>
</v-toolbar>
</template> </template>
<template v-slot:[`item.image`]="{ item }"> <template v-slot:[`item.image`]="{ item }">
......
import axios from "axios"; import axios from "axios";
export default { export default {
fetchCustomerData({ commit }) { fetchCustomerData({ dispatch, commit }, data = {}) {
let query;
if (data.filterColumn == "all") {
query = "q=" + data.searchInput;
} else if (data.filterColumn) {
query = data.filterColumn + "_like=" + data.searchInput;
}
axios axios
.get("http://localhost:3000/customers") .get(`http://localhost:3000/customers?${query}`)
.then((response) => { .then((response) => {
commit("setCustomerList", response.data); commit("setCustomerList", response.data);
console.log("searchInput", data.searchInput);
console.log("filterColumn", data.filterColumn);
dispatch("filterCustomer", { searchInput: "" });
}) })
.catch((e) => { .catch((e) => {
console.log(e); console.log(e);
}); });
}, },
toggleSingleExpand({ commit }) { toggleSingleExpand({ commit }) {
commit("setSingleExpand"); commit("setSingleExpand");
}, },
...@@ -39,4 +50,48 @@ export default { ...@@ -39,4 +50,48 @@ export default {
console.log(itemList); console.log(itemList);
dispatch("deleteCustomer", itemList); dispatch("deleteCustomer", itemList);
}, },
saveCustomer({ getters, dispatch }) {
const postConfig = {
method: "post",
url: `http://localhost:3000/customers/`,
data: getters.editedItem,
};
const putConfig = {
method: "put",
url: `http://localhost:3000/customers/${getters.editedItem.id}`,
data: getters.editedItem,
};
axios(!getters.editedItem.id ? postConfig : putConfig).then(() => {
dispatch("fetchCustomerData");
});
dispatch("closeDialog");
},
editCustomer({ commit, getters }, item) {
commit("setEditedIndex", getters.customerList.indexOf(item));
commit("setEditedItem", Object.assign({}, item));
commit("setDialog", true);
},
filterCustomer({ getters, commit }, data) {
let x;
if (!data.searchInput) {
x = getters.customerList;
console.log(getters.customerList);
} else {
console.log("searchInput", data.searchInput);
console.log("filterColumn", data.filterColumn);
x = getters.customerList.filter((customer) => {
if (customer[data.filterColumn]) {
return customer[data.filterColumn]
.toLowerCase()
.includes(data.searchInput.toLowerCase());
}
});
}
commit("setfilteredCustomerList", x);
},
}; };
...@@ -11,10 +11,26 @@ export default { ...@@ -11,10 +11,26 @@ export default {
{ text: "Email", value: "email", type: "text" }, { text: "Email", value: "email", type: "text" },
{ text: "Country", value: "country", type: "text" }, { text: "Country", value: "country", type: "text" },
{ text: "City", value: "city", type: "text" }, { text: "City", value: "city", type: "text" },
{ text: "Image", value: "image", type: "text" }, { text: "Image", value: "image", type: "text", sortable: false },
{ text: "Actions", value: "actions", sortable: false }, { text: "Actions", value: "actions", sortable: false },
]; ];
}, },
dialogHeaders() {
return [
{ text: "All Data", value: "all", type: "text" },
{
text: "First Name",
align: "left",
value: "firstName",
type: "text",
},
{ text: "Last Name", value: "lastName", type: "text" },
{ text: "Email", value: "email", type: "text" },
{ text: "Country", value: "country", type: "text" },
{ text: "City", value: "city", type: "text" },
{ text: "Image", value: "image", type: "text", sortable: false },
];
},
customerList(state) { customerList(state) {
return state.customerList; return state.customerList;
}, },
...@@ -27,4 +43,7 @@ export default { ...@@ -27,4 +43,7 @@ export default {
dialog(state) { dialog(state) {
return state.dialog; return state.dialog;
}, },
filteredCustomerList(state) {
return state.filteredCustomerList;
},
}; };
...@@ -2,10 +2,16 @@ export default { ...@@ -2,10 +2,16 @@ export default {
setCustomerList(state, data) { setCustomerList(state, data) {
state.customerList = data; state.customerList = data;
}, },
setSingleExpand(state) { setEditedIndex(state, index) {
state.singleExpand = !state.singleExpand; state.editedIndex = index;
},
setEditedItem(state, item) {
state.editedItem = item;
}, },
setDialog(state, value) { setDialog(state, value) {
state.dialog = value; state.dialog = value;
}, },
setfilteredCustomerList(state, data) {
state.filteredCustomerList = data;
},
}; };
export default () => ({ export default () => ({
customerList: [], customerList: [],
filteredCustomerList: [],
editedIndex: -1, editedIndex: -1,
editedItem: {}, editedItem: {},
dialog: false, dialog: false,
......
...@@ -1227,6 +1227,15 @@ ...@@ -1227,6 +1227,15 @@
"country": "Antarctica (the territory South of 60 deg S)", "country": "Antarctica (the territory South of 60 deg S)",
"city": "New Braunfels", "city": "New Braunfels",
"image": "https://cloudflare-ipfs.com/ipfs/Qmd3W5DuhgHirLHGVixi6V76LhCkZUz6pnFt5AJBiyvHye/avatar/680.jpg" "image": "https://cloudflare-ipfs.com/ipfs/Qmd3W5DuhgHirLHGVixi6V76LhCkZUz6pnFt5AJBiyvHye/avatar/680.jpg"
},
{
"firstName": "Esat",
"lastName": "Akpunar",
"email": "akpunar@reybex.com",
"country": "Turkey",
"city": "Sakarya",
"image": "https://media-exp2.licdn.com/dms/image/C4D03AQH4AA-B_TDbyQ/profile-displayphoto-shrink_200_200/0/1654085687745?e=2147483647&v=beta&t=1RAWuKlHHWPWpCnhxK8h6nhNyhqlNR56BHprJscOqKM",
"id": "DlDXazG"
} }
], ],
"vendors": [ "vendors": [
......
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