diff --git a/frontend-react/src/components/filters/NekretnineFilter/AllFiltersDefined.js b/frontend-react/src/components/filters/NekretnineFilter/AllFiltersDefined.js new file mode 100644 index 0000000..fd9d619 --- /dev/null +++ b/frontend-react/src/components/filters/NekretnineFilter/AllFiltersDefined.js @@ -0,0 +1,73 @@ +export const vrstaElements = [ + { + value: "", + name: "Sve", + type: "radio", + optionName: "vrsta" + }, + { + value: "samoprodaja", + name: "Prodaja", + type: "radio", + optionName: "vrsta" + }, + { + value: "samoizdavanje", + name: "Iznajmljivanje", + type: "radio", + optionName: "vrsta" + }, + { + value: "samopotraznja", + name: "Potražnja", + type: "radio", + optionName: "vrsta" + } +]; + +export const lokacijaOptions = { + choices: [ + { value: "9", label: "Sarajevo" }, + { value: "2", label: "Posavski" } + ], + value: "kanton", + optionName: "kanton" +}; + +export const cijenaRangeOptions = { + min: 0, + max: 100000, + defaultValues: [0, 100000], + step: 100, + optionNames: ["od", "do"] +}; + +export const velicinaRangeOptions = { + min: 0, + max: 1000, + defaultValues: [0, new Date().getFullYear()], + step: 1, + optionNames: ["kvadrata_min", "kvadrata_max"] +}; + +export const gradoviOptions = { + parentOptionName: "kanton", + checkboxOptions: { + "9": { + elements: [ + { + type: "checkbox", + name: "Ilidza", + optionName: "grad-ilidza", + value: "3879" + }, + { + type: "checkbox", + name: "Sarajevo-Centar", + optionName: "grad-centar", + value: "3812" + } + ] + } + } +}; diff --git a/frontend-react/src/components/filters/NekretnineFilter/Cijena.js b/frontend-react/src/components/filters/NekretnineFilter/Cijena.js deleted file mode 100644 index 8363a2d..0000000 --- a/frontend-react/src/components/filters/NekretnineFilter/Cijena.js +++ /dev/null @@ -1,7 +0,0 @@ -export const rangeOptions = { - min: 0, - max: 100000, - defaultValues: [0, 100000], - step: 100, - optionNames: ["od", "do"] -}; diff --git a/frontend-react/src/components/filters/NekretnineFilter/Lokacija.js b/frontend-react/src/components/filters/NekretnineFilter/Lokacija.js deleted file mode 100644 index bcee7b2..0000000 --- a/frontend-react/src/components/filters/NekretnineFilter/Lokacija.js +++ /dev/null @@ -1,8 +0,0 @@ -export const lokacijaOptions = { - choices: [ - { value: "9", label: "Sarajevo" }, - { value: "2", label: "Posavski" } - ], - value: "kanton", - optionName: "kanton" -}; diff --git a/frontend-react/src/components/filters/NekretnineFilter/Velicina.js b/frontend-react/src/components/filters/NekretnineFilter/Velicina.js deleted file mode 100644 index 5e9b162..0000000 --- a/frontend-react/src/components/filters/NekretnineFilter/Velicina.js +++ /dev/null @@ -1,7 +0,0 @@ -export const rangeOptions = { - min: 0, - max: 1000, - defaultValues: [0, new Date().getFullYear()], - step: 1, - optionNames: ["kvadrata_min", "kvadrata_max"] -}; diff --git a/frontend-react/src/components/filters/NekretnineFilter/Vrsta.js b/frontend-react/src/components/filters/NekretnineFilter/Vrsta.js deleted file mode 100644 index 75029ca..0000000 --- a/frontend-react/src/components/filters/NekretnineFilter/Vrsta.js +++ /dev/null @@ -1,26 +0,0 @@ -export const elements = [ - { - value: "", - name: "Sve", - type: "radio", - optionName: "vrsta" - }, - { - value: "samoprodaja", - name: "Prodaja", - type: "radio", - optionName: "vrsta" - }, - { - value: "samoizdavanje", - name: "Iznajmljivanje", - type: "radio", - optionName: "vrsta" - }, - { - value: "samopotraznja", - name: "Potražnja", - type: "radio", - optionName: "vrsta" - } -]; diff --git a/frontend-react/src/components/filters/NekretnineFilter/index.js b/frontend-react/src/components/filters/NekretnineFilter/index.js index 5062be5..ef5bd9e 100644 --- a/frontend-react/src/components/filters/NekretnineFilter/index.js +++ b/frontend-react/src/components/filters/NekretnineFilter/index.js @@ -1,9 +1,7 @@ import React from "react"; -import * as Vrsta from "./Vrsta"; -import * as Lokacija from "./Lokacija"; -import * as Cijena from "./Cijena"; -import * as Velicina from "./Velicina"; +import * as Filters from "./AllFiltersDefined"; import CheckboxAndRadioWrapper from "components/widgets/CheckboxAndRadioWrapper"; +import SelectDisplayCheckboxWrapper from "components/widgets/SelectDisplayCheckboxWrapper"; import RangeWrapper from "components/widgets/RangeWrapper"; import SelectWrapper from "components/widgets/SelectWrapper"; @@ -13,11 +11,12 @@ class NekretnineFilter extends React.Component {
- - - + + + +
); } diff --git a/frontend-react/src/components/filters/VozilaFilter/AllFiltersDefined.js b/frontend-react/src/components/filters/VozilaFilter/AllFiltersDefined.js new file mode 100644 index 0000000..d9a0692 --- /dev/null +++ b/frontend-react/src/components/filters/VozilaFilter/AllFiltersDefined.js @@ -0,0 +1,104 @@ +export const cijenaRangeOptions = { + min: 0, + max: 100000, + defaultValues: [0, 100000], + step: 100, + optionNames: ["od", "do"] +}; + +export const godisteRangeOptions = { + min: 1960, + max: new Date().getFullYear(), + defaultValues: [1960, new Date().getFullYear()], + step: 1, + optionNames: ["godiste_min", "godiste_max"] +}; + +export const gorivoElements = [ + { + name: "Dizel", + optionName: "gorivo_select_dizel", + type: "checkbox", + value: "Dizel" + }, + { + name: "Benzin", + optionName: "gorivo_select_benzin", + type: "checkbox", + value: "Benzin" + }, + { + name: "Plin", + optionName: "gorivo_select_plin", + type: "checkbox", + value: "Plin" + }, + { + name: "Hibrid", + optionName: "gorivo_select_hibrid", + type: "checkbox", + value: "Hibrid" + }, + { + name: "Elektro", + optionName: "gorivo_select_elektro", + type: "checkbox", + value: "Elektro" + } +]; + +export const kilometrazaOptions = { + kilometraMin: { + choices: [{ value: 5000, label: "5000" }, { value: 10000, label: "10000" }], + value: "kilometra-a_min", + optionName: "kilometra-a_min" + }, + kilometraMax: { + choices: [ + { value: 15000, label: "15000" }, + { value: 200000, label: "200000" } + ], + value: "kilometra-a_max", + optionName: "kilometra-a_max" + } +}; + +export const lokacijaOptions = { + choices: [ + { value: "9", label: "Sarajevo" }, + { value: "2", label: "Posavski" } + ], + value: "kanton", + optionName: "kanton" +}; +export const proizvodacOptions = { + choices: [{ value: "1900", label: "Audi" }, { value: "9000", label: "Ford" }], + value: "v_b", + optionName: "v_b" +}; +export const stanjeElements = [ + { + type: "radio", + value: "", + name: "Nova i polovna vozila", + optionName: "stanje" + }, + { + type: "radio", + value: 1, + name: "Nova", + optionName: "stanje" + }, + { + type: "radio", + value: 2, + name: "Polovna vozila", + optionName: "stanje" + }, + { + type: "checkbox", + name: "Udarena vozila", + optionName: "udaren_checkbox", + value: "on" + } +]; diff --git a/frontend-react/src/components/filters/VozilaFilter/Cijena.js b/frontend-react/src/components/filters/VozilaFilter/Cijena.js deleted file mode 100644 index 8363a2d..0000000 --- a/frontend-react/src/components/filters/VozilaFilter/Cijena.js +++ /dev/null @@ -1,7 +0,0 @@ -export const rangeOptions = { - min: 0, - max: 100000, - defaultValues: [0, 100000], - step: 100, - optionNames: ["od", "do"] -}; diff --git a/frontend-react/src/components/filters/VozilaFilter/Godiste.js b/frontend-react/src/components/filters/VozilaFilter/Godiste.js deleted file mode 100644 index c61253c..0000000 --- a/frontend-react/src/components/filters/VozilaFilter/Godiste.js +++ /dev/null @@ -1,7 +0,0 @@ -export const rangeOptions = { - min: 1960, - max: new Date().getFullYear(), - defaultValues: [1960, new Date().getFullYear()], - step: 1, - optionNames: ["godiste_min", "godiste_max"] -}; diff --git a/frontend-react/src/components/filters/VozilaFilter/Gorivo.js b/frontend-react/src/components/filters/VozilaFilter/Gorivo.js deleted file mode 100644 index 3ecae73..0000000 --- a/frontend-react/src/components/filters/VozilaFilter/Gorivo.js +++ /dev/null @@ -1,32 +0,0 @@ -export const elements = [ - { - name: "Dizel", - optionName: "gorivo_select_dizel", - type: "checkbox", - value: "Dizel" - }, - { - name: "Benzin", - optionName: "gorivo_select_benzin", - type: "checkbox", - value: "Benzin" - }, - { - name: "Plin", - optionName: "gorivo_select_plin", - type: "checkbox", - value: "Plin" - }, - { - name: "Hibrid", - optionName: "gorivo_select_hibrid", - type: "checkbox", - value: "Hibrid" - }, - { - name: "Elektro", - optionName: "gorivo_select_elektro", - type: "checkbox", - value: "Elektro" - } -]; diff --git a/frontend-react/src/components/filters/VozilaFilter/Kilometraza.js b/frontend-react/src/components/filters/VozilaFilter/Kilometraza.js deleted file mode 100644 index 38a0a19..0000000 --- a/frontend-react/src/components/filters/VozilaFilter/Kilometraza.js +++ /dev/null @@ -1,15 +0,0 @@ -export const kilometrazaOptions = { - kilometraMin: { - choices: [{ value: 5000, label: "5000" }, { value: 10000, label: "10000" }], - value: "kilometra-a_min", - optionName: "kilometra-a_min" - }, - kilometraMax: { - choices: [ - { value: 15000, label: "15000" }, - { value: 200000, label: "200000" } - ], - value: "kilometra-a_max", - optionName: "kilometra-a_max" - } -}; diff --git a/frontend-react/src/components/filters/VozilaFilter/Lokacija.js b/frontend-react/src/components/filters/VozilaFilter/Lokacija.js deleted file mode 100644 index bcee7b2..0000000 --- a/frontend-react/src/components/filters/VozilaFilter/Lokacija.js +++ /dev/null @@ -1,8 +0,0 @@ -export const lokacijaOptions = { - choices: [ - { value: "9", label: "Sarajevo" }, - { value: "2", label: "Posavski" } - ], - value: "kanton", - optionName: "kanton" -}; diff --git a/frontend-react/src/components/filters/VozilaFilter/Proizvodac.js b/frontend-react/src/components/filters/VozilaFilter/Proizvodac.js deleted file mode 100644 index 948f227..0000000 --- a/frontend-react/src/components/filters/VozilaFilter/Proizvodac.js +++ /dev/null @@ -1,5 +0,0 @@ -export const proizvodacOptions = { - choices: [{ value: "1900", label: "Audi" }, { value: "9000", label: "Ford" }], - value: "v_b", - optionName: "v_b" -}; diff --git a/frontend-react/src/components/filters/VozilaFilter/Stanje.js b/frontend-react/src/components/filters/VozilaFilter/Stanje.js deleted file mode 100644 index 25ea375..0000000 --- a/frontend-react/src/components/filters/VozilaFilter/Stanje.js +++ /dev/null @@ -1,26 +0,0 @@ -export const elements = [ - { - type: "radio", - value: "", - name: "Nova i polovna vozila", - optionName: "stanje" - }, - { - type: "radio", - value: 1, - name: "Nova", - optionName: "stanje" - }, - { - type: "radio", - value: 2, - name: "Polovna vozila", - optionName: "stanje" - }, - { - type: "checkbox", - name: "Udarena vozila", - optionName: "udaren_checkbox", - value: "on" - } -]; diff --git a/frontend-react/src/components/filters/VozilaFilter/index.js b/frontend-react/src/components/filters/VozilaFilter/index.js index 64eeb28..cc731f5 100644 --- a/frontend-react/src/components/filters/VozilaFilter/index.js +++ b/frontend-react/src/components/filters/VozilaFilter/index.js @@ -1,11 +1,5 @@ import React from "react"; -import * as Stanje from "./Stanje"; -import * as Proizvodac from "./Proizvodac"; -import * as Cijena from "./Cijena"; -import * as Lokacija from "./Lokacija"; -import * as Godiste from "./Godiste"; -import * as Kilometraza from "./Kilometraza"; -import * as Gorivo from "./Gorivo"; +import * as Filters from "./AllFiltersDefined"; import CheckboxAndRadioWrapper from "components/widgets/CheckboxAndRadioWrapper"; import RangeWrapper from "components/widgets/RangeWrapper"; import SelectWrapper from "components/widgets/SelectWrapper"; @@ -16,17 +10,17 @@ class VozilaFilter extends React.Component {
- - - - - - + + + + + +
); diff --git a/frontend-react/src/components/widgets/SelectDisplayCheckboxWrapper.js b/frontend-react/src/components/widgets/SelectDisplayCheckboxWrapper.js new file mode 100644 index 0000000..773ad33 --- /dev/null +++ b/frontend-react/src/components/widgets/SelectDisplayCheckboxWrapper.js @@ -0,0 +1,21 @@ +import React from "react"; +import CheckboxAndRadioWrapper from "components/widgets/CheckboxAndRadioWrapper"; +import { optionchangewrapper } from "utils/optionchangewrapper"; + +class SelectDisplayCheckboxWrapper extends React.Component { + render() { + const { options, checkboxOptions, parentOptionName } = this.props; + let elements = + options[parentOptionName] && + checkboxOptions[options[parentOptionName].value].elements; + return elements ? ( +
+ +
+ ) : null; + } +} +export default optionchangewrapper(SelectDisplayCheckboxWrapper); diff --git a/frontend-react/src/utils/createOlxLink.js b/frontend-react/src/utils/createOlxLink.js index 355c9d7..6dbfd30 100644 --- a/frontend-react/src/utils/createOlxLink.js +++ b/frontend-react/src/utils/createOlxLink.js @@ -1,21 +1,38 @@ const isObject = obj => obj === Object(obj); -const mapOptionToLink = (options, option) => - options[option] !== false - ? `${option}=${ - isObject(options[option]) ? options[option].value : options[option] - }&` - : ""; +const mapOptionsToLink = options => { + const multipleOptions = ["grad"]; + return Object.entries(options) + .filter(([optionName, optionValue]) => optionValue !== false) + .map(([optionName, optionValue]) => + isObject(options[optionName]) + ? [optionName, options[optionName].value] + : [optionName, optionValue] + ) + .map( + ([optionName, optionValue]) => + !console.log(optionName, optionValue) && [optionName, optionValue] + ) + .reduce((acc, [optionName, optionValue]) => { + console.log(optionName, typeof optionName); + if (multipleOptions.some(option => ~optionName.indexOf(option))) { + const whatOption = multipleOptions.filter( + option => ~optionName.indexOf(option) + )[0]; + return acc + `${whatOption}[]=${optionValue}&`; + } + return acc + `${optionName}=${optionValue}&`; + }, ""); +}; export const createOlxLink = (category, subcategory, options) => { - const deepSubCategory = - Boolean(Object.keys(subcategory).length) && - subcategory[ - Object.keys(subcategory).reduce((max, key) => (max < key ? key : max)) - ]; - return deepSubCategory - ? Object.keys(options).reduce( - (link, option) => link + mapOptionToLink(options, option), - `kategorija=${deepSubCategory.value}&` - ) + const categoryChoice = + (Boolean(Object.keys(subcategory).length) && + subcategory[ + Object.keys(subcategory).reduce((max, key) => (max < key ? key : max)) + ]) || + category; + + return categoryChoice + ? `kategorija=${categoryChoice.value}&${mapOptionsToLink(options)}` : ""; };