66 * LICENSE file in the root directory of this source tree.
77 */
88const React = require ( 'react' ) ;
9- const moment = require ( 'moment' ) ;
109
11- const { Form, FormGroup, ControlLabel, FormControl, InputGroup} = require ( 'react-bootstrap' ) ;
10+ const moment = require ( 'moment' ) ;
11+ const tooltip = require ( '../misc/enhancers/tooltip' ) ;
12+ const { isNaN } = require ( 'lodash' ) ;
13+ const { Form, FormGroup, ControlLabel, FormControl, InputGroup, Glyphicon, Button : BButton } = require ( 'react-bootstrap' ) ;
1214const Message = require ( '../I18N/Message' ) ;
13-
15+ const InfoPopover = require ( '../widgets/widget/InfoPopover' ) ;
1416
1517const InlineDateTimeSelector = require ( '../time/InlineDateTimeSelector' ) ;
1618const SwitchButton = require ( '../misc/switch/SwitchButton' ) ;
19+ const Button = tooltip ( BButton ) ;
20+
21+ /**
22+ *
23+ * @param {number } v the number to evaluate
24+ * @param {function } fun the function to execute with number as parameter, if the string is va valid number
25+ * @param {function } validate the function to execute with number as parameter, if the string is va valid number
26+ * @param {function } errFun the function to execute in case of error or not valid number
27+ */
28+ const onValidInteger = ( v , fun , errFun = ( ) => { } ) => {
29+ try {
30+ if ( ! isNaN ( parseInt ( v , 10 ) ) ) {
31+ const value = parseInt ( v , 10 ) ;
32+ if ( value < 1 ) {
33+ return fun ( 1 ) ;
34+ }
35+ return fun ( value ) ;
36+ }
37+ return errFun ( ) ;
38+ } catch ( e ) {
39+ return errFun ( e ) ;
40+ }
41+ } ;
1742const getPlaybackRange = ( { startPlaybackTime, endPlaybackTime } ) => {
1843 const diff = moment ( startPlaybackTime ) . diff ( endPlaybackTime ) ;
1944 return {
@@ -26,67 +51,93 @@ const getPlaybackRange = ({ startPlaybackTime, endPlaybackTime }) => {
2651 * Form div for settings of the playback
2752 */
2853module . exports = ( {
54+ following,
2955 frameDuration,
3056 timeStep,
31- setPlaybackRange = ( ) => { } ,
57+ stepUnit,
58+ onSettingChange = ( ) => { } ,
59+ /*
60+ * Boolean step for animation
61+ */
62+ fixedStep = false ,
63+
3264 playbackRange = {
3365 startPlaybackTime : new Date ( ) . toISOString ( ) ,
3466 endPlaybackTime : new Date ( ) . toISOString ( )
3567 } ,
68+ setPlaybackRange = ( ) => { } ,
69+
3670 dateSelectorStyle = {
3771 padding : 0 ,
3872 margin : 0 ,
3973 border : 'none'
4074 }
4175
4276} ) => ( < div className = "ms-playback-settings" >
43- < h4 > < Message msgId = "playback.settings.title" /> </ h4 >
44- < FormGroup controlId = "formPlaybackTime" >
77+ < h4 > < Message msgId = "playback.settings.title" /> </ h4 >
78+ < FormGroup controlId = "frameDuration" >
4579 < ControlLabel > < Message msgId = "playback.settings.frameDuration" /> </ ControlLabel >
46- < InputGroup >
47- < FormControl componentClass = "input" type = "number" value = { frameDuration } /> < InputGroup . Addon > s</ InputGroup . Addon >
80+ < InputGroup >
81+ < FormControl
82+ componentClass = "input"
83+ type = "number"
84+ value = { frameDuration }
85+
86+ onChange = { ( { target = { } } = { } ) => onValidInteger (
87+ target . value ,
88+ v => {
89+ onSettingChange ( "frameDuration" , v ) ;
90+ }
91+ ) } /> < InputGroup . Addon > s</ InputGroup . Addon >
4892 </ InputGroup >
4993
5094 </ FormGroup >
51- < ControlLabel > < Message msgId = "playback.settings.step.label" /> </ ControlLabel >
95+ < ControlLabel > < Message msgId = "playback.settings.step.label" /> </ ControlLabel >
96+ < FormGroup controlId = "formPlaybackStep" >
5297 < Form componentClass = "fieldset" inline >
53- < FormGroup controlId = "formPlaybackStep" >
54- < ControlLabel > < Message msgId = "Fixed" /> </ ControlLabel >
55- < span > < SwitchButton /> </ span >
56- < FormControl componentClass = "input" type = "number" value = { timeStep } />
57- < FormControl componentClass = "select" placeholder = "Select mode" >
58- < option value = "years" > < Message msgId = "playback.settings.step.year" msgParams = { { number : timeStep || 1 } } /> </ option >
59- < option value = "weeks" > < Message msgId = "playback.settings.step.week" msgParams = { { number : timeStep || 1 } } /> </ option >
60- < option value = "days" > < Message msgId = "playback.settings.step.day" msgParams = { { number : timeStep || 1 } } /> </ option >
61- < option value = "hour" > < Message msgId = "playback.settings.step.hour" msgParams = { { number : timeStep || 1 } } /> </ option >
62- < option value = "minutes" > < Message msgId = "playback.settings.step.minute" msgParams = { { number : timeStep || 1 } } /> </ option >
63- < option value = "seconds" > < Message msgId = "playback.settings.step.second" msgParams = { { number : timeStep || 1 } } /> </ option >
64- </ FormControl >
65- </ FormGroup >
66- </ Form >
67- < FormGroup controlId = "formPlaybackMode" >
68- < ControlLabel > Mode</ ControlLabel >
69- < FormControl componentClass = "select" placeholder = "Select mode" >
70- < option value = "normal" > Normal</ option >
71- < option value = "cumulative" > Cumulative</ option >
72- < option value = "ranged" > Ranged</ option >
98+ < ControlLabel > < Message msgId = "playback.settings.step.fixed" /> </ ControlLabel >
99+ < span > < SwitchButton checked = { fixedStep } onChange = { v => onSettingChange ( "fixedStep" , v ) } /> </ span >
100+ < FormControl
101+ disabled = { ! fixedStep }
102+ componentClass = "input"
103+ type = "number"
104+ style = { { maxWidth : 120 } }
105+ value = { timeStep }
106+ onChange = { ( { target = { } } = { } ) => onValidInteger (
107+ target . value ,
108+ v => {
109+ onSettingChange ( "timeStep" , v ) ;
110+ }
111+ ) } />
112+ < FormControl disabled = { ! fixedStep } componentClass = "select" value = { stepUnit } onChange = { ( { target = { } } ) => onSettingChange ( "stepUnit" , target . value ) } >
113+ < option value = "years" > < Message msgId = "playback.settings.step.year" msgParams = { { number : timeStep || 1 } } /> </ option >
114+ < option value = "weeks" > < Message msgId = "playback.settings.step.week" msgParams = { { number : timeStep || 1 } } /> </ option >
115+ < option value = "days" > < Message msgId = "playback.settings.step.day" msgParams = { { number : timeStep || 1 } } /> </ option >
116+ < option value = "hour" > < Message msgId = "playback.settings.step.hour" msgParams = { { number : timeStep || 1 } } /> </ option >
117+ < option value = "minutes" > < Message msgId = "playback.settings.step.minute" msgParams = { { number : timeStep || 1 } } /> </ option >
118+ < option value = "seconds" > < Message msgId = "playback.settings.step.second" msgParams = { { number : timeStep || 1 } } /> </ option >
73119 </ FormControl >
74- </ FormGroup >
75-
76-
120+ </ Form >
121+ </ FormGroup >
77122 < FormGroup controlId = "formPlaybackMode" >
78- < ControlLabel > Range </ ControlLabel >
123+ < ControlLabel > < Message msgId = "playback.settings.range.title" /> < Button className = "no-border" bsSize = "xs" tooltipId = "playback.settings.range.zoomTooltip" > < Glyphicon glyph = "search" /> </ Button > </ ControlLabel >
79124 < InlineDateTimeSelector
80125 tooltipId = "playback.settings.range.animationStart"
81126 glyph = "play"
82127 date = { playbackRange . startPlaybackTime }
83- onUpdate = { startPlaybackTime => setPlaybackRange ( getPlaybackRange ( { ...playbackRange , startPlaybackTime} ) ) }
84- style = { dateSelectorStyle } />
128+ onUpdate = { startPlaybackTime => setPlaybackRange ( getPlaybackRange ( { ...playbackRange , startPlaybackTime } ) ) }
129+ style = { dateSelectorStyle } />
85130 < InlineDateTimeSelector
86131 glyph = "stop"
87132 tooltipId = "playback.settings.range.animationEnd"
88133 date = { playbackRange . endPlaybackTime }
89- onUpdate = { endPlaybackTime => setPlaybackRange ( getPlaybackRange ( { ...playbackRange , endPlaybackTime} ) ) }
90- style = { dateSelectorStyle } />
134+ onUpdate = { endPlaybackTime => setPlaybackRange ( getPlaybackRange ( { ...playbackRange , endPlaybackTime } ) ) }
135+ style = { dateSelectorStyle } />
136+ </ FormGroup >
137+ < FormGroup controlId = "formPlaybackFollowingMode" >
138+ < Form componentClass = "fieldset" inline >
139+ < ControlLabel > < Message msgId = "playback.settings.mode.following" /> < InfoPopover text = { < Message msgId = "playback.settings.mode.followingDescription" /> } /> </ ControlLabel >
140+ < span > < SwitchButton checked = { following } onChange = { v => onSettingChange ( "following" , v ) } /> </ span >
141+ </ Form >
91142 </ FormGroup >
92143</ div > ) ;
0 commit comments