Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions include/motis/endpoints/initial.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ struct initial {
api::initial_response operator()(boost::urls::url_view const&) const;

nigiri::timetable const& tt_;
config const& config_;
};

} // namespace motis::ep
33 changes: 32 additions & 1 deletion openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1716,7 +1716,7 @@ paths:
schema:
$ref: '#/components/schemas/Error'
'200':
description: latitude, longitude and zoom level to set the map to
description: latitude, longitude, zoom level to set the map to, and routing options configuration and limits
content:
application/json:
schema:
Expand All @@ -1735,6 +1735,8 @@ paths:
zoom:
description: zoom level
type: number
serverConfig:
$ref: '#/components/schemas/ServerConfig'

/api/v1/map/stops:
get:
Expand Down Expand Up @@ -3587,6 +3589,35 @@ components:
true = many to one
false = one to many
type: boolean
ServerConfig:
Description: server configuration
type: object
required:
- hasElevation
- hasRoutedTransfers
- hasStreetRouting
- maxTravelTimeLimit
- maxPrePostTransitTimeLimit
- maxDirectTimeLimit
properties:
hasElevation:
description: true if elevation is loaded
type: boolean
hasRoutedTransfers:
description: true if routed transfers available
type: boolean
hasStreetRouting:
description: true if street routing is available
type: boolean
maxOneToAllTravelTimeLimit:
description: limit for maxTravelTime API param in minutes
type: number
maxPrePostTransitTimeLimit:
description: limit for maxPrePostTransitTime API param in seconds
type: number
maxDirectTimeLimit:
description: limit for maxDirectTime API param in seconds
type: number
Error:
type: object
properties:
Expand Down
25 changes: 24 additions & 1 deletion src/endpoints/initial.cc
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include "motis/endpoints/initial.h"
#include "motis/config.h"

#include "utl/erase_if.h"
#include "utl/to_vec.h"
Expand Down Expand Up @@ -51,9 +52,31 @@ api::initial_response initial::operator()(boost::urls::url_view const&) const {
}
}

auto const onetoall_max_travel_minutes =
config_.limits_->onetoall_max_travel_minutes_;
auto const street_routing_max_direct_seconds =
config_.limits_->street_routing_max_direct_seconds_;
auto const street_routing_max_prepost_transit_seconds =
config_.limits_->street_routing_max_prepost_transit_seconds_;
auto const has_osr_footpath = config_.osr_footpath_;
auto const has_street_routing = config_.get_street_routing().has_value();
auto const has_elevation_data_dir =
has_street_routing &&
config_.get_street_routing()->elevation_data_dir_.has_value();

return {.lat_ = center.lat_,
.lon_ = center.lng_,
.zoom_ = static_cast<double>(zoom)};
.zoom_ = static_cast<double>(zoom),
.serverConfig_ = api::ServerConfig{
.hasElevation_ = has_elevation_data_dir,
.hasRoutedTransfers_ = has_osr_footpath,
.hasStreetRouting_ = has_street_routing,
.maxOneToAllTravelTimeLimit_ =
static_cast<double>(onetoall_max_travel_minutes),
.maxPrePostTransitTimeLimit_ = static_cast<double>(
street_routing_max_prepost_transit_seconds),
.maxDirectTimeLimit_ =
static_cast<double>(street_routing_max_direct_seconds)}};
}

} // namespace motis::ep
32 changes: 32 additions & 0 deletions ui/api/openapi/schemas.gen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1737,6 +1737,38 @@ false = one to many
}
} as const;

export const ServerConfigSchema = {
Description: 'server configuration',
type: 'object',
required: ['hasElevation', 'hasRoutedTransfers', 'hasStreetRouting', 'maxTravelTimeLimit', 'maxPrePostTransitTimeLimit', 'maxDirectTimeLimit'],
properties: {
hasElevation: {
description: 'true if elevation is loaded',
type: 'boolean'
},
hasRoutedTransfers: {
description: 'true if routed transfers available',
type: 'boolean'
},
hasStreetRouting: {
description: 'true if street routing is available',
type: 'boolean'
},
maxOneToAllTravelTimeLimit: {
description: 'limit for maxTravelTime API param in minutes',
type: 'number'
},
maxPrePostTransitTimeLimit: {
description: 'limit for maxPrePostTransitTime API param in seconds',
type: 'number'
},
maxDirectTimeLimit: {
description: 'limit for maxDirectTime API param in seconds',
type: 'number'
}
}
} as const;

export const ErrorSchema = {
type: 'object',
properties: {
Expand Down
28 changes: 28 additions & 0 deletions ui/api/openapi/types.gen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1389,6 +1389,33 @@ export type OneToManyParams = {
arriveBy: boolean;
};

export type ServerConfig = {
/**
* true if elevation is loaded
*/
hasElevation: boolean;
/**
* true if routed transfers available
*/
hasRoutedTransfers: boolean;
/**
* true if street routing is available
*/
hasStreetRouting: boolean;
/**
* limit for maxTravelTime API param in minutes
*/
maxOneToAllTravelTimeLimit?: number;
/**
* limit for maxPrePostTransitTime API param in seconds
*/
maxPrePostTransitTimeLimit: number;
/**
* limit for maxDirectTime API param in seconds
*/
maxDirectTimeLimit: number;
};

export type Error = {
error?: string;
};
Expand Down Expand Up @@ -2463,6 +2490,7 @@ export type InitialResponse = ({
* zoom level
*/
zoom: number;
serverConfig?: ServerConfig;
});

export type InitialError = (Error);
Expand Down
70 changes: 31 additions & 39 deletions ui/src/lib/AdvancedOptions.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import * as Select from '$lib/components/ui/select';
import { ChevronUp, ChevronDown } from '@lucide/svelte';
import { Switch } from './components/ui/switch';
import type { ElevationCosts } from '@motis-project/motis-client';
import type { ElevationCosts, ServerConfig } from '@motis-project/motis-client';
import { defaultQuery } from '$lib/defaults';
import { formatDurationSec } from './formatDuration';
import {
Expand All @@ -18,9 +18,11 @@
import StreetModes from '$lib/StreetModes.svelte';
import TransitModeSelect from '$lib/TransitModeSelect.svelte';
import { type NumberSelectOption } from '$lib/NumberSelect.svelte';
import { generateTimes } from './generateTimes';

let {
useRoutedTransfers = $bindable(),
serverConfig,
wheelchair = $bindable(),
requireBikeTransport = $bindable(),
requireCarTransport = $bindable(),
Expand All @@ -44,6 +46,7 @@
additionalComponents
}: {
useRoutedTransfers: boolean;
serverConfig: ServerConfig | undefined;
wheelchair: boolean;
requireBikeTransport: boolean;
requireCarTransport: boolean;
Expand Down Expand Up @@ -72,37 +75,13 @@
label: i.toString()
}));

const possibleDirectDurations = [
5 * 60,
10 * 60,
15 * 60,
20 * 60,
25 * 60,
30 * 60,
35 * 60,
40 * 60,
45 * 60,
50 * 60,
60 * 60,
90 * 60,
120 * 60,
180 * 60,
240 * 60,
300 * 60,
360 * 60
];
const possiblePrePostDurations = [
1 * 60,
5 * 60,
10 * 60,
15 * 60,
20 * 60,
25 * 60,
30 * 60,
40 * 60,
50 * 60,
60 * 60
];
const possibleDirectDurations = $derived(
generateTimes(serverConfig?.maxDirectTimeLimit ?? 60 * 60)
);
const possiblePrePostDurations = $derived(
generateTimes(serverConfig?.maxPrePostTransitTimeLimit ?? 60 * 60)
);

function setModes(mode: PrePostDirectMode) {
return function (checked: boolean) {
if (checked) {
Expand All @@ -129,11 +108,14 @@
];
let expanded = $state<boolean>(false);
let allowElevationCosts = $derived(
requireBikeTransport ||
preTransitModes.includes('BIKE') ||
postTransitModes.includes('BIKE') ||
directModes?.includes('BIKE')
serverConfig?.hasElevation &&
(requireBikeTransport ||
preTransitModes.includes('BIKE') ||
postTransitModes.includes('BIKE') ||
directModes?.includes('BIKE'))
);
let allowStreetRouting = $derived(serverConfig?.hasStreetRouting);
let allowRoutedTransfers = $derived(serverConfig?.hasRoutedTransfers);
</script>

<Button variant="ghost" onclick={() => (expanded = !expanded)}>
Expand All @@ -152,6 +134,7 @@
<div class="space-y-2">
<Switch
bind:checked={useRoutedTransfers}
disabled={!allowRoutedTransfers}
label={t.useRoutedTransfers}
id="useRoutedTransfers"
onCheckedChange={(checked) => {
Expand All @@ -160,8 +143,10 @@
}
}}
/>

<Switch
bind:checked={wheelchair}
disabled={!allowRoutedTransfers}
label={t.wheelchair}
id="wheelchair"
onCheckedChange={(checked) => {
Expand All @@ -178,10 +163,11 @@
/>
<Switch
bind:checked={requireCarTransport}
disabled={!allowRoutedTransfers}
label={t.requireCarTransport}
id="requireCarTransport"
onCheckedChange={(checked) => {
if (checked && !useRoutedTransfers) {
if (checked && !useRoutedTransfers && allowRoutedTransfers) {
useRoutedTransfers = true;
}
setModes('CAR')(checked);
Expand Down Expand Up @@ -212,6 +198,7 @@
<!-- First mile -->
<StreetModes
label={t.routingSegments.firstMile}
disabled={!allowStreetRouting}
bind:modes={preTransitModes}
bind:maxTransitTime={maxPreTransitTime}
possibleModes={prePostDirectModes}
Expand All @@ -223,6 +210,7 @@
<!-- Last mile -->
<StreetModes
label={t.routingSegments.lastMile}
disabled={!allowStreetRouting}
bind:modes={postTransitModes}
bind:maxTransitTime={maxPostTransitTime}
possibleModes={prePostDirectModes}
Expand All @@ -235,6 +223,7 @@
{#if directModes !== undefined && maxDirectTime !== undefined && ignoreDirectRentalReturnConstraints !== undefined}
<StreetModes
label={t.routingSegments.direct}
disabled={!allowStreetRouting}
bind:modes={directModes}
bind:maxTransitTime={maxDirectTime}
possibleModes={prePostDirectModes}
Expand All @@ -250,7 +239,11 @@
<div class="text-sm">
{t.selectElevationCosts}
</div>
<Select.Root disabled={!allowElevationCosts} type="single" bind:value={elevationCosts}>
<Select.Root
disabled={!allowElevationCosts || !allowStreetRouting}
type="single"
bind:value={elevationCosts}
>
<Select.Trigger aria-label={t.selectElevationCosts}>
{t.elevationCosts[elevationCosts]}
</Select.Trigger>
Expand All @@ -263,7 +256,6 @@
</Select.Content>
</Select.Root>
</div>

{#if additionalComponents}
{@render additionalComponents()}
{/if}
Expand Down
Loading
Loading