mirror of
https://github.com/Spythere/station-manager-2.0.git
synced 2026-05-03 13:38:13 +00:00
refactor: revamped vehicle manager adjusted for new API, improved file structure
This commit is contained in:
@@ -0,0 +1,126 @@
|
||||
<template>
|
||||
<div class="table-search-box">
|
||||
<input type="text" placeholder="Wyszukaj pojazd..." v-model="vehicleSearchInput" />
|
||||
<button @click="addVehicleRow()">DODAJ NOWY POJAZD</button>
|
||||
</div>
|
||||
|
||||
<div class="table-wrapper">
|
||||
<table class="vehicle-manager-table">
|
||||
<thead>
|
||||
<tr>
|
||||
<td style="width: 50px">#</td>
|
||||
<td style="width: 200px">Nazwa</td>
|
||||
<td style="width: 150px">Typ</td>
|
||||
<td style="width: 150px">Kabina (lok.)</td>
|
||||
<td style="width: 100px">Grupa</td>
|
||||
<td style="width: 100px">Tylko sponsorzy do</td>
|
||||
<td style="width: 100px">Tylko zespół</td>
|
||||
</tr>
|
||||
</thead>
|
||||
|
||||
<tbody>
|
||||
<tr v-for="row in vehiclesTableComp" :key="row.vehicleRef.id">
|
||||
<td>{{ row.vehicleRef.id }}</td>
|
||||
<td class="editable" @click="editRowPrimitive(row, VehicleEditRowKey.NAME)">
|
||||
{{ row.vehicleRef.name }}
|
||||
</td>
|
||||
<td class="editable" @click="editRowPrimitive(row, VehicleEditRowKey.TYPE)">
|
||||
{{ row.vehicleRef.type }}
|
||||
</td>
|
||||
|
||||
<td class="editable" @click="editRowPrimitive(row, VehicleEditRowKey.CABIN)">
|
||||
{{ row.vehicleRef.cabinName }}
|
||||
</td>
|
||||
|
||||
<td class="editable">{{ row.vehicleRef.group.name }}</td>
|
||||
<td class="editable" @click="editRowRestrictions(row, VehicleEditRestrictionKey.SPONSOR_ONLY)">
|
||||
<span v-if="row.vehicleRef.restrictions?.sponsorOnly !== undefined">
|
||||
{{ new Date(row.vehicleRef.restrictions.sponsorOnly).toLocaleString() }}
|
||||
</span>
|
||||
|
||||
<span v-else>❌</span>
|
||||
</td>
|
||||
<td class="editable" @click="editRowRestrictions(row, VehicleEditRestrictionKey.TEAM_ONLY)">
|
||||
<span v-if="row.vehicleRef.restrictions?.teamOnly !== undefined">
|
||||
{{ row.vehicleRef.restrictions.teamOnly ? '✅' : '❌' }}
|
||||
</span>
|
||||
|
||||
<span v-else>❌</span>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script lang="ts" setup>
|
||||
import { computed, ref } from 'vue';
|
||||
import { useVehiclesStore } from '../../stores/vehicles.store';
|
||||
import { IVehicleTableRow, VehicleEditRestrictionKey, VehicleEditRowKey } from '../../types/vehicles.types';
|
||||
|
||||
const vehiclesStore = useVehiclesStore();
|
||||
const vehicleSearchInput = ref('');
|
||||
|
||||
const vehiclesTableComp = computed(() => {
|
||||
return vehiclesStore.vehiclesTable
|
||||
.filter((row) => row.vehicleRef.name.toLowerCase().startsWith(vehicleSearchInput.value.trim().toLowerCase()))
|
||||
.sort((r1, r2) => {
|
||||
return r1.vehicleRef.id - r2.vehicleRef.id;
|
||||
});
|
||||
});
|
||||
|
||||
async function editRowPrimitive(row: IVehicleTableRow, editKey: VehicleEditRowKey) {
|
||||
if (!(editKey in row.vehicleRef)) return;
|
||||
|
||||
const promptValue = prompt('Zmień wartość:', row.vehicleRef[editKey]);
|
||||
if (promptValue == null) return;
|
||||
|
||||
const updatedData = await vehiclesStore.updateVehicle(row.vehicleRef.id, editKey, promptValue);
|
||||
|
||||
if (updatedData) {
|
||||
row.vehicleRef[editKey] = updatedData[editKey]!;
|
||||
}
|
||||
}
|
||||
|
||||
async function editRowRestrictions(row: IVehicleTableRow, editKey: VehicleEditRestrictionKey) {
|
||||
const restrictions: Record<VehicleEditRestrictionKey, any> = {
|
||||
teamOnly: row.vehicleRef.restrictions?.teamOnly ?? undefined,
|
||||
sponsorOnly: row.vehicleRef.restrictions?.sponsorOnly ?? undefined,
|
||||
};
|
||||
|
||||
if (editKey == VehicleEditRestrictionKey.TEAM_ONLY) {
|
||||
restrictions[editKey] = row.vehicleRef.restrictions ? !row.vehicleRef.restrictions[editKey] : true;
|
||||
|
||||
const updatedData = await vehiclesStore.updateVehicle(row.vehicleRef.id, 'restrictions', restrictions);
|
||||
|
||||
if (updatedData) {
|
||||
if (!row.vehicleRef.restrictions) row.vehicleRef.restrictions = {};
|
||||
|
||||
row.vehicleRef.restrictions[editKey] = updatedData.restrictions![editKey];
|
||||
}
|
||||
}
|
||||
|
||||
if (editKey == VehicleEditRestrictionKey.SPONSOR_ONLY) {
|
||||
const promptValue = prompt(
|
||||
'Zmień wartość (timestamp):',
|
||||
row.vehicleRef.restrictions?.sponsorOnly?.toString() ?? Date.now().toString(),
|
||||
);
|
||||
|
||||
if (promptValue == null) return;
|
||||
|
||||
restrictions[editKey] = promptValue.trim() != '' ? parseInt(promptValue) : undefined;
|
||||
|
||||
const updatedData = await vehiclesStore.updateVehicle(row.vehicleRef.id, 'restrictions', restrictions);
|
||||
|
||||
if (updatedData) {
|
||||
if (!row.vehicleRef.restrictions) row.vehicleRef.restrictions = {};
|
||||
|
||||
row.vehicleRef.restrictions[editKey] = updatedData.restrictions![editKey];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function addVehicleRow() {}
|
||||
</script>
|
||||
|
||||
<style></style>
|
||||
Reference in New Issue
Block a user