aboutsummaryrefslogtreecommitdiffstats
path: root/app/javascript
diff options
context:
space:
mode:
Diffstat (limited to 'app/javascript')
-rw-r--r--app/javascript/helpers/stop_area_header_manager.js5
-rw-r--r--app/javascript/packs/vehicle_journeys/index.js3
-rw-r--r--app/javascript/vehicle_journeys/actions/index.js17
-rw-r--r--app/javascript/vehicle_journeys/components/App.js1
-rw-r--r--app/javascript/vehicle_journeys/components/VehicleJourney.js6
-rw-r--r--app/javascript/vehicle_journeys/components/VehicleJourneys.js41
-rw-r--r--app/javascript/vehicle_journeys/components/tools/EditVehicleJourney.js8
-rw-r--r--app/javascript/vehicle_journeys/containers/VehicleJourneysList.js8
-rw-r--r--app/javascript/vehicle_journeys/reducers/index.js3
-rw-r--r--app/javascript/vehicle_journeys/reducers/returnVehicleJourneys.js11
10 files changed, 81 insertions, 22 deletions
diff --git a/app/javascript/helpers/stop_area_header_manager.js b/app/javascript/helpers/stop_area_header_manager.js
index 2c820caf9..5b18e2f63 100644
--- a/app/javascript/helpers/stop_area_header_manager.js
+++ b/app/javascript/helpers/stop_area_header_manager.js
@@ -42,6 +42,11 @@ export default class StopAreaHeaderManager {
let index = this.ids_list.indexOf(object_id)
let sp = this.stopPointsList[index]
let previousBreakpoint = this.stopPointsList[index - 1]
+ if(sp == undefined){
+ console.log("STOP_POINT NOT FOUND: " + object_id)
+ console.log("AVAILABLE IDS:" + this.ids_list)
+ return
+ }
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
diff --git a/app/javascript/packs/vehicle_journeys/index.js b/app/javascript/packs/vehicle_journeys/index.js
index aa5738d59..e6867cb17 100644
--- a/app/javascript/packs/vehicle_journeys/index.js
+++ b/app/javascript/packs/vehicle_journeys/index.js
@@ -60,6 +60,7 @@ var initialState = {
},
vehicleJourneys: [],
stopPointsList: window.stopPoints,
+ returnStopPointsList: window.returnStopPoints,
pagination: {
page : 1,
totalCount: 0,
@@ -99,7 +100,7 @@ let store = createStore(
render(
<Provider store={store}>
- <App />
+ <App returnRouteUrl={window.returnRouteUrl} />
</Provider>,
document.getElementById('vehicle_journeys_wip')
)
diff --git a/app/javascript/vehicle_journeys/actions/index.js b/app/javascript/vehicle_journeys/actions/index.js
index 8970c6025..74a333b53 100644
--- a/app/javascript/vehicle_journeys/actions/index.js
+++ b/app/javascript/vehicle_journeys/actions/index.js
@@ -13,8 +13,8 @@ const actions = {
exitEditMode: () => ({
type: "EXIT_EDIT_MODE"
}),
- receiveVehicleJourneys : (json) => ({
- type: "RECEIVE_VEHICLE_JOURNEYS",
+ receiveVehicleJourneys : (json, returnJourneys) => ({
+ type: (returnJourneys ? "RECEIVE_RETURN_VEHICLE_JOURNEYS" : "RECEIVE_VEHICLE_JOURNEYS"),
json
}),
receiveErrors : (json) => ({
@@ -290,10 +290,17 @@ const actions = {
type: 'RECEIVE_TOTAL_COUNT',
total
}),
- fetchVehicleJourneys : (dispatch, currentPage, nextPage, queryString) => {
+ fetchVehicleJourneys : (dispatch, currentPage, nextPage, queryString, url) => {
+ let returnJourneys = false
if(currentPage == undefined){
currentPage = 1
}
+ if(url == undefined){
+ url = window.location.pathname
+ }
+ else{
+ returnJourneys = true
+ }
let vehicleJourneys = []
let page
switch (nextPage) {
@@ -315,7 +322,7 @@ const actions = {
str = '.json?page=' + page.toString()
sep = '&'
}
- let urlJSON = window.location.pathname + str
+ let urlJSON = url + str
if (queryString){
urlJSON = urlJSON + sep + queryString
}
@@ -375,7 +382,7 @@ const actions = {
)
}
window.currentItemsLength = vehicleJourneys.length
- dispatch(actions.receiveVehicleJourneys(vehicleJourneys))
+ dispatch(actions.receiveVehicleJourneys(vehicleJourneys, returnJourneys))
dispatch(actions.receiveTotalCount(json.total))
}
})
diff --git a/app/javascript/vehicle_journeys/components/App.js b/app/javascript/vehicle_journeys/components/App.js
index 44559c7c6..5ac284438 100644
--- a/app/javascript/vehicle_journeys/components/App.js
+++ b/app/javascript/vehicle_journeys/components/App.js
@@ -22,6 +22,7 @@ export default function App() {
<Filters />
<VehicleJourneysList />
+ {window.returnRouteUrl && <VehicleJourneysList routeUrl={window.returnRouteUrl}/>}
<div className='row'>
<div className='col-lg-12 text-right'>
diff --git a/app/javascript/vehicle_journeys/components/VehicleJourney.js b/app/javascript/vehicle_journeys/components/VehicleJourney.js
index 2b5783dda..e7d4b5b30 100644
--- a/app/javascript/vehicle_journeys/components/VehicleJourney.js
+++ b/app/javascript/vehicle_journeys/components/VehicleJourney.js
@@ -1,6 +1,7 @@
import React, { Component } from 'react'
import PropTypes from 'prop-types'
import actions from '../actions'
+import EditVehicleJourney from '../containers/tools/EditVehicleJourney'
export default class VehicleJourney extends Component {
constructor(props) {
@@ -80,7 +81,7 @@ export default class VehicleJourney extends Component {
{purchase_windows.length > 3 && <span className='vj_tt'> + {purchase_windows.length - 3}</span>}
</div>
}
- <div className={(this.props.value.deletable ? 'disabled ' : '') + 'checkbox'}>
+ {!this.props.disabled && <div className={(this.props.value.deletable ? 'disabled ' : '') + 'checkbox'}>
<input
id={this.props.index}
name={this.props.index}
@@ -91,7 +92,8 @@ export default class VehicleJourney extends Component {
checked={this.props.value.selected}
></input>
<label htmlFor={this.props.index}></label>
- </div>
+ </div>}
+ {this.props.disabled && <EditVehicleJourney disabled={false} vehicleJourney={this.props.value} />}
</div>
{this.props.value.vehicle_journey_at_stops.map((vj, i) =>
<div key={i} className='td text-center'>
diff --git a/app/javascript/vehicle_journeys/components/VehicleJourneys.js b/app/javascript/vehicle_journeys/components/VehicleJourneys.js
index 256ca81f9..ae852b35a 100644
--- a/app/javascript/vehicle_journeys/components/VehicleJourneys.js
+++ b/app/javascript/vehicle_journeys/components/VehicleJourneys.js
@@ -8,14 +8,36 @@ export default class VehicleJourneys extends Component {
constructor(props){
super(props)
this.headerManager = new StopAreaHeaderManager(
- _.map(this.props.stopPointsList, (sp)=>{return sp.object_id}),
- this.props.stopPointsList,
+ _.map(this.stopPoints(), (sp)=>{return sp.object_id}),
+ this.stopPoints(),
this.props.filters.features
)
}
+ isReturn() {
+ return this.props.routeUrl != undefined
+ }
+
+ vehicleJourneysList() {
+ if(this.isReturn()){
+ return this.props.returnVehicleJourneys
+ }
+ else{
+ return this.props.vehicleJourneys
+ }
+ }
+
+ stopPoints() {
+ if(this.isReturn()){
+ return this.props.returnStopPointsList
+ }
+ else{
+ return this.props.stopPointsList
+ }
+ }
+
componentDidMount() {
- this.props.onLoadFirstPage(this.props.filters)
+ this.props.onLoadFirstPage(this.props.filters, this.props.routeUrl)
}
hasFeature(key) {
@@ -89,10 +111,10 @@ export default class VehicleJourneys extends Component {
</div>
)}
- { this.props.vehicleJourneys.errors && this.props.vehicleJourneys.errors.length && _.some(this.props.vehicleJourneys, 'errors') && (
+ { this.vehicleJourneysList().errors && this.vehicleJourneysList().errors.length && _.some(this.vehicleJourneysList(), 'errors') && (
<div className="alert alert-danger mt-sm">
<strong>Erreur : </strong>
- {this.props.vehicleJourneys.map((vj, index) =>
+ {this.vehicleJourneysList().map((vj, index) =>
vj.errors && vj.errors.map((err, i) => {
return (
<ul key={i}>
@@ -104,7 +126,7 @@ export default class VehicleJourneys extends Component {
</div>
)}
- <div className={'table table-2entries mt-sm mb-sm' + ((this.props.vehicleJourneys.length > 0) ? '' : ' no_result')}>
+ <div className={'table table-2entries mt-sm mb-sm' + ((this.vehicleJourneysList().length > 0) ? '' : ' no_result')}>
<div className='t2e-head w20'>
<div className='th'>
<div className='strong mb-xs'>ID course</div>
@@ -114,7 +136,7 @@ export default class VehicleJourneys extends Component {
<div>Calendriers</div>
{ this.hasFeature('purchase_windows') && <div>Calendriers Commerciaux</div> }
</div>
- {this.props.stopPointsList.map((sp, i) =>{
+ {this.stopPoints().map((sp, i) =>{
return (
<div key={i} className='td'>
{this.headerManager.stopPointHeader(sp.object_id)}
@@ -125,17 +147,18 @@ export default class VehicleJourneys extends Component {
<div className='t2e-item-list w80'>
<div>
- {this.props.vehicleJourneys.map((vj, index) =>
+ {this.vehicleJourneysList().map((vj, index) =>
<VehicleJourney
value={vj}
key={index}
index={index}
- editMode={this.props.editMode}
+ editMode={this.isReturn() ? false : this.props.editMode}
filters={this.props.filters}
features={this.props.features}
onUpdateTime={this.props.onUpdateTime}
onSelectVehicleJourney={this.props.onSelectVehicleJourney}
vehicleJourneys={this}
+ disabled={this.isReturn()}
/>
)}
</div>
diff --git a/app/javascript/vehicle_journeys/components/tools/EditVehicleJourney.js b/app/javascript/vehicle_journeys/components/tools/EditVehicleJourney.js
index 2893422f8..f814c0459 100644
--- a/app/javascript/vehicle_journeys/components/tools/EditVehicleJourney.js
+++ b/app/javascript/vehicle_journeys/components/tools/EditVehicleJourney.js
@@ -23,6 +23,10 @@ export default class EditVehicleJourney extends Component {
}
}
+ getSelected() {
+ return this.props.vehicleJourney ? [this.props.vehicleJourney] : actions.getSelected(this.props.vehicleJourneys)
+ }
+
render() {
if(this.props.status.isFetching == true) {
return false
@@ -35,10 +39,10 @@ export default class EditVehicleJourney extends Component {
<li className='st_action'>
<button
type='button'
- disabled={(actions.getSelected(this.props.vehicleJourneys).length != 1 || this.props.disabled)}
+ disabled={(this.getSelected().length != 1 || this.props.disabled)}
data-toggle='modal'
data-target='#EditVehicleJourneyModal'
- onClick={() => this.props.onOpenEditModal(actions.getSelected(this.props.vehicleJourneys)[0])}
+ onClick={() => this.props.onOpenEditModal(this.getSelected()[0])}
>
<span className='fa fa-info'></span>
</button>
diff --git a/app/javascript/vehicle_journeys/containers/VehicleJourneysList.js b/app/javascript/vehicle_journeys/containers/VehicleJourneysList.js
index 38ab9f6d3..76d1c3a78 100644
--- a/app/javascript/vehicle_journeys/containers/VehicleJourneysList.js
+++ b/app/javascript/vehicle_journeys/containers/VehicleJourneysList.js
@@ -6,17 +6,19 @@ const mapStateToProps = (state) => {
return {
editMode: state.editMode,
vehicleJourneys: state.vehicleJourneys,
+ returnVehicleJourneys: state.returnVehicleJourneys,
status: state.status,
filters: state.filters,
- stopPointsList: state.stopPointsList
+ stopPointsList: state.stopPointsList,
+ returnStopPointsList: state.returnStopPointsList
}
}
const mapDispatchToProps = (dispatch) => {
return {
- onLoadFirstPage: (filters) =>{
+ onLoadFirstPage: (filters, routeUrl) =>{
dispatch(actions.fetchingApi())
- actions.fetchVehicleJourneys(dispatch, undefined, undefined, filters.queryString)
+ actions.fetchVehicleJourneys(dispatch, undefined, undefined, filters.queryString, routeUrl)
},
onUpdateTime: (e, subIndex, index, timeUnit, isDeparture, isArrivalsToggled) => {
dispatch(actions.updateTime(e.target.value, subIndex, index, timeUnit, isDeparture, isArrivalsToggled))
diff --git a/app/javascript/vehicle_journeys/reducers/index.js b/app/javascript/vehicle_journeys/reducers/index.js
index 1963f7c6d..95ac9c7e1 100644
--- a/app/javascript/vehicle_journeys/reducers/index.js
+++ b/app/javascript/vehicle_journeys/reducers/index.js
@@ -1,5 +1,6 @@
import { combineReducers } from 'redux'
import vehicleJourneys from './vehicleJourneys'
+import returnVehicleJourneys from './returnVehicleJourneys'
import pagination from './pagination'
import modal from './modal'
import status from './status'
@@ -11,12 +12,14 @@ import custom_fields from './custom_fields'
const vehicleJourneysApp = combineReducers({
vehicleJourneys,
+ returnVehicleJourneys,
pagination,
modal,
status,
filters,
editMode,
stopPointsList,
+ returnStopPointsList: stopPointsList,
missions,
custom_fields
})
diff --git a/app/javascript/vehicle_journeys/reducers/returnVehicleJourneys.js b/app/javascript/vehicle_journeys/reducers/returnVehicleJourneys.js
new file mode 100644
index 000000000..db3c71d17
--- /dev/null
+++ b/app/javascript/vehicle_journeys/reducers/returnVehicleJourneys.js
@@ -0,0 +1,11 @@
+import _ from 'lodash'
+import actions from '../actions'
+
+export default function returnVehicleJourneys(state = [], action) {
+ switch (action.type) {
+ case 'RECEIVE_RETURN_VEHICLE_JOURNEYS':
+ return [...action.json]
+ default:
+ return state
+ }
+}