From 9e1df1fb6143c12d77a0749c0f18bdf9b83fb8b2 Mon Sep 17 00:00:00 2001 From: Spythere Date: Wed, 15 Mar 2023 15:19:50 +0100 Subject: [PATCH] =?UTF-8?q?filtry=20poci=C4=85g=C3=B3w?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/TrainsView/TrainOptions.vue | 39 ++++++++++++++-------- src/components/TrainsView/TrainTable.vue | 15 +-------- src/constants/Trains/TrainOptionsConsts.ts | 24 +++++++++++-- src/locales/en.json | 10 +++--- src/locales/pl.json | 6 ++-- src/scripts/enums/TrainFilterType.ts | 26 ++++++++++----- src/scripts/managers/trainFilterManager.ts | 27 +++++++++------ src/types/Trains/TrainOptionsTypes.ts | 5 +-- 8 files changed, 96 insertions(+), 56 deletions(-) diff --git a/src/components/TrainsView/TrainOptions.vue b/src/components/TrainsView/TrainOptions.vue index a3be8b1..9552e9f 100644 --- a/src/components/TrainsView/TrainOptions.vue +++ b/src/components/TrainsView/TrainOptions.vue @@ -55,17 +55,23 @@

{{ $t('options.filter-title') }}

+
-
-
+
-
- - -
+
+
+
@@ -80,6 +86,7 @@ import keyMixin from '../../mixins/keyMixin'; import { TrainFilter } from '../../types/Trains/TrainOptionsTypes'; import ActionButton from '../Global/ActionButton.vue'; import SelectBox from '../Global/SelectBox.vue'; +import { TrainFilterSection } from '../../scripts/enums/TrainFilterType'; export default defineComponent({ components: { SelectBox, ActionButton }, @@ -101,6 +108,7 @@ export default defineComponent({ return { showOptions: false, lastSelectedFilter: null as TrainFilter | null, + TrainFilterSection, }; }, @@ -183,14 +191,17 @@ export default defineComponent({ margin: 0 auto; } -.filter-option { - button { - color: white; - font-weight: bold; +.options_filters div { + display: flex; + width: 100%; - &[data-disabled='true'] { - color: #888; - } + gap: 0.25em; + margin-bottom: 0.5em; + + button { + width: 100%; + color: $accentCol; + font-weight: bold; } } @@ -201,7 +212,7 @@ export default defineComponent({ margin-top: 1em; - button { + > * { width: 100%; } } diff --git a/src/components/TrainsView/TrainTable.vue b/src/components/TrainsView/TrainTable.vue index 738e9ec..e927e42 100644 --- a/src/components/TrainsView/TrainTable.vue +++ b/src/components/TrainsView/TrainTable.vue @@ -12,10 +12,6 @@ {{ $t('trains.no-trains') }} -
  • props.trains.findIndex(({ timetableData }) => timetableData && timetableData.routeDistance > 200) != -1 - ), }; }, - computed: { - trainNumbersWithTimeouts() { - return this.store.trainList.filter((train) => train.isTimeout).map((train) => train.trainNo); - }, - }, - activated() { const query = this.$route.query; if (query.trainNo && query.driverName) { @@ -159,7 +146,7 @@ img.train-image { .train { &-list { position: relative; - + @include smallScreen() { width: 100%; } diff --git a/src/constants/Trains/TrainOptionsConsts.ts b/src/constants/Trains/TrainOptionsConsts.ts index fff4f34..0a2f5c9 100644 --- a/src/constants/Trains/TrainOptionsConsts.ts +++ b/src/constants/Trains/TrainOptionsConsts.ts @@ -1,33 +1,53 @@ -import { TrainFilterType } from '../../scripts/enums/TrainFilterType'; +import { TrainFilterSection, TrainFilterType } from '../../scripts/enums/TrainFilterType'; import { TrainFilter } from '../../types/Trains/TrainOptionsTypes'; export const trainFilters: TrainFilter[] = [ { id: TrainFilterType.twr, + section: TrainFilterSection.TRAIN_TYPE, isActive: true, }, { id: TrainFilterType.skr, + section: TrainFilterSection.TRAIN_TYPE, isActive: true, }, + { id: TrainFilterType.passenger, + section: TrainFilterSection.TIMETABLE_TYPE, isActive: true, }, { id: TrainFilterType.freight, + section: TrainFilterSection.TIMETABLE_TYPE, isActive: true, }, { id: TrainFilterType.other, + section: TrainFilterSection.TIMETABLE_TYPE, + isActive: true, + }, + + { + id: TrainFilterType.withComments, + section: TrainFilterSection.COMMENTS, isActive: true, }, { - id: TrainFilterType.comments, + id: TrainFilterType.noComments, + section: TrainFilterSection.COMMENTS, + isActive: true, + }, + + { + id: TrainFilterType.withTimetable, + section: TrainFilterSection.TIMETABLE, isActive: true, }, { id: TrainFilterType.noTimetable, + section: TrainFilterSection.TIMETABLE, isActive: true, }, ]; diff --git a/src/locales/en.json b/src/locales/en.json index 2d6e1c8..cd22c61 100644 --- a/src/locales/en.json +++ b/src/locales/en.json @@ -112,13 +112,15 @@ "sort-timestampFrom": "date", "sort-duration": "duration", - "filter-comments": "COMMENTS", - "filter-twr": "TWR", - "filter-skr": "SKR", + "filter-noComments": "NO COMMENTS", + "filter-withComments": "COMMENTS", + "filter-twr": "HIGH RISK CARGO", + "filter-skr": "EXCEEDED GAUGE", "filter-passenger": "PASSENGER", "filter-freight": "FREIGHT", "filter-other": "OTHER", "filter-noTimetable": "NO TIMETABLE", + "filter-withTimetable": "TIMETABLE", "filter-reset": "RESET FILTERS", "filter-clear": "CLEAR FILTERS", @@ -211,7 +213,7 @@ "no-stations": "No stations to show here!", "scenery-search": "Search for scenery..." }, - "trains": { + "trains": { "no-trains": "No trains to show here!", "loading": "Loading train data...", "offline": "Offline ride", diff --git a/src/locales/pl.json b/src/locales/pl.json index 6d3247c..e26d307 100644 --- a/src/locales/pl.json +++ b/src/locales/pl.json @@ -115,13 +115,15 @@ "sort-delay": "opóźnienie", "sort-comments": "uwagi ekspl.", - "filter-comments": "UWAGI EKSPLOATACYJNE", - "filter-twr": "TWR", + "filter-withComments": "UWAGI EKSPLOATACYJNE", + "filter-noComments": "BEZ UWAG", + "filter-twr": "WYSOKIEGO RYZYKA", "filter-skr": "PRZEKR. SKRAJNIA", "filter-passenger": "PASAŻERSKIE", "filter-freight": "TOWAROWE", "filter-other": "INNE", "filter-noTimetable": "BEZ RJ", + "filter-withTimetable": "ROZKŁAD JAZDY", "filter-reset": "ZRESETUJ FILTRY", "filter-clear": "WYŁĄCZ FILTRY", diff --git a/src/scripts/enums/TrainFilterType.ts b/src/scripts/enums/TrainFilterType.ts index 4ce8b04..dc19774 100644 --- a/src/scripts/enums/TrainFilterType.ts +++ b/src/scripts/enums/TrainFilterType.ts @@ -1,9 +1,19 @@ -export const enum TrainFilterType { - comments = "comments", - twr = "twr", - skr = "skr", - passenger = "passenger", - freight = "freight", - other = "other", - noTimetable = "noTimetable" +export enum TrainFilterSection { + TRAIN_TYPE = 'TRAIN_TYPE', + TIMETABLE_TYPE = 'TIMETABLE_TYPE', + COMMENTS = 'COMMENTS', + TIMETABLE = 'TIMETABLE', +} + +export const enum TrainFilterType { + noComments = 'noComments', + withComments = 'withComments', + + twr = 'twr', + skr = 'skr', + passenger = 'passenger', + freight = 'freight', + other = 'other', + noTimetable = 'noTimetable', + withTimetable = 'withTimetable', } diff --git a/src/scripts/managers/trainFilterManager.ts b/src/scripts/managers/trainFilterManager.ts index 674ab58..758043e 100644 --- a/src/scripts/managers/trainFilterManager.ts +++ b/src/scripts/managers/trainFilterManager.ts @@ -24,26 +24,33 @@ function filterTrainList(trainList: Train[], searchedTrain: string, searchedDriv const isFiltered = filters.every((f) => { if (f.isActive) return true; - if (!train.timetableData) return filters.find((filter) => filter.id == TrainFilterType.noTimetable)!.isActive; - switch (f.id) { - case TrainFilterType.comments: - return !train.timetableData.followingStops.some((stop) => stop.comments); + case TrainFilterType.noTimetable: + return train.timetableData; + + case TrainFilterType.withTimetable: + return !train.timetableData; + + case TrainFilterType.noComments: + return train.timetableData?.followingStops.some((stop) => stop.comments) || false; + + case TrainFilterType.withComments: + return train.timetableData?.followingStops.every((stop) => stop.comments) || true; case TrainFilterType.twr: - return !train.timetableData.TWR; + return !train.timetableData?.TWR || true; case TrainFilterType.skr: - return !train.timetableData.SKR; + return !train.timetableData?.SKR || true; case TrainFilterType.passenger: - return !/^[AMRE]\D{2}$/.test(train.timetableData.category); + return !/^[AMRE]\D{2}$/.test(train.timetableData?.category || ''); case TrainFilterType.freight: - return !train.timetableData.category.startsWith('T'); + return !train.timetableData?.category.startsWith('T'); case TrainFilterType.other: - return !/^[PXZL]\D{2}$/.test(train.timetableData.category); + return !/^[PXZL]\D{2}$/.test(train.timetableData?.category || ''); default: return true; @@ -53,7 +60,7 @@ function filterTrainList(trainList: Train[], searchedTrain: string, searchedDriv return ( (searchedTrain.length > 0 ? train.trainNo.toString().startsWith(searchedTrain) : true) && (searchedDriver.length > 0 ? train.driverName.toLowerCase().startsWith(searchedDriver.toLowerCase()) : true) && - (!train.timetableData ? !train.online : true) && + (!train.timetableData ? train.online : train.timetableData) && isFiltered ); }); diff --git a/src/types/Trains/TrainOptionsTypes.ts b/src/types/Trains/TrainOptionsTypes.ts index b9db0a3..1c28fcb 100644 --- a/src/types/Trains/TrainOptionsTypes.ts +++ b/src/types/Trains/TrainOptionsTypes.ts @@ -1,6 +1,7 @@ -import { TrainFilterType } from "../../scripts/enums/TrainFilterType"; +import { TrainFilterSection, TrainFilterType } from '../../scripts/enums/TrainFilterType'; export interface TrainFilter { id: TrainFilterType; + section: TrainFilterSection; isActive: boolean; -} \ No newline at end of file +}