Skip to content

Commit

Permalink
feat: added filtering
Browse files Browse the repository at this point in the history
  • Loading branch information
Ondřej Mikolášek committed Apr 1, 2024
1 parent e60426e commit 12a743c
Show file tree
Hide file tree
Showing 14 changed files with 5,157 additions and 4,460 deletions.
6 changes: 5 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
{
"vue3snippets.enable-compile-vue-file-on-did-save-code": true
"vue3snippets.enable-compile-vue-file-on-did-save-code": true,
"typescript.tsdk": "node_modules/typescript/lib",
"files.exclude": {
"**/.nuxt": true
}
}
12 changes: 3 additions & 9 deletions components/BrandSelector.vue
Original file line number Diff line number Diff line change
@@ -1,15 +1,9 @@
<template>
<p class="title">Brand</p>
<Tree
v-model:selectionKeys="selectedKey"
:value="getNodes()"
selectionMode="checkbox"
class="no-border"
></Tree>
<Tree :value="getNodes()" selectionMode="checkbox" class="no-border"></Tree>
</template>

<script setup lang="ts">
const selectedKey = ref<any>(null);
const { categoryId } = defineProps({
categoryId: {
type: Number,
Expand All @@ -19,7 +13,7 @@ const { categoryId } = defineProps({
const { data } = await useAsyncGql("getBrands", { categoryId: categoryId });
const getNodes = () => {
function getNodes(): object[] {
const brands: object[] = [];
const rawBrands =
data.value?.queryProduct.extraResults.facetSummary?.brand?.facetStatistics;
Expand All @@ -33,7 +27,7 @@ const getNodes = () => {
}
}
return brands;
};
}
</script>

<style scoped>
Expand Down
4 changes: 2 additions & 2 deletions components/ListSpecialItems.vue
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@
{{ item.data.priceForSale.priceWithTax }},-Kč
</div>
<span>
<Button icon="pi pi-heart" severity="secondary" outlined />
<Button icon="pi pi-shopping-cart" class="ml-2" />
<Button icon="pi pi-heart" severity="secondary" outlined></Button>
<Button icon="pi pi-shopping-cart" class="ml-2"></Button>
</span>
</div>
</div>
Expand Down
29 changes: 23 additions & 6 deletions components/NavMenu.vue
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,12 @@
<div>
<Menubar v-if="data && data.listCategory" :model="getItems()">
<template #start>
<NuxtImg format="avif" height="40" src="/evitadb.png" alt="Icon EvitaDB" />
<NuxtImg
format="avif"
height="40"
src="/evitadb.png"
alt="Icon EvitaDB"
/>
</template>
<template #item="{ item, props, hasSubmenu, root }">
<NuxtLink
Expand Down Expand Up @@ -34,7 +39,13 @@
</template>
<template #end>
<div class="flex align-items-center gap-2">
<InputText placeholder="Search" type="text" class="w-8rem sm:w-auto" />
<InputText
placeholder="Search"
type="text"
class="w-8rem sm:w-auto"
/>
<Avatar image="/person.svg" shape="circle" />
<i class="pi pi-shopping-cart icon"></i>
</div>
</template>
</Menubar>
Expand All @@ -44,15 +55,17 @@
<script lang="ts" setup>
const { data } = await useAsyncGql("listCategory");
function getItems(): Object[] {
const menuItems: Object[] = [];
function getItems(): object[] {
const menuItems: object[] = [];
menuItems.push({
label: "Home",
icon: "pi pi-home",
link: "/",
});
if (data.value) {
for (const menuItem of data.value?.listCategory.filter((x) => !x.parentPrimaryKey)) {
for (const menuItem of data.value?.listCategory.filter(
(x) => !x.parentPrimaryKey
)) {
const subItemsNames = data.value?.listCategory.filter(
(x) => x.parentPrimaryKey === menuItem.primaryKey
);
Expand All @@ -68,7 +81,6 @@ function getItems(): Object[] {
menuItems.push({
label: menuItem.attributes?.name,
items: subItems,
link: `/offer/${menuItem.primaryKey}/1`,
});
} else {
menuItems.push({
Expand Down Expand Up @@ -99,4 +111,9 @@ ul li a {
color: black;
font-weight: bold;
}
.icon {
font-size: 1.5em;
color: black;
}
</style>
24 changes: 18 additions & 6 deletions components/PageCounter.vue
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
<template>
<div class="container">
<div class="left-controls">
<button class="move" @click="moveStart()">
<button class="move" @click="moveStart()" :disabled="page === 1">
<i class="pi pi-angle-double-left"></i>
</button>
<button class="move" @click="movePrevious()">
<button class="move" @click="movePrevious()" :disabled="page === 1">
<i class="pi pi-angle-left"></i>
</button>
</div>
Expand All @@ -18,10 +18,18 @@
</ul>
</div>
<div class="right-controls">
<button class="move" @click="moveNext()">
<button
class="move"
@click="moveNext()"
:disabled="page === lastPageNumber"
>
<i class="pi pi-angle-right"></i>
</button>
<button class="move" @click="moveEnd()">
<button
class="move"
@click="moveEnd()"
:disabled="page === lastPageNumber"
>
<i class="pi pi-angle-double-right"></i>
</button>
</div>
Expand Down Expand Up @@ -105,8 +113,9 @@ const getPages = () => {
.active {
font-weight: bold;
border-radius: 50%;
background-color: #14b8a6;
color: white;
color: #ffffff;
background: #10b981;
border: 1px solid #10b981;
display: block;
width: 40px;
height: 40px;
Expand Down Expand Up @@ -151,4 +160,7 @@ a {
text-decoration: none;
color: black;
}
button:disabled {
cursor: default;
}
</style>
62 changes: 49 additions & 13 deletions components/PropertiesSelector.vue
Original file line number Diff line number Diff line change
@@ -1,36 +1,49 @@
<template>
<p class="title">Properties</p>
<Tree
v-model:selectionKeys="selectedKeys"
@change="update"
:value="getNodes()"
selectionMode="checkbox"
class="w-full md:w-30rem no-border"
></Tree>
</template>

<script setup lang="ts">
const { categoryId } = defineProps({
categoryId: {
type: Number,
import { ref } from "vue";
type Emits = {
(event: "filter", value: Number[]): void;
};
const emit = defineEmits<Emits>();
const { selectedProps, data } = defineProps({
selectedProps: {
type: Array as () => Array<Number>,
required: false,
},
data: {
type: Array as () => Array<object>,
required: true,
},
});
const { data } = await useAsyncGql("getParametrs", { categoryId: categoryId });
const getNodes = () => {
const properties: Object[] = [];
const rawProperties =
data.value?.queryProduct.extraResults.facetSummary?.parameterValues;
const selectedKeys = ref<object>(getSelectedKeys());
function getNodes(): object[] {
const properties: object[] = [];
const rawProperties = data;
if (rawProperties) {
for (let i = 0; i < rawProperties.length; i++) {
let property = {
key: i,
key: "ignore-" + i,
label: rawProperties[i].groupEntity?.attributes?.name,
data: rawProperties[i].groupEntity?.attributes?.name,
children: new Array<Object>(),
data: rawProperties[i].groupEntity?.attributes?.code,
children: new Array<object>(),
};
for (let j = 0; j < rawProperties[i].facetStatistics.length; j++) {
property.children.push({
key: i + "-" + j,
key: rawProperties[i].facetStatistics[j].facetEntity?.primaryKey,
label:
rawProperties[i].facetStatistics[j].facetEntity?.attributes?.name,
data: rawProperties[i].facetStatistics[j].facetEntity?.attributes
Expand All @@ -41,7 +54,30 @@ const getNodes = () => {
}
}
return properties;
};
}
function getSelectedKeys(): object {
let selected = {};
for(const num of selectedProps){
selected[`${num}`] = {
checked: true,
partialChecked: false
}
}
return {
/*108656: { checked: true, partialChecked: false }, 108701: { checked: true, partialChecked: false }*/
};
}
function update(): void {
const checked: Number[] = [];
for (const item in selectedKeys.value) {
if (!item.includes("ignore-")) {
checked.push(parseInt(item));
}
}
emit("filter", checked);
}
</script>

<style scoped>
Expand Down
5 changes: 1 addition & 4 deletions nuxt.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,6 @@
import { resolve } from "path";

export default defineNuxtConfig({
typescript: {
typeCheck: true,
},
primevue: {
usePrimeVue: true,
options: {
Expand All @@ -14,7 +11,7 @@ export default defineNuxtConfig({
css: [
"primevue/resources/themes/lara-light-green/theme.css",
"primeicons/primeicons.css",
"primeflex/primeflex.css",
"primeflex/primeflex.css"
],
devtools: { enabled: true },
modules: ["nuxt-graphql-client", "nuxt-primevue", "@nuxt/image"],
Expand Down
Loading

0 comments on commit 12a743c

Please sign in to comment.