move all filters to one page
This commit is contained in:
@@ -1,48 +0,0 @@
|
||||
const { currentSearchRequest } = require("../helpers/url");
|
||||
const { AD_CATEGORY } = require("../common/enums");
|
||||
|
||||
const getGardenSize = (req, res) => {
|
||||
const title = "Koliko okućnice tražite ?";
|
||||
|
||||
const unit = " m2";
|
||||
const rangeFrom = {
|
||||
min: 10,
|
||||
max: 3000,
|
||||
value: 0,
|
||||
step: 10
|
||||
};
|
||||
|
||||
const rangeTo = {
|
||||
min: 10,
|
||||
max: 3000,
|
||||
value: 100,
|
||||
step: 10
|
||||
};
|
||||
|
||||
res.render("gardenSize", { rangeFrom, rangeTo, unit, title });
|
||||
};
|
||||
|
||||
const postGardenSize = async (req, res) => {
|
||||
const searchRequest = await currentSearchRequest(req);
|
||||
|
||||
const nextStepPage = req.query.nextStep || "cijena";
|
||||
const nextStepUrl = `/${nextStepPage}/${searchRequest.id}`;
|
||||
|
||||
const realEstateType = AD_CATEGORY[searchRequest.realEstateType];
|
||||
if (realEstateType && realEstateType.hasGardenSize) {
|
||||
const gardenSizeMin = req.body.from || 0;
|
||||
const gardenSizeMax = req.body.to || 0;
|
||||
//TODO: Validate input
|
||||
|
||||
searchRequest.gardenSizeMin = gardenSizeMin;
|
||||
searchRequest.gardenSizeMax = gardenSizeMax;
|
||||
await searchRequest.save();
|
||||
}
|
||||
|
||||
res.redirect(nextStepUrl);
|
||||
};
|
||||
|
||||
module.exports = {
|
||||
getGardenSize,
|
||||
postGardenSize
|
||||
};
|
||||
@@ -40,7 +40,7 @@ const postLocation = async (req, res) => {
|
||||
|
||||
await searchRequest.save();
|
||||
|
||||
const nextStepPage = req.query.nextStep || "povrsina";
|
||||
const nextStepPage = req.query.nextStep || "filteri";
|
||||
const nextStepUrl = `/${nextStepPage}/${searchRequest.id}`;
|
||||
|
||||
res.redirect(nextStepUrl);
|
||||
|
||||
@@ -1,43 +0,0 @@
|
||||
const { currentSearchRequest } = require("../helpers/url");
|
||||
|
||||
const getPrice = (req, res) => {
|
||||
const title = "Koja Vam okvirna cijena odgovara ?";
|
||||
|
||||
const unit = " KM";
|
||||
const rangeFrom = {
|
||||
min: 1000,
|
||||
max: 250000,
|
||||
value: 0,
|
||||
step: 1000
|
||||
};
|
||||
|
||||
const rangeTo = {
|
||||
min: 1000,
|
||||
max: 250000,
|
||||
value: 50000,
|
||||
step: 1000
|
||||
};
|
||||
|
||||
res.render("price", { rangeFrom, rangeTo, unit, title });
|
||||
};
|
||||
|
||||
const postPrice = async (req, res) => {
|
||||
const searchRequest = await currentSearchRequest(req);
|
||||
|
||||
const nextStepPage = req.query.nextStep || "pregled";
|
||||
const nextStepUrl = `/${nextStepPage}/${searchRequest.id}`;
|
||||
const priceMin = req.body.from || 0;
|
||||
const priceMax = req.body.to || 0;
|
||||
//TODO: price validation
|
||||
|
||||
searchRequest.priceMin = priceMin;
|
||||
searchRequest.priceMax = priceMax;
|
||||
await searchRequest.save();
|
||||
|
||||
res.redirect(nextStepUrl);
|
||||
};
|
||||
|
||||
module.exports = {
|
||||
getPrice,
|
||||
postPrice
|
||||
};
|
||||
@@ -49,17 +49,17 @@ const getQueryReviewData = searchRequest => {
|
||||
{
|
||||
id: "size",
|
||||
title: sizeTitle,
|
||||
url: `/povrsina/${id}?nextStep=pregled`
|
||||
url: `/filteri/${id}?nextStep=pregled`
|
||||
},
|
||||
{
|
||||
id: "gardenSize",
|
||||
title: gardenSizeTitle,
|
||||
url: enableGardenSizeEdit ? `/okucnica/${id}?nextStep=pregled` : ""
|
||||
url: enableGardenSizeEdit ? `/filteri/${id}?nextStep=pregled` : ""
|
||||
},
|
||||
{
|
||||
id: "price",
|
||||
title: priceTitle,
|
||||
url: `/cijena/${id}?nextStep=pregled`
|
||||
url: `/filteri/${id}?nextStep=pregled`
|
||||
}
|
||||
];
|
||||
};
|
||||
|
||||
83
app/controllers/realEstateFilters.js
Normal file
83
app/controllers/realEstateFilters.js
Normal file
@@ -0,0 +1,83 @@
|
||||
const { currentSearchRequest } = require("../helpers/url");
|
||||
const { AD_CATEGORY } = require("../common/enums");
|
||||
|
||||
const getFilters = async (req, res) => {
|
||||
const searchRequest = await currentSearchRequest(req);
|
||||
const title = "Filteri za pretraživanje";
|
||||
|
||||
const {
|
||||
realEstateType,
|
||||
priceMin,
|
||||
priceMax,
|
||||
sizeMin,
|
||||
sizeMax,
|
||||
gardenSizeMin,
|
||||
gardenSizeMax
|
||||
} = searchRequest;
|
||||
const category = AD_CATEGORY[realEstateType] || AD_CATEGORY.FLAT;
|
||||
|
||||
const {
|
||||
hasGardenSize,
|
||||
priceSliderOptions,
|
||||
sizeSliderOptions,
|
||||
gardenSizeSliderOptions
|
||||
} = category;
|
||||
|
||||
if (priceMin && priceMax) {
|
||||
priceSliderOptions.start = [priceMin, priceMax];
|
||||
}
|
||||
|
||||
if (sizeMin && sizeMax) {
|
||||
sizeSliderOptions.start = [sizeMin, sizeMax];
|
||||
}
|
||||
|
||||
if (gardenSizeSliderOptions && gardenSizeMin && gardenSizeMax) {
|
||||
gardenSizeSliderOptions.start = [gardenSizeMin, gardenSizeMax];
|
||||
}
|
||||
|
||||
res.render("realEstateFilters", {
|
||||
title,
|
||||
hasGardenSize,
|
||||
priceSliderOptions: JSON.stringify(priceSliderOptions),
|
||||
sizeSliderOptions: JSON.stringify(sizeSliderOptions),
|
||||
gardenSizeSliderOptions: JSON.stringify(gardenSizeSliderOptions)
|
||||
});
|
||||
};
|
||||
|
||||
const postFilters = async (req, res) => {
|
||||
const searchRequest = await currentSearchRequest(req);
|
||||
|
||||
const nextStepPage = req.query.nextStep || "pregled";
|
||||
const nextStepUrl = `/${nextStepPage}/${searchRequest.id}`;
|
||||
|
||||
const priceMin = parseInt(req.body.priceFilterMin) || 0;
|
||||
const priceMax = parseInt(req.body.priceFilterMax) || 0;
|
||||
const sizeMin = parseInt(req.body.sizeFilterMin) || 0;
|
||||
const sizeMax = parseInt(req.body.sizeFilterMax) || 0;
|
||||
|
||||
//TODO: Filter validation
|
||||
|
||||
searchRequest.priceMin = priceMin;
|
||||
searchRequest.priceMax = priceMax;
|
||||
searchRequest.sizeMin = sizeMin;
|
||||
searchRequest.sizeMax = sizeMax;
|
||||
|
||||
if (req.body.gardenSizeFilterMin && req.body.gardenSizeFilterMax) {
|
||||
const gardenSizeMin = parseInt(req.body.gardenSizeFilterMin);
|
||||
const gardenSizeMax = parseInt(req.body.gardenSizeFilterMax);
|
||||
|
||||
//TODO: Filter validation
|
||||
|
||||
searchRequest.gardenSizeMin = gardenSizeMin;
|
||||
searchRequest.gardenSizeMax = gardenSizeMax;
|
||||
}
|
||||
|
||||
await searchRequest.save();
|
||||
|
||||
res.redirect(nextStepUrl);
|
||||
};
|
||||
|
||||
module.exports = {
|
||||
getFilters,
|
||||
postFilters
|
||||
};
|
||||
@@ -1,47 +0,0 @@
|
||||
const { currentSearchRequest } = require("../helpers/url");
|
||||
const { AD_CATEGORY } = require("../common/enums");
|
||||
|
||||
const getSize = (req, res) => {
|
||||
const title = "Od koliko kvadrata tražite nekretninu ?";
|
||||
const unit = " m2";
|
||||
const rangeFrom = {
|
||||
min: 10,
|
||||
max: 250,
|
||||
value: 0,
|
||||
step: 10
|
||||
};
|
||||
|
||||
const rangeTo = {
|
||||
min: 10,
|
||||
max: 250,
|
||||
value: 50,
|
||||
step: 10
|
||||
};
|
||||
|
||||
res.render("size", { rangeFrom, rangeTo, unit, title });
|
||||
};
|
||||
|
||||
const postSize = async (req, res) => {
|
||||
const searchRequest = await currentSearchRequest(req);
|
||||
|
||||
const realEstateType = AD_CATEGORY[searchRequest.realEstateType];
|
||||
const sizeMin = req.body.from || 0;
|
||||
const sizeMax = req.body.to || 0;
|
||||
//TODO: Validation, check if real estate type is valid, ...
|
||||
const nextStep =
|
||||
realEstateType && realEstateType.hasGardenSize ? "okucnica" : "cijena";
|
||||
|
||||
const nextStepPage = req.query.nextStep || nextStep;
|
||||
const nextStepUrl = `/${nextStepPage}/${searchRequest.id}`;
|
||||
|
||||
searchRequest.sizeMin = sizeMin;
|
||||
searchRequest.sizeMax = sizeMax;
|
||||
await searchRequest.save();
|
||||
|
||||
res.redirect(nextStepUrl);
|
||||
};
|
||||
|
||||
module.exports = {
|
||||
getSize,
|
||||
postSize
|
||||
};
|
||||
Reference in New Issue
Block a user