From 6572f48475924f3c14456890642d89fcda19e49d Mon Sep 17 00:00:00 2001 From: Joel Lappalainen Date: Fri, 25 May 2018 09:43:06 +0300 Subject: [PATCH 01/34] Add first routing settings parameter --- app/component/AdminPage.js | 71 ++++++++++++++++++++++ app/component/SaveRoutingSettingsButton.js | 42 +++++++++++++ app/component/SummaryPage.js | 5 +- app/component/SummaryPlanContainer.js | 4 +- app/routes.js | 8 +++ app/store/localStorage.js | 23 +++++++ app/util/planParamUtil.js | 16 ++++- 7 files changed, 164 insertions(+), 5 deletions(-) create mode 100644 app/component/AdminPage.js create mode 100644 app/component/SaveRoutingSettingsButton.js diff --git a/app/component/AdminPage.js b/app/component/AdminPage.js new file mode 100644 index 0000000000..d66449a034 --- /dev/null +++ b/app/component/AdminPage.js @@ -0,0 +1,71 @@ +import PropTypes from 'prop-types'; +/* eslint-disable react/no-array-index-key */ +import React from 'react'; +import { Link } from 'react-router'; +import connectToStores from 'fluxible-addons-react/connectToStores'; +import { getRoutingSettings } from '../store/localStorage'; +import SaveRoutingSettingsButton from './SaveRoutingSettingsButton'; + +export const defaultRoutingSettings = { + ignoreRealtimeUpdates: false, +}; + +const AdminPage = (context) => { + const merged = { + ...defaultRoutingSettings, + ...getRoutingSettings(), + ...context.location.query, + }; + + const replaceParams = newParams => + context.router.replace({ + ...context.location, + query: { + ...context.location.query, + ...newParams, + }, + }); + + const toggleRealtimeUpdates = ({ target }) => { + const ignoreRealtimeUpdates = target.value; + context.router.replace({ + pathname: context.location.pathname, + query: { + ...context.location.query, + ignoreRealtimeUpdates, + }, + }); + }; + + return ( +
+ + +
+ ); +}; + +AdminPage.propTypes = { + currentLanguage: PropTypes.string.isRequired, +}; + +AdminPage.contextTypes = { + config: PropTypes.object.isRequired, +}; + +export default connectToStores(AdminPage, ['PreferencesStore'], context => ({ + currentLanguage: context.getStore('PreferencesStore').getLanguage(), +})); diff --git a/app/component/SaveRoutingSettingsButton.js b/app/component/SaveRoutingSettingsButton.js new file mode 100644 index 0000000000..3d2cc896b5 --- /dev/null +++ b/app/component/SaveRoutingSettingsButton.js @@ -0,0 +1,42 @@ +import React from 'react'; + +import { FormattedMessage } from 'react-intl'; +import { locationShape } from 'react-router'; +import { setRoutingSettings } from '../store/localStorage'; + +class SaveRoutingSettingsButton extends React.Component { + static contextTypes = { + location: locationShape.isRequired, + }; + + setSettingsData = () => { + console.log(this.context.location.query); + // Test if has new set values + const settings = { + ignoreRealtimeUpdates: this.context.location.query.ignoreRealtimeUpdates + ? this.context.location.query.ignoreRealtimeUpdates + : undefined, + }; + setRoutingSettings(settings); + alert('Settings updated'); + }; + + render() { + return ( +
+
+ +
+ ); + } +} + +export default SaveRoutingSettingsButton; \ No newline at end of file diff --git a/app/component/SummaryPage.js b/app/component/SummaryPage.js index 6b4669ec13..28fdc206d9 100644 --- a/app/component/SummaryPage.js +++ b/app/component/SummaryPage.js @@ -448,8 +448,8 @@ export default Relay.createContainer(withBreakpoint(SummaryPage), { disableRemainingWeightHeuristic: $disableRemainingWeightHeuristic, arriveBy: $arriveBy, transferPenalty: $transferPenalty, - preferred: $preferred, - itineraryFiltering: $itineraryFiltering) + ignoreRealtimeUpdates: $ignoreRealtimeUpdates, + preferred: $preferred) { ${SummaryPlanContainer.getFragment('plan')} ${ItineraryTab.getFragment('searchTime')} @@ -494,6 +494,7 @@ export default Relay.createContainer(withBreakpoint(SummaryPage), { arriveBy: false, disableRemainingWeightHeuristic: false, transferPenalty: null, + ignoreRealtimeUpdates: null, modes: null, maxWalkDistance: 0, preferred: null, diff --git a/app/component/SummaryPlanContainer.js b/app/component/SummaryPlanContainer.js index 0d97fd04fb..dd6e4e68c4 100644 --- a/app/component/SummaryPlanContainer.js +++ b/app/component/SummaryPlanContainer.js @@ -276,7 +276,7 @@ class SummaryPlanContainer extends React.Component { $arriveBy: Boolean!, $modes: String!, $transferPenalty: Int!, - $itineraryFiltering: Float!, + $ignoreRealtimeUpdates: Boolean!, ) { viewer { plan( fromPlace:$fromPlace, @@ -296,7 +296,7 @@ class SummaryPlanContainer extends React.Component { preferred:$preferred, modes:$modes transferPenalty:$transferPenalty, - itineraryFiltering:$itineraryFiltering, + ignoreRealtimeUpdates:$ignoreRealtimeUpdates, ) {itineraries {startTime,endTime}} } }`; diff --git a/app/routes.js b/app/routes.js index 3d8c712a91..52cfccc95b 100644 --- a/app/routes.js +++ b/app/routes.js @@ -480,6 +480,14 @@ export default config => { ]).then(([title, content]) => cb(null, { title, content })); }} /> + { + import(/* webpackChunkName: "admin" */ './component/AdminPage') + .then(loadRoute(cb)) + .catch(errorLoading); + }} + /> { const custSettings = getCustomizedSettings(); + const routingSettings = getRoutingSettings(); return { walkSpeed: @@ -82,6 +87,10 @@ export const getSettings = () => { custSettings.transferPenalty !== undefined ? Number(custSettings.transferPenalty) : undefined, + ignoreRealtimeUpdates: + routingSettings.ignoreRealtimeUpdates !== undefined + ? isTrue(routingSettings.ignoreRealtimeUpdates) + : undefined, }; }; @@ -118,6 +127,7 @@ export const preparePlanParams = config => ( accessibilityOption, ticketTypes, transferPenalty, + ignoreRealtimeUpdates, }, }, }, @@ -171,6 +181,10 @@ export const preparePlanParams = config => ( transferPenalty !== undefined ? Number(transferPenalty) : settings.transferPenalty, + ignoreRealtimeUpdates: + ignoreRealtimeUpdates !== undefined + ? isTrue(ignoreRealtimeUpdates) + : settings.ignoreRealtimeUpdates, preferred: { agencies: config.preferredAgency || '' }, disableRemainingWeightHeuristic: modes && modes.split(',').includes('CITYBIKE'), From 698d59f69efd7c7914547573721587cd7de43139 Mon Sep 17 00:00:00 2001 From: Joel Lappalainen Date: Fri, 25 May 2018 12:47:57 +0300 Subject: [PATCH 02/34] Add bikeSpeed setting --- app/component/AdminPage.js | 27 +++++++++++++++++++++- app/component/SaveRoutingSettingsButton.js | 3 +++ app/component/SummaryPage.js | 2 ++ app/component/SummaryPlanContainer.js | 2 ++ app/store/localStorage.js | 3 +++ app/util/planParamUtil.js | 9 ++++++++ 6 files changed, 45 insertions(+), 1 deletion(-) diff --git a/app/component/AdminPage.js b/app/component/AdminPage.js index d66449a034..b341abab9c 100644 --- a/app/component/AdminPage.js +++ b/app/component/AdminPage.js @@ -8,6 +8,7 @@ import SaveRoutingSettingsButton from './SaveRoutingSettingsButton'; export const defaultRoutingSettings = { ignoreRealtimeUpdates: false, + bikeSpeed: 5.0, }; const AdminPage = (context) => { @@ -17,6 +18,11 @@ const AdminPage = (context) => { ...context.location.query, }; + const mergedCurrent = { + ...defaultRoutingSettings, + ...getRoutingSettings(), + }; + const replaceParams = newParams => context.router.replace({ ...context.location, @@ -37,10 +43,25 @@ const AdminPage = (context) => { }); }; + const updateBikeSpeed = ({ target }) => { + const bikeSpeed = target.value; + if (bikeSpeed < 0) { + alert('Bike speed needs to be over 0'); + target.value = mergedCurrent.bikeSpeed; + } + context.router.replace({ + pathname: context.location.pathname, + query: { + ...context.location.query, + bikeSpeed, + }, + }); + }; + return (
+
); diff --git a/app/component/SaveRoutingSettingsButton.js b/app/component/SaveRoutingSettingsButton.js index 3d2cc896b5..3df0e53d47 100644 --- a/app/component/SaveRoutingSettingsButton.js +++ b/app/component/SaveRoutingSettingsButton.js @@ -16,6 +16,9 @@ class SaveRoutingSettingsButton extends React.Component { ignoreRealtimeUpdates: this.context.location.query.ignoreRealtimeUpdates ? this.context.location.query.ignoreRealtimeUpdates : undefined, + bikeSpeed: this.context.location.query.bikeSpeed + ? this.context.location.query.bikeSpeed + : undefined, }; setRoutingSettings(settings); alert('Settings updated'); diff --git a/app/component/SummaryPage.js b/app/component/SummaryPage.js index 28fdc206d9..18c4765823 100644 --- a/app/component/SummaryPage.js +++ b/app/component/SummaryPage.js @@ -449,6 +449,7 @@ export default Relay.createContainer(withBreakpoint(SummaryPage), { arriveBy: $arriveBy, transferPenalty: $transferPenalty, ignoreRealtimeUpdates: $ignoreRealtimeUpdates, + bikeSpeed: $bikeSpeed, preferred: $preferred) { ${SummaryPlanContainer.getFragment('plan')} @@ -495,6 +496,7 @@ export default Relay.createContainer(withBreakpoint(SummaryPage), { disableRemainingWeightHeuristic: false, transferPenalty: null, ignoreRealtimeUpdates: null, + bikeSpeed: null, modes: null, maxWalkDistance: 0, preferred: null, diff --git a/app/component/SummaryPlanContainer.js b/app/component/SummaryPlanContainer.js index dd6e4e68c4..7efb019224 100644 --- a/app/component/SummaryPlanContainer.js +++ b/app/component/SummaryPlanContainer.js @@ -277,6 +277,7 @@ class SummaryPlanContainer extends React.Component { $modes: String!, $transferPenalty: Int!, $ignoreRealtimeUpdates: Boolean!, + $bikeSpeed: Float!, ) { viewer { plan( fromPlace:$fromPlace, @@ -297,6 +298,7 @@ class SummaryPlanContainer extends React.Component { modes:$modes transferPenalty:$transferPenalty, ignoreRealtimeUpdates:$ignoreRealtimeUpdates, + bikeSpeed: $bikeSpeed, ) {itineraries {startTime,endTime}} } }`; diff --git a/app/store/localStorage.js b/app/store/localStorage.js index 20f911058c..644068aac3 100644 --- a/app/store/localStorage.js +++ b/app/store/localStorage.js @@ -117,6 +117,9 @@ export function setRoutingSettings(data) { ignoreRealtimeUpdates: data.ignoreRealtimeUpdates ? data.ignoreRealtimeUpdates : oldSettings.ignoreRealtimeUpdates, + bikeSpeed: data.bikeSpeed + ? data.bikeSpeed + : oldSettings.bikeSpeed, }; setItem('routingSettings', newSettings); } diff --git a/app/util/planParamUtil.js b/app/util/planParamUtil.js index 4dc6312ae4..d61bce2de4 100644 --- a/app/util/planParamUtil.js +++ b/app/util/planParamUtil.js @@ -91,6 +91,10 @@ export const getSettings = () => { routingSettings.ignoreRealtimeUpdates !== undefined ? isTrue(routingSettings.ignoreRealtimeUpdates) : undefined, + bikeSpeed: + routingSettings.bikeSpeed !== undefined + ? Number(routingSettings.bikeSpeed) + : undefined, }; }; @@ -128,6 +132,7 @@ export const preparePlanParams = config => ( ticketTypes, transferPenalty, ignoreRealtimeUpdates, + bikeSpeed, }, }, }, @@ -185,6 +190,10 @@ export const preparePlanParams = config => ( ignoreRealtimeUpdates !== undefined ? isTrue(ignoreRealtimeUpdates) : settings.ignoreRealtimeUpdates, + bikeSpeed: + bikeSpeed !== undefined + ? Number(bikeSpeed) + : settings.bikeSpeed, preferred: { agencies: config.preferredAgency || '' }, disableRemainingWeightHeuristic: modes && modes.split(',').includes('CITYBIKE'), From 6103a4770d5e58f7433457094464180ebb66565f Mon Sep 17 00:00:00 2001 From: Joel Lappalainen Date: Fri, 25 May 2018 14:47:16 +0300 Subject: [PATCH 03/34] Add maxPreTransitTime setting --- app/component/AdminPage.js | 20 ++++++++++++++++++++ app/component/SaveRoutingSettingsButton.js | 3 +++ app/component/SummaryPage.js | 2 ++ app/component/SummaryPlanContainer.js | 2 ++ app/store/localStorage.js | 3 +++ app/util/planParamUtil.js | 9 +++++++++ 6 files changed, 39 insertions(+) diff --git a/app/component/AdminPage.js b/app/component/AdminPage.js index b341abab9c..902159fc2a 100644 --- a/app/component/AdminPage.js +++ b/app/component/AdminPage.js @@ -9,6 +9,7 @@ import SaveRoutingSettingsButton from './SaveRoutingSettingsButton'; export const defaultRoutingSettings = { ignoreRealtimeUpdates: false, bikeSpeed: 5.0, + maxPreTransitTime: 1800, }; const AdminPage = (context) => { @@ -43,6 +44,21 @@ const AdminPage = (context) => { }); }; + const updateMaxPreTransitTime = ({ target }) => { + const maxPreTransitTime = target.value; + if (maxPreTransitTime < 0) { + alert('Insert positive number'); + target.value = mergedCurrent.maxPreTransitTime; + } + context.router.replace({ + pathname: context.location.pathname, + query: { + ...context.location.query, + maxPreTransitTime, + }, + }); + }; + const updateBikeSpeed = ({ target }) => { const bikeSpeed = target.value; if (bikeSpeed < 0) { @@ -74,6 +90,10 @@ const AdminPage = (context) => { + + +