aboutsummaryrefslogtreecommitdiffstats
path: root/app/javascript/journey_patterns/components
diff options
context:
space:
mode:
authorLuc Donnet2018-02-19 11:04:29 +0100
committerLuc Donnet2018-02-19 11:04:29 +0100
commit7b17deff51545358009cb417cbb9d796565e7540 (patch)
treea43a5586ad39d838dd607e600dbc15ff18a58ab3 /app/javascript/journey_patterns/components
parent89428163fc93a7e09ebb0ca47939f8558afeb5eb (diff)
parent5f6008d165df4499319a2121a71842657d6ac3c9 (diff)
downloadchouette-core-7b17deff51545358009cb417cbb9d796565e7540.tar.bz2
Merge branch 'master' into 0000-docker
Diffstat (limited to 'app/javascript/journey_patterns/components')
-rw-r--r--app/javascript/journey_patterns/components/ConfirmModal.js4
-rw-r--r--app/javascript/journey_patterns/components/CreateModal.js3
-rw-r--r--app/javascript/journey_patterns/components/EditModal.js16
-rw-r--r--app/javascript/journey_patterns/components/JourneyPattern.js131
-rw-r--r--app/javascript/journey_patterns/components/JourneyPatterns.js42
-rw-r--r--app/javascript/journey_patterns/components/Navigate.js3
-rw-r--r--app/javascript/journey_patterns/components/SaveJourneyPattern.js41
7 files changed, 163 insertions, 77 deletions
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 e7ce24aa1..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 {
@@ -36,7 +37,6 @@ export default class EditModal extends Component {
{this.renderModalTitle()}
<span type="button" className="close modal-close" data-dismiss="modal">&times;</span>
</div>
-
{(this.props.modal.type == 'edit') && (
<form>
<div className='modal-body'>
@@ -85,6 +85,16 @@ export default class EditModal extends Component {
</div>
</div>
</div>
+ <div>
+ <label className='control-label'>Signature métier</label>
+ <input
+ type='text'
+ ref='checksum'
+ className='form-control'
+ disabled='disabled'
+ defaultValue={this.props.modal.modalProps.journeyPattern.checksum}
+ />
+ </div>
</div>
{
this.props.editMode &&
@@ -121,4 +131,4 @@ EditModal.propTypes = {
modal: PropTypes.object,
onModalClose: PropTypes.func.isRequired,
saveModal: PropTypes.func.isRequired
-} \ No newline at end of file
+}
diff --git a/app/javascript/journey_patterns/components/JourneyPattern.js b/app/javascript/journey_patterns/components/JourneyPattern.js
index d4c9816ec..35765b99a 100644
--- a/app/javascript/journey_patterns/components/JourneyPattern.js
+++ b/app/javascript/journey_patterns/components/JourneyPattern.js
@@ -1,10 +1,21 @@
-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{
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]: parseFloat(e.target.value)
+ }
+ }
+ this.props.onUpdateJourneyPatternCosts(costs)
}
vehicleJourneyURL(jpOid) {
@@ -16,16 +27,20 @@ export default class JourneyPattern extends Component{
)
}
- cityNameChecker(sp) {
- let bool = false
- if(sp.city_name != this.previousCity){
- bool = true
- this.previousCity = sp.city_name
- }
+ hasFeature(key) {
+ return this.props.status.features[key]
+ }
+
+ cityNameChecker(sp, i) {
+ return this.props.journeyPatterns.showHeader((sp.stop_area_object_id || sp.object_id) + "-" + i)
+ }
+
+ spNode(sp, headlined){
return (
<div
- className={(bool) ? 'headlined' : ''}
+ className={(headlined) ? 'headlined' : ''}
>
+ <div className={'link '}></div>
<span className='has_radio'>
<input
onChange = {(e) => this.props.onCheckboxChange(e)}
@@ -59,19 +74,60 @@ export default class JourneyPattern extends Component{
return !this.props.status.policy[`journey_patterns.${action}`]
}
- render() {
- this.previousCity = undefined
+ 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)]
+ }
- return (
- <div className={'t2e-item' + (this.props.value.deletable ? ' disabled' : '') + (this.props.value.object_id ? '' : ' to_record') + (this.props.value.errors ? ' has-error': '')}>
- {/* Errors */}
- {/* this.props.value.errors ? this.getErrors(this.props.value.errors) : '' */}
+ 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)
+ }
+ }
+ render() {
+ this.previousSpId = undefined
+ let [totalTime, totalDistance] = this.totals()
+ return (
+ <div className={'t2e-item' + (this.props.value.deletable ? ' disabled' : '') + (this.props.value.object_id ? '' : ' to_record') + (this.props.value.errors ? ' has-error': '') + (this.hasFeature('costs_in_journey_patterns') ? ' with-costs' : '')}>
<div className='th'>
<div className='strong mb-xs'>{this.props.value.object_id ? this.props.value.short_id : '-'}</div>
<div>{this.props.value.registration_number}</div>
<div>{actions.getChecked(this.props.value.stop_points).length} arrêt(s)</div>
-
+ {this.hasFeature('costs_in_journey_patterns') &&
+ <div className="small row totals">
+ <span className="col-md-6"><i className="fa fa-arrows-h"></i>{totalDistance}</span>
+ <span className="col-md-6"><i className="fa fa-clock-o"></i>{totalTime}</span>
+ </div>
+ }
<div className={this.props.value.deletable ? 'btn-group disabled' : 'btn-group'}>
<div
className={this.props.value.deletable ? 'btn dropdown-toggle disabled' : 'btn dropdown-toggle'}
@@ -80,10 +136,9 @@ export default class JourneyPattern extends Component{
<span className='fa fa-cog'></span>
</div>
<ul className='dropdown-menu'>
- <li className={this.isDisabled('update') ? 'disabled' : ''}>
+ <li>
<button
type='button'
- disabled={this.isDisabled('update')}
onClick={this.props.onOpenEditModal}
data-toggle='modal'
data-target='#JourneyPatternModal'
@@ -112,9 +167,40 @@ export default class JourneyPattern extends Component{
</div>
{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, costs, time, distance] = this.getTimeAndDistanceBetweenStops(this.previousSpId, stopPoint.id)
+ time_in_words = this.formatTime(time)
+ }
+ if(stopPoint.checked){
+ this.previousSpId = stopPoint.id
+ }
+ let headlined = this.cityNameChecker(stopPoint, i)
return (
- <div key={i} className='td'>
- {this.cityNameChecker(stopPoint)}
+ <div key={i} className={(stopPoint.checked ? 'activated' : 'deactivated') + (this.props.editMode ? ' edit-mode' : '')}>
+ <div className={'td' + (headlined ? ' with-headline' : '')}>
+ {this.spNode(stopPoint, headlined)}
+ </div>
+ {this.hasFeature('costs_in_journey_patterns') && costs && <div className='costs' id={'costs-' + this.props.value.id + '-' + costsKey }>
+ {this.props.editMode && <div>
+ <p>
+ <input type="number" value={costs['distance'] || 0} min='0' name="distance" step="0.01" onChange={this.updateCosts} data-costs-key={costsKey}/>
+ <span>km</span>
+ </p>
+ <p>
+ <input type="number" value={costs['time'] || 0} min='0' name="time" onChange={this.updateCosts} data-costs-key={costsKey}/>
+ <span>min</span>
+ </p>
+ </div>}
+ {!this.props.editMode && <div>
+ <p><i className="fa fa-arrows-h"></i>{this.formatDistance(costs['distance'] || 0)}</p>
+ <p><i className="fa fa-clock-o"></i>{time_in_words}</p>
+ </div>}
+ </div>}
</div>
)
})}
@@ -128,5 +214,6 @@ JourneyPattern.propTypes = {
index: PropTypes.number,
onCheckboxChange: PropTypes.func.isRequired,
onOpenEditModal: PropTypes.func.isRequired,
- onDeleteJourneyPattern: PropTypes.func.isRequired
-} \ No newline at end of file
+ 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 4b2badabb..31727fefc 100644
--- a/app/javascript/journey_patterns/components/JourneyPatterns.js
+++ b/app/javascript/journey_patterns/components/JourneyPatterns.js
@@ -1,16 +1,23 @@
-import React, { PropTypes, Component } from 'react'
+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.previousCity = undefined
+ 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() {
this.props.onLoadFirstPage()
}
+
componentDidUpdate(prevProps, prevState) {
if(this.props.status.isFetching == false){
$('.table-2entries').each(function() {
@@ -54,21 +61,12 @@ export default class JourneyPatterns extends Component {
}
}
- cityNameChecker(sp) {
- let bool = false
- if(sp.city_name != this.previousCity){
- bool = true
- this.previousCity = sp.city_name
- }
- return (
- <div
- className={(bool) ? 'headlined' : ''}
- data-headline={(bool) ? sp.city_name : ''}
- title={sp.city_name + ' (' + sp.zip_code +')'}
- >
- <span><span>{sp.name}</span></span>
- </div>
- )
+ showHeader(object_id) {
+ return this.headerManager.showHeader(object_id)
+ }
+
+ hasFeature(key) {
+ return this.props.status.features[key]
}
render() {
@@ -115,8 +113,8 @@ export default class JourneyPatterns extends Component {
</div>
{this.props.stopPointsList.map((sp, i) =>{
return (
- <div key={i} className='td'>
- {this.cityNameChecker(sp)}
+ <div key={i} className={'td' + (this.hasFeature('costs_in_journey_patterns') ? ' with-costs' : '')}>
+ {this.headerManager.stopPointHeader(sp.stop_area_object_id + "-" + i)}
</div>
)
})}
@@ -131,8 +129,10 @@ 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}
+ journeyPatterns= {this}
/>
)}
</div>
@@ -152,4 +152,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/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..4bb6a73a0 100644
--- a/app/javascript/journey_patterns/components/SaveJourneyPattern.js
+++ b/app/javascript/journey_patterns/components/SaveJourneyPattern.js
@@ -1,34 +1,19 @@
-import React, { PropTypes, Component } from 'react'
+import React, { Component } from 'react'
+import PropTypes from 'prop-types'
+import SaveButton from '../../helpers/save_button'
import actions from '../actions'
-export default class SaveJourneyPattern extends Component {
- constructor(props){
- super(props)
+export default class SaveJourneyPattern extends SaveButton {
+ hasPolicy(){
+ return this.props.status.policy['journey_patterns.update'] == true
}
- render() {
- if(this.props.status.policy['journey_patterns.update'] == false) {
- return false
- }else{
- return (
- <div className='row mt-md'>
- <div className='col-lg-12 text-right'>
- <form className='jp_collection formSubmitr ml-xs' onSubmit={e => {e.preventDefault()}}>
- <button
- className='btn btn-default'
- type='button'
- onClick={e => {
- e.preventDefault()
- this.props.editMode ? this.props.onSubmitJourneyPattern(this.props.dispatch, this.props.journeyPatterns) : this.props.onEnterEditMode()
- }}
- >
- {this.props.editMode ? "Valider" : "Editer"}
- </button>
- </form>
- </div>
- </div>
- )
- }
+ formClassName(){
+ return 'jp_collection'
+ }
+
+ submitForm(){
+ this.props.onSubmitJourneyPattern(this.props.dispatch, this.props.journeyPatterns)
}
}
@@ -36,4 +21,4 @@ SaveJourneyPattern.propTypes = {
journeyPatterns: PropTypes.array.isRequired,
status: PropTypes.object.isRequired,
page: PropTypes.number.isRequired
-} \ No newline at end of file
+}