1 | /*global Module*/ |
---|
2 | "use strict"; |
---|
3 | |
---|
4 | import React from 'react'; |
---|
5 | import Slider from 'react-input-slider'; |
---|
6 | |
---|
7 | const styles = { |
---|
8 | header: { |
---|
9 | textAlign: 'center', |
---|
10 | letterSpacing: '5px', |
---|
11 | fontFamily: "'Fira Mono', Monaco, 'Andale Mono', 'Lucida Console', 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace", |
---|
12 | webkitUserSelect : 'none', |
---|
13 | mozUserSelect: 'none', |
---|
14 | msUserSelect: 'none', |
---|
15 | userSelect: 'none' |
---|
16 | }, |
---|
17 | interval: { |
---|
18 | display: 'table', |
---|
19 | width: '100%', |
---|
20 | height: '20px' |
---|
21 | }, |
---|
22 | small_interval: { |
---|
23 | display: 'table', |
---|
24 | width: '100%', |
---|
25 | height: '5px' |
---|
26 | }, |
---|
27 | slider_position: { |
---|
28 | textAlign: 'center', |
---|
29 | width: '100%' |
---|
30 | }, |
---|
31 | nextButton_position: { |
---|
32 | display: 'table', |
---|
33 | width: '100%', |
---|
34 | textAlign: 'center' |
---|
35 | }, |
---|
36 | finishButton_position: { |
---|
37 | display: 'table', |
---|
38 | width: '90%', |
---|
39 | textAlign: 'right' |
---|
40 | }, |
---|
41 | slider: { |
---|
42 | width: '80%' |
---|
43 | }, |
---|
44 | nextButton: { |
---|
45 | width: '250px', |
---|
46 | height: '50px', |
---|
47 | fontSize: '28px' |
---|
48 | }, |
---|
49 | finishButton: { |
---|
50 | width: '200px', |
---|
51 | height: '40px', |
---|
52 | backgroundColor: 'red', |
---|
53 | color: 'white', |
---|
54 | fontSize: '16px' |
---|
55 | }, |
---|
56 | percent: { |
---|
57 | textAlign: 'center', |
---|
58 | fontFamily: "'Fira Mono', Monaco, 'Andale Mono', 'Lucida Console', 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace", |
---|
59 | webkitUserSelect : 'none', |
---|
60 | mozUserSelect: 'none', |
---|
61 | msUserSelect: 'none', |
---|
62 | userSelect: 'none' |
---|
63 | } |
---|
64 | } |
---|
65 | |
---|
66 | /** |
---|
67 | * Component for adding user parameters |
---|
68 | */ |
---|
69 | class SliderViewer extends React.Component { |
---|
70 | /** |
---|
71 | * Basic constructor. |
---|
72 | * @param {any} props properties of Component |
---|
73 | */ |
---|
74 | constructor(props) { |
---|
75 | super(props); |
---|
76 | this.props = props; |
---|
77 | this.state = { |
---|
78 | percent: 50 |
---|
79 | } |
---|
80 | |
---|
81 | this.handleChangePercent = this.handleChangePercent.bind(this); |
---|
82 | this.onClickNext = this.onClickNext.bind(this); |
---|
83 | } |
---|
84 | |
---|
85 | /** |
---|
86 | * Allow to change percent in state of sliderViewer and set it also in props |
---|
87 | * @param {number} per choosed similarity of framsticks by user in percentage |
---|
88 | */ |
---|
89 | handleChangePercent(per) { |
---|
90 | this.setState({ percent: per.x }, function() { |
---|
91 | console.log(this.state.percent); |
---|
92 | this.props.handleChangePercent(this.state.percent); |
---|
93 | }); |
---|
94 | } |
---|
95 | |
---|
96 | onClickNext() { |
---|
97 | let index1 = this.props.selected1.indexOf(' '); |
---|
98 | let index2 = this.props.selected2.indexOf(' '); |
---|
99 | |
---|
100 | if (index1 < 0 && index2 < 0) { |
---|
101 | this.props.onClickNext(); |
---|
102 | this.setState({ percent: 50 }, function() { |
---|
103 | console.log(this.state.percent); |
---|
104 | this.props.handleChangePercent(this.state.percent); |
---|
105 | }); |
---|
106 | } else { |
---|
107 | let min = ''; |
---|
108 | let max = ''; |
---|
109 | if (this.props.parts1 <= this.props.parts2) { |
---|
110 | min = 'pierwszego'; |
---|
111 | max = 'drugiego'; |
---|
112 | } else { |
---|
113 | min = 'drugiego'; |
---|
114 | max = 'pierwszego'; |
---|
115 | } |
---|
116 | alert('Należy dopasować wszystkie wierzchołki z '+min+' modelu z wierzchołkami '+max+' modelu.'); |
---|
117 | } |
---|
118 | |
---|
119 | } |
---|
120 | |
---|
121 | render() { |
---|
122 | return ( |
---|
123 | <div onMouseDown={ev => {if (ev) ev.stopPropagation();}} onTouchStart={ev => {if (ev) ev.stopPropagation();}}> |
---|
124 | <h2 className='title' style={styles.header}> |
---|
125 | PODOBIEŃSTWO |
---|
126 | </h2> |
---|
127 | <div style={styles.interval}/> |
---|
128 | <div className='slider' style={styles.slider_position}> |
---|
129 | <Slider |
---|
130 | min={0} |
---|
131 | max={100} |
---|
132 | x = {this.state.percent} |
---|
133 | percent = {this.state.percent} |
---|
134 | style={styles.slider} |
---|
135 | onChange={this.handleChangePercent} |
---|
136 | /> |
---|
137 | </div> |
---|
138 | <div style={styles.small_interval}/> |
---|
139 | <div className='percent' style={styles.percent}> |
---|
140 | {this.state.percent} % |
---|
141 | </div> |
---|
142 | <div style={styles.interval}/> |
---|
143 | <div style={styles.nextButton_position}> |
---|
144 | <button type='button' onClick={this.onClickNext} disabled={this.props.isDisable} style={styles.nextButton}> |
---|
145 | Następny |
---|
146 | </button> |
---|
147 | </div> |
---|
148 | <div style={styles.small_interval}/> |
---|
149 | <div style={styles.finishButton_position}> |
---|
150 | <button type='button' onClick={this.props.onClickFinish} style={styles.finishButton}> |
---|
151 | Zamknij |
---|
152 | </button> |
---|
153 | </div> |
---|
154 | |
---|
155 | </div> |
---|
156 | ); |
---|
157 | } |
---|
158 | } |
---|
159 | |
---|
160 | export default SliderViewer; |
---|