mirror of
https://github.com/Spythere/stacjownik.git
synced 2026-05-03 05:18:11 +00:00
chore(scenery): advanced active train tooltip information
This commit is contained in:
@@ -124,7 +124,7 @@
|
|||||||
<!-- Train info -->
|
<!-- Train info -->
|
||||||
<span
|
<span
|
||||||
data-tooltip-type="TrainInfoTooltip"
|
data-tooltip-type="TrainInfoTooltip"
|
||||||
:data-tooltip-content="JSON.stringify(row.train)"
|
:data-tooltip-content="row.train.id"
|
||||||
class="tooltip-help"
|
class="tooltip-help"
|
||||||
>
|
>
|
||||||
<b class="text--primary">
|
<b class="text--primary">
|
||||||
@@ -239,7 +239,7 @@ import { useMainStore } from '../../store/mainStore';
|
|||||||
import { useApiStore } from '../../store/apiStore';
|
import { useApiStore } from '../../store/apiStore';
|
||||||
import ScheduledTrainStatus from './ScheduledTrainStatus.vue';
|
import ScheduledTrainStatus from './ScheduledTrainStatus.vue';
|
||||||
import { SceneryTimetableRow } from './typings';
|
import { SceneryTimetableRow } from './typings';
|
||||||
import { ActiveScenery, Station, Train } from '../../typings/common';
|
import { ActiveScenery, Station, TooltipTrainInfo, Train } from '../../typings/common';
|
||||||
import { getTrainStopStatus, stopStatusPriority } from './utils';
|
import { getTrainStopStatus, stopStatusPriority } from './utils';
|
||||||
|
|
||||||
export default defineComponent({
|
export default defineComponent({
|
||||||
|
|||||||
@@ -248,9 +248,7 @@
|
|||||||
class="station-users"
|
class="station-users"
|
||||||
:class="{ inactive: !station.onlineInfo }"
|
:class="{ inactive: !station.onlineInfo }"
|
||||||
data-tooltip-type="UsersTooltip"
|
data-tooltip-type="UsersTooltip"
|
||||||
:data-tooltip-content="
|
:data-tooltip-content="getUsersTooltipContent(station.onlineInfo?.stationTrains ?? [])"
|
||||||
JSON.stringify(getStationUsersTrains(station.onlineInfo?.stationTrains ?? []))
|
|
||||||
"
|
|
||||||
>
|
>
|
||||||
<span class="text--primary">{{
|
<span class="text--primary">{{
|
||||||
station.onlineInfo?.stationTrains?.length ?? '-'
|
station.onlineInfo?.stationTrains?.length ?? '-'
|
||||||
@@ -398,11 +396,13 @@ export default defineComponent({
|
|||||||
this.activeSorter.headerName = headerName;
|
this.activeSorter.headerName = headerName;
|
||||||
},
|
},
|
||||||
|
|
||||||
getStationUsersTrains(stationTrains: Train[]): TooltipUserTrain[] {
|
getUsersTooltipContent(stationTrains: Train[]): string {
|
||||||
return stationTrains.map((train) => ({
|
const usersTrains: TooltipUserTrain[] = stationTrains.map((train) => ({
|
||||||
driverName: train.driverName,
|
driverName: train.driverName,
|
||||||
trainNo: train.trainNo
|
trainNo: train.trainNo
|
||||||
}));
|
}));
|
||||||
|
|
||||||
|
return JSON.stringify(usersTrains);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -1,37 +1,49 @@
|
|||||||
<template>
|
<template>
|
||||||
<div class="tooltip-content">
|
<div class="tooltip-content">
|
||||||
<span v-if="trainInfoObj">
|
<span v-if="trainInfo">
|
||||||
{{ trainInfoObj.driverName }}
|
<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>
|
</span>
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script lang="ts" setup>
|
<script lang="ts">
|
||||||
import { computed } from 'vue';
|
import { defineComponent } from 'vue';
|
||||||
import { useTooltipStore } from '../../store/tooltipStore';
|
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(() => {
|
data: () => ({
|
||||||
if (tooltipStore.content == '') return null;
|
tooltipStore: useTooltipStore(),
|
||||||
|
mainStore: useMainStore()
|
||||||
|
}),
|
||||||
|
|
||||||
try {
|
computed: {
|
||||||
return (JSON.parse(tooltipStore.content) as Train) ?? null;
|
trainInfo() {
|
||||||
} catch (error) {
|
if (this.tooltipStore.content == '') return null;
|
||||||
return null;
|
|
||||||
|
// Passed "content" string should be the desired train's ID
|
||||||
|
return this.mainStore.trainList.find((t) => t.id === this.tooltipStore.content);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<style lang="scss" scoped>
|
<style lang="scss" scoped>
|
||||||
.tooltip-content {
|
.tooltip-content {
|
||||||
display: flex;
|
|
||||||
justify-content: center;
|
|
||||||
align-items: center;
|
|
||||||
gap: 0.5em;
|
|
||||||
white-space: pre-line;
|
|
||||||
|
|
||||||
padding: 0.25em 0.5em;
|
padding: 0.25em 0.5em;
|
||||||
border-radius: 0.25em;
|
border-radius: 0.25em;
|
||||||
|
|
||||||
|
|||||||
@@ -34,6 +34,7 @@ export const useTooltipStore = defineStore('tooltipStore', {
|
|||||||
this.content = '';
|
this.content = '';
|
||||||
},
|
},
|
||||||
|
|
||||||
|
// Tooltip handler reading attributes of DOM elements
|
||||||
handle(e: MouseEvent) {
|
handle(e: MouseEvent) {
|
||||||
const targetEl = e
|
const targetEl = e
|
||||||
.composedPath()
|
.composedPath()
|
||||||
@@ -45,6 +46,7 @@ export const useTooltipStore = defineStore('tooltipStore', {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Tooltip content is a string but may be parsed to objects / html in corresponding tooltip type components
|
||||||
const tooltipType = targetEl.getAttribute('data-tooltip-type');
|
const tooltipType = targetEl.getAttribute('data-tooltip-type');
|
||||||
const tooltipContent = targetEl.getAttribute('data-tooltip-content');
|
const tooltipContent = targetEl.getAttribute('data-tooltip-content');
|
||||||
|
|
||||||
|
|||||||
@@ -272,5 +272,6 @@ export interface TooltipTrainInfo {
|
|||||||
currentStationName: string;
|
currentStationName: string;
|
||||||
currentStationHash: string;
|
currentStationHash: string;
|
||||||
headVehicleName: string;
|
headVehicleName: string;
|
||||||
stockLength: number;
|
stockCount: number;
|
||||||
|
trainTimetableCategory?: string;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user