@@ -2,39 +2,135 @@ import React, { Component } from 'react';
2
2
import { Items } from '../../model.js' ;
3
3
import Selection from '../../Selection.js' ;
4
4
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' ;
5
8
6
9
class AttributeSearch extends Component {
7
10
constructor ( props ) {
8
11
super ( props ) ;
9
12
this . handleChange = this . handleChange . bind ( this ) ;
10
13
this . state = {
11
14
selectedValue : '' ,
15
+ slider : [ ] ,
16
+ value : [ 2010 , 2021 ] ,
17
+ min : 2010 ,
18
+ max : 2021 ,
12
19
} ;
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
+ ) ;
13
39
}
40
+
14
41
render ( ) {
15
42
let attributeValues = this . _getValues ( ) ;
16
43
let options = this . _getOptions ( attributeValues ) ;
17
44
let handleChange = ( e ) => {
18
45
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 {
21
54
selection . removeTopic ( this . state . selectedValue ) ;
22
55
}
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 } ) ;
24
59
} else {
25
- selection . removeTopic ( this . state . selectedValue ) ;
60
+ console . log ( selection . toURI ( ) ) ;
61
+
26
62
}
27
- console . log ( selection . toURI ( ) ) ;
28
- this . props . history . push ( selection . toURI ( ) ) ;
29
- this . setState ( { selectedValue : e . target . value } ) ;
30
63
} ;
64
+
31
65
return (
32
66
< div className = { 'AttributesList ' + this . props . name } >
33
67
{ 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
+ }
38
134
</ div >
39
135
) ;
40
136
}
0 commit comments