aboutsummaryrefslogtreecommitdiffstats
path: root/app/assets/javascripts
diff options
context:
space:
mode:
authorThomas Haddad2017-04-04 17:03:49 +0200
committerThomas Haddad2017-04-04 17:04:25 +0200
commite2cae59e05914688b0d23b83a3dd80761c4df453 (patch)
tree91a58dc46908144358b478bdc18fd60c93ed482c /app/assets/javascripts
parent2620efba52c5ce68ec9f0b812f387d7ef66c9d13 (diff)
downloadchouette-core-e2cae59e05914688b0d23b83a3dd80761c4df453.tar.bz2
Refs #3039: Fix pad when setting value in inputs
Signed-off-by: Thomas Shawarma Haddad <thomas.haddad@af83.com>
Diffstat (limited to 'app/assets/javascripts')
-rw-r--r--app/assets/javascripts/es6_browserified/vehicle_journeys/actions/index.js29
-rw-r--r--app/assets/javascripts/es6_browserified/vehicle_journeys/reducers/filters.js4
-rw-r--r--app/assets/javascripts/es6_browserified/vehicle_journeys/reducers/vehicleJourneys.js6
3 files changed, 24 insertions, 15 deletions
diff --git a/app/assets/javascripts/es6_browserified/vehicle_journeys/actions/index.js b/app/assets/javascripts/es6_browserified/vehicle_journeys/actions/index.js
index 4e67482da..c1ac1bd0e 100644
--- a/app/assets/javascripts/es6_browserified/vehicle_journeys/actions/index.js
+++ b/app/assets/javascripts/es6_browserified/vehicle_journeys/actions/index.js
@@ -362,12 +362,21 @@ const actions = {
return obj.selected
})
},
- pad: (d) => {
+ pad: (d, timeUnit) => {
+ let val = d.toString()
if(d.toString().length == 1){
- return (d < 10) ? '0' + d.toString() : d.toString();
- }else{
- return d.toString()
+ val = (d < 10) ? '0' + d.toString() : d.toString();
+ }
+ if(val.length > 2){
+ val = val.substr(1)
+ }
+ if(timeUnit == 'minute' && parseInt(val) > 59){
+ val = '59'
+ }
+ if(timeUnit == 'hour' && parseInt(val) > 23){
+ val = '23'
}
+ return val
},
encodeParams: (params) => {
let esc = encodeURIComponent
@@ -391,18 +400,18 @@ const actions = {
},
checkSchedules: (schedule) => {
if (parseInt(schedule.departure_time.minute) > 59){
- schedule.departure_time.minute = actions.pad(parseInt(schedule.departure_time.minute) - 60)
- schedule.departure_time.hour = actions.pad(parseInt(schedule.departure_time.hour) + 1)
+ schedule.departure_time.minute = actions.pad(parseInt(schedule.departure_time.minute) - 60, 'minute')
+ schedule.departure_time.hour = actions.pad(parseInt(schedule.departure_time.hour) + 1, 'hour')
}
if (parseInt(schedule.arrival_time.minute) > 59){
- schedule.arrival_time.minute = actions.pad(parseInt(schedule.arrival_time.minute) - 60)
- schedule.arrival_time.hour = actions.pad(parseInt(schedule.arrival_time.hour) + 1)
+ schedule.arrival_time.minute = actions.pad(parseInt(schedule.arrival_time.minute) - 60, 'minute')
+ schedule.arrival_time.hour = actions.pad(parseInt(schedule.arrival_time.hour) + 1, 'hour')
}
if (parseInt(schedule.departure_time.hour) > 23){
- schedule.departure_time.hour = actions.pad(parseInt(schedule.departure_time.hour) - 24)
+ schedule.departure_time.hour = actions.pad(parseInt(schedule.departure_time.hour) - 24, 'hour')
}
if (parseInt(schedule.arrival_time.hour) > 23){
- schedule.arrival_time.hour = actions.pad(parseInt(schedule.arrival_time.hour) - 24)
+ schedule.arrival_time.hour = actions.pad(parseInt(schedule.arrival_time.hour) - 24, 'hour')
}
}
}
diff --git a/app/assets/javascripts/es6_browserified/vehicle_journeys/reducers/filters.js b/app/assets/javascripts/es6_browserified/vehicle_journeys/reducers/filters.js
index 4b67dc4df..e7d5baafc 100644
--- a/app/assets/javascripts/es6_browserified/vehicle_journeys/reducers/filters.js
+++ b/app/assets/javascripts/es6_browserified/vehicle_journeys/reducers/filters.js
@@ -22,7 +22,7 @@ const filters = (state = {}, action) => {
return _.assign({}, state, {query: newQuery})
case 'UPDATE_END_TIME_FILTER':
newInterval = JSON.parse(JSON.stringify(state.query.interval))
- newInterval.end[action.unit] = actions.pad(action.val)
+ newInterval.end[action.unit] = actions.pad(action.val, action.unit)
if(parseInt(newInterval.start.hour + newInterval.start.minute) < parseInt(newInterval.end.hour + newInterval.end.minute)){
newQuery = _.assign({}, state.query, {interval: newInterval})
return _.assign({}, state, {query: newQuery})
@@ -31,7 +31,7 @@ const filters = (state = {}, action) => {
}
case 'UPDATE_START_TIME_FILTER':
newInterval = JSON.parse(JSON.stringify(state.query.interval))
- newInterval.start[action.unit] = actions.pad(action.val)
+ newInterval.start[action.unit] = actions.pad(action.val, action.unit)
if(parseInt(newInterval.start.hour + newInterval.start.minute) < parseInt(newInterval.end.hour + newInterval.end.minute)){
newQuery = _.assign({}, state.query, {interval: newInterval})
return _.assign({}, state, {query: newQuery})
diff --git a/app/assets/javascripts/es6_browserified/vehicle_journeys/reducers/vehicleJourneys.js b/app/assets/javascripts/es6_browserified/vehicle_journeys/reducers/vehicleJourneys.js
index b42cf5f93..cb3ca90ad 100644
--- a/app/assets/javascripts/es6_browserified/vehicle_journeys/reducers/vehicleJourneys.js
+++ b/app/assets/javascripts/es6_browserified/vehicle_journeys/reducers/vehicleJourneys.js
@@ -71,16 +71,16 @@ const vehicleJourney= (state = {}, action) => {
arrival_time: _.assign({}, vjas.arrival_time)
}
if (action.isDeparture){
- newSchedule.departure_time[action.timeUnit] = actions.pad(action.val)
+ newSchedule.departure_time[action.timeUnit] = actions.pad(action.val, action.timeUnit)
if(!action.isArrivalsToggled)
- newSchedule.arrival_time[action.timeUnit] = actions.pad(action.val)
+ newSchedule.arrival_time[action.timeUnit] = actions.pad(action.val, action.timeUnit)
newSchedule = actions.getDelta(newSchedule)
if(newSchedule.delta < 0){
return vjas
}
return _.assign({}, state.vehicle_journey_at_stops[action.subIndex], {arrival_time: newSchedule.arrival_time, departure_time: newSchedule.departure_time, delta: newSchedule.delta})
}else{
- newSchedule.arrival_time[action.timeUnit] = actions.pad(action.val)
+ newSchedule.arrival_time[action.timeUnit] = actions.pad(action.val, action.timeUnit)
newSchedule = actions.getDelta(newSchedule)
if(newSchedule.delta < 0){
return vjas