From d114d549f7bc8a772803175dee9a665266d8ed04 Mon Sep 17 00:00:00 2001 From: Zog Date: Thu, 1 Feb 2018 10:34:40 +0100 Subject: Refs #5798 @3h; Show return journeys on the journeys' editor. --- app/javascript/helpers/stop_area_header_manager.js | 5 +++ app/javascript/packs/vehicle_journeys/index.js | 3 +- app/javascript/vehicle_journeys/actions/index.js | 17 ++++++--- app/javascript/vehicle_journeys/components/App.js | 1 + .../vehicle_journeys/components/VehicleJourney.js | 6 ++-- .../vehicle_journeys/components/VehicleJourneys.js | 41 +++++++++++++++++----- .../components/tools/EditVehicleJourney.js | 8 +++-- .../containers/VehicleJourneysList.js | 8 +++-- .../containers/tools/EditVehicleJourney.js | 1 + app/javascript/vehicle_journeys/reducers/index.js | 3 ++ .../reducers/returnVehicleJourneys.js | 11 ++++++ 11 files changed, 82 insertions(+), 22 deletions(-) create mode 100644 app/javascript/vehicle_journeys/reducers/returnVehicleJourneys.js (limited to 'app/javascript') 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( - + , 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() { + {window.returnRouteUrl && }
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 && + {purchase_windows.length - 3}}
} -
+ {!this.props.disabled &&
-
+
} + {this.props.disabled && }
{this.props.value.vehicle_journey_at_stops.map((vj, i) =>
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 {
)} - { 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') && (
Erreur : - {this.props.vehicleJourneys.map((vj, index) => + {this.vehicleJourneysList().map((vj, index) => vj.errors && vj.errors.map((err, i) => { return (
    @@ -104,7 +126,7 @@ export default class VehicleJourneys extends Component {
)} -
0) ? '' : ' no_result')}> +
0) ? '' : ' no_result')}>
ID course
@@ -114,7 +136,7 @@ export default class VehicleJourneys extends Component {
Calendriers
{ this.hasFeature('purchase_windows') &&
Calendriers Commerciaux
}
- {this.props.stopPointsList.map((sp, i) =>{ + {this.stopPoints().map((sp, i) =>{ return (
{this.headerManager.stopPointHeader(sp.object_id)} @@ -125,17 +147,18 @@ export default class VehicleJourneys extends Component {
- {this.props.vehicleJourneys.map((vj, index) => + {this.vehicleJourneysList().map((vj, index) => )}
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 {
  • 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/containers/tools/EditVehicleJourney.js b/app/javascript/vehicle_journeys/containers/tools/EditVehicleJourney.js index c2eabcc10..a851b6e7d 100644 --- a/app/javascript/vehicle_journeys/containers/tools/EditVehicleJourney.js +++ b/app/javascript/vehicle_journeys/containers/tools/EditVehicleJourney.js @@ -18,6 +18,7 @@ const mapDispatchToProps = (dispatch) => { dispatch(actions.closeModal()) }, onOpenEditModal: (vj) =>{ + console.log({vj}) dispatch(actions.openEditModal(vj)) }, onEditVehicleJourney: (data, selectedCompany) =>{ 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 + } +} -- cgit v1.2.3