diff --git a/src/components/VehiclesManager/VehiclesTable.vue b/src/components/VehiclesManager/VehiclesTable.vue
index 6989e58..e81f9d4 100644
--- a/src/components/VehiclesManager/VehiclesTable.vue
+++ b/src/components/VehiclesManager/VehiclesTable.vue
@@ -15,6 +15,7 @@
Grupa |
Tylko sponsorzy do |
Tylko zespół |
+ Ukryty |
@@ -47,6 +48,9 @@
❌
+
+ {{ row.vehicleRef.hidden ? '✅' : '❌' }}
+ |
@@ -71,14 +75,24 @@ const vehiclesTableComp = computed(() => {
async function editRowPrimitive(row: IVehicleTableRow, editKey: VehicleEditRowKey) {
if (!(editKey in row.vehicleRef)) return;
+
+ let rowValue = row.vehicleRef[editKey];
- const promptValue = prompt('Zmień wartość:', row.vehicleRef[editKey]);
- if (promptValue == null) return;
+ if (typeof rowValue === 'string' || typeof rowValue === 'undefined' || rowValue == null) {
+ const promptValue = prompt('Zmień wartość:', rowValue ?? '');
+ if (promptValue == null) return;
- const updatedData = await vehiclesStore.updateVehicle(row.vehicleRef.id, editKey, promptValue);
+ const updatedData = await vehiclesStore.updateVehicle(row.vehicleRef.id, editKey, promptValue);
- if (updatedData) {
- row.vehicleRef[editKey] = updatedData[editKey]!;
+ if (updatedData) {
+ (row.vehicleRef[editKey] as any) = updatedData[editKey];
+ }
+ } else if (typeof rowValue == 'boolean') {
+ const updatedData = await vehiclesStore.updateVehicle(row.vehicleRef.id, editKey, !rowValue);
+
+ if (updatedData) {
+ (row.vehicleRef[editKey] as any) = updatedData[editKey];
+ }
}
}
@@ -120,7 +134,26 @@ async function editRowRestrictions(row: IVehicleTableRow, editKey: VehicleEditRe
}
}
-function addVehicleRow() {}
+async function addVehicleRow() {
+ const createdVehicleData = await vehiclesStore.createVehicle({
+ name: 'Vehicle-' + Date.now(),
+ type: 'loco-electric',
+ hidden: true,
+ vehicleGroupsId: 1,
+ });
+
+ if (createdVehicleData) {
+ vehiclesStore.vehiclesTable.push({
+ vehicleRef: {
+ ...createdVehicleData,
+ group: vehiclesStore.vehicleGroupsTable.find((g) => g.vehicleGroupRef.id == createdVehicleData.vehicleGroupsId)!
+ .vehicleGroupRef,
+ },
+ });
+
+ vehicleSearchInput.value = createdVehicleData.name;
+ }
+}
diff --git a/src/stores/vehicles.store.ts b/src/stores/vehicles.store.ts
index 08f6bf7..4787c19 100644
--- a/src/stores/vehicles.store.ts
+++ b/src/stores/vehicles.store.ts
@@ -1,6 +1,7 @@
import { defineStore } from 'pinia';
import client from '../common/http';
import {
+ ICreateVehicleBody,
IVehicle,
IVehicleAPI,
IVehicleGroupTableRow,
@@ -64,5 +65,23 @@ export const useVehiclesStore = defineStore('vehiclesStore', {
return null;
},
+
+ async createVehicle(vehicleRowData: ICreateVehicleBody) {
+ try {
+ const response = await client.post(`/manager/vehicles`, {
+ name: vehicleRowData.name,
+ type: vehicleRowData.type,
+ vehicleGroupId: vehicleRowData.vehicleGroupsId,
+ hidden: vehicleRowData.hidden,
+ simulatorVersion: '2025.3.2',
+ });
+
+ return response.data;
+ } catch (error) {
+ console.error(error);
+ }
+
+ return null;
+ },
},
});
diff --git a/src/types/vehicles.types.ts b/src/types/vehicles.types.ts
index a664703..c7edf80 100644
--- a/src/types/vehicles.types.ts
+++ b/src/types/vehicles.types.ts
@@ -8,6 +8,16 @@ export interface IVehicleAPI {
cabinName?: string;
restrictions?: IVehicleRestrictions;
vehicleGroupsId: number;
+ hidden: boolean;
+}
+
+export interface ICreateVehicleBody {
+ name: string;
+ type: string;
+ cabinName?: string;
+ restrictions?: IVehicleRestrictions;
+ vehicleGroupsId: number;
+ hidden: boolean;
}
export interface IVehicle {
@@ -17,6 +27,7 @@ export interface IVehicle {
cabinName?: string;
restrictions?: IVehicleRestrictions;
group: IVehicleGroup;
+ hidden: boolean;
}
export interface IVehicleRestrictions {
@@ -68,6 +79,7 @@ export enum VehicleEditRowKey {
NAME = 'name',
TYPE = 'type',
CABIN = 'cabinName',
+ HIDDEN = 'hidden',
}
export enum VehicleEditRestrictionKey {