-
Notifications
You must be signed in to change notification settings - Fork 163
Expand file tree
/
Copy pathAttributeSearch.jsx
More file actions
160 lines (149 loc) · 5.01 KB
/
AttributeSearch.jsx
File metadata and controls
160 lines (149 loc) · 5.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
import React, { Component } from 'react';
import { Items } from '../../model.js';
import Selection from '../../Selection.js';
import { withRouter } from 'react-router-dom';
import Slider from 'rc-slider';
import 'rc-slider/assets/index.css';
import conf from '../../config.js';
class AttributeSearch extends Component {
constructor(props) {
super(props);
this.handleChange = this.handleChange.bind(this);
this.state = {
selectedValue: '',
slider: [],
value: [2010, 2021],
min: 2010,
max: 2021,
};
conf.then(settings => {
if (settings.portfolio && settings.portfolio[settings.user])
this.setState({
slider: settings.portfolio[settings.user].slider || false,
});
}).then(valeur => {
if (this.state.slider.includes(this.props.name)) {
let dates = new Set();
this._getValues().forEach(value => {
dates.add((parseInt(value.substring(0, 4)) || 0));
});
this.setState({min: Math.min(...dates)});
var today = new Date();
this.setState({max: today.getFullYear()});
this.setState({value: [this.state.min, this.state.max]});
}
}
);
}
render() {
let attributeValues = this._getValues();
let options = this._getOptions(attributeValues);
let handleChange = (e) => {
const selection = Selection.fromURI();
console.log(selection.selectionJSON);
if (!this.state.slider.includes(this.props.name)) {
if (e.target.value !== '') {
if (this.state.selectedValue !== '') {
selection.removeTopic(this.state.selectedValue);
}
selection.addTopic(e.target.value);
} else {
selection.removeTopic(this.state.selectedValue);
}
console.log(selection.toURI());
this.props.history.push(selection.toURI());
this.setState({selectedValue: e.target.value});
} else {
console.log(selection.toURI());
}
};
return (
<div className={'AttributesList ' + this.props.name}>
{this.props.name}
{(this.state.slider.includes(this.props.name))
? ' : ' + this.state.value[0] + ' - ' + this.state.value[1]
: null
}
{(this.state.slider.includes(this.props.name)
? <div>
<div>{}</div>
<div>{}</div>
<Slider
range
min={this.state.min}
max={this.state.max}
value={this.state.value}
count={1}
onChange={value => {
this.setState(
{
value
},
);
let todelete = [];
const selection = Selection.fromURI();
selection.selectionJSON.data.forEach((element) => {
if (element.selection[0] && element.selection[0].includes(this.props.name)) {
todelete.push(element.selection[0]);
}
if (element.exclusion[0] && element.exclusion[0].includes(this.props.name)) {
todelete.push(element.exclusion[0]);
}
});
for (const item of todelete) {
selection.removeTopic(item);
}
let values = this._getValues();
let valuesParsed = [];
let realValues = [];
for (let value of values) {
valuesParsed.push(parseInt(value));
}
for (let i = this.state.value[0]; i <= this.state.value[1]; i++) {
if (valuesParsed.includes(i)) {
realValues.push(this.props.name + ' : ' + valuesParsed[valuesParsed.indexOf(i)]);
}
}
selection.addTopicArray(realValues);
this.props.history.push(selection.toURI());
}}
railStyle={{
height: 4,
}}
handleStyle={{
height: 10,
width: 10,
marginLeft: -5,
marginTop: -3,
backgroundColor: 'blue',
border: 0
}}
/>
</div>
: <select id={this.props.name} onChange={handleChange} className="selectValue">
<option value="">Choisir</option>
{options}
</select>)
}
</div>
);
}
_getValues() {
let attributesValues = new Items(this.props.items)
.getAttributeValues(this.props.name);
attributesValues = new Set(attributesValues);
attributesValues = Array.from(attributesValues);
return attributesValues;
}
_getOptions(attributeValues) {
return attributeValues.map(value => {
let optVal = this.props.name + ' : ' + value;
return <option key={optVal} value={optVal}>{value}</option>;
});
}
handleChange(e) {
e.preventDefault();
console.log(this.props.query.toURI());
}
}
export default withRouter(AttributeSearch);