From 26bee528514488617142982fd7b76c061ad1b936 Mon Sep 17 00:00:00 2001 From: Spythere Date: Thu, 3 Feb 2022 12:56:19 +0100 Subject: [PATCH] =?UTF-8?q?Doko=C5=84czono=20widok=20listy=20i=20karty=20p?= =?UTF-8?q?oci=C4=85g=C3=B3w?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/TrainsView/TrainInfo.vue | 458 +----------------- .../TrainsView/TrainInfoExtended.vue | 251 ++++++++++ src/components/TrainsView/TrainInfoSimple.vue | 189 ++++++++ .../TrainsView/TrainTimetableCard.vue | 10 +- src/main.ts | 2 +- src/mixins/trainInfoMixin.ts | 104 ++++ 6 files changed, 555 insertions(+), 459 deletions(-) create mode 100644 src/components/TrainsView/TrainInfoExtended.vue create mode 100644 src/components/TrainsView/TrainInfoSimple.vue create mode 100644 src/mixins/trainInfoMixin.ts diff --git a/src/components/TrainsView/TrainInfo.vue b/src/components/TrainsView/TrainInfo.vue index f6ee236..d574044 100644 --- a/src/components/TrainsView/TrainInfo.vue +++ b/src/components/TrainsView/TrainInfo.vue @@ -1,189 +1,21 @@ diff --git a/src/components/TrainsView/TrainInfoExtended.vue b/src/components/TrainsView/TrainInfoExtended.vue new file mode 100644 index 0000000..629b4cf --- /dev/null +++ b/src/components/TrainsView/TrainInfoExtended.vue @@ -0,0 +1,251 @@ + + + + + diff --git a/src/components/TrainsView/TrainInfoSimple.vue b/src/components/TrainsView/TrainInfoSimple.vue new file mode 100644 index 0000000..acf56ef --- /dev/null +++ b/src/components/TrainsView/TrainInfoSimple.vue @@ -0,0 +1,189 @@ + + + + + diff --git a/src/components/TrainsView/TrainTimetableCard.vue b/src/components/TrainsView/TrainTimetableCard.vue index 7df70a8..dc4051f 100644 --- a/src/components/TrainsView/TrainTimetableCard.vue +++ b/src/components/TrainsView/TrainTimetableCard.vue @@ -6,7 +6,7 @@ - + @@ -38,11 +38,7 @@ export default defineComponent({ methods: { close() { this.$emit('close'); - }, - - test() { - console.log('xd'); - }, + } }, }); @@ -73,7 +69,7 @@ export default defineComponent({ padding: 0.5em; width: 100%; - max-width: 1000px; + max-width: 1300px; @include smallScreen { diff --git a/src/main.ts b/src/main.ts index 8e9f790..6ccc58f 100644 --- a/src/main.ts +++ b/src/main.ts @@ -15,7 +15,7 @@ const i18n = createI18n({ en: enLang, pl: plLang, }, - enableLegacy: false + enableLegacy: false, }) const clickOutsideDirective: Directive = { diff --git a/src/mixins/trainInfoMixin.ts b/src/mixins/trainInfoMixin.ts new file mode 100644 index 0000000..47422ad --- /dev/null +++ b/src/mixins/trainInfoMixin.ts @@ -0,0 +1,104 @@ +import Train from "@/scripts/interfaces/Train"; +import TrainStop from "@/scripts/interfaces/TrainStop"; +import { defineComponent } from "vue"; + +export default defineComponent({ + data: () => ({ + STATS: { + main: [ + { + name: 'speed', + unit: 'km/h', + }, + { + name: 'length', + unit: 'm', + }, + { + name: 'mass', + unit: 't', + multiplier: 0.001, + }, + ], + + position: [ + { + name: 'scenery', + prop: 'currentStationName', + }, + { + name: 'route', + prop: 'connectedTrack', + }, + { + name: 'signal', + prop: 'signal', + }, + { + name: 'distance', + prop: 'distance', + unit: 'm', + }, + ], + }, + }), + + methods: { + displayStopList(stops: TrainStop[]): string | undefined { + if (!stops) return ''; + + return stops + .reduce((acc: string[], stop: TrainStop, i: number) => { + if (stop.stopType.includes('ph') && !stop.stopNameRAW.includes('po.')) + acc.push(`${stop.stopName}`); + else if ( + i > 0 && + i < stops.length - 1 && + !stop.stopNameRAW.includes('po.') && + !stop.stopNameRAW.includes('SBL') + ) + acc.push(`${stop.stopName}`); + return acc; + }, []) + .join(' > '); + }, + + confirmedPercentage(stops: TrainStop[]) { + return ((stops.filter((stop) => stop.confirmed).length / stops.length) * 100).toFixed(0); + }, + + currentDelay(stops: TrainStop[]) { + const delay = + stops.find((stop, i) => (i == 0 && !stop.confirmed) || (i > 0 && stops[i - 1].confirmed && !stop.confirmed)) + ?.departureDelay || 0; + + if (delay > 0) return `${this.$t('trains.delayed')} ${delay} min`; + else if (delay < 0) return `${this.$t('trains.preponed')} ${delay} min`; + else return this.$t('trains.on-time'); + }, + + displayLocoInfo(locoType: string) { + if (locoType.includes('EN')) return `${this.$t('trains.EZT')}`; + if (locoType.includes('SN')) return `${this.$t('trains.SZT')}`; + if (locoType.startsWith('E')) return `${this.$t('trains.loco-electric')}`; + if (locoType.startsWith('S')) return `${this.$t('trains.loco-diesel')}`; + + return ''; + }, + + getSceneriesWithComments(timetableData: Train['timetableData']) { + return ( + timetableData?.followingStops.reduce((acc, stop) => { + if (stop.comments) acc.push(stop.stopNameRAW); + + return acc; + }, [] as string[]) || [] + ); + }, + + onImageError(e: Event) { + const imageEl = e.target as HTMLImageElement; + imageEl.src = require('@/assets/unknown.png'); + } + } +}) \ No newline at end of file