Filters done
This commit is contained in:
@@ -74,7 +74,7 @@
|
|||||||
|
|
||||||
router.get('/search', function () {
|
router.get('/search', function () {
|
||||||
var _ref = _asyncToGenerator(regeneratorRuntime.mark(function _callee(req, res, next) {
|
var _ref = _asyncToGenerator(regeneratorRuntime.mark(function _callee(req, res, next) {
|
||||||
var bounds, minPrice, maxPrice, minSize, maxSize, rooms, adType, properties, query, _bounds$split$map, _bounds$split$map2, lat1, lng1, lat2, lng2, box, price, allRooms, or, size, all;
|
var bounds, minPrice, maxPrice, minSize, maxSize, rooms, adType, category, sort, properties, query, _bounds$split$map, _bounds$split$map2, lat1, lng1, lat2, lng2, box, price, allRooms, or, size, allCategories, _or, all;
|
||||||
|
|
||||||
return regeneratorRuntime.wrap(function _callee$(_context) {
|
return regeneratorRuntime.wrap(function _callee$(_context) {
|
||||||
while (1) {
|
while (1) {
|
||||||
@@ -88,6 +88,8 @@
|
|||||||
maxSize = req.query.maxSize;
|
maxSize = req.query.maxSize;
|
||||||
rooms = req.query.rooms;
|
rooms = req.query.rooms;
|
||||||
adType = req.query.adType;
|
adType = req.query.adType;
|
||||||
|
category = req.query.category;
|
||||||
|
sort = req.query.sort;
|
||||||
properties = db.collection('listings');
|
properties = db.collection('listings');
|
||||||
query = {};
|
query = {};
|
||||||
|
|
||||||
@@ -165,35 +167,49 @@
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (category) {
|
||||||
|
allCategories = category.split(',');
|
||||||
|
_or = allCategories.map(function (val) {
|
||||||
|
return {
|
||||||
|
category: parseInt(val)
|
||||||
|
};
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
query = Object.assign(query, {
|
||||||
|
"$or": _or
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
console.log('QUERY: ', query);
|
console.log('QUERY: ', query);
|
||||||
_context.next = 18;
|
_context.next = 21;
|
||||||
return properties.find(query, {
|
return properties.find(query, {
|
||||||
//"sort": [['field1','asc'], ['field2','desc']]
|
//"sort": [['field1','asc'], ['field2','desc']]
|
||||||
"sort": [['price', 'asc']]
|
"sort": [['price', 'asc']]
|
||||||
}).toArray();
|
}).toArray();
|
||||||
|
|
||||||
case 18:
|
case 21:
|
||||||
all = _context.sent;
|
all = _context.sent;
|
||||||
|
|
||||||
|
|
||||||
res.json(all);
|
res.json(all);
|
||||||
res.end();
|
res.end();
|
||||||
_context.next = 27;
|
_context.next = 30;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 23:
|
case 26:
|
||||||
_context.prev = 23;
|
_context.prev = 26;
|
||||||
_context.t0 = _context['catch'](0);
|
_context.t0 = _context['catch'](0);
|
||||||
|
|
||||||
console.log('error:', _context.t0);
|
console.log('error:', _context.t0);
|
||||||
next(_context.t0);
|
next(_context.t0);
|
||||||
|
|
||||||
case 27:
|
case 30:
|
||||||
case 'end':
|
case 'end':
|
||||||
return _context.stop();
|
return _context.stop();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}, _callee, undefined, [[0, 23]]);
|
}, _callee, undefined, [[0, 26]]);
|
||||||
}));
|
}));
|
||||||
|
|
||||||
return function (_x, _x2, _x3) {
|
return function (_x, _x2, _x3) {
|
||||||
|
|||||||
@@ -21,6 +21,8 @@ router.get('/search', async (req, res, next) => {
|
|||||||
const maxSize = req.query.maxSize;
|
const maxSize = req.query.maxSize;
|
||||||
const rooms = req.query.rooms;
|
const rooms = req.query.rooms;
|
||||||
const adType = req.query.adType;
|
const adType = req.query.adType;
|
||||||
|
const category = req.query.category;
|
||||||
|
const sort = req.query.sort;
|
||||||
const properties = db.collection('listings');
|
const properties = db.collection('listings');
|
||||||
let query = {};
|
let query = {};
|
||||||
|
|
||||||
@@ -93,6 +95,19 @@ router.get('/search', async (req, res, next) => {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (category) {
|
||||||
|
const allCategories = category.split(',');
|
||||||
|
const or = allCategories.map(val => {
|
||||||
|
return {
|
||||||
|
category: parseInt(val)
|
||||||
|
};
|
||||||
|
});
|
||||||
|
|
||||||
|
query = Object.assign(query, {
|
||||||
|
"$or": or
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
console.log('QUERY: ', query);
|
console.log('QUERY: ', query);
|
||||||
const all = await properties.find(query, {
|
const all = await properties.find(query, {
|
||||||
//"sort": [['field1','asc'], ['field2','desc']]
|
//"sort": [['field1','asc'], ['field2','desc']]
|
||||||
|
|||||||
@@ -3,3 +3,8 @@ export const AD_TYPE_RENT = 2;
|
|||||||
|
|
||||||
export const IGNORED_USERNAMES = ['rental']
|
export const IGNORED_USERNAMES = ['rental']
|
||||||
|
|
||||||
|
export const CATEGORY_FLAT = 0;
|
||||||
|
export const CATEGORY_HOUSE = 1;
|
||||||
|
export const CATEGORY_OFFICE = 2;
|
||||||
|
export const CATEGORY_LAND = 3;
|
||||||
|
|
||||||
|
|||||||
@@ -32,7 +32,9 @@ export default class MongoSaver {
|
|||||||
let resultsForMongo = Object.keys(results).map((key) => {
|
let resultsForMongo = Object.keys(results).map((key) => {
|
||||||
return results[key]
|
return results[key]
|
||||||
});
|
});
|
||||||
this.collection.insert(resultsForMongo);
|
|
||||||
|
this.collection.update({ url: results.url }, resultsForMongo, { upsert: true });
|
||||||
|
// this.collection.insert(resultsForMongo);
|
||||||
}
|
}
|
||||||
|
|
||||||
async close() {
|
async close() {
|
||||||
|
|||||||
@@ -3,7 +3,15 @@
|
|||||||
let fetch = require('node-fetch');
|
let fetch = require('node-fetch');
|
||||||
let cheerio = require('cheerio');
|
let cheerio = require('cheerio');
|
||||||
let fs = require('fs');
|
let fs = require('fs');
|
||||||
import {AD_TYPE_SALE, IGNORED_USERNAMES} from '../enums';
|
|
||||||
|
import {
|
||||||
|
AD_TYPE_SALE,
|
||||||
|
IGNORED_USERNAMES,
|
||||||
|
CATEGORY_FLAT,
|
||||||
|
CATEGORY_HOUSE,
|
||||||
|
CATEGORY_OFFICE,
|
||||||
|
CATEGORY_LAND
|
||||||
|
} from '../enums';
|
||||||
|
|
||||||
export default class OlxCrawler {
|
export default class OlxCrawler {
|
||||||
|
|
||||||
@@ -26,6 +34,8 @@ export default class OlxCrawler {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const title = $('#naslovartikla').text();
|
const title = $('#naslovartikla').text();
|
||||||
|
const category = $('#artikal_glavni_div > div.artikal_lijevo > div:nth-child(3) > div > span:nth-child(3) > a > span').text();
|
||||||
|
|
||||||
const price = $('#pc > p:nth-child(2)').text();
|
const price = $('#pc > p:nth-child(2)').text();
|
||||||
const size = $('#dodatnapolja1 > div:nth-child(1) > div.df2').text();
|
const size = $('#dodatnapolja1 > div:nth-child(1) > div.df2').text();
|
||||||
const rooms = $('#dodatnapolja1 > div:nth-child(2) > div.df2').text();
|
const rooms = $('#dodatnapolja1 > div:nth-child(2) > div.df2').text();
|
||||||
@@ -64,13 +74,21 @@ export default class OlxCrawler {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const parsedPrice = parsePrice(price);
|
const parsedPrice = parsePrice(price);
|
||||||
|
let parsedRooms;
|
||||||
|
|
||||||
|
if (rooms === 'Garsonjera') {
|
||||||
|
parsedRooms = 0;
|
||||||
|
} else {
|
||||||
|
parsedRooms = parseRooms(rooms);
|
||||||
|
}
|
||||||
|
|
||||||
const data = {
|
const data = {
|
||||||
|
category: this.getCategoryId(category),
|
||||||
url,
|
url,
|
||||||
title,
|
title,
|
||||||
price: isNaN(parsedPrice) || price,
|
price: isNaN(parsedPrice) ? price : parsedPrice,
|
||||||
size: parseFloat(size),
|
size: parseFloat(size),
|
||||||
rooms: parseRooms(rooms),
|
rooms: parsedRooms,
|
||||||
floor: parseInt(floor),
|
floor: parseInt(floor),
|
||||||
address,
|
address,
|
||||||
location,
|
location,
|
||||||
@@ -127,6 +145,18 @@ export default class OlxCrawler {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
getCategoryId (category) {
|
||||||
|
if (category === 'Stanovi') {
|
||||||
|
return CATEGORY_FLAT;
|
||||||
|
} else if (category === 'Zemljišta') {
|
||||||
|
return CATEGORY_LAND;
|
||||||
|
} else if (category === 'Kuće') {
|
||||||
|
return CATEGORY_HOUSE;
|
||||||
|
} else if (category === 'Poslovni prostori') {
|
||||||
|
return CATEGORY_OFFICE;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
async sleep(ms) {
|
async sleep(ms) {
|
||||||
return new Promise(resolve => setTimeout(resolve, ms));
|
return new Promise(resolve => setTimeout(resolve, ms));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,11 @@
|
|||||||
import React from "react";
|
import React from "react";
|
||||||
import { formatFilterNumber } from "../lib/helpers";
|
import { formatFilterNumber } from "../lib/helpers";
|
||||||
|
import {
|
||||||
|
CATEGORY_FLAT,
|
||||||
|
CATEGORY_HOUSE,
|
||||||
|
CATEGORY_OFFICE,
|
||||||
|
CATEGORY_LAND
|
||||||
|
} from '../../crawler/enums';
|
||||||
|
|
||||||
export default class Filters extends React.Component {
|
export default class Filters extends React.Component {
|
||||||
onCloseClick(e) {
|
onCloseClick(e) {
|
||||||
@@ -40,6 +46,10 @@ export default class Filters extends React.Component {
|
|||||||
this.props.dispatch({type: 'SET_ROOMS', action: {rooms}});
|
this.props.dispatch({type: 'SET_ROOMS', action: {rooms}});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
onCategoryClick(category) {
|
||||||
|
this.props.dispatch({type: 'SET_CATEGORY', action: {category}});
|
||||||
|
}
|
||||||
|
|
||||||
onRefreshClick() {
|
onRefreshClick() {
|
||||||
this.updateSearch();
|
this.updateSearch();
|
||||||
}
|
}
|
||||||
@@ -57,6 +67,7 @@ export default class Filters extends React.Component {
|
|||||||
render() {
|
render() {
|
||||||
const { filters } = this.props;
|
const { filters } = this.props;
|
||||||
const selectedRooms = val => filters.rooms[val] ? "selected" : "";
|
const selectedRooms = val => filters.rooms[val] ? "selected" : "";
|
||||||
|
const selectedCategory = val => filters.category[val] ? "selected": "";
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="filters">
|
<div className="filters">
|
||||||
@@ -105,18 +116,26 @@ export default class Filters extends React.Component {
|
|||||||
TIP
|
TIP
|
||||||
</div>
|
</div>
|
||||||
<div className="filter-content">
|
<div className="filter-content">
|
||||||
<div className="filter-btn property-type-btn">
|
<div
|
||||||
|
onClick={this.onCategoryClick.bind(this, CATEGORY_FLAT)}
|
||||||
|
className={`filter-btn property-type-btn ${selectedCategory(CATEGORY_FLAT)}`}>
|
||||||
Stan
|
Stan
|
||||||
</div>
|
</div>
|
||||||
<div className="filter-btn property-type-btn">
|
<div
|
||||||
|
onClick={this.onCategoryClick.bind(this, CATEGORY_HOUSE)}
|
||||||
|
className={`filter-btn property-type-btn ${selectedCategory(CATEGORY_HOUSE)}`}>
|
||||||
Kuća
|
Kuća
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div className="filter-content">
|
<div className="filter-content">
|
||||||
<div className="filter-btn property-type-btn">
|
<div
|
||||||
|
onClick={this.onCategoryClick.bind(this, CATEGORY_LAND)}
|
||||||
|
className={`filter-btn property-type-btn ${selectedCategory(CATEGORY_LAND)}`}>
|
||||||
Zemljište
|
Zemljište
|
||||||
</div>
|
</div>
|
||||||
<div className="filter-btn property-type-btn">
|
<div
|
||||||
|
onClick={this.onCategoryClick.bind(this, CATEGORY_OFFICE)}
|
||||||
|
className={`filter-btn property-type-btn ${selectedCategory(CATEGORY_OFFICE)}`}>
|
||||||
Poslovni prostor
|
Poslovni prostor
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@@ -155,9 +174,9 @@ export default class Filters extends React.Component {
|
|||||||
</div>
|
</div>
|
||||||
<div className="filter-content">
|
<div className="filter-content">
|
||||||
<div
|
<div
|
||||||
onClick={this.onRoomsClick.bind(this, "Garsonjera")}
|
onClick={this.onRoomsClick.bind(this, 0)}
|
||||||
className={
|
className={
|
||||||
`filter-btn property-rooms-studio-btn ${selectedRooms("Garsonjera")}`
|
`filter-btn property-rooms-studio-btn ${selectedRooms(0)}`
|
||||||
}
|
}
|
||||||
>
|
>
|
||||||
Garsonjera
|
Garsonjera
|
||||||
|
|||||||
@@ -14,7 +14,8 @@ class Main extends React.Component {
|
|||||||
listings: (new Map()),
|
listings: (new Map()),
|
||||||
imageIndex: 0,
|
imageIndex: 0,
|
||||||
filters: {
|
filters: {
|
||||||
rooms: {}
|
rooms: {},
|
||||||
|
category: {}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@@ -99,7 +100,14 @@ class Main extends React.Component {
|
|||||||
|
|
||||||
refreshListings() {
|
refreshListings() {
|
||||||
const map = this.map;
|
const map = this.map;
|
||||||
const {rooms, minSize, maxSize, minPrice, maxPrice} = this.state.filters;
|
const {
|
||||||
|
rooms,
|
||||||
|
minSize,
|
||||||
|
maxSize,
|
||||||
|
minPrice,
|
||||||
|
maxPrice,
|
||||||
|
category
|
||||||
|
} = this.state.filters;
|
||||||
|
|
||||||
const properties = loadProperties({
|
const properties = loadProperties({
|
||||||
bounds: map.getBounds().toUrlValue(),
|
bounds: map.getBounds().toUrlValue(),
|
||||||
@@ -107,7 +115,8 @@ class Main extends React.Component {
|
|||||||
minSize,
|
minSize,
|
||||||
maxSize,
|
maxSize,
|
||||||
minPrice,
|
minPrice,
|
||||||
maxPrice
|
maxPrice,
|
||||||
|
category
|
||||||
});
|
});
|
||||||
|
|
||||||
properties.then(p=> p.text()).then(p => {
|
properties.then(p=> p.text()).then(p => {
|
||||||
|
|||||||
@@ -4,18 +4,24 @@ export const loadProperties = ({
|
|||||||
bounds,
|
bounds,
|
||||||
minPrice = '',
|
minPrice = '',
|
||||||
maxPrice = '',
|
maxPrice = '',
|
||||||
minSize = '',
|
minSize = '',
|
||||||
maxSize = '',
|
maxSize = '',
|
||||||
rooms
|
rooms = {},
|
||||||
|
category = {}
|
||||||
}) => {
|
}) => {
|
||||||
const allRooms = Object
|
const allRooms = Object
|
||||||
.keys(rooms)
|
.keys(rooms)
|
||||||
.filter((v) => rooms[v])
|
.filter((v) => rooms[v])
|
||||||
.join(',');
|
.join(',');
|
||||||
|
|
||||||
|
const allCategories = Object
|
||||||
|
.keys(category)
|
||||||
|
.filter((v) => category[v])
|
||||||
|
.join(',');
|
||||||
|
|
||||||
// TODO: handle errors
|
// TODO: handle errors
|
||||||
//return fetch(process.env.API_URL + '/api/search', {
|
//return fetch(process.env.API_URL + '/api/search', {
|
||||||
return fetch(`http://localhost:3001/api/search?bounds=${bounds}&minPrice=${minPrice}&maxPrice=${maxPrice}&rooms=${allRooms}&minSize=${minSize}&maxSize=${maxSize}`, {
|
return fetch(`http://localhost:3001/api/search?bounds=${bounds}&minPrice=${minPrice}&maxPrice=${maxPrice}&rooms=${allRooms}&minSize=${minSize}&maxSize=${maxSize}&category=${allCategories}`, {
|
||||||
//credentials: 'include'
|
//credentials: 'include'
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -99,7 +99,6 @@ const searchPlaceChanged = ({ type, action }, component) => {
|
|||||||
|
|
||||||
const setRooms = ({ type, action }, component) => {
|
const setRooms = ({ type, action }, component) => {
|
||||||
const prevRooms = component.state.filters.rooms || {};
|
const prevRooms = component.state.filters.rooms || {};
|
||||||
console.log('BERORE ROOMS');
|
|
||||||
|
|
||||||
component.setState(
|
component.setState(
|
||||||
{
|
{
|
||||||
@@ -112,14 +111,12 @@ const setRooms = ({ type, action }, component) => {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
() => {
|
() => {
|
||||||
console.log('after rooms');
|
|
||||||
component.refreshListings();
|
component.refreshListings();
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
const updateSearch = ({ type, action }, component) => {
|
const updateSearch = ({ type, action }, component) => {
|
||||||
console.log("updating search");
|
|
||||||
component.setState(
|
component.setState(
|
||||||
{
|
{
|
||||||
filters: {
|
filters: {
|
||||||
@@ -134,6 +131,26 @@ const updateSearch = ({ type, action }, component) => {
|
|||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const setCategory = ({type, action}, component) => {
|
||||||
|
|
||||||
|
const prevCategory = component.state.filters.category || {};
|
||||||
|
|
||||||
|
component.setState(
|
||||||
|
{
|
||||||
|
filters: {
|
||||||
|
...component.state.filters,
|
||||||
|
category: {
|
||||||
|
...prevCategory,
|
||||||
|
[action.category]: !prevCategory[action.category]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
() => {
|
||||||
|
component.refreshListings();
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
const handlers = {
|
const handlers = {
|
||||||
SET_MIN_PRICE: setMinPrice,
|
SET_MIN_PRICE: setMinPrice,
|
||||||
SET_MAX_PRICE: setMaxPrice,
|
SET_MAX_PRICE: setMaxPrice,
|
||||||
@@ -147,7 +164,8 @@ const handlers = {
|
|||||||
SEARCH_PLACE_CHANGED: searchPlaceChanged,
|
SEARCH_PLACE_CHANGED: searchPlaceChanged,
|
||||||
SET_ROOMS: setRooms,
|
SET_ROOMS: setRooms,
|
||||||
VIEW_LISTING_DETAILS: viewListingDetails,
|
VIEW_LISTING_DETAILS: viewListingDetails,
|
||||||
UPDATE_SEARCH: updateSearch
|
UPDATE_SEARCH: updateSearch,
|
||||||
|
SET_CATEGORY: setCategory
|
||||||
};
|
};
|
||||||
|
|
||||||
export const handleMessage = ({ type, action }, component) => {
|
export const handleMessage = ({ type, action }, component) => {
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
export const formatPrice = (p) => {
|
export const formatPrice = (p) => {
|
||||||
if (p === -1) {
|
if (isNaN(p)) {
|
||||||
return 'Po dogovoru'
|
return 'Po dogovoru'
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user