Skip to content

Commit

Permalink
Merge pull request #28 from moevm/kharitonov_small_filters
Browse files Browse the repository at this point in the history
Add sort and bug fix
  • Loading branch information
necitboss authored Dec 12, 2024
2 parents 152da6c + ee423b8 commit d8a0ab9
Show file tree
Hide file tree
Showing 14 changed files with 1,754 additions and 72 deletions.
Empty file.
2 changes: 1 addition & 1 deletion main/_front/dist/component.html
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ <h1 class="title__text">
<div class="container">
<div class="info__inner">
<div class="info__img">
<img src="https://via.placeholder.com/200x200" alt="">
<img src="./img/img200x200.png" alt="">
</div>
<div class="info__block">
<div class="subtitle info__title">Характеристики:</div>
Expand Down
2 changes: 1 addition & 1 deletion main/_front/dist/components.html
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,7 @@ <h4 class="filter__title">Фильтры</h4>
<div class="sort__block">
<div class="choice" id="sort_by">
<button class="choice__elem active" data-value="price">Цена</button>
<button class="choice__elem" data-value="rating">Рейтинг</button>
<button class="choice__elem" data-value="name">Название</button>
</div>
<div class="choice" id="sort_in">
<button class="choice__elem choice__elem-wide active" data-value="to up">По возрастанию</button>
Expand Down
77 changes: 39 additions & 38 deletions main/_front/dist/css/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,45 @@ body.no-scroll {
line-height: 19px;
}

.dialog {
position: fixed;
width: 100%;
height: 100vh;
background-color: rgba(0, 0, 0, 0.4);
display: none;
align-items: center;
justify-content: center;
z-index: 1000;
}
.dialog.show {
display: flex;
}

.dialog__inner {
display: flex;
flex-direction: column;
align-items: center;
padding: 20px;
background-color: #fff;
border-radius: 10px;
border: 1px solid #d8d8d8;
}

.dialog__name {
font-size: 24px;
margin-bottom: 10px;
}

.dialog__text {
font-size: 28px;
margin-bottom: 20px;
}

.dialog__buttons {
display: flex;
column-gap: 15px;
}

.filter__title {
text-align: center;
font-size: 20px;
Expand Down Expand Up @@ -520,44 +559,6 @@ body.no-scroll {
line-height: 47px;
}

.dialog {
position: fixed;
width: 100%;
height: 100vh;
background-color: rgba(0, 0, 0, 0.4);
display: none;
align-items: center;
justify-content: center;
}
.dialog.show {
display: flex;
}

.dialog__inner {
display: flex;
flex-direction: column;
align-items: center;
padding: 20px;
background-color: #fff;
border-radius: 10px;
border: 1px solid #d8d8d8;
}

.dialog__name {
font-size: 24px;
margin-bottom: 10px;
}

.dialog__text {
font-size: 28px;
margin-bottom: 20px;
}

.dialog__buttons {
display: flex;
column-gap: 15px;
}

.add-center {
width: 468px;
padding: 20px;
Expand Down
Binary file added main/_front/dist/img/img200x200.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
43 changes: 41 additions & 2 deletions main/_front/dist/js/components.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ const filter_name = document.querySelector("#filter_name");
const filter_from = document.querySelector("#filter_from");
const filter_to = document.querySelector("#filter_to");
const filter_submit = document.querySelector("#filter_submit");
const sort_by = document.querySelector("#sort_by");
const sort_in = document.querySelector("#sort_in");

let isAdmin = false;

Expand Down Expand Up @@ -97,7 +99,7 @@ const addCards = (filters) => {
data.forEach((item) => {
cards_place.insertAdjacentHTML("beforeend", `
<div class="card" data-id="${item._id}">
<img src="https://via.placeholder.com/200x200" alt="">
<img src="img/img200x200.png" alt="">
<div class="card__description">
<div class="card__name">${item.name}</div>
<div class="card__price">${item.price} ₽</div>
Expand Down Expand Up @@ -144,8 +146,34 @@ choiceLists.forEach((choiceList) => {
const params = {
type: choice.dataset.value
};
if (sort_by.dataset.value.trim() !== ""){
params["sort_by"] = sort_by.dataset.value
}
if (sort_in.dataset.value.trim() !== ""){
params["sort_in"] = sort_in.dataset.value;
}
addCards(params)
}
if (choiceList.id === "sort_by" || choiceList.id === "sort_in") {
const params = {};
if (filter_name.value.trim() !== ""){
params["name"] = filter_name.value.trim();
}
if (filter_to.value.trim() !== ""){
params["max_price"] = filter_to.value;
}
if (filter_from.value.trim() !== ""){
params["min_price"] = filter_from.value;
}
if (sort_by.dataset.value.trim() !== ""){
params["sort_by"] = sort_by.dataset.value
}
if (sort_in.dataset.value.trim() !== ""){
params["sort_in"] = sort_in.dataset.value;
}
params["type"] = choice_components.dataset.value;
addCards(params);
}
}else {
choice.classList.remove("active");
}
Expand Down Expand Up @@ -176,7 +204,12 @@ document.addEventListener("DOMContentLoaded", function() {
const params = {
type: "cpu"
};

if (sort_by.dataset.value.trim() !== ""){
params["sort_by"] = sort_by.dataset.value
}
if (sort_in.dataset.value.trim() !== ""){
params["sort_in"] = sort_in.dataset.value;
}
addCards(params);
})
})
Expand All @@ -192,6 +225,12 @@ filter_submit.addEventListener('click', () => {
if (filter_from.value.trim() !== ""){
params["min_price"] = filter_from.value;
}
if (sort_by.dataset.value === "price"){
params["sort_by"] = "price"
}
if (sort_in.dataset.value.trim() !== ""){
params["sort_in"] = sort_in.dataset.value;
}
params["type"] = choice_components.dataset.value;
addCards(params);
})
Empty file.
2 changes: 1 addition & 1 deletion main/_front/src/html/component.html
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ <h1 class="title__text">
<div class="container">
<div class="info__inner">
<div class="info__img">
<img src="https://via.placeholder.com/200x200" alt="">
<img src="../img/img200x200.png" alt="">
</div>
<div class="info__block">
<div class="subtitle info__title">Характеристики:</div>
Expand Down
2 changes: 1 addition & 1 deletion main/_front/src/html/components.html
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,7 @@ <h4 class="filter__title">Фильтры</h4>
<div class="sort__block">
<div class="choice" id="sort_by">
<button class="choice__elem active" data-value="price">Цена</button>
<button class="choice__elem" data-value="rating">Рейтинг</button>
<button class="choice__elem" data-value="name">Название</button>
</div>
<div class="choice" id="sort_in">
<button class="choice__elem choice__elem-wide active" data-value="to up">По возрастанию</button>
Expand Down
Binary file added main/_front/src/img/img200x200.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
43 changes: 41 additions & 2 deletions main/_front/src/js/components.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ const filter_name = document.querySelector("#filter_name");
const filter_from = document.querySelector("#filter_from");
const filter_to = document.querySelector("#filter_to");
const filter_submit = document.querySelector("#filter_submit");
const sort_by = document.querySelector("#sort_by");
const sort_in = document.querySelector("#sort_in");

let isAdmin = false;

Expand Down Expand Up @@ -97,7 +99,7 @@ const addCards = (filters) => {
data.forEach((item) => {
cards_place.insertAdjacentHTML("beforeend", `
<div class="card" data-id="${item._id}">
<img src="https://via.placeholder.com/200x200" alt="">
<img src="img/img200x200.png" alt="">
<div class="card__description">
<div class="card__name">${item.name}</div>
<div class="card__price">${item.price} ₽</div>
Expand Down Expand Up @@ -144,8 +146,34 @@ choiceLists.forEach((choiceList) => {
const params = {
type: choice.dataset.value
};
if (sort_by.dataset.value.trim() !== ""){
params["sort_by"] = sort_by.dataset.value
}
if (sort_in.dataset.value.trim() !== ""){
params["sort_in"] = sort_in.dataset.value;
}
addCards(params)
}
if (choiceList.id === "sort_by" || choiceList.id === "sort_in") {
const params = {};
if (filter_name.value.trim() !== ""){
params["name"] = filter_name.value.trim();
}
if (filter_to.value.trim() !== ""){
params["max_price"] = filter_to.value;
}
if (filter_from.value.trim() !== ""){
params["min_price"] = filter_from.value;
}
if (sort_by.dataset.value.trim() !== ""){
params["sort_by"] = sort_by.dataset.value
}
if (sort_in.dataset.value.trim() !== ""){
params["sort_in"] = sort_in.dataset.value;
}
params["type"] = choice_components.dataset.value;
addCards(params);
}
}else {
choice.classList.remove("active");
}
Expand Down Expand Up @@ -176,7 +204,12 @@ document.addEventListener("DOMContentLoaded", function() {
const params = {
type: "cpu"
};

if (sort_by.dataset.value.trim() !== ""){
params["sort_by"] = sort_by.dataset.value
}
if (sort_in.dataset.value.trim() !== ""){
params["sort_in"] = sort_in.dataset.value;
}
addCards(params);
})
})
Expand All @@ -192,6 +225,12 @@ filter_submit.addEventListener('click', () => {
if (filter_from.value.trim() !== ""){
params["min_price"] = filter_from.value;
}
if (sort_by.dataset.value === "price"){
params["sort_by"] = "price"
}
if (sort_in.dataset.value.trim() !== ""){
params["sort_in"] = sort_in.dataset.value;
}
params["type"] = choice_components.dataset.value;
addCards(params);
})
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
display: none;
align-items: center;
justify-content: center;
z-index: 1000;
&.show {
display: flex;
}
Expand Down
41 changes: 15 additions & 26 deletions main/controllers/ComponentsController.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,30 +57,20 @@ export const getAll = async (req, res) => {
})
}
const query = conditions.length > 0 ? {$and: conditions} : {}
const components = await ComponentsModel.find(query)
console.log(components);
// let components;
// if (req.query.type){
// components = await ComponentsModel.find({type: req.query.type}).exec();
// }else {
// components = await ComponentsModel.find().exec();
// }
// const conditions = [];
// conditions.push({
// main_properties: {
// $elemMatch: {
// name: "Сокет (разъем на плате)",
// value: "LGA 1700"
// }
// },
// })
// conditions.push({
// price: {$gte: 9000, $lte: 18000}
// })
// const query = conditions.length > 0 ? {$and: conditions} : {}
// const components2 = await ComponentsModel.find(query)
// console.log(components2);
res.json(components);
if (req.query.sort_by && req.query.sort_in) {
if (req.query.sort_by === "price"){
console.log("by price!")
const components = await ComponentsModel.find(query).sort({"price": req.query.sort_in === "to up" ? 1 : -1});
res.json(components);
}else {
const components = await ComponentsModel.find(query).sort({"name": req.query.sort_in === "to up" ? 1 : -1});
res.json(components);
}
}else {
const components = await ComponentsModel.find(query)
res.json(components);
}
// console.log(components);
}catch (err){
console.warn(err);
res.status(500).json({
Expand Down Expand Up @@ -215,11 +205,10 @@ export const exportToClient = async (req, res) => {

export const importFromClient = async (req, res) => {
try {
console.log(req.body);
if (req.body.components){
const components = req.body.components;
for (const component of components){
const component_from_db = await ComponentsModel.find({name: req.body.name});
const component_from_db = await ComponentsModel.find({name: component.name});
if (!component_from_db[0]){
const doc = new ComponentsModel({
name: component.name,
Expand Down
Loading

0 comments on commit d8a0ab9

Please sign in to comment.