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">Grupa</td>
<td style="width: 100px">Tylko sponsorzy do</td> <td style="width: 100px">Tylko sponsorzy do</td>
<td style="width: 100px">Tylko zespół</td> <td style="width: 100px">Tylko zespół</td>
<td style="width: 50px">Ukryty</td>
</tr> </tr>
</thead> </thead>
@@ -47,6 +48,9 @@
<span v-else></span> <span v-else></span>
</td> </td>
<td class="editable" @click="editRowPrimitive(row, VehicleEditRowKey.HIDDEN)">
{{ row.vehicleRef.hidden ? '' : '' }}
</td>
</tr> </tr>
</tbody> </tbody>
</table> </table>
@@ -72,13 +76,23 @@ const vehiclesTableComp = computed(() => {
async function editRowPrimitive(row: IVehicleTableRow, editKey: VehicleEditRowKey) { async function editRowPrimitive(row: IVehicleTableRow, editKey: VehicleEditRowKey) {
if (!(editKey in row.vehicleRef)) return; if (!(editKey in row.vehicleRef)) return;
const promptValue = prompt('Zmień wartość:', row.vehicleRef[editKey]); let rowValue = row.vehicleRef[editKey];
if (promptValue == null) return;
const updatedData = await vehiclesStore.updateVehicle(row.vehicleRef.id, editKey, promptValue); if (typeof rowValue === 'string' || typeof rowValue === 'undefined' || rowValue == null) {
const promptValue = prompt('Zmień wartość:', rowValue ?? '');
if (promptValue == null) return;
if (updatedData) { const updatedData = await vehiclesStore.updateVehicle(row.vehicleRef.id, editKey, promptValue);
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> </script>
<style></style> <style></style>
+19
View File
@@ -1,6 +1,7 @@
import { defineStore } from 'pinia'; import { defineStore } from 'pinia';
import client from '../common/http'; import client from '../common/http';
import { import {
ICreateVehicleBody,
IVehicle, IVehicle,
IVehicleAPI, IVehicleAPI,
IVehicleGroupTableRow, IVehicleGroupTableRow,
@@ -64,5 +65,23 @@ export const useVehiclesStore = defineStore('vehiclesStore', {
return null; 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; cabinName?: string;
restrictions?: IVehicleRestrictions; restrictions?: IVehicleRestrictions;
vehicleGroupsId: number; vehicleGroupsId: number;
hidden: boolean;
}
export interface ICreateVehicleBody {
name: string;
type: string;
cabinName?: string;
restrictions?: IVehicleRestrictions;
vehicleGroupsId: number;
hidden: boolean;
} }
export interface IVehicle { export interface IVehicle {
@@ -17,6 +27,7 @@ export interface IVehicle {
cabinName?: string; cabinName?: string;
restrictions?: IVehicleRestrictions; restrictions?: IVehicleRestrictions;
group: IVehicleGroup; group: IVehicleGroup;
hidden: boolean;
} }
export interface IVehicleRestrictions { export interface IVehicleRestrictions {
@@ -68,6 +79,7 @@ export enum VehicleEditRowKey {
NAME = 'name', NAME = 'name',
TYPE = 'type', TYPE = 'type',
CABIN = 'cabinName', CABIN = 'cabinName',
HIDDEN = 'hidden',
} }
export enum VehicleEditRestrictionKey { export enum VehicleEditRestrictionKey {