Skip to content

Commit

Permalink
Merge pull request #2361 from HSLdevcom/DT-1869
Browse files Browse the repository at this point in the history
Dt 1869
  • Loading branch information
vesameskanen authored Jun 20, 2018
2 parents 06afc37 + 8853dc5 commit 4c8c0e1
Show file tree
Hide file tree
Showing 10 changed files with 1,260 additions and 18 deletions.
493 changes: 493 additions & 0 deletions app/component/AdminForm.js

Large diffs are not rendered by default.

40 changes: 40 additions & 0 deletions app/component/AdminPage.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import PropTypes from 'prop-types';
import React from 'react';
import AdminForm from './AdminForm';

class AdminPage extends React.Component {
static contextTypes = {
config: PropTypes.object.isRequired,
};

state = { loading: true, dataConDefaults: {} };

componentDidMount() {
const OTPURLSplit = this.context.config.URL.OTP.split('/');
const dataContainerURL = `${
this.context.config.URL.API_URL
}/routing-data/v2/${
OTPURLSplit[OTPURLSplit.length - 2]
}/router-config.json`;
fetch(dataContainerURL)
.then(res => res.json())
.then(
result => {
this.setState({
loading: false,
dataConDefaults: result.routingDefaults,
});
},
err => {
console.log(err);
this.setState({ loading: false });
},
);
}

render() {
return <AdminForm {...this.state} />;
}
}

export default AdminPage;
175 changes: 175 additions & 0 deletions app/component/RoutingSettingsButtons.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,175 @@
import React from 'react';
import Snackbar from 'material-ui/Snackbar';
import PropTypes from 'prop-types';

import { FormattedMessage } from 'react-intl';
import { locationShape } from 'react-router';
import { setRoutingSettings } from '../store/localStorage';

class RoutingSettingsButtons extends React.Component {
static contextTypes = {
location: locationShape.isRequired,
};

static propTypes = {
onReset: PropTypes.func.isRequired,
};

constructor(props) {
super(props);
this.state = {
autoHideDuration: 940,
open: false,
message: '',
};
}

setSettingsData = () => {
const settings = {
maxWalkDistance: this.context.location.query.maxWalkDistance
? this.context.location.query.maxWalkDistance
: undefined,
maxBikingDistance: this.context.location.query.maxBikingDistance
? this.context.location.query.maxBikingDistance
: undefined,
ignoreRealtimeUpdates: this.context.location.query.ignoreRealtimeUpdates
? this.context.location.query.ignoreRealtimeUpdates
: undefined,
maxPreTransitTime: this.context.location.query.maxPreTransitTime
? this.context.location.query.maxPreTransitTime
: undefined,
walkOnStreetReluctance: this.context.location.query.walkOnStreetReluctance
? this.context.location.query.walkOnStreetReluctance
: undefined,
waitReluctance: this.context.location.query.waitReluctance
? this.context.location.query.waitReluctance
: undefined,
bikeSpeed: this.context.location.query.bikeSpeed
? this.context.location.query.bikeSpeed
: undefined,
bikeSwitchTime: this.context.location.query.bikeSwitchTime
? this.context.location.query.bikeSwitchTime
: undefined,
bikeSwitchCost: this.context.location.query.bikeSwitchCost
? this.context.location.query.bikeSwitchCost
: undefined,
bikeBoardCost: this.context.location.query.bikeBoardCost
? this.context.location.query.bikeBoardCost
: undefined,
optimize: this.context.location.query.optimize
? this.context.location.query.optimize
: undefined,
safetyFactor: this.context.location.query.safetyFactor
? this.context.location.query.safetyFactor
: undefined,
slopeFactor: this.context.location.query.slopeFactor
? this.context.location.query.slopeFactor
: undefined,
timeFactor: this.context.location.query.timeFactor
? this.context.location.query.timeFactor
: undefined,
carParkCarLegWeight: this.context.location.query.carParkCarLegWeight
? this.context.location.query.carParkCarLegWeight
: undefined,
maxTransfers: this.context.location.query.maxTransfers
? this.context.location.query.maxTransfers
: undefined,
waitAtBeginningFactor: this.context.location.query.waitAtBeginningFactor
? this.context.location.query.waitAtBeginningFactor
: undefined,
heuristicStepsPerMainStep: this.context.location.query
.heuristicStepsPerMainStep
? this.context.location.query.heuristicStepsPerMainStep
: undefined,
compactLegsByReversedSearch: this.context.location.query
.compactLegsByReversedSearch
? this.context.location.query.compactLegsByReversedSearch
: undefined,
disableRemainingWeightHeuristic: this.context.location.query
.disableRemainingWeightHeuristic
? this.context.location.query.disableRemainingWeightHeuristic
: undefined,
itineraryFiltering: this.context.location.query.itineraryFiltering
? this.context.location.query.itineraryFiltering
: undefined,
};

if (
settings.optimize === 'TRIANGLE' &&
Number(settings.safetyFactor) +
Number(settings.slopeFactor) +
Number(settings.timeFactor) !==
1.0
) {
alert('Cycling safety, slope, and time factors should equal to 1.0');
} else {
setRoutingSettings(settings);
this.setState({
open: true,
message: (
<FormattedMessage
tagName="span"
defaultMessage="Tallenna asetukset"
id="settings-saved"
/>
),
});
}
};

resetSettings = () => {
this.props.onReset();
this.setState({
open: true,
message: 'Reseted settings!',
});
};

handleRequestClose = () => {
this.setState({
open: false,
});
};

render() {
return (
<div className="save-settings">
<hr />
<button
onClick={this.setSettingsData}
style={{
margin: '0 10px 0 0',
}}
>
<FormattedMessage
defaultMessage="Tallenna asetukset"
id="settings-savebutton"
/>
</button>
<button onClick={this.resetSettings}>
<FormattedMessage
defaultMessage="Palauta oletusasetukset"
id="settings-reset"
/>
</button>
<Snackbar
open={this.state.open}
message={this.state.message}
autoHideDuration={this.state.autoHideDuration}
onRequestClose={this.handleRequestClose}
bodyStyle={{
backgroundColor: '#585a5b',
color: '#fff',
textAlign: 'center',
width: 'auto',
fontSize: '0.8rem',
fontFamily:
'"Gotham Rounded SSm A", "Gotham Rounded SSm B", Arial, Georgia, Serif',
}}
/>
</div>
);
}
}

export default RoutingSettingsButtons;
23 changes: 20 additions & 3 deletions app/component/SummaryPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,9 @@ import Loading from './Loading';
import { getHomeUrl } from '../util/path';
import withBreakpoint from '../util/withBreakpoint';
import { validateServiceTimeRange } from '../util/timeUtils';
import { defaultRoutingSettings } from '../util/planParamUtil';

export const ITINERARYFILTERING_DEFAULT = 2.0;
export const ITINERARYFILTERING_DEFAULT = 1.5;

function getActiveIndex(state) {
return (state && state.summaryPageSelected) || 0;
Expand Down Expand Up @@ -448,8 +449,23 @@ export default Relay.createContainer(withBreakpoint(SummaryPage), {
disableRemainingWeightHeuristic: $disableRemainingWeightHeuristic,
arriveBy: $arriveBy,
transferPenalty: $transferPenalty,
preferred: $preferred,
itineraryFiltering: $itineraryFiltering)
ignoreRealtimeUpdates: $ignoreRealtimeUpdates,
maxPreTransitTime: $maxPreTransitTime,
walkOnStreetReluctance: $walkOnStreetReluctance,
waitReluctance: $waitReluctance,
bikeSpeed: $bikeSpeed,
bikeSwitchTime: $bikeSwitchTime,
bikeSwitchCost: $bikeSwitchCost,
bikeBoardCost: $bikeBoardCost,
optimize: $optimize,
triangle: $triangle,
carParkCarLegWeight: $carParkCarLegWeight,
maxTransfers: $maxTransfers,
waitAtBeginningFactor: $waitAtBeginningFactor,
heuristicStepsPerMainStep: $heuristicStepsPerMainStep,
compactLegsByReversedSearch: $compactLegsByReversedSearch,
itineraryFiltering: $itineraryFiltering,
preferred: $preferred)
{
${SummaryPlanContainer.getFragment('plan')}
${ItineraryTab.getFragment('searchTime')}
Expand Down Expand Up @@ -500,6 +516,7 @@ export default Relay.createContainer(withBreakpoint(SummaryPage), {
ticketTypes: null,
itineraryFiltering: ITINERARYFILTERING_DEFAULT,
},
...defaultRoutingSettings,
...SummaryPage.hcParameters,
},
});
48 changes: 44 additions & 4 deletions app/component/SummaryPlanContainer.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,11 @@ import ItinerarySummaryListContainer from './ItinerarySummaryListContainer';
import TimeNavigationButtons from './TimeNavigationButtons';
import { getRoutePath } from '../util/path';
import Loading from './Loading';
import { preparePlanParams, getDefaultOTPModes } from '../util/planParamUtil';
import {
preparePlanParams,
getDefaultOTPModes,
defaultRoutingSettings,
} from '../util/planParamUtil';
import withBreakpoint from '../util/withBreakpoint';

class SummaryPlanContainer extends React.Component {
Expand Down Expand Up @@ -129,7 +133,9 @@ class SummaryPlanContainer extends React.Component {
);

const tunedParams = {
wheelchair: null,
...{ modes: getDefaultOTPModes(this.props.config).join(',') },
...defaultRoutingSettings,
...params,
numItineraries:
this.props.itineraries.length > 0 ? this.props.itineraries.length : 3,
Expand Down Expand Up @@ -201,7 +207,9 @@ class SummaryPlanContainer extends React.Component {
);

const tunedParams = {
wheelchair: null,
...{ modes: getDefaultOTPModes(this.props.config).join(',') },
...defaultRoutingSettings,
...params,
numItineraries:
this.props.itineraries.length > 0 ? this.props.itineraries.length : 3,
Expand Down Expand Up @@ -269,6 +277,8 @@ class SummaryPlanContainer extends React.Component {
$walkReluctance:Float!,
$walkSpeed:Float!,
$maxWalkDistance:Float!,
$wheelchair:Boolean!,
$disableRemainingWeightHeuristic:Boolean!,
$preferred:InputPreferred!,
$fromPlace:String!,
$toPlace:String!
Expand All @@ -277,6 +287,21 @@ class SummaryPlanContainer extends React.Component {
$arriveBy: Boolean!,
$modes: String!,
$transferPenalty: Int!,
$ignoreRealtimeUpdates: Boolean!,
$maxPreTransitTime: Int!,
$walkOnStreetReluctance: Float!,
$waitReluctance: Float!,
$bikeSpeed: Float!,
$bikeSwitchTime: Int!,
$bikeSwitchCost: Int!,
$bikeBoardCost: Int!,
$optimize: OptimizeType!,
$triangle: InputTriangle!,
$carParkCarLegWeight: Float!,
$maxTransfers: Int!,
$waitAtBeginningFactor: Float!,
$heuristicStepsPerMainStep: Int!,
$compactLegsByReversedSearch: Boolean!,
$itineraryFiltering: Float!,
) { viewer {
plan(
Expand All @@ -291,13 +316,28 @@ class SummaryPlanContainer extends React.Component {
minTransferTime:$minTransferTime,
walkSpeed:$walkSpeed,
maxWalkDistance:$maxWalkDistance,
wheelchair:false,
disableRemainingWeightHeuristic:false,
wheelchair:$wheelchair,
disableRemainingWeightHeuristic:$disableRemainingWeightHeuristic,
arriveBy:$arriveBy,
preferred:$preferred,
modes:$modes
transferPenalty:$transferPenalty,
itineraryFiltering:$itineraryFiltering,
ignoreRealtimeUpdates:$ignoreRealtimeUpdates,
maxPreTransitTime:$maxPreTransitTime,
walkOnStreetReluctance:$walkOnStreetReluctance,
waitReluctance:$waitReluctance,
bikeSpeed:$bikeSpeed,
bikeSwitchTime:$bikeSwitchTime,
bikeSwitchCost:$bikeSwitchCost,
bikeBoardCost:$bikeBoardCost,
optimize:$optimize,
triangle:$triangle,
carParkCarLegWeight:$carParkCarLegWeight,
maxTransfers:$maxTransfers,
waitAtBeginningFactor:$waitAtBeginningFactor,
heuristicStepsPerMainStep:$heuristicStepsPerMainStep,
compactLegsByReversedSearch:$compactLegsByReversedSearch,
itineraryFiltering: $itineraryFiltering,
) {itineraries {startTime,endTime}}
}
}`;
Expand Down
10 changes: 10 additions & 0 deletions app/routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -480,6 +480,16 @@ export default config => {
]).then(([title, content]) => cb(null, { title, content }));
}}
/>
{!config.URL.API_URL.includes('/api.') && (
<Route
path="/admin"
getComponent={(location, cb) => {
import(/* webpackChunkName: "admin" */ './component/AdminPage')
.then(loadRoute(cb))
.catch(errorLoading);
}}
/>
)}
<Route path="/js/:name" component={Error404} />
<Route path="/css/:name" component={Error404} />
<Route
Expand Down
Loading

0 comments on commit 4c8c0e1

Please sign in to comment.