From 4318fa8a2d0f479ffc6eb6def28b72a23dbb3127 Mon Sep 17 00:00:00 2001 From: Bilal Catic Date: Wed, 30 Oct 2019 20:53:07 +0100 Subject: [PATCH 1/8] extend AD_TYPE enum in specific crawler files --- app/crawler/specificCrawlers/aktido.js | 4 ++-- app/crawler/specificCrawlers/olx.js | 6 +++--- app/crawler/specificCrawlers/prostor.js | 4 ++-- app/crawler/specificCrawlers/rental.js | 4 ++-- 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/app/crawler/specificCrawlers/aktido.js b/app/crawler/specificCrawlers/aktido.js index 6512f15..373a6ef 100644 --- a/app/crawler/specificCrawlers/aktido.js +++ b/app/crawler/specificCrawlers/aktido.js @@ -342,9 +342,9 @@ class AktidoCrawler { getKiviAdTypeFromAktidoActionId(actionId) { switch (actionId) { case 1: - return AD_TYPE.AD_TYPE_SALE; + return AD_TYPE.AD_TYPE_SALE.stringId; case 2: - return AD_TYPE.AD_TYPE_RENT; + return AD_TYPE.AD_TYPE_RENT.stringId; default: return undefined; } diff --git a/app/crawler/specificCrawlers/olx.js b/app/crawler/specificCrawlers/olx.js index bb08b95..2ccfeaa 100644 --- a/app/crawler/specificCrawlers/olx.js +++ b/app/crawler/specificCrawlers/olx.js @@ -475,11 +475,11 @@ class OlxCrawler { getAdTypeId(adTypeText) { switch (adTypeText) { case "Prodaja": - return AD_TYPE.AD_TYPE_SALE; + return AD_TYPE.AD_TYPE_SALE.stringId; case "Izdavanje": - return AD_TYPE.AD_TYPE_RENT; + return AD_TYPE.AD_TYPE_RENT.stringId; case "Potražnja": - return AD_TYPE.AD_TYPE_RENT; + return AD_TYPE.AD_TYPE_RENT.stringId; default: return undefined; } diff --git a/app/crawler/specificCrawlers/prostor.js b/app/crawler/specificCrawlers/prostor.js index bb3133c..7b970e0 100644 --- a/app/crawler/specificCrawlers/prostor.js +++ b/app/crawler/specificCrawlers/prostor.js @@ -228,9 +228,9 @@ class ProstorCrawler { static getAdTypeId(adTypeText) { switch (adTypeText) { case "prodaja": - return AD_TYPE.AD_TYPE_SALE; + return AD_TYPE.AD_TYPE_SALE.stringId; case "najam": - return AD_TYPE.AD_TYPE_RENT; + return AD_TYPE.AD_TYPE_RENT.stringId; default: return undefined; } diff --git a/app/crawler/specificCrawlers/rental.js b/app/crawler/specificCrawlers/rental.js index 6293d1f..65a7bc6 100644 --- a/app/crawler/specificCrawlers/rental.js +++ b/app/crawler/specificCrawlers/rental.js @@ -342,9 +342,9 @@ class RentalCrawler { getKiviAdTypeFromRentalActionId(actionId) { switch (actionId) { case 1: - return AD_TYPE.AD_TYPE_SALE; + return AD_TYPE.AD_TYPE_SALE.stringId; case 2: - return AD_TYPE.AD_TYPE_RENT; + return AD_TYPE.AD_TYPE_RENT.stringId; default: return undefined; } -- 2.47.3 From 127691f7bb584b2e64bd6b57c68edc87bde58f80 Mon Sep 17 00:00:00 2001 From: Bilal Catic Date: Wed, 30 Oct 2019 20:53:50 +0100 Subject: [PATCH 2/8] extend AD_TYPE enum --- app/common/enums.js | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/app/common/enums.js b/app/common/enums.js index aa61b84..c48956c 100644 --- a/app/common/enums.js +++ b/app/common/enums.js @@ -59,9 +59,21 @@ const GARAGE_PRICE_SLIDER_OPTIONS = { }; const AD_TYPE = { - AD_TYPE_SALE: "SALE", - AD_TYPE_RENT: "RENT", - AD_TYPE_REQUEST: "REQUEST" + AD_TYPE_SALE: { + id: 1, + stringId: "SALE", + title: "Prodaja" + }, + AD_TYPE_RENT: { + id: 2, + stringId: "RENT", + title: "Najam" + }, + AD_TYPE_REQUEST: { + id: 3, + stringId: "REQUEST", + title: "Potražnja" + } }; const AD_CATEGORY = { -- 2.47.3 From 59565885cb91342301af82eaff33ba743198cc34 Mon Sep 17 00:00:00 2001 From: Bilal Catic Date: Wed, 30 Oct 2019 20:55:33 +0100 Subject: [PATCH 3/8] extend AD_TPYE in db model --- app/models/searchRequest.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/models/searchRequest.js b/app/models/searchRequest.js index 431f708..71ab26e 100644 --- a/app/models/searchRequest.js +++ b/app/models/searchRequest.js @@ -26,7 +26,7 @@ module.exports = (sequelize, DataTypes) => { adType: { type: DataTypes.TEXT, allowNull: false, - defaultValue: AD_TYPE.AD_TYPE_SALE + defaultValue: AD_TYPE.AD_TYPE_SALE.stringId }, email: DataTypes.TEXT, locality: DataTypes.TEXT, -- 2.47.3 From 5817964b509b6efa3b1c9ef9887d0bd1057d589a Mon Sep 17 00:00:00 2001 From: Bilal Catic Date: Wed, 30 Oct 2019 20:55:57 +0100 Subject: [PATCH 4/8] remove disabled css --- app/public/segment.css | 49 ++++++++++++++++++++---------------------- 1 file changed, 23 insertions(+), 26 deletions(-) diff --git a/app/public/segment.css b/app/public/segment.css index e04a054..fdd0372 100644 --- a/app/public/segment.css +++ b/app/public/segment.css @@ -1,32 +1,29 @@ -.ui-segment{ - color: #02adba; - border: 1px solid #02adba; - border-radius: 4px; - display:inline-block; +.ui-segment { + color: #02adba; + border: 1px solid #02adba; + border-radius: 4px; + display: inline-block; } -.ui-segment span.option.active{ - background-color: #02adba; - color: white; +.ui-segment span.option.active { + background-color: #02adba; + color: white; } -.ui-segment span.option{ - padding-left: 30px; - padding-right: 30px; - height: 35px; - text-align:center; - display:inline-block; - line-height: 35px; - margin: 0px; - float:left; - cursor:pointer; - border-right:1px solid #02adba; -} -.ui-segment span.option[disabled]{ - color: gray; +.ui-segment span.option { + padding-left: 30px; + padding-right: 30px; + height: 35px; + text-align: center; + display: inline-block; + line-height: 35px; + margin: 0px; + float: left; + cursor: pointer; + border-right: 1px solid #02adba; } -.ui-segment span.option:last-child{ - border-right: none; +.ui-segment span.option:last-child { + border-right: none; } -.segment-select{ - display:none; +.segment-select { + display: none; } -- 2.47.3 From d32b98bb7b8aefb039b7f8cad7a3aaf59cca568f Mon Sep 17 00:00:00 2001 From: Bilal Catic Date: Wed, 30 Oct 2019 22:13:22 +0100 Subject: [PATCH 5/8] implement Rent option on the frontend --- app/controllers/queryReview.js | 18 ++++++++++++++-- app/controllers/realEstateTypes.js | 33 +++++++++++++++++++++++++++--- app/views/realEstateType.ejs | 27 ++++++++++++++++++------ 3 files changed, 67 insertions(+), 11 deletions(-) diff --git a/app/controllers/queryReview.js b/app/controllers/queryReview.js index 1ea8a59..2b08d82 100644 --- a/app/controllers/queryReview.js +++ b/app/controllers/queryReview.js @@ -3,11 +3,12 @@ const { isValidEmail } = require("../helpers/email"); const { notifyForNewSearchRequest } = require("../services/notificationService"); -const { AD_CATEGORY } = require("../common/enums"); +const { AD_CATEGORY, AD_TYPE } = require("../common/enums"); const getQueryReviewData = searchRequest => { const { id, + adType, realEstateType, sizeMin, sizeMax, @@ -22,8 +23,21 @@ const getQueryReviewData = searchRequest => { ? realEstateTypeObject.hasGardenSize : false; + let adTypeTitle = ""; + switch (adType) { + case AD_TYPE.AD_TYPE_SALE.stringId: + adTypeTitle = AD_TYPE.AD_TYPE_SALE.title; + break; + case AD_TYPE.AD_TYPE_RENT.stringId: + adTypeTitle = AD_TYPE.AD_TYPE_RENT.title; + break; + default: + adTypeTitle = "-"; + break; + } + const realEstateTypeTitle = realEstateTypeObject - ? realEstateTypeObject.title + ? `[${adTypeTitle}] ${realEstateTypeObject.title}` : "-"; const locationTitle = "Promjenite lokaciju"; diff --git a/app/controllers/realEstateTypes.js b/app/controllers/realEstateTypes.js index d1a6411..8cc1638 100644 --- a/app/controllers/realEstateTypes.js +++ b/app/controllers/realEstateTypes.js @@ -1,20 +1,45 @@ const { currentSearchRequest } = require("../helpers/url"); const { createSearchRequest } = require("../helpers/db/searchRequest"); -const { AD_CATEGORY } = require("../common/enums"); +const { AD_CATEGORY, AD_TYPE } = require("../common/enums"); + +const getRealEstateTypes = async (req, res) => { + const searchRequest = await currentSearchRequest(req); -const getRealEstateTypes = (req, res) => { const title = "Koju nekretninu tražite?"; + let selectedAdType = AD_TYPE.AD_TYPE_SALE.id; + if ( + searchRequest && + searchRequest.adType && + searchRequest.adType === AD_TYPE.AD_TYPE_RENT.stringId + ) { + selectedAdType = AD_TYPE.AD_TYPE_RENT.id; + } const realEstateTypes = Object.keys(AD_CATEGORY) .map(category => AD_CATEGORY[category]) .filter(category => category.title); - res.render("realEstateType", { realEstateTypes, title }); + res.render("realEstateType", { + selectedAdType, + realEstateTypes, + title, + AD_TYPE + }); }; const postRealEstateTypes = async (req, res) => { const searchRequest = await currentSearchRequest(req); + const adType = parseInt(req.body.adType); + + const adTypeStringIds = { + [AD_TYPE.AD_TYPE_SALE.id]: AD_TYPE.AD_TYPE_SALE.stringId, + [AD_TYPE.AD_TYPE_RENT.id]: AD_TYPE.AD_TYPE_RENT.stringId + }; + + const adTypeStringId = + adTypeStringIds[adType] || AD_TYPE.AD_TYPE_SALE.stringId; + const validRealEstateTypes = Object.keys(AD_CATEGORY).filter( category => !!AD_CATEGORY[category].title ); @@ -30,12 +55,14 @@ const postRealEstateTypes = async (req, res) => { let nextStepUrl = ""; if (searchRequest && searchRequest.id) { nextStepUrl = `/${nextStepPage}/${searchRequest.id}`; + searchRequest.adType = adTypeStringId; searchRequest.realEstateType = selectedRealEstateType; await searchRequest.save(); } else { try { const newSearchRequest = await createSearchRequest({ + adType: adTypeStringId, realEstateType: selectedRealEstateType }); diff --git a/app/views/realEstateType.ejs b/app/views/realEstateType.ejs index 50cdfca..1e92e6d 100644 --- a/app/views/realEstateType.ejs +++ b/app/views/realEstateType.ejs @@ -3,9 +3,17 @@
- + +
@@ -33,16 +41,17 @@ $.fn.extend({ Segment: function() { $(this).each(function() { + const self = $(this); + const onchange = self.attr('onchange'); const wrapper = $("
", { class: "ui-segment" }); $(this) .find("option") - .each(function(param, param2) { - const isDisabled = $(param2).attr("disabled"); + .each(function() { const option = $("", { class: "option", + onclick: onchange, text: $(this).text(), value: $(this).val(), - disabled: isDisabled }); if ($(this).is(":selected")) { option.addClass("active"); @@ -50,6 +59,12 @@ wrapper.append(option); }); + wrapper.find("span.option").click(function (){ + wrapper.find("span.option").removeClass("active"); + $(this).addClass("active"); + self.val($(this).attr('value')); + }); + $(this).after(wrapper); $(this).hide(); }); -- 2.47.3 From aab32fc60893161435e82b48adf53525a571aec0 Mon Sep 17 00:00:00 2001 From: Bilal Catic Date: Thu, 31 Oct 2019 00:26:02 +0100 Subject: [PATCH 6/8] disable button on first click --- app/views/queryReview.ejs | 1 + 1 file changed, 1 insertion(+) diff --git a/app/views/queryReview.ejs b/app/views/queryReview.ejs index b697e66..022322f 100644 --- a/app/views/queryReview.ejs +++ b/app/views/queryReview.ejs @@ -58,6 +58,7 @@ } if (simpleEmailRegex.test(email)){ + $("#submit").attr("disabled", true); $("#form-queryreview").submit(); }else{ $("#error-label-email").text("Greška ! Unešeni emailovi nisu isti"); -- 2.47.3 From 9612b28c9189b8138be8d70bd3fb04a1eb18d22d Mon Sep 17 00:00:00 2001 From: Bilal Catic Date: Thu, 31 Oct 2019 00:43:20 +0100 Subject: [PATCH 7/8] disable real estate type selection after first click --- app/views/realEstateType.ejs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/app/views/realEstateType.ejs b/app/views/realEstateType.ejs index 1e92e6d..4187365 100644 --- a/app/views/realEstateType.ejs +++ b/app/views/realEstateType.ejs @@ -18,7 +18,7 @@

-
+
<% for(const realEstateType of realEstateTypes) { %> a").attr("onclick", ""); $("#form-real-estate-type").submit(); } -- 2.47.3 From 026d7cded7de50c9de6fa6356c9e8126c5d5430c Mon Sep 17 00:00:00 2001 From: Bilal Catic Date: Thu, 31 Oct 2019 10:55:34 +0100 Subject: [PATCH 8/8] change price slider options for renting option --- app/common/enums.js | 33 +++++++++++++++++++++------- app/controllers/realEstateFilters.js | 16 ++++++++++++-- 2 files changed, 39 insertions(+), 10 deletions(-) diff --git a/app/common/enums.js b/app/common/enums.js index c48956c..efdbe28 100644 --- a/app/common/enums.js +++ b/app/common/enums.js @@ -1,4 +1,4 @@ -const PRICE_SLIDER_OPTIONS = { +const PRICE_SLIDER_OPTIONS_SALE = { start: [50000, 85000], range: { min: [0], @@ -8,6 +8,16 @@ const PRICE_SLIDER_OPTIONS = { connect: true }; +const PRICE_SLIDER_OPTIONS_RENT = { + start: [300, 500], + range: { + min: [0], + max: [2000] + }, + step: 50, + connect: true +}; + //This will be used for Flats, Apartments, Houses const HOME_SIZE_SLIDER_OPTIONS = { start: [30, 75], @@ -84,14 +94,16 @@ const AD_CATEGORY = { id: "FLAT", title: "Stan", hasGardenSize: false, - priceSliderOptions: PRICE_SLIDER_OPTIONS, + priceSliderOptionsSale: PRICE_SLIDER_OPTIONS_SALE, + priceSliderOptionsRent: PRICE_SLIDER_OPTIONS_RENT, sizeSliderOptions: HOME_SIZE_SLIDER_OPTIONS }, HOUSE: { id: "HOUSE", title: "Kuća", hasGardenSize: true, - priceSliderOptions: PRICE_SLIDER_OPTIONS, + priceSliderOptionsSale: PRICE_SLIDER_OPTIONS_SALE, + priceSliderOptionsRent: PRICE_SLIDER_OPTIONS_RENT, sizeSliderOptions: HOME_SIZE_SLIDER_OPTIONS, gardenSizeSliderOptions: GARDEN_SIZE_SLIDER_OPTIONS }, @@ -99,35 +111,40 @@ const AD_CATEGORY = { id: "OFFICE", title: "Kancelarija", hasGardenSize: false, - priceSliderOptions: PRICE_SLIDER_OPTIONS, + priceSliderOptionsSale: PRICE_SLIDER_OPTIONS_SALE, + priceSliderOptionsRent: PRICE_SLIDER_OPTIONS_RENT, sizeSliderOptions: HOME_SIZE_SLIDER_OPTIONS }, LAND: { id: "LAND", title: "Zemljište", hasGardenSize: false, - priceSliderOptions: PRICE_SLIDER_OPTIONS, + priceSliderOptionsSale: PRICE_SLIDER_OPTIONS_SALE, + priceSliderOptionsRent: PRICE_SLIDER_OPTIONS_RENT, sizeSliderOptions: LAND_SIZE_SLIDER_OPTIONS }, APARTMENT: { id: "APARTMENT", title: "Apartman", hasGardenSize: false, - priceSliderOptions: PRICE_SLIDER_OPTIONS, + priceSliderOptionsSale: PRICE_SLIDER_OPTIONS_SALE, + priceSliderOptionsRent: PRICE_SLIDER_OPTIONS_RENT, sizeSliderOptions: HOME_SIZE_SLIDER_OPTIONS }, GARAGE: { id: "GARAGE", title: "Garaža", hasGardenSize: false, - priceSliderOptions: GARAGE_PRICE_SLIDER_OPTIONS, + priceSliderOptionsSale: PRICE_SLIDER_OPTIONS_SALE, + priceSliderOptionsRent: PRICE_SLIDER_OPTIONS_RENT, sizeSliderOptions: GARAGE_SIZE_SLIDER_OPTIONS }, COTTAGE: { id: "COTTAGE", title: "Vikendica", hasGardenSize: true, - priceSliderOptions: PRICE_SLIDER_OPTIONS, + priceSliderOptionsSale: PRICE_SLIDER_OPTIONS_SALE, + priceSliderOptionsRent: PRICE_SLIDER_OPTIONS_RENT, sizeSliderOptions: HOME_SIZE_SLIDER_OPTIONS, gardenSizeSliderOptions: GARDEN_SIZE_SLIDER_OPTIONS } diff --git a/app/controllers/realEstateFilters.js b/app/controllers/realEstateFilters.js index 9e23f91..8949cc1 100644 --- a/app/controllers/realEstateFilters.js +++ b/app/controllers/realEstateFilters.js @@ -1,5 +1,5 @@ const { currentSearchRequest } = require("../helpers/url"); -const { AD_CATEGORY } = require("../common/enums"); +const { AD_CATEGORY, AD_TYPE } = require("../common/enums"); const getFilters = async (req, res) => { const searchRequest = await currentSearchRequest(req); @@ -12,6 +12,7 @@ const getFilters = async (req, res) => { const title = "Filteri za pretraživanje"; const { + adType, realEstateType, priceMin, priceMax, @@ -24,11 +25,22 @@ const getFilters = async (req, res) => { const { hasGardenSize, - priceSliderOptions, + priceSliderOptionsSale, + priceSliderOptionsRent, sizeSliderOptions, gardenSizeSliderOptions } = category; + let priceSliderOptions; + if (adType === AD_TYPE.AD_TYPE_SALE.stringId) { + priceSliderOptions = Object.assign({}, priceSliderOptionsSale); + } else if (adType === AD_TYPE.AD_TYPE_RENT.stringId) { + priceSliderOptions = Object.assign({}, priceSliderOptionsRent); + } else { + res.render("notFound", { title: " " }); + return; + } + if (priceMin || priceMax) { priceSliderOptions.start = [priceMin, priceMax]; } -- 2.47.3