Skip to content

Commit 07fbf66

Browse files
committed
Single status
1 parent eacafb4 commit 07fbf66

File tree

6 files changed

+95
-2
lines changed

6 files changed

+95
-2
lines changed

app/Http/Controllers/FrontendStatusController.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,12 @@ public function statusesByEvent(string $slug): Renderable {
6262
}
6363

6464
public function getStatus($statusId): Renderable {
65+
if (\auth()->user()?->hasRole('open-beta')) {
66+
return view('vue-status', [
67+
'statusId' => $statusId,
68+
]);
69+
}
70+
6571
$status = StatusBackend::getStatus($statusId);
6672

6773
try {

resources/js/app.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import StatsDashboard from "../vue/components/Stats/StatsDashboard.vue";
2525
import Request from "../vue/components/Events/Request.vue";
2626
import ApiAlerts from "../vue/components/ApiAlerts.vue";
2727
import Dashboard from "../vue/views/Dashboard.vue";
28+
import SingleStatus from "../vue/views/SingleStatus.vue";
2829

2930
window.notyf = new Notyf({
3031
duration: 5000,
@@ -144,6 +145,7 @@ document.addEventListener("DOMContentLoaded", function () {
144145
contentApp.component("StatsDashboard", StatsDashboard);
145146
contentApp.component("Webhooks", WebhookSettings);
146147
contentApp.component("TripCreationForm", TripCreationForm);
148+
contentApp.component("SingleStatus", SingleStatus);
147149
contentApp.use(i18nVue, i18nOptions);
148150
contentApp.use(pinia);
149151
contentApp.mount("#vue-content");

resources/views/vue-status.blade.php

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', __('status.ogp-title', ['name' => '']))
4+
5+
@section('content')
6+
<div class="container">
7+
<div id="vue-content">
8+
<single-status></single-status>
9+
</div>
10+
</div>
11+
@endsection

resources/vue/components/Status/Partials/DestinationRow.vue

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@ const arrival = getArrivalAttribute(props.status);
2626
{{ arrival.time?.toLocaleString(DateTime.TIME_SIMPLE) }}
2727
</span>
2828
</span>
29-
<a href="#" class="text-trwl clearfix"><!-- todo: link to destination -->
29+
<a :href="`/stationboard?stationId=${status.train.destination.id}&stationName=${status.train.destination.name}`"
30+
class="text-trwl clearfix">
3031
{{ status.train.destination.name }}
3132
</a>
3233
</li>

resources/vue/components/Status/Partials/OriginRow.vue

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,8 @@ const duration = getArrivalForStatus(props.status).dateTime.diff(getDepartureFor
3434
{{ arrival.time?.toLocaleString(DateTime.TIME_SIMPLE) }}
3535
</span>
3636
</span>
37-
<a href="#" class="text-trwl clearfix"><!-- todo: link to origin -->
37+
<a :href="`/stationboard?stationId=${status.train.origin.id}&${status.train.origin.name}`"
38+
class="text-trwl clearfix">
3839
{{ status.train.origin.name }}
3940
</a>
4041
<p class="train-status text-muted m-0">

resources/vue/views/SingleStatus.vue

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
<script setup lang="ts">
2+
import {ref} from "vue";
3+
import {Api, StatusResource, UserAuthResource} from "../../types/Api.gen";
4+
import StatusCard from "../components/Status/StatusCard.vue";
5+
import {trans} from "laravel-vue-i18n";
6+
import {getDepartureForStatus} from "../helpers/DateTimeHelper";
7+
import {DateTime} from "luxon";
8+
9+
const loading = ref(true);
10+
const status = ref<StatusResource | null>(null);
11+
const user = ref<UserAuthResource | null>(null);
12+
const pageError = ref<string | null>(null);
13+
14+
const api = new Api({baseUrl: window.location.origin + '/api/v1'});
15+
16+
function fetchStatus() {
17+
const statusId = window.location.pathname.split('/').pop();
18+
if (!statusId) {
19+
console.error('Status ID not found in URL');
20+
return;
21+
}
22+
23+
api.status.getSingleStatus(parseInt(statusId)).then((response) => {
24+
response.json().then((data) => {
25+
loading.value = false;
26+
status.value = data.data;
27+
});
28+
}).catch((error) => {
29+
loading.value = false;
30+
if (error.status === 404) {
31+
pageError.value = trans('error.404');
32+
} else if (error.status === 403) {
33+
pageError.value = trans('error.403');
34+
}
35+
console.error('Error fetching status:', error);
36+
});
37+
}
38+
39+
function fetchUser() {
40+
api.auth.getAuthenticatedUser().then((response) => {
41+
response.json().then((data) => {
42+
user.value = data.data;
43+
});
44+
}).catch((error) => {
45+
console.error('Error fetching user:', error);
46+
});
47+
}
48+
49+
fetchStatus();
50+
fetchUser();
51+
</script>
52+
53+
<template>
54+
<div class="row justify-content-center">
55+
<div class="col-md-8 col-lg-7">
56+
<div v-if="loading">
57+
<p class="text-center mt-5">
58+
<i class="fas fa-spinner fa-spin"></i> Loading status...
59+
</p>
60+
</div>
61+
<template v-else-if="status">
62+
<h2 class="fs-5">{{ getDepartureForStatus(status).toLocaleString(DateTime.DATE_HUGE) }}</h2>
63+
<StatusCard :status :show-map="true" :authenticated-user="user"/>
64+
</template>
65+
<h2 v-if="pageError">{{ pageError }} :(</h2>
66+
</div>
67+
</div>
68+
</template>
69+
70+
<style scoped lang="scss">
71+
72+
</style>

0 commit comments

Comments
 (0)