From cabb321262a603c93b7c2fef830e97720dc686d8 Mon Sep 17 00:00:00 2001 From: Spythere Date: Tue, 2 Dec 2025 02:09:04 +0100 Subject: [PATCH] chore: finished vehicle groups table filters, added default sorters dir on change --- .../VehiclesManager/VehicleGroupsTable.vue | 61 +++++++++++-------- 1 file changed, 34 insertions(+), 27 deletions(-) diff --git a/src/components/VehiclesManager/VehicleGroupsTable.vue b/src/components/VehiclesManager/VehicleGroupsTable.vue index 4e08175..6b2f47b 100644 --- a/src/components/VehiclesManager/VehicleGroupsTable.vue +++ b/src/components/VehiclesManager/VehicleGroupsTable.vue @@ -24,12 +24,7 @@ - - - + + + + @@ -97,14 +96,14 @@ import { computed, onMounted, ref, watch } from 'vue'; import { useVehiclesStore } from '../../stores/vehicles.store'; import { LucideArrowDown, LucideArrowUp, LucidePlus, LucideX } from 'lucide-vue-next'; -import { IVehicleGroup, IVehicleGroupTableRow, VehicleGroupEditRowKey } from '../../types/vehicles.types'; +import { IVehicleGroup } from '../../types/vehicles.types'; import VehicleGroupEditModal from './VehicleGroupEditModal.vue'; interface TableHeader { id: string; elementWidth: number; title: string; - sortable: boolean; + defaultSorterDir: number; } const sorterFunctions: Record number> = { @@ -115,20 +114,28 @@ const sorterFunctions: Record speed: (v1, v2) => (v1.speed - v2.speed) * activeSortDir.value, speedLoco: (v1, v2) => ((v1.speedLoco || 0) - (v2.speedLoco || 0)) * activeSortDir.value, speedLoaded: (v1, v2) => ((v1.speedLoaded || 0) - (v2.speedLoaded || 0)) * activeSortDir.value, + coldStart: (v1, v2) => + ((v1.locoProps?.coldStart ? 1 : -1) - (v2.locoProps?.coldStart ? 1 : -1)) * activeSortDir.value, + doubleManned: (v1, v2) => + ((v1.locoProps?.doubleManned ? 1 : -1) - (v2.locoProps?.doubleManned ? 1 : -1)) * activeSortDir.value, + massSpeeds: (v1, v2) => ((v1.massSpeeds ? 1 : -1) - (v2.massSpeeds ? 1 : -1)) * activeSortDir.value, + cargoTypes: (v1, v2) => ((v1.cargoTypes?.length ?? 0) - (v2.cargoTypes?.length ?? 0)) * activeSortDir.value, + vehicles: (v1, v2) => (v1._count.vehicles - v2._count.vehicles) * activeSortDir.value, }; const headers: TableHeader[] = [ - { id: 'id', elementWidth: 50, title: '#', sortable: true }, - { id: 'name', elementWidth: 150, title: 'Nazwa', sortable: true }, - { id: 'length', elementWidth: 100, title: 'Długość', sortable: true }, - { id: 'weight', elementWidth: 100, title: 'Masa', sortable: true }, - { id: 'speed', elementWidth: 100, title: 'Prędkość', sortable: true }, - { id: 'speedLoco', elementWidth: 100, title: 'Prędkość (lok)', sortable: true }, - { id: 'speedLoaded', elementWidth: 100, title: 'Prędkość (ład.)', sortable: true }, - { id: 'vehicles', elementWidth: 80, title: 'Pojazdy', sortable: true }, - { id: 'coldStart', elementWidth: 75, title: 'Zimny start', sortable: true }, - { id: 'doubleManned', elementWidth: 75, title: 'Podwójna obsada', sortable: true }, - { id: 'massSpeeds', elementWidth: 100, title: 'Prędkości wg masy', sortable: false }, + { id: 'id', elementWidth: 50, title: '#', defaultSorterDir: 1 }, + { id: 'name', elementWidth: 150, title: 'Nazwa', defaultSorterDir: 1 }, + { id: 'length', elementWidth: 100, title: 'Długość', defaultSorterDir: -1 }, + { id: 'weight', elementWidth: 100, title: 'Masa', defaultSorterDir: -1 }, + { id: 'speed', elementWidth: 100, title: 'Prędkość', defaultSorterDir: -1 }, + { id: 'speedLoco', elementWidth: 100, title: 'Prędkość (lok)', defaultSorterDir: -1 }, + { id: 'speedLoaded', elementWidth: 100, title: 'Prędkość (ład.)', defaultSorterDir: -1 }, + { id: 'coldStart', elementWidth: 75, title: 'Zimny start', defaultSorterDir: -1 }, + { id: 'doubleManned', elementWidth: 75, title: 'Podwójna obsada', defaultSorterDir: -1 }, + { id: 'massSpeeds', elementWidth: 80, title: 'Prędkości wg masy', defaultSorterDir: -1 }, + { id: 'cargoTypes', elementWidth: 80, title: 'Ładunki', defaultSorterDir: -1 }, + { id: 'vehicles', elementWidth: 80, title: 'Pojazdy', defaultSorterDir: -1 }, ]; const vehiclesStore = useVehiclesStore(); @@ -164,7 +171,7 @@ function sortTableBy(id: string) { if (!(id in sorterFunctions)) return; if (activeSortKey.value == id) activeSortDir.value *= -1; - else activeSortDir.value = 1; + else activeSortDir.value = headers.find((h) => h.id == id)?.defaultSorterDir ?? 1; activeSortKey.value = id; }
+
{{ header.title }} @@ -65,15 +60,11 @@
- {{ row.vehicleGroupRef.speedLoco }} + {{ row.vehicleGroupRef.speedLoco ?? '-' }} - {{ row.vehicleGroupRef.speedLoaded }} - - {{ row.vehicleGroupRef._count.vehicles }} + {{ row.vehicleGroupRef.speedLoaded ?? '-' }} @@ -85,7 +76,15 @@ - {{ row.vehicleGroupRef.massSpeeds ? 'WPISANE' : 'BRAK' }} + {{ row.vehicleGroupRef.massSpeeds ? '✅' : '❌' }} + + {{ row.vehicleGroupRef.cargoTypes?.length ?? '-' }} + + {{ row.vehicleGroupRef._count.vehicles ?? '0' }}