Skip to content

Commit

Permalink
✨ Add back-button functionality to Experimental Check-In (+ working d…
Browse files Browse the repository at this point in the history
…irect links) (#2571)

Co-authored-by: Kristian Stöckel <[email protected]>
  • Loading branch information
HerrLevin and MrKrisKrisu authored May 20, 2024
1 parent d58aa71 commit 1735a9f
Show file tree
Hide file tree
Showing 8 changed files with 371 additions and 210 deletions.
14 changes: 14 additions & 0 deletions app/Http/Controllers/Frontend/VueFrontendController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?php

namespace App\Http\Controllers\Frontend;



use Illuminate\View\View;

class VueFrontendController
{
public function stationboard(): View {
return view('vuestationboard', []);
}
}
19 changes: 17 additions & 2 deletions app/Http/Controllers/FrontendTransportController.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,10 @@ public function TrainStationboard(Request $request): Renderable|RedirectResponse
$station = StationController::lookupStation($searchQuery);
}

if ($request->user()->hasRole('open-beta')) {
return redirect()->route('stationboard', ['stationId' => $station->id, 'stationName' => $station->name]);
}

$when = isset($validated['when'])
? Carbon::parse($validated['when'], auth()->user()->timezone ?? config('app.timezone'))
: Carbon::now(auth()->user()->timezone ?? config('app.timezone'))->subMinutes(5);
Expand Down Expand Up @@ -132,10 +136,21 @@ public function TrainTrip(Request $request): Renderable|RedirectResponse {
'tripID' => ['required'],
'lineName' => ['required'],
'start' => ['required', 'numeric'],
'destination' => ['nullable', 'numeric'],
'departure' => ['required', 'date'],
'searchedStation' => ['nullable', 'exists:train_stations,id'],
]);

if ($request->user()->hasRole('open-beta')) {
return redirect()->route('stationboard', [
'tripId' => $validated['tripID'],
'lineName' => $validated['lineName'],
'start' => $validated['start'],
'departure' => $validated['departure'],
'destination' => $validated['destination'] ?? null,
]);
}

try {
$startStation = Station::where('ibnr', $validated['start'])->first();
if ($startStation === null) {
Expand Down Expand Up @@ -173,8 +188,8 @@ public function TrainTrip(Request $request): Renderable|RedirectResponse {
'searchedStation' => isset($validated['searchedStation']) ? Station::findOrFail($validated['searchedStation']) : null,
'lastStopover' => $lastStopover,
]);
} catch (HafasException $exception) {
return back()->with('error', $exception->getMessage());
} catch (HafasException) {
return redirect()->back()->with(['error' => __('messages.exception.generalHafas')]);
} catch (StationNotOnTripException) {
return redirect()->back()->with('error', __('controller.transport.not-in-stopovers'));
}
Expand Down
312 changes: 146 additions & 166 deletions resources/views/stationboard.blade.php

Large diffs are not rendered by default.

25 changes: 25 additions & 0 deletions resources/views/vuestationboard.blade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
@extends('layouts.app')

@section('title', 'RIS')

@section('content')
<div class="container">
<div class="row justify-content-center">
<div class="col-md-8 col-lg-7" id="station-board-new">
<Stationboard></Stationboard>

<div class="text-center mt-4">
<hr/>
<p>
<span class="badge text-bg-info">Beta</span>
{{__('missing-journey')}}
</p>
<a href="{{ route('trip.create') }}" class="btn btn-sm btn-outline-secondary">
<i class="fa-solid fa-plus"></i>
{{__('create-journey')}}
</a>
</div>
</div>
</div>
</div>
@endsection
37 changes: 26 additions & 11 deletions resources/vue/components/CheckinLineRun.vue
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ export default {
type: Object,
required: false,
default: {}
},
fastCheckinIbnr: {
type: Number,
required: false,
}
},
watch: {
Expand All @@ -25,7 +29,7 @@ export default {
loading: false,
};
},
methods: {
methods: {
handleSetDestination(selected) {
this.$emit('update:destination', selected);
},
Expand All @@ -48,16 +52,29 @@ export default {
return !remove;
});
this.loading = false;
if (this.$props.fastCheckinIbnr) {
this.fastCheckin();
}
});
});
},
fastCheckin() {
const destination = this.lineRun.stopovers.find((item) => {
return Number(item.evaIdentifier) === Number(this.fastCheckinIbnr);
})
if (destination) {
this.handleSetDestination(destination);
}
},
formatTime(time) {
return DateTime.fromISO(time).toFormat('HH:mm');
},
getTime(item) {
return item.arrivalPlanned
? (item.arrivalReal ? item.arrivalReal : item.arrivalPlanned)
: (item.departureReal ? item.departureReal : item.departurePlanned);
if (item.arrivalPlanned) {
return item.arrivalReal ? item.arrivalReal : item.arrivalPlanned;
}
return item.departureReal ? item.departureReal : item.departurePlanned;
}
},
mounted() {
Expand All @@ -71,23 +88,21 @@ export default {
<span class="visually-hidden">Loading...</span>
</div>
<ul class="timeline" v-else>
<li v-for="item in lineRun.stopovers" :key="item" @click="handleSetDestination(item)">
<li v-for="item in lineRun.stopovers" :key="item" @click.prevent="handleSetDestination(item)">
<i class="trwl-bulletpoint" aria-hidden="true"></i>
<span class="text-trwl float-end">
<small
class="text-muted text-decoration-line-through"
v-if="item.isArrivalDelayed || item.isDepartureDelayed">
{{ item.isArrivalDelayed ? formatTime(item.arrivalPlanned) : formatTime(item.departurePlanned) }}
{{
item.isArrivalDelayed ? formatTime(item.arrivalPlanned) : formatTime(item.departurePlanned)
}}
</small>
&nbsp;
<span>{{ formatTime(getTime(item))}}</span>
<span>{{ formatTime(getTime(item)) }}</span>
</span>

<a href="#" class="text-trwl clearfix">{{ item.name }}</a>
</li>
</ul>
</template>

<style scoped lang="scss">
</style>
20 changes: 17 additions & 3 deletions resources/vue/components/StationAutocomplete.vue
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@ export default {
components: {FullScreenModal, VueDatePicker},
props: {
station: {
type: Object,
required: false,
default: null,
},
stationName: {
type: Object,
required: false
},
Expand Down Expand Up @@ -44,6 +49,7 @@ export default {
stationInput: "",
showFilter: false,
date: null,
selectedStation: null,
selectedType: null,
fetchingGps: false,
travelTypes: [
Expand Down Expand Up @@ -96,9 +102,13 @@ export default {
},
setStation(item) {
this.stationInput = item.name;
this.selectedStation = item;
this.$emit("update:station", item);
this.$refs.modal.hide();
window.location = "/trains/stationboard?station=" + item.name;
const url = `/stationboard?stationId=${item.id}&stationName=${item.name}`;
if (this.$props.dashboard) {
window.location = url;
}
},
setTravelType(travelType) {
this.selectedType = this.selectedType === travelType.value ? null : travelType.value;
Expand Down Expand Up @@ -127,13 +137,17 @@ export default {
stationInput: _.debounce(function () {
this.autocomplete();
}, 500),
stationName() {
this.stationInput = this.stationName ? this.stationName : this.stationInput;
},
station() {
this.stationInput = this.station ? this.station.name : this.stationInput;
this.selectedStation = this.station;
}
},
mounted() {
this.date = this.time;
this.stationInput = this.station ? this.station.name : "";
this.stationInput = this.stationName ? this.stationName : "";
this.selectedStation = this.station;
this.getRecent();
},
computed: {
Expand Down
Loading

0 comments on commit 1735a9f

Please sign in to comment.