From 69f4fe0c2ef6426282bb8315b185f2e13e37310c Mon Sep 17 00:00:00 2001 From: Zog Date: Thu, 11 Jan 2018 17:47:21 +0100 Subject: Refs #5556 @0.25h; Show total time and distance in JP editor --- .../journey_patterns/components/JourneyPattern.js | 65 ++++++++++++++++------ 1 file changed, 49 insertions(+), 16 deletions(-) (limited to 'app/javascript') diff --git a/app/javascript/journey_patterns/components/JourneyPattern.js b/app/javascript/journey_patterns/components/JourneyPattern.js index 8dc542bc8..b951b4445 100644 --- a/app/javascript/journey_patterns/components/JourneyPattern.js +++ b/app/javascript/journey_patterns/components/JourneyPattern.js @@ -74,18 +74,60 @@ export default class JourneyPattern extends Component{ return !this.props.status.policy[`journey_patterns.${action}`] } + totals(){ + let totalTime = 0 + let totalDistance = 0 + let from = null + this.props.value.stop_points.map((stopPoint, i) =>{ + if(from && stopPoint.checked){ + let [costsKey, costs, time, distance] = this.getTimeAndDistanceBetweenStops(from, stopPoint.id) + totalTime += time + totalDistance += distance + } + if(stopPoint.checked){ + from = stopPoint.id + } + }) + return [this.formatTime(totalTime), this.formatDistance(totalDistance)] + } + + getTimeAndDistanceBetweenStops(from, to){ + let costsKey = from + "-" + to + let costs = this.props.value.costs[costsKey] || {distance: 0, time: 0} + let time = costs['time'] || 0 + let distance = costs['distance'] || 0 + return [costsKey, costs, time, distance] + } + + formatDistance(distance){ + return parseFloat(Math.round(distance * 100) / 100).toFixed(2) + " km" + } + + formatTime(time){ + if(time < 60){ + return time + " min" + } + else{ + let hours = parseInt(time/60) + return hours + " h " + (time - 60*hours) + " min" + } + } + render() { this.previousSpId = undefined + let [totalTime, totalDistance] = this.totals() return (
- {/* Errors */} - {/* this.props.value.errors ? this.getErrors(this.props.value.errors) : '' */} -
{this.props.value.object_id ? this.props.value.short_id : '-'}
{this.props.value.registration_number}
{actions.getChecked(this.props.value.stop_points).length} arrĂȘt(s)
- + {this.hasFeature('costs_in_journey_patterns') && +
+ {totalTime} + {totalDistance} +
+ }
} {!this.props.editMode &&
-

{(costs['distance'] || 0) + " km"}

+

{this.formatDistance(costs['distance'] || 0)}

{time_in_words}

}
} -- cgit v1.2.3 From 5844565ac4e4fe6cc6572bbe42b850e3cce0b541 Mon Sep 17 00:00:00 2001 From: Alban Peignier Date: Thu, 11 Jan 2018 18:58:42 +0100 Subject: Fixes icons and order of total. Refs #5556 --- app/javascript/journey_patterns/components/JourneyPattern.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'app/javascript') diff --git a/app/javascript/journey_patterns/components/JourneyPattern.js b/app/javascript/journey_patterns/components/JourneyPattern.js index b951b4445..ecbebe2cc 100644 --- a/app/javascript/journey_patterns/components/JourneyPattern.js +++ b/app/javascript/journey_patterns/components/JourneyPattern.js @@ -124,8 +124,8 @@ export default class JourneyPattern extends Component{
{actions.getChecked(this.props.value.stop_points).length} arrĂȘt(s)
{this.hasFeature('costs_in_journey_patterns') &&
- {totalTime} - {totalDistance} + {totalDistance} + {totalTime}
}
-- cgit v1.2.3