From ad537be88672bc6472925685e3e204ef562ad8c9 Mon Sep 17 00:00:00 2001 From: Xinhui Date: Thu, 4 Jan 2018 14:22:45 +0100 Subject: Display checksum for journey patterns -m Refs --- app/javascript/journey_patterns/actions/index.js | 3 ++- app/javascript/journey_patterns/components/EditModal.js | 13 +++++++++++-- 2 files changed, 13 insertions(+), 3 deletions(-) (limited to 'app/javascript/journey_patterns') diff --git a/app/javascript/journey_patterns/actions/index.js b/app/javascript/journey_patterns/actions/index.js index 4ff3f77ea..1c2eb68b2 100644 --- a/app/javascript/journey_patterns/actions/index.js +++ b/app/javascript/journey_patterns/actions/index.js @@ -198,6 +198,7 @@ const actions = { name: val.name, object_id: val.object_id, short_id: val.short_id, + checksum: val.checksum, published_name: val.published_name, registration_number: val.registration_number, stop_points: val.route_short_description.stop_points, @@ -217,4 +218,4 @@ const actions = { } } -export default actions \ No newline at end of file +export default actions diff --git a/app/javascript/journey_patterns/components/EditModal.js b/app/javascript/journey_patterns/components/EditModal.js index e7ce24aa1..29154da3c 100644 --- a/app/javascript/journey_patterns/components/EditModal.js +++ b/app/javascript/journey_patterns/components/EditModal.js @@ -36,10 +36,19 @@ export default class EditModal extends Component { {this.renderModalTitle()} × - {(this.props.modal.type == 'edit') && (
+
+ + +
-
- - -
+
+ + +
{ this.props.editMode && -- cgit v1.2.3 From 913d6935727ace3ac94c08adb4e1ec378741fb19 Mon Sep 17 00:00:00 2001 From: Zog Date: Wed, 3 Jan 2018 16:31:33 +0100 Subject: Refs #5455 @6h; Add time and distance between stops in Journey Patterns - Adds a `JSON` attribute in the model - Adds the fields in the editor --- app/javascript/journey_patterns/actions/index.js | 14 +++++ .../journey_patterns/components/JourneyPattern.js | 73 ++++++++++++++++++++-- .../journey_patterns/components/JourneyPatterns.js | 3 +- .../containers/JourneyPatternList.js | 5 +- .../journey_patterns/reducers/journeyPatterns.js | 16 ++++- 5 files changed, 102 insertions(+), 9 deletions(-) (limited to 'app/javascript/journey_patterns') diff --git a/app/javascript/journey_patterns/actions/index.js b/app/javascript/journey_patterns/actions/index.js index 1c2eb68b2..09e2001c1 100644 --- a/app/javascript/journey_patterns/actions/index.js +++ b/app/javascript/journey_patterns/actions/index.js @@ -64,6 +64,11 @@ const actions = { type : 'DELETE_JOURNEYPATTERN', index, }), + updateJourneyPatternCosts : (index, costs) => ({ + type : 'UPDATE_JOURNEYPATTERN_COSTS', + index, + costs + }), closeModal : () => ({ type : 'CLOSE_MODAL' }), @@ -194,6 +199,7 @@ const actions = { } }) } +<<<<<<< HEAD journeyPatterns.push({ name: val.name, object_id: val.object_id, @@ -204,6 +210,14 @@ const actions = { stop_points: val.route_short_description.stop_points, deletable: false }) +======= + journeyPatterns.push( + _.assign({}, val, { + stop_points: val.route_short_description.stop_points, + deletable: false + }) + ) +>>>>>>> Refs #5455 @6h; Add time and distance between stops in Journey Patterns } } window.currentItemsLength = journeyPatterns.length diff --git a/app/javascript/journey_patterns/components/JourneyPattern.js b/app/javascript/journey_patterns/components/JourneyPattern.js index d4c9816ec..40a6899e2 100644 --- a/app/javascript/journey_patterns/components/JourneyPattern.js +++ b/app/javascript/journey_patterns/components/JourneyPattern.js @@ -5,6 +5,17 @@ export default class JourneyPattern extends Component{ constructor(props){ super(props) this.previousCity = undefined + this.previousSpId = undefined + this.updateCosts = this.updateCosts.bind(this) + } + + updateCosts(e) { + let costs = { + [e.target.dataset.costsKey]: { + [e.target.name]: parseInt(e.target.value) + } + } + this.props.onUpdateJourneyPatternCosts(costs) } vehicleJourneyURL(jpOid) { @@ -16,16 +27,26 @@ export default class JourneyPattern extends Component{ ) } + hasFeature(key) { + return this.props.status.features[key] + } + cityNameChecker(sp) { let bool = false + if(sp.city_name != this.previousCity){ bool = true this.previousCity = sp.city_name } + return bool + } + + spNode(sp, headlined){ return (
+
this.props.onCheckboxChange(e)} @@ -61,9 +82,9 @@ export default class JourneyPattern extends Component{ render() { this.previousCity = undefined - + this.previousSpId = undefined return ( -
+
{/* Errors */} {/* this.props.value.errors ? this.getErrors(this.props.value.errors) : '' */} @@ -112,9 +133,49 @@ export default class JourneyPattern extends Component{
{this.props.value.stop_points.map((stopPoint, i) =>{ + let costs = null + let costsKey = null + let time = null + let distance = null + let time_in_words = null + if(this.previousSpId && stopPoint.checked){ + costsKey = this.previousSpId + "-" + stopPoint.id + costs = this.props.value.costs[costsKey] || {distance: 0, time: 0} + time = costs['time'] || 0 + distance = costs['distance'] || 0 + if(time < 60){ + time_in_words = time + " min" + } + else{ + let hours = parseInt(time/60) + time_in_words = hours + " h " + (time - 60*hours) + " min" + } + } + if(stopPoint.checked){ + this.previousSpId = stopPoint.id + } + let headlined = this.cityNameChecker(stopPoint) return ( -
- {this.cityNameChecker(stopPoint)} +
+
+ {this.spNode(stopPoint, headlined)} +
+ {this.hasFeature('costs_in_journey_patterns') && costs &&
+ {this.props.editMode &&
+

+ + km +

+

+ + min +

+
} + {!this.props.editMode &&
+

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

+

{time_in_words}

+
} +
}
) })} @@ -129,4 +190,4 @@ JourneyPattern.propTypes = { onCheckboxChange: PropTypes.func.isRequired, onOpenEditModal: PropTypes.func.isRequired, onDeleteJourneyPattern: PropTypes.func.isRequired -} \ No newline at end of file +} diff --git a/app/javascript/journey_patterns/components/JourneyPatterns.js b/app/javascript/journey_patterns/components/JourneyPatterns.js index 4b2badabb..69024050f 100644 --- a/app/javascript/journey_patterns/components/JourneyPatterns.js +++ b/app/javascript/journey_patterns/components/JourneyPatterns.js @@ -131,6 +131,7 @@ export default class JourneyPatterns extends Component { onCheckboxChange= {(e) => this.props.onCheckboxChange(e, index)} onOpenEditModal= {() => this.props.onOpenEditModal(index, journeyPattern)} onDeleteJourneyPattern={() => this.props.onDeleteJourneyPattern(index)} + onUpdateJourneyPatternCosts={(costs) => this.props.onUpdateJourneyPatternCosts(index, costs)} status= {this.props.status} editMode= {this.props.editMode} /> @@ -152,4 +153,4 @@ JourneyPatterns.propTypes = { onCheckboxChange: PropTypes.func.isRequired, onLoadFirstPage: PropTypes.func.isRequired, onOpenEditModal: PropTypes.func.isRequired -} \ No newline at end of file +} diff --git a/app/javascript/journey_patterns/containers/JourneyPatternList.js b/app/javascript/journey_patterns/containers/JourneyPatternList.js index d98734407..d338345f2 100644 --- a/app/javascript/journey_patterns/containers/JourneyPatternList.js +++ b/app/javascript/journey_patterns/containers/JourneyPatternList.js @@ -25,7 +25,10 @@ const mapDispatchToProps = (dispatch) => { }, onDeleteJourneyPattern: (index) =>{ dispatch(actions.deleteJourneyPattern(index)) - } + }, + onUpdateJourneyPatternCosts: (index, costs) =>{ + dispatch(actions.updateJourneyPatternCosts(index, costs)) + }, } } diff --git a/app/javascript/journey_patterns/reducers/journeyPatterns.js b/app/javascript/journey_patterns/reducers/journeyPatterns.js index 0bbcba976..1ce069522 100644 --- a/app/javascript/journey_patterns/reducers/journeyPatterns.js +++ b/app/javascript/journey_patterns/reducers/journeyPatterns.js @@ -17,6 +17,7 @@ const journeyPattern = (state = {}, action) =>{ published_name: action.data.published_name.value, registration_number: action.data.registration_number.value, stop_points: stopPoints, + costs: {}, deletable: false } case 'UPDATE_CHECKBOX_VALUE': @@ -67,6 +68,19 @@ export default function journeyPatterns (state = [], action) { return j } }) + case 'UPDATE_JOURNEYPATTERN_COSTS': + return state.map((j, i) =>{ + if(i == action.index) { + const new_costs = Object.assign({}, j.costs) + Object.keys(action.costs).map((key) => { + let new_costs_for_key = Object.assign({}, j.costs[key] || {}, action.costs[key]) + new_costs[key] = new_costs_for_key + }) + return _.assign({}, j, {costs: new_costs}) + } else { + return j + } + }) case 'ADD_JOURNEYPATTERN': return [ journeyPattern(state, action), @@ -87,4 +101,4 @@ export default function journeyPatterns (state = [], action) { default: return state } -} \ No newline at end of file +} -- cgit v1.2.3 From bd0ccefe3b876bc9513966b20d3afa01631a72e1 Mon Sep 17 00:00:00 2001 From: Zog Date: Wed, 3 Jan 2018 18:33:31 +0100 Subject: Refs #5455; Fix JourneyPattern editor --- app/javascript/journey_patterns/actions/index.js | 1 + 1 file changed, 1 insertion(+) (limited to 'app/javascript/journey_patterns') diff --git a/app/javascript/journey_patterns/actions/index.js b/app/javascript/journey_patterns/actions/index.js index 09e2001c1..9f1c1c8d3 100644 --- a/app/javascript/journey_patterns/actions/index.js +++ b/app/javascript/journey_patterns/actions/index.js @@ -214,6 +214,7 @@ const actions = { journeyPatterns.push( _.assign({}, val, { stop_points: val.route_short_description.stop_points, + costs: val.costs || {}, deletable: false }) ) -- cgit v1.2.3 From 2fdcfb30655599c19629d8f0afc96f64b430358f Mon Sep 17 00:00:00 2001 From: Zog Date: Fri, 5 Jan 2018 16:34:40 +0100 Subject: Refs #45455 @1h; CR updates #1 --- app/javascript/journey_patterns/components/JourneyPattern.js | 4 ++-- app/javascript/journey_patterns/components/JourneyPatterns.js | 6 +++++- 2 files changed, 7 insertions(+), 3 deletions(-) (limited to 'app/javascript/journey_patterns') diff --git a/app/javascript/journey_patterns/components/JourneyPattern.js b/app/javascript/journey_patterns/components/JourneyPattern.js index 40a6899e2..69eff978e 100644 --- a/app/javascript/journey_patterns/components/JourneyPattern.js +++ b/app/javascript/journey_patterns/components/JourneyPattern.js @@ -12,7 +12,7 @@ export default class JourneyPattern extends Component{ updateCosts(e) { let costs = { [e.target.dataset.costsKey]: { - [e.target.name]: parseInt(e.target.value) + [e.target.name]: parseFloat(e.target.value) } } this.props.onUpdateJourneyPatternCosts(costs) @@ -163,7 +163,7 @@ export default class JourneyPattern extends Component{ {this.hasFeature('costs_in_journey_patterns') && costs &&
{this.props.editMode &&

- + km

diff --git a/app/javascript/journey_patterns/components/JourneyPatterns.js b/app/javascript/journey_patterns/components/JourneyPatterns.js index 69024050f..1e391b0c2 100644 --- a/app/javascript/journey_patterns/components/JourneyPatterns.js +++ b/app/javascript/journey_patterns/components/JourneyPatterns.js @@ -54,6 +54,10 @@ export default class JourneyPatterns extends Component { } } + hasFeature(key) { + return this.props.status.features[key] + } + cityNameChecker(sp) { let bool = false if(sp.city_name != this.previousCity){ @@ -115,7 +119,7 @@ export default class JourneyPatterns extends Component {

{this.props.stopPointsList.map((sp, i) =>{ return ( -
+
{this.cityNameChecker(sp)}
) -- cgit v1.2.3 From 5134b83b0bd07d62b6ab1e334977962addfebf47 Mon Sep 17 00:00:00 2001 From: Zog Date: Mon, 8 Jan 2018 08:21:25 +0100 Subject: Rebase master --- app/javascript/journey_patterns/actions/index.js | 13 ------------- 1 file changed, 13 deletions(-) (limited to 'app/javascript/journey_patterns') diff --git a/app/javascript/journey_patterns/actions/index.js b/app/javascript/journey_patterns/actions/index.js index 9f1c1c8d3..a70a2e6f2 100644 --- a/app/javascript/journey_patterns/actions/index.js +++ b/app/javascript/journey_patterns/actions/index.js @@ -199,18 +199,6 @@ const actions = { } }) } -<<<<<<< HEAD - journeyPatterns.push({ - name: val.name, - object_id: val.object_id, - short_id: val.short_id, - checksum: val.checksum, - published_name: val.published_name, - registration_number: val.registration_number, - stop_points: val.route_short_description.stop_points, - deletable: false - }) -======= journeyPatterns.push( _.assign({}, val, { stop_points: val.route_short_description.stop_points, @@ -218,7 +206,6 @@ const actions = { deletable: false }) ) ->>>>>>> Refs #5455 @6h; Add time and distance between stops in Journey Patterns } } window.currentItemsLength = journeyPatterns.length -- cgit v1.2.3 From b4d016c8aa2e671e2b5a492d7e742d5166069495 Mon Sep 17 00:00:00 2001 From: Zog Date: Thu, 28 Dec 2017 17:05:48 +0100 Subject: Refs #5437 @2h; Update Rect to v16 Because it is needed to test the components. Major issue: Proptype now lives in a separate package, hence the huge diff --- app/javascript/journey_patterns/components/ConfirmModal.js | 4 +++- app/javascript/journey_patterns/components/CreateModal.js | 3 ++- app/javascript/journey_patterns/components/EditModal.js | 3 ++- app/javascript/journey_patterns/components/JourneyPattern.js | 3 ++- app/javascript/journey_patterns/components/JourneyPatterns.js | 3 ++- app/javascript/journey_patterns/components/Navigate.js | 3 ++- app/javascript/journey_patterns/components/SaveJourneyPattern.js | 3 ++- 7 files changed, 15 insertions(+), 7 deletions(-) (limited to 'app/javascript/journey_patterns') diff --git a/app/javascript/journey_patterns/components/ConfirmModal.js b/app/javascript/journey_patterns/components/ConfirmModal.js index 2cc1bef44..ccd0a9384 100644 --- a/app/javascript/journey_patterns/components/ConfirmModal.js +++ b/app/javascript/journey_patterns/components/ConfirmModal.js @@ -1,4 +1,6 @@ -import React, { PropTypes } from 'react' +import React from 'react' +import PropTypes from 'prop-types' + export default function ConfirmModal({dispatch, modal, onModalAccept, onModalCancel, journeyPatterns}) { return ( diff --git a/app/javascript/journey_patterns/components/CreateModal.js b/app/javascript/journey_patterns/components/CreateModal.js index d0eff6e57..a6c1b608a 100644 --- a/app/javascript/journey_patterns/components/CreateModal.js +++ b/app/javascript/journey_patterns/components/CreateModal.js @@ -1,4 +1,5 @@ -import React, { PropTypes, Component } from 'react' +import React, { Component } from 'react' +import PropTypes from 'prop-types' import actions from '../actions' export default class CreateModal extends Component { diff --git a/app/javascript/journey_patterns/components/EditModal.js b/app/javascript/journey_patterns/components/EditModal.js index 7a5d24fba..c960cb41c 100644 --- a/app/javascript/journey_patterns/components/EditModal.js +++ b/app/javascript/journey_patterns/components/EditModal.js @@ -1,4 +1,5 @@ -import React, { PropTypes, Component } from 'react' +import React, { Component } from 'react' +import PropTypes from 'prop-types' import actions from '../actions' export default class EditModal extends Component { diff --git a/app/javascript/journey_patterns/components/JourneyPattern.js b/app/javascript/journey_patterns/components/JourneyPattern.js index 69eff978e..52641c94e 100644 --- a/app/javascript/journey_patterns/components/JourneyPattern.js +++ b/app/javascript/journey_patterns/components/JourneyPattern.js @@ -1,4 +1,5 @@ -import React, { PropTypes, Component } from 'react' +import React, { Component } from 'react' +import PropTypes from 'prop-types' import actions from '../actions' export default class JourneyPattern extends Component{ diff --git a/app/javascript/journey_patterns/components/JourneyPatterns.js b/app/javascript/journey_patterns/components/JourneyPatterns.js index 1e391b0c2..67315346d 100644 --- a/app/javascript/journey_patterns/components/JourneyPatterns.js +++ b/app/javascript/journey_patterns/components/JourneyPatterns.js @@ -1,4 +1,5 @@ -import React, { PropTypes, Component } from 'react' +import React, { Component } from 'react' +import PropTypes from 'prop-types' import _ from 'lodash' import JourneyPattern from './JourneyPattern' diff --git a/app/javascript/journey_patterns/components/Navigate.js b/app/javascript/journey_patterns/components/Navigate.js index f2fdd668f..78f324a7d 100644 --- a/app/javascript/journey_patterns/components/Navigate.js +++ b/app/javascript/journey_patterns/components/Navigate.js @@ -1,4 +1,5 @@ -import React, { PropTypes, Component } from 'react' +import React, { Component } from 'react' +import PropTypes from 'prop-types' import actions from '../actions' export default function Navigate({ dispatch, journeyPatterns, pagination, status }) { diff --git a/app/javascript/journey_patterns/components/SaveJourneyPattern.js b/app/javascript/journey_patterns/components/SaveJourneyPattern.js index d071fa542..7e4492e0e 100644 --- a/app/javascript/journey_patterns/components/SaveJourneyPattern.js +++ b/app/javascript/journey_patterns/components/SaveJourneyPattern.js @@ -1,4 +1,5 @@ -import React, { PropTypes, Component } from 'react' +import React, { Component } from 'react' +import PropTypes from 'prop-types' import actions from '../actions' export default class SaveJourneyPattern extends Component { -- cgit v1.2.3 From d0e51ea2058163b76863797a4e337ba3f5d6611d Mon Sep 17 00:00:00 2001 From: Zog Date: Wed, 10 Jan 2018 10:08:34 +0100 Subject: Refs #5437 @0.5h; Propagate behaviour to the JourneyPatterns editor --- .../journey_patterns/components/JourneyPattern.js | 11 ++----- .../journey_patterns/components/JourneyPatterns.js | 37 +++++++++++++++------- 2 files changed, 28 insertions(+), 20 deletions(-) (limited to 'app/javascript/journey_patterns') diff --git a/app/javascript/journey_patterns/components/JourneyPattern.js b/app/javascript/journey_patterns/components/JourneyPattern.js index 52641c94e..47fb6882d 100644 --- a/app/javascript/journey_patterns/components/JourneyPattern.js +++ b/app/javascript/journey_patterns/components/JourneyPattern.js @@ -33,13 +33,7 @@ export default class JourneyPattern extends Component{ } cityNameChecker(sp) { - let bool = false - - if(sp.city_name != this.previousCity){ - bool = true - this.previousCity = sp.city_name - } - return bool + return this.props.journeyPatterns.showHeader(sp.object_id) } spNode(sp, headlined){ @@ -190,5 +184,6 @@ JourneyPattern.propTypes = { index: PropTypes.number, onCheckboxChange: PropTypes.func.isRequired, onOpenEditModal: PropTypes.func.isRequired, - onDeleteJourneyPattern: PropTypes.func.isRequired + onDeleteJourneyPattern: PropTypes.func.isRequired, + journeyPatterns: PropTypes.object.isRequired } diff --git a/app/javascript/journey_patterns/components/JourneyPatterns.js b/app/javascript/journey_patterns/components/JourneyPatterns.js index 67315346d..c261b408a 100644 --- a/app/javascript/journey_patterns/components/JourneyPatterns.js +++ b/app/javascript/journey_patterns/components/JourneyPatterns.js @@ -7,11 +7,13 @@ import JourneyPattern from './JourneyPattern' export default class JourneyPatterns extends Component { constructor(props){ super(props) - this.previousCity = undefined + this.stopPointsIds = _.map(this.props.stopPointsList, (sp)=>{return sp.stop_area_object_id}) } + componentDidMount() { this.props.onLoadFirstPage() } + componentDidUpdate(prevProps, prevState) { if(this.props.status.isFetching == false){ $('.table-2entries').each(function() { @@ -55,20 +57,26 @@ export default class JourneyPatterns extends Component { } } - hasFeature(key) { - return this.props.status.features[key] + showHeader(object_id) { + let showHeadline = false + let headline = "" + let attribute_to_check = this.hasFeature('long_distance_routes') ? "country_code" : "city_name" + let index = this.stopPointsIds.indexOf(object_id) + let sp = this.props.stopPointsList[index] + let previousBreakpoint = this.props.stopPointsList[index - 1] + if(index == 0 || (sp[attribute_to_check] != previousBreakpoint[attribute_to_check])){ + showHeadline = true + headline = this.hasFeature('long_distance_routes') ? sp.country_name : sp.city_name + } + return showHeadline ? headline : "" } - cityNameChecker(sp) { - let bool = false - if(sp.city_name != this.previousCity){ - bool = true - this.previousCity = sp.city_name - } + stopPointHeader(sp) { + let showHeadline = this.showHeader(sp.stop_area_object_id) return (
{sp.name} @@ -76,6 +84,10 @@ export default class JourneyPatterns extends Component { ) } + hasFeature(key) { + return this.props.status.features[key] + } + render() { this.previousCity = undefined @@ -121,7 +133,7 @@ export default class JourneyPatterns extends Component { {this.props.stopPointsList.map((sp, i) =>{ return (
- {this.cityNameChecker(sp)} + {this.stopPointHeader(sp)}
) })} @@ -139,6 +151,7 @@ export default class JourneyPatterns extends Component { onUpdateJourneyPatternCosts={(costs) => this.props.onUpdateJourneyPatternCosts(index, costs)} status= {this.props.status} editMode= {this.props.editMode} + journeyPatterns= {this} /> )}
-- cgit v1.2.3 From aaa9ee2fabe87209df028bb225339108bf389f64 Mon Sep 17 00:00:00 2001 From: Zog Date: Wed, 10 Jan 2018 10:47:23 +0100 Subject: Refs #5437 @1h; Refactor code --- .../journey_patterns/components/JourneyPattern.js | 6 ++-- .../journey_patterns/components/JourneyPatterns.js | 35 +++++----------------- 2 files changed, 11 insertions(+), 30 deletions(-) (limited to 'app/javascript/journey_patterns') diff --git a/app/javascript/journey_patterns/components/JourneyPattern.js b/app/javascript/journey_patterns/components/JourneyPattern.js index 47fb6882d..2ae9f5552 100644 --- a/app/javascript/journey_patterns/components/JourneyPattern.js +++ b/app/javascript/journey_patterns/components/JourneyPattern.js @@ -32,8 +32,8 @@ export default class JourneyPattern extends Component{ return this.props.status.features[key] } - cityNameChecker(sp) { - return this.props.journeyPatterns.showHeader(sp.object_id) + cityNameChecker(sp, i) { + return this.props.journeyPatterns.showHeader(sp.object_id + "-" + i) } spNode(sp, headlined){ @@ -149,7 +149,7 @@ export default class JourneyPattern extends Component{ if(stopPoint.checked){ this.previousSpId = stopPoint.id } - let headlined = this.cityNameChecker(stopPoint) + let headlined = this.cityNameChecker(stopPoint, i) return (
diff --git a/app/javascript/journey_patterns/components/JourneyPatterns.js b/app/javascript/journey_patterns/components/JourneyPatterns.js index c261b408a..31727fefc 100644 --- a/app/javascript/journey_patterns/components/JourneyPatterns.js +++ b/app/javascript/journey_patterns/components/JourneyPatterns.js @@ -2,12 +2,16 @@ import React, { Component } from 'react' import PropTypes from 'prop-types' import _ from 'lodash' import JourneyPattern from './JourneyPattern' - +import StopAreaHeaderManager from '../../helpers/stop_area_header_manager' export default class JourneyPatterns extends Component { constructor(props){ super(props) - this.stopPointsIds = _.map(this.props.stopPointsList, (sp)=>{return sp.stop_area_object_id}) + this.headerManager = new StopAreaHeaderManager( + _.map(this.props.stopPointsList, (sp, i)=>{return sp.stop_area_object_id + "-" + i}), + this.props.stopPointsList, + this.props.status.features + ) } componentDidMount() { @@ -58,30 +62,7 @@ export default class JourneyPatterns extends Component { } showHeader(object_id) { - let showHeadline = false - let headline = "" - let attribute_to_check = this.hasFeature('long_distance_routes') ? "country_code" : "city_name" - let index = this.stopPointsIds.indexOf(object_id) - let sp = this.props.stopPointsList[index] - let previousBreakpoint = this.props.stopPointsList[index - 1] - if(index == 0 || (sp[attribute_to_check] != previousBreakpoint[attribute_to_check])){ - showHeadline = true - headline = this.hasFeature('long_distance_routes') ? sp.country_name : sp.city_name - } - return showHeadline ? headline : "" - } - - stopPointHeader(sp) { - let showHeadline = this.showHeader(sp.stop_area_object_id) - return ( -
- {sp.name} -
- ) + return this.headerManager.showHeader(object_id) } hasFeature(key) { @@ -133,7 +114,7 @@ export default class JourneyPatterns extends Component { {this.props.stopPointsList.map((sp, i) =>{ return (
- {this.stopPointHeader(sp)} + {this.headerManager.stopPointHeader(sp.stop_area_object_id + "-" + i)}
) })} -- cgit v1.2.3 From f7ed3ca6615bb4950b644d56136016c4482395a8 Mon Sep 17 00:00:00 2001 From: Zog Date: Thu, 11 Jan 2018 10:49:46 +0100 Subject: Refs #5536; Fix JourneyPattern creation --- app/javascript/journey_patterns/components/JourneyPattern.js | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) (limited to 'app/javascript/journey_patterns') diff --git a/app/javascript/journey_patterns/components/JourneyPattern.js b/app/javascript/journey_patterns/components/JourneyPattern.js index 2ae9f5552..8dc542bc8 100644 --- a/app/javascript/journey_patterns/components/JourneyPattern.js +++ b/app/javascript/journey_patterns/components/JourneyPattern.js @@ -5,7 +5,6 @@ import actions from '../actions' export default class JourneyPattern extends Component{ constructor(props){ super(props) - this.previousCity = undefined this.previousSpId = undefined this.updateCosts = this.updateCosts.bind(this) } @@ -33,7 +32,7 @@ export default class JourneyPattern extends Component{ } cityNameChecker(sp, i) { - return this.props.journeyPatterns.showHeader(sp.object_id + "-" + i) + return this.props.journeyPatterns.showHeader((sp.stop_area_object_id || sp.object_id) + "-" + i) } spNode(sp, headlined){ @@ -76,7 +75,6 @@ export default class JourneyPattern extends Component{ } render() { - this.previousCity = undefined this.previousSpId = undefined return (
-- cgit v1.2.3 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/journey_patterns') 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/journey_patterns') 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 From 853c7494b908c8b9dea3b91332ab1265aa40f428 Mon Sep 17 00:00:00 2001 From: Zog Date: Wed, 10 Jan 2018 15:21:42 +0100 Subject: Refs #5529 @0.5h; Prevent double submitting of react forms --- .../journey_patterns/components/SaveJourneyPattern.js | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) (limited to 'app/javascript/journey_patterns') diff --git a/app/javascript/journey_patterns/components/SaveJourneyPattern.js b/app/javascript/journey_patterns/components/SaveJourneyPattern.js index 7e4492e0e..d973147a0 100644 --- a/app/javascript/journey_patterns/components/SaveJourneyPattern.js +++ b/app/javascript/journey_patterns/components/SaveJourneyPattern.js @@ -7,6 +7,18 @@ export default class SaveJourneyPattern extends Component { super(props) } + btnDisabled(){ + return !this.props.status.fetchSuccess || this.props.status.isFetching + } + + btnClass(){ + let className = ['btn btn-default'] + if(this.btnDisabled()){ + className.push('disabled') + } + return className.join(' ') + } + render() { if(this.props.status.policy['journey_patterns.update'] == false) { return false @@ -16,8 +28,9 @@ export default class SaveJourneyPattern extends Component {
{e.preventDefault()}}> - -
-
- ) - } + submitForm(){ + this.props.onSubmitJourneyPattern(this.props.dispatch, this.props.journeyPatterns) } } -- cgit v1.2.3 From 050772225bdff8ef165c1e8e841b1eec664d6c99 Mon Sep 17 00:00:00 2001 From: Zog Date: Thu, 25 Jan 2018 11:39:32 +0100 Subject: Refs #5598; Enable button to view a JourneyPattern when the user is not allowed to edit it --- app/javascript/journey_patterns/components/JourneyPattern.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'app/javascript/journey_patterns') diff --git a/app/javascript/journey_patterns/components/JourneyPattern.js b/app/javascript/journey_patterns/components/JourneyPattern.js index ecbebe2cc..01734f3a3 100644 --- a/app/javascript/journey_patterns/components/JourneyPattern.js +++ b/app/javascript/journey_patterns/components/JourneyPattern.js @@ -136,10 +136,9 @@ export default class JourneyPattern extends Component{
    -
  • +