Skip to content

Commit 1defb53

Browse files
committed
Auto-fill origin; focus time fields on span-click
1 parent 0d49200 commit 1defb53

File tree

6 files changed

+139
-5
lines changed

6 files changed

+139
-5
lines changed

app/Http/Controllers/API/v1/StationController.php

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ public function update(Request $request, int $id): StationResource {
9696
'longitude' => ['nullable', 'numeric', 'between:-180,180'],
9797
'time_offset' => ['nullable', 'numeric'],
9898
]);
99-
99+
100100
if (array_key_exists('time_offset', $request->json()->all()) && $request->json('time_offset') === null) {
101101
$validated['time_offset'] = null;
102102
}
@@ -145,4 +145,38 @@ public function index(Request $request): JsonResponse {
145145
return $this->sendResponse($stations);
146146
}
147147

148+
149+
/**
150+
* @OA\Get(
151+
* path="/station/{id}",
152+
* operationId="showStation",
153+
* tags={"Checkin"},
154+
* summary="Show station",
155+
* description="This request returns a single station object",
156+
* @OA\Parameter(
157+
* name="id",
158+
* in="path",
159+
* description="station id",
160+
* example="1337"
161+
* ),
162+
* @OA\Response(
163+
* response=200,
164+
* description="successful operation",
165+
* @OA\JsonContent(
166+
* @OA\Property(property="data", type="object", ref="#/components/schemas/StationResource")
167+
* )
168+
* ),
169+
* @OA\Response(response=401, description="Unauthorized"),
170+
* @OA\Response(response=503, description="There has been an error with our data provider"),
171+
* security={
172+
* {"passport": {"create-statuses"}}, {"token": {}}
173+
*
174+
* }
175+
* )
176+
*/
177+
public function show(int $id): JsonResponse {
178+
$station = Station::findOrFail($id);
179+
180+
return $this->sendResponse(new StationResource($station));
181+
}
148182
}

resources/views/vuestationboard.blade.php

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,13 @@
22

33
@section('title', 'RIS')
44

5+
@php
6+
$createTripQuery = '';
7+
if (isset($station)) {
8+
$createTripQuery = '?from=' . $station->id;
9+
}
10+
@endphp
11+
512
@section('content')
613
<div class="container">
714
<div class="row justify-content-center">
@@ -15,7 +22,8 @@
1522
<i class="fa-solid fa-plus"></i>
1623
{{__('missing-journey')}}
1724
</p>
18-
<a href="{{ route('trip.create') }}" class="btn btn-sm btn-outline-secondary">
25+
<a href="{{ route('trip.create') . $createTripQuery }}"
26+
class="btn btn-sm btn-outline-secondary">
1927
<i class="fa-solid fa-plus"></i>
2028
{{__('create-journey')}}
2129
</a>

resources/vue/components/TripCreation/StationInput.vue

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,12 +72,22 @@ export default {
7272
this.$refs.stationInputField.focus();
7373
}, 100);
7474
},
75+
showModalFocusTime(fieldB = true) {
76+
this.$refs.modal.show();
77+
// delay focus to make sure the modal is shown
78+
setTimeout(() => {
79+
if (fieldB) {
80+
this.$refs.timeFieldB.focus();
81+
} else {
82+
this.$refs.timeFieldA.focus();
83+
}
84+
}, 100);
85+
},
7586
setStation(item) {
7687
this.stationInput = item.name;
7788
this.$emit('update:station', item);
7889
this.autocompleteList = [];
7990
this.pauseAutoComplete = true;
80-
//this.$refs.modal.hide();
8191
},
8292
timeFieldAChanged(event) {
8393
this.$emit('update:timeFieldA', event.target.value)
@@ -169,6 +179,7 @@ export default {
169179
:placeholder="timeFieldALabel"
170180
class="form-control mobile-input-fs-16"
171181
type="datetime-local"
182+
ref="timeFieldA"
172183
@input="timeFieldAChanged"
173184
>
174185
</div>
@@ -185,6 +196,7 @@ export default {
185196
:placeholder="timeFieldBLabel"
186197
class="form-control mobile-input-fs-16"
187198
type="datetime-local"
199+
ref="timeFieldB"
188200
@input="timeFieldBChanged"
189201
>
190202
</div>
@@ -198,10 +210,10 @@ export default {
198210
:aria-label="placeholder" aria-describedby="basic-addon1"
199211
v-model="stationInput" @focusin="showModal"
200212
>
201-
<span class="input-group-text font-monospace" v-if="departure && arrival">
213+
<span class="input-group-text font-monospace" v-if="departure && arrival" @click="showModalFocusTime(false)">
202214
{{ this.timeFieldA }}
203215
</span>
204-
<span class="input-group-text font-monospace">
216+
<span class="input-group-text font-monospace" @click="showModalFocusTime">
205217
{{ this.timeFieldB }}
206218
</span>
207219
<button class="btn btn-sm btn-outline-danger input-group-button py-1" type="button" @click="$emit('delete')">

resources/vue/components/TripCreation/TripCreationPage.vue

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ export default {
1111
mounted() {
1212
this.initForm();
1313
this.loadOperators();
14+
this.getOriginFromQuery();
1415
},
1516
data() {
1617
return {
@@ -179,6 +180,32 @@ export default {
179180
// todo: guess mode of transport based on line input
180181
// e.g.: if line starts with ICE or TGV, set category to nationalExpress
181182
},
183+
getOriginFromQuery() {
184+
const urlParams = new URLSearchParams(window.location.search);
185+
const stationId = urlParams.get("from");
186+
187+
if (stationId) {
188+
fetch(`/api/v1/stations/${stationId}`, {
189+
method: "GET",
190+
headers: {
191+
"Content-Type": "application/json",
192+
},
193+
})
194+
.then((response) => {
195+
if (!response.ok) {
196+
throw new Error(response.statusText);
197+
}
198+
return response.json();
199+
})
200+
.then((result) => {
201+
console.log(result.data);
202+
this.$refs.originInput.setStation(result.data);
203+
})
204+
.catch((error) => {
205+
console.error(error);
206+
});
207+
}
208+
},
182209
onLineInput() {
183210
this.checkDisallowed()
184211
this.guessModeOfTransport();
@@ -323,6 +350,7 @@ export default {
323350

324351
<form @submit.prevent="sendForm" class="px-4 mt-4">
325352
<StationInput
353+
ref="originInput"
326354
:placeholder="trans('trip_creation.form.origin')"
327355
:arrival="false"
328356
v-on:update:station="setOrigin"

routes/api.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@
9797
Route::prefix('station')->middleware(['scope:write-statuses'])->group(static function() {
9898
Route::put('/{id}/home', [TransportController::class, 'setHome'])->whereNumber('id');
9999
Route::get('/{id}/departures', [TransportController::class, 'getDepartures'])->whereNumber('id');
100+
Route::get('/{id}', [StationController::class, 'show'])->whereNumber('id');
100101
});
101102

102103
Route::group(['prefix' => 'statistics', 'middleware' => 'scope:read-statistics'], static function() {

storage/api-docs/api-docs.json

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1605,6 +1605,57 @@
16051605
]
16061606
}
16071607
},
1608+
"/station/{id}": {
1609+
"get": {
1610+
"tags": [
1611+
"Checkin"
1612+
],
1613+
"summary": "Show station",
1614+
"description": "This request returns a single station object",
1615+
"operationId": "showStation",
1616+
"parameters": [
1617+
{
1618+
"name": "id",
1619+
"in": "path",
1620+
"description": "station id",
1621+
"example": "1337"
1622+
}
1623+
],
1624+
"responses": {
1625+
"200": {
1626+
"description": "successful operation",
1627+
"content": {
1628+
"application/json": {
1629+
"schema": {
1630+
"properties": {
1631+
"data": {
1632+
"$ref": "#/components/schemas/StationResource"
1633+
}
1634+
},
1635+
"type": "object"
1636+
}
1637+
}
1638+
}
1639+
},
1640+
"401": {
1641+
"description": "Unauthorized"
1642+
},
1643+
"503": {
1644+
"description": "There has been an error with our data provider"
1645+
}
1646+
},
1647+
"security": [
1648+
{
1649+
"passport": [
1650+
"create-statuses"
1651+
]
1652+
},
1653+
{
1654+
"token": []
1655+
}
1656+
]
1657+
}
1658+
},
16081659
"/leaderboard": {
16091660
"get": {
16101661
"tags": [

0 commit comments

Comments
 (0)