Skip to content

Commit 564b2c1

Browse files
FloFARThibH2OMaximeMZ
committed
FEATURE: Search for items from a range of attribute values (see Hypertopic#573 ).
Co-Authored-By: Thibault P. <[email protected]> Co-Authored-By: MaximeMZ <[email protected]>
1 parent 3cc36fb commit 564b2c1

File tree

3 files changed

+126
-11
lines changed

3 files changed

+126
-11
lines changed

public/config.yml

+3
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,6 @@ services:
99
portfolio:
1010
vitraux:
1111
visitMap: true
12+
dessins:
13+
slider:
14+
- année

src/Selection.js

+16
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,22 @@ export default class Selection {
125125
}
126126
}
127127

128+
addTopicArray = (arrayAttributes) => {
129+
const data = this.selectionJSON.data;
130+
try {
131+
for (let i = 0; i < data.length; i++) {
132+
if (data[i].selection[0].includes(':')) {
133+
if (data[i].selection[0].split(':')[0] === arrayAttributes[0].split(':')[0]) {
134+
data.splice(i, 1);
135+
}
136+
}
137+
}
138+
this.selectionJSON.data.push({type: 'union', selection: arrayAttributes, exclusion: []});
139+
} catch (error) {
140+
console.log(error);
141+
}
142+
}
143+
128144
/**
129145
* Remove topic from selection.
130146
*

src/components/portfolioPage/AttributeSearch.jsx

+107-11
Original file line numberDiff line numberDiff line change
@@ -2,39 +2,135 @@ import React, { Component } from 'react';
22
import { Items } from '../../model.js';
33
import Selection from '../../Selection.js';
44
import { withRouter } from 'react-router-dom';
5+
import Slider from 'rc-slider';
6+
import 'rc-slider/assets/index.css';
7+
import conf from '../../config.js';
58

69
class AttributeSearch extends Component {
710
constructor(props) {
811
super(props);
912
this.handleChange = this.handleChange.bind(this);
1013
this.state = {
1114
selectedValue: '',
15+
slider: [],
16+
value: [2010, 2021],
17+
min: 2010,
18+
max: 2021,
1219
};
20+
conf.then(settings => {
21+
if (settings.portfolio && settings.portfolio[settings.user])
22+
this.setState({
23+
slider: settings.portfolio[settings.user].slider || false,
24+
});
25+
}).then(valeur => {
26+
if (this.state.slider.includes(this.props.name)) {
27+
28+
let dates = new Set();
29+
this._getValues().forEach(value => {
30+
dates.add((parseInt(value.substring(0, 4)) || 0));
31+
});
32+
this.setState({min: Math.min(...dates)});
33+
var today = new Date();
34+
this.setState({max: today.getFullYear()});
35+
this.setState({value: [this.state.min, this.state.max]});
36+
}
37+
}
38+
);
1339
}
40+
1441
render() {
1542
let attributeValues = this._getValues();
1643
let options = this._getOptions(attributeValues);
1744
let handleChange = (e) => {
1845
const selection = Selection.fromURI();
19-
if (e.target.value !== '') {
20-
if (this.state.selectedValue !== '') {
46+
console.log(selection.selectionJSON);
47+
if (!this.state.slider.includes(this.props.name)) {
48+
if (e.target.value !== '') {
49+
if (this.state.selectedValue !== '') {
50+
selection.removeTopic(this.state.selectedValue);
51+
}
52+
selection.addTopic(e.target.value);
53+
} else {
2154
selection.removeTopic(this.state.selectedValue);
2255
}
23-
selection.addTopic(e.target.value);
56+
console.log(selection.toURI());
57+
this.props.history.push(selection.toURI());
58+
this.setState({selectedValue: e.target.value});
2459
} else {
25-
selection.removeTopic(this.state.selectedValue);
60+
console.log(selection.toURI());
61+
2662
}
27-
console.log(selection.toURI());
28-
this.props.history.push(selection.toURI());
29-
this.setState({selectedValue: e.target.value});
3063
};
64+
3165
return (
3266
<div className={'AttributesList ' + this.props.name}>
3367
{this.props.name}
34-
<select id={this.props.name} onChange={handleChange} className="selectValue">
35-
<option value="" />
36-
{options}
37-
</select>
68+
{(this.state.slider.includes(this.props.name))
69+
? ' : ' + this.state.value[0] + ' - ' + this.state.value[1]
70+
: null
71+
}
72+
{(this.state.slider.includes(this.props.name)
73+
? <div>
74+
<div>{}</div>
75+
<div>{}</div>
76+
<Slider
77+
range
78+
min={this.state.min}
79+
max={this.state.max}
80+
value={this.state.value}
81+
count={1}
82+
onChange={value => {
83+
this.setState(
84+
{
85+
value
86+
},
87+
);
88+
let todelete = [];
89+
const selection = Selection.fromURI();
90+
selection.selectionJSON.data.forEach((element) => {
91+
if (element.selection[0] && element.selection[0].includes(this.props.name)) {
92+
todelete.push(element.selection[0]);
93+
}
94+
if (element.exclusion[0] && element.exclusion[0].includes(this.props.name)) {
95+
todelete.push(element.exclusion[0]);
96+
}
97+
});
98+
for (const item of todelete) {
99+
selection.removeTopic(item);
100+
}
101+
let values = this._getValues();
102+
let valuesParsed = [];
103+
let realValues = [];
104+
105+
for (let value of values) {
106+
valuesParsed.push(parseInt(value));
107+
}
108+
for (let i = this.state.value[0]; i <= this.state.value[1]; i++) {
109+
if (valuesParsed.includes(i)) {
110+
realValues.push(this.props.name + ' : ' + valuesParsed[valuesParsed.indexOf(i)]);
111+
}
112+
}
113+
selection.addTopicArray(realValues);
114+
this.props.history.push(selection.toURI());
115+
}}
116+
railStyle={{
117+
height: 4,
118+
}}
119+
handleStyle={{
120+
height: 10,
121+
width: 10,
122+
marginLeft: -5,
123+
marginTop: -3,
124+
backgroundColor: 'blue',
125+
border: 0
126+
}}
127+
/>
128+
</div>
129+
: <select id={this.props.name} onChange={handleChange} className="selectValue">
130+
<option value="">Choisir</option>
131+
{options}
132+
</select>)
133+
}
38134
</div>
39135
);
40136
}

0 commit comments

Comments
 (0)