Skip to content

Commit 3d88193

Browse files
authored
✨ let closed-beta users create manual trips (#2280)
1 parent 25a9e88 commit 3d88193

File tree

7 files changed

+61
-25
lines changed

7 files changed

+61
-25
lines changed

.idea/trwl.iml

Lines changed: 0 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ class TripController extends Controller
3030
* -> later solve the problem for non-existing stations
3131
*/
3232
public function createTrip(Request $request): TripResource {
33-
if (!auth()->user()?->hasRole('closed-beta')) {
33+
if (!auth()->user()?->can('create-manual-trip')) {
3434
abort(403, 'this endpoint is currently only available for beta users');
3535
}
3636

resources/js/app.js

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
/**
22
* Here, we include all of our external dependencies
33
*/
4-
import { Notyf } from "notyf";
5-
import { createApp } from "vue";
4+
import {Notyf} from "notyf";
5+
import {createApp} from "vue";
66
import NotificationBell from "../vue/components/NotificationBell.vue";
77
import ActiveJourneyMap from "../vue/components/ActiveJourneyMap.vue";
88
import Stationboard from "../vue/components/Stationboard.vue";
@@ -15,10 +15,11 @@ import "./components/maps";
1515
import CheckinSuccessHelper from "../vue/components/CheckinSuccessHelper.vue";
1616
import {i18nVue} from "laravel-vue-i18n";
1717
import TagHelper from "../vue/components/TagHelper.vue";
18+
import TripCreationForm from "../vue/components/TripCreation/TripCreationForm.vue";
1819

1920
window.notyf = new Notyf({
2021
duration: 5000,
21-
position: { x: "right", y: window.innerWidth > 480 ? "top" : "bottom" },
22+
position: {x: "right", y: window.innerWidth > 480 ? "top" : "bottom"},
2223
dismissible: true,
2324
ripple: true,
2425
types: [
@@ -43,11 +44,11 @@ window.notyf = new Notyf({
4344
],
4445
});
4546

46-
document.addEventListener("DOMContentLoaded", function() {
47+
document.addEventListener("DOMContentLoaded", function () {
4748
// get language query parameter
4849
let fallbackLang = "en";
49-
const urlParams = new URLSearchParams(window.location.search);
50-
const lang = urlParams.get("language");
50+
const urlParams = new URLSearchParams(window.location.search);
51+
const lang = urlParams.get("language");
5152

5253
if (lang && lang.startsWith("de_")) {
5354
fallbackLang = "de";
@@ -95,7 +96,9 @@ document.addEventListener("DOMContentLoaded", function() {
9596
});
9697
app5.mount("#tag-helper");
9798

98-
99+
const app6 = createApp({});
100+
app6.component("TripCreationForm", TripCreationForm);
101+
app6.mount("#trip-creation-form");
99102
});
100103

101104
/**

resources/views/admin/trip/create.blade.php

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,6 @@
33
@section('title', 'Create new trip manually')
44

55
@section('content')
6-
7-
<div class="alert alert-info">
8-
This form is currently for testing purposes only.
9-
Admins can create a trip with manually entered data.
10-
Users can check in to this trip.
11-
It should be tested if the trip is created correctly and all data required for the trip is present, so no (500)
12-
errors occur.
13-
</div>
14-
156
<div id="trip-creation-form">
167
<trip-creation-form></trip-creation-form>
178
</div>
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
@extends('layouts.app')
2+
3+
@section('title', 'Create trip manually')
4+
5+
@section('content')
6+
<div class="container">
7+
<div id="trip-creation-form">
8+
<trip-creation-form></trip-creation-form>
9+
</div>
10+
</div>
11+
@endsection

resources/vue/components/TripCreation/TripCreationForm.vue

Lines changed: 35 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
<script>
22
import StationRow from "./StationRow.vue";
3-
import {isNumber, random} from "lodash";
43
import {DateTime} from "luxon";
54
65
export default {
@@ -58,9 +57,9 @@ export default {
5857
this.form.destinationArrivalPlanned = DateTime.fromISO(time).setZone(this.destinationTimezone);
5958
},
6059
sendform() {
61-
this.form.lineName = this.trainTypeInput + " " + this.trainNumberInput;
60+
this.form.lineName = this.trainTypeInput + " " + this.trainNumberInput;
6261
63-
let trainNumber = parseInt(this.trainNumberInput);
62+
let trainNumber = parseInt(this.trainNumberInput);
6463
this.form.journeyNumber = trainNumber || null;
6564
6665
fetch("/api/v1/trains/trip", {
@@ -72,7 +71,7 @@ export default {
7271
}).then((data) => {
7372
if (data.ok) {
7473
data.json().then((result) => {
75-
result = result.data;
74+
result = result.data;
7675
let query = {
7776
tripID: result.id,
7877
lineName: result.lineName,
@@ -91,8 +90,25 @@ export default {
9190

9291
<template>
9392
<div>
94-
<h1>TripCreationForm</h1>
95-
<form @submit.prevent="sendform">
93+
<h1 class="fs-4">
94+
<i class="fa fa-plus" aria-hidden="true"></i>
95+
Create trip manually (closed-beta)
96+
</h1>
97+
98+
<div class="alert alert-info">
99+
<h2 class="fs-5">
100+
<i class="fa fa-info-circle" aria-hidden="true"></i>
101+
Beta users only
102+
</h2>
103+
104+
This form is currently for testing purposes only.
105+
Beta users can create a trip with manually entered data.
106+
All Users can check in to this trip.
107+
It should be tested if the trip is created correctly and all data required for the trip is present, so no
108+
(500) errors occur or if features are missing which are not mentioned in the limitations section.
109+
</div>
110+
111+
<form @submit.prevent="sendform" class="mb-3">
96112
<div class="row g-3 mb-3">
97113
<StationRow
98114
placeholder="Startbahnhof"
@@ -135,8 +151,20 @@ export default {
135151
<button type="submit" class="btn btn-primary float-end">Speichern</button>
136152
</div>
137153
</div>
138-
139154
</form>
155+
156+
<div class="alert alert-warning">
157+
<h2 class="fs-5">
158+
<i class="fa fa-exclamation-triangle" aria-hidden="true"></i>
159+
Current limitations
160+
</h2>
161+
162+
<ul>
163+
<li>Only stations available in DB-HAFAS are supported</li>
164+
<li>Stopovers can't be created yet</li>
165+
<li>Polyline is generated straight from origin to destination (Brouter generation will apply if the difference between air distance and distance by train isn't too big)</li>
166+
</ul>
167+
</div>
140168
</div>
141169
</template>
142170

routes/web.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,10 @@
123123
* All of these routes can only be used by fully registered users.
124124
*/
125125
Route::middleware(['auth', 'privacy'])->group(function() {
126+
Route::view('/beta/trip-creation', 'closed-beta.trip-creation')
127+
->can('create-manual-trip')
128+
->name('beta.trip-creation');
129+
126130
Route::post('/ics/createToken', [IcsController::class, 'createIcsToken'])
127131
->name('ics.createToken'); //TODO: Replace with API Endpoint
128132
Route::post('/ics/revokeToken', [IcsController::class, 'revokeIcsToken'])

0 commit comments

Comments
 (0)