mirror of
https://github.com/Spythere/station-manager-2.0.git
synced 2026-05-03 13:38:13 +00:00
chore: added creating new vehicles
This commit is contained in:
@@ -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>
|
||||||
|
|||||||
@@ -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;
|
||||||
|
},
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -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 {
|
||||||
|
|||||||
Reference in New Issue
Block a user