mirror of
https://github.com/Spythere/stacjownik.git
synced 2026-05-04 05:48:11 +00:00
chore(scenery): advanced active train tooltip information
This commit is contained in:
@@ -124,7 +124,7 @@
|
||||
<!-- Train info -->
|
||||
<span
|
||||
data-tooltip-type="TrainInfoTooltip"
|
||||
:data-tooltip-content="JSON.stringify(row.train)"
|
||||
:data-tooltip-content="row.train.id"
|
||||
class="tooltip-help"
|
||||
>
|
||||
<b class="text--primary">
|
||||
@@ -239,7 +239,7 @@ import { useMainStore } from '../../store/mainStore';
|
||||
import { useApiStore } from '../../store/apiStore';
|
||||
import ScheduledTrainStatus from './ScheduledTrainStatus.vue';
|
||||
import { SceneryTimetableRow } from './typings';
|
||||
import { ActiveScenery, Station, Train } from '../../typings/common';
|
||||
import { ActiveScenery, Station, TooltipTrainInfo, Train } from '../../typings/common';
|
||||
import { getTrainStopStatus, stopStatusPriority } from './utils';
|
||||
|
||||
export default defineComponent({
|
||||
|
||||
@@ -248,9 +248,7 @@
|
||||
class="station-users"
|
||||
:class="{ inactive: !station.onlineInfo }"
|
||||
data-tooltip-type="UsersTooltip"
|
||||
:data-tooltip-content="
|
||||
JSON.stringify(getStationUsersTrains(station.onlineInfo?.stationTrains ?? []))
|
||||
"
|
||||
:data-tooltip-content="getUsersTooltipContent(station.onlineInfo?.stationTrains ?? [])"
|
||||
>
|
||||
<span class="text--primary">{{
|
||||
station.onlineInfo?.stationTrains?.length ?? '-'
|
||||
@@ -398,11 +396,13 @@ export default defineComponent({
|
||||
this.activeSorter.headerName = headerName;
|
||||
},
|
||||
|
||||
getStationUsersTrains(stationTrains: Train[]): TooltipUserTrain[] {
|
||||
return stationTrains.map((train) => ({
|
||||
getUsersTooltipContent(stationTrains: Train[]): string {
|
||||
const usersTrains: TooltipUserTrain[] = stationTrains.map((train) => ({
|
||||
driverName: train.driverName,
|
||||
trainNo: train.trainNo
|
||||
}));
|
||||
|
||||
return JSON.stringify(usersTrains);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
@@ -1,37 +1,49 @@
|
||||
<template>
|
||||
<div class="tooltip-content">
|
||||
<span v-if="trainInfoObj">
|
||||
{{ trainInfoObj.driverName }}
|
||||
<span v-if="trainInfo">
|
||||
<b v-if="trainInfo.timetableData" style="text-transform: uppercase">
|
||||
{{ getCategoryExplanation(trainInfo.timetableData.category) }}
|
||||
</b>
|
||||
|
||||
<div class="text--primary">
|
||||
<b>{{ trainInfo.stockList[0] }}</b> •
|
||||
{{ trainInfo.length }}m • {{ (trainInfo.mass / 1000).toFixed(2) }}t •
|
||||
{{ trainInfo.speed }}km/h
|
||||
</div>
|
||||
|
||||
<div class="text--grayed">{{ displayTrainPosition(trainInfo) }}</div>
|
||||
</span>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script lang="ts" setup>
|
||||
import { computed } from 'vue';
|
||||
<script lang="ts">
|
||||
import { defineComponent } from 'vue';
|
||||
import { useTooltipStore } from '../../store/tooltipStore';
|
||||
import { Train } from '../../typings/common';
|
||||
import trainCategoryMixin from '../../mixins/trainCategoryMixin';
|
||||
import trainInfoMixin from '../../mixins/trainInfoMixin';
|
||||
import { useMainStore } from '../../store/mainStore';
|
||||
|
||||
const tooltipStore = useTooltipStore();
|
||||
export default defineComponent({
|
||||
mixins: [trainCategoryMixin, trainInfoMixin],
|
||||
|
||||
const trainInfoObj = computed(() => {
|
||||
if (tooltipStore.content == '') return null;
|
||||
data: () => ({
|
||||
tooltipStore: useTooltipStore(),
|
||||
mainStore: useMainStore()
|
||||
}),
|
||||
|
||||
try {
|
||||
return (JSON.parse(tooltipStore.content) as Train) ?? null;
|
||||
} catch (error) {
|
||||
return null;
|
||||
computed: {
|
||||
trainInfo() {
|
||||
if (this.tooltipStore.content == '') return null;
|
||||
|
||||
// Passed "content" string should be the desired train's ID
|
||||
return this.mainStore.trainList.find((t) => t.id === this.tooltipStore.content);
|
||||
}
|
||||
}
|
||||
});
|
||||
</script>
|
||||
|
||||
<style lang="scss" scoped>
|
||||
.tooltip-content {
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
gap: 0.5em;
|
||||
white-space: pre-line;
|
||||
|
||||
padding: 0.25em 0.5em;
|
||||
border-radius: 0.25em;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user