chore: added creating new vehicles

This commit is contained in:
2025-11-25 02:14:23 +01:00
parent 9e111295dd
commit 3e94ec2826
3 changed files with 70 additions and 6 deletions
@@ -15,6 +15,7 @@
<td style="width: 100px">Grupa</td>
<td style="width: 100px">Tylko sponsorzy do</td>
<td style="width: 100px">Tylko zespół</td>
<td style="width: 50px">Ukryty</td>
</tr>
</thead>
@@ -47,6 +48,9 @@
<span v-else></span>
</td>
<td class="editable" @click="editRowPrimitive(row, VehicleEditRowKey.HIDDEN)">
{{ row.vehicleRef.hidden ? '' : '' }}
</td>
</tr>
</tbody>
</table>
@@ -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;
}
}
</script>
<style></style>
+19
View File
@@ -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<IVehicleAPI>(`/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;
},
},
});
+12
View File
@@ -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 {