mirror of
https://github.com/Spythere/station-manager-2.0.git
synced 2026-05-03 05:28:13 +00:00
Przywrócono zmianę nazwy scenerii i usuwanie
This commit is contained in:
@@ -1 +1,2 @@
|
|||||||
VITE_API_URL="https://stacjownik.eu-4.evennode.com"
|
VITE_API_URL="http://localhost:3000"
|
||||||
|
VITE_API_URL_DEV="https://stacjownik.eu-4.evennode.com"
|
||||||
@@ -226,7 +226,7 @@ export default defineComponent({
|
|||||||
this.store.stationList[index]['routes'] = routeString;
|
this.store.stationList[index]['routes'] = routeString;
|
||||||
this.currentRoutes = routeString;
|
this.currentRoutes = routeString;
|
||||||
|
|
||||||
this.addChange(this.store.currentStation!.name, 'routes', this.routeBackup, routeString);
|
this.addChange(this.store.currentStation!, 'routes', this.routeBackup, routeString);
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -108,11 +108,16 @@ export default defineComponent({
|
|||||||
|
|
||||||
async updateListToDb() {
|
async updateListToDb() {
|
||||||
try {
|
try {
|
||||||
const mappedChangeList = Object.entries(this.store.changeList).map(([k, v]) => {
|
const mappedChangeList = Object.entries(this.store.changeList).map(([id, v]) => {
|
||||||
return { name: k, ...v };
|
if (/^#/.test(id)) {
|
||||||
|
delete v.id;
|
||||||
|
return { ...v };
|
||||||
|
}
|
||||||
|
|
||||||
|
return { id: id, ...v };
|
||||||
});
|
});
|
||||||
|
|
||||||
await axios.post(
|
const response = await axios.post(
|
||||||
`${this.API_URL}/manager/updateSceneryList`,
|
`${this.API_URL}/manager/updateSceneryList`,
|
||||||
{
|
{
|
||||||
changeList: mappedChangeList,
|
changeList: mappedChangeList,
|
||||||
@@ -127,10 +132,12 @@ export default defineComponent({
|
|||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
|
console.log(response.data);
|
||||||
|
|
||||||
alert('Zapisano do bazy!');
|
alert('Zapisano do bazy!');
|
||||||
this.loadData();
|
this.loadData();
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
this.store.alertMessage = 'Ups! Wystąpił błąd podczas zapisywania danych!';
|
this.store.alertMessage = 'Ups! Wystąpił błąd podczas zapisywania danych!';
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
@@ -162,10 +169,11 @@ export default defineComponent({
|
|||||||
checkpoints: '',
|
checkpoints: '',
|
||||||
authors: '',
|
authors: '',
|
||||||
availability: 'default',
|
availability: 'default',
|
||||||
|
id: `#${Math.random().toString(32).substring(2)}`,
|
||||||
};
|
};
|
||||||
|
|
||||||
this.store.changeList[name] = { ...newSt };
|
this.store.changeList[newSt.id] = { ...newSt };
|
||||||
this.store.changeBackupList[name] = null;
|
this.store.changeBackupList[newSt.id] = null;
|
||||||
this.store.searchedSceneryName = name;
|
this.store.searchedSceneryName = name;
|
||||||
|
|
||||||
this.store.unsavedChanges = true;
|
this.store.unsavedChanges = true;
|
||||||
|
|||||||
+36
-22
@@ -1,5 +1,6 @@
|
|||||||
import { defineComponent } from 'vue';
|
import { defineComponent } from 'vue';
|
||||||
import { useStore } from '../store';
|
import { useStore } from '../store';
|
||||||
|
import { SceneryRowItem } from '../types/types';
|
||||||
|
|
||||||
export default defineComponent({
|
export default defineComponent({
|
||||||
setup() {
|
setup() {
|
||||||
@@ -9,41 +10,54 @@ export default defineComponent({
|
|||||||
},
|
},
|
||||||
|
|
||||||
methods: {
|
methods: {
|
||||||
addChange(stationName: string, propName: string, oldValue: any, newValue: any) {
|
addChange(sceneryData: SceneryRowItem, propName: string, oldValue: any, newValue: any) {
|
||||||
if (oldValue === newValue) return;
|
if (oldValue === newValue) return;
|
||||||
|
|
||||||
if (this.store.changeList[stationName] === null || !(stationName in this.store.changeList))
|
const sceneryId = sceneryData.id;
|
||||||
this.store.changeList[stationName] = {};
|
|
||||||
|
|
||||||
if (propName === 'name') {
|
if (this.store.changeList[sceneryId] === null || !(sceneryId in this.store.changeList))
|
||||||
const station = this.store.stationList[this.store.stationList.findIndex((v) => v.name == newValue)];
|
this.store.changeList[sceneryId] = {};
|
||||||
console.log(oldValue, newValue, station);
|
|
||||||
|
|
||||||
this.store.changeBackupList[oldValue] = { ...station, name: oldValue };
|
// if (propName === 'name') {
|
||||||
this.store.changeBackupList[newValue] = null;
|
// const rowStationData = this.store.stationList[this.store.stationList.findIndex((v) => v.id == sceneryId)];
|
||||||
|
|
||||||
this.store.changeList[oldValue] = null;
|
// this.store.changeList[sceneryId][propName] = newValue;
|
||||||
this.store.changeList[newValue] = { ...station };
|
// this.store.changeBackupList[sceneryId] = { ...rowStationData, name: oldValue };
|
||||||
} else {
|
// } else {
|
||||||
this.store.changeList[stationName][propName] = newValue;
|
this.store.changeList[sceneryId][propName] = newValue;
|
||||||
|
|
||||||
if (!this.store.changeBackupList[stationName]) this.store.changeBackupList[stationName] = {};
|
if (!this.store.changeBackupList[sceneryId]) this.store.changeBackupList[sceneryId] = {};
|
||||||
|
|
||||||
if (this.store.changeBackupList[stationName][propName] === undefined)
|
if (this.store.changeBackupList[sceneryId][propName] === undefined)
|
||||||
this.store.changeBackupList[stationName][propName] = oldValue;
|
this.store.changeBackupList[sceneryId][propName] = oldValue;
|
||||||
}
|
// }
|
||||||
|
|
||||||
if (this.store.changeList[stationName][propName] == this.store.changeBackupList[stationName][propName]) {
|
if (this.store.changeList[sceneryId][propName] == this.store.changeBackupList[sceneryId][propName]) {
|
||||||
delete this.store.changeList[stationName][propName];
|
delete this.store.changeList[sceneryId][propName];
|
||||||
delete this.store.changeBackupList[stationName][propName];
|
delete this.store.changeBackupList[sceneryId][propName];
|
||||||
|
|
||||||
if (Object.keys(this.store.changeList[stationName]).length == 0) delete this.store.changeList[stationName];
|
if (Object.keys(this.store.changeList[sceneryId]).length == 0) delete this.store.changeList[sceneryId];
|
||||||
|
|
||||||
if (Object.keys(this.store.changeBackupList[stationName]).length == 0)
|
if (Object.keys(this.store.changeBackupList[sceneryId]).length == 0)
|
||||||
delete this.store.changeBackupList[stationName];
|
delete this.store.changeBackupList[sceneryId];
|
||||||
}
|
}
|
||||||
|
|
||||||
this.store.unsavedChanges = Object.keys(this.store.changeList).length != 0;
|
this.store.unsavedChanges = Object.keys(this.store.changeList).length != 0;
|
||||||
},
|
},
|
||||||
|
|
||||||
|
addRemovalChange(sceneryData: SceneryRowItem) {
|
||||||
|
const sceneryId = sceneryData.id;
|
||||||
|
|
||||||
|
this.store.changeBackupList[sceneryId] = { ...sceneryData };
|
||||||
|
|
||||||
|
this.store.changeList[sceneryId] = {
|
||||||
|
name: sceneryData.name,
|
||||||
|
toRemove: true,
|
||||||
|
};
|
||||||
|
|
||||||
|
this.store.unsavedChanges = Object.keys(this.store.changeList).length != 0;
|
||||||
|
|
||||||
|
console.log(this.store.changeList);
|
||||||
|
},
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
export type Availability = 'default' | 'unavailable' | 'nonPublic' | 'abandoned' | 'nonDefault';
|
export type Availability = 'default' | 'unavailable' | 'nonPublic' | 'abandoned' | 'nonDefault';
|
||||||
|
|
||||||
export interface SceneryRowItem {
|
export interface SceneryRowItem {
|
||||||
|
id: string;
|
||||||
name: string;
|
name: string;
|
||||||
url: string;
|
url: string;
|
||||||
lines: string;
|
lines: string;
|
||||||
|
|||||||
+29
-34
@@ -11,6 +11,7 @@
|
|||||||
<thead>
|
<thead>
|
||||||
<th v-for="header in headerNameList">{{ header }}</th>
|
<th v-for="header in headerNameList">{{ header }}</th>
|
||||||
<th>Dostępność</th>
|
<th>Dostępność</th>
|
||||||
|
<th>Usuń</th>
|
||||||
</thead>
|
</thead>
|
||||||
|
|
||||||
<tbody>
|
<tbody>
|
||||||
@@ -19,7 +20,7 @@
|
|||||||
<span v-if="propName === 'url'" :style="station.url ? 'color: gold' : 'color: gray;'">URL</span>
|
<span v-if="propName === 'url'" :style="station.url ? 'color: gold' : 'color: gray;'">URL</span>
|
||||||
<span v-else-if="propName === 'checkpoints'">{{ station[propName] ? 'POKAŻ' : 'DODAJ' }}</span>
|
<span v-else-if="propName === 'checkpoints'">{{ station[propName] ? 'POKAŻ' : 'DODAJ' }}</span>
|
||||||
<span v-else-if="propName === 'routes'" v-html="getRouteNames(station)"></span>
|
<span v-else-if="propName === 'routes'" v-html="getRouteNames(station)"></span>
|
||||||
<span v-else-if="typeof (station as any)[propName] === 'boolean' && propName !== 'supportersOnly'">
|
<span v-else-if="typeof (station as any)[propName] === 'boolean'">
|
||||||
{{ (station as any)[propName] ? '✅' : '❌' }}
|
{{ (station as any)[propName] ? '✅' : '❌' }}
|
||||||
</span>
|
</span>
|
||||||
<span v-else>{{ (station as any)[propName] }}</span>
|
<span v-else>{{ (station as any)[propName] }}</span>
|
||||||
@@ -30,7 +31,7 @@
|
|||||||
name="availability"
|
name="availability"
|
||||||
:id="`select-${row}`"
|
:id="`select-${row}`"
|
||||||
v-model="sortedStationList[row]['availability']"
|
v-model="sortedStationList[row]['availability']"
|
||||||
@input="(e) => changeAvailability(station.name, sortedStationList[row]['availability'], e)"
|
@input="(e) => changeAvailability(station, sortedStationList[row]['availability'], e)"
|
||||||
>
|
>
|
||||||
<option value="default">dostępna (w paczce)</option>
|
<option value="default">dostępna (w paczce)</option>
|
||||||
<option value="nonDefault">dostępna (poza paczką)</option>
|
<option value="nonDefault">dostępna (poza paczką)</option>
|
||||||
@@ -39,6 +40,8 @@
|
|||||||
<option value="abandoned">wycofana</option>
|
<option value="abandoned">wycofana</option>
|
||||||
</select>
|
</select>
|
||||||
</td>
|
</td>
|
||||||
|
|
||||||
|
<td @click="removeStation(station)"><img src="/icon-trash.svg" alt="remove" /></td>
|
||||||
</tr>
|
</tr>
|
||||||
</tbody>
|
</tbody>
|
||||||
</table>
|
</table>
|
||||||
@@ -100,25 +103,6 @@ export default defineComponent({
|
|||||||
},
|
},
|
||||||
|
|
||||||
methods: {
|
methods: {
|
||||||
addNewStation() {
|
|
||||||
this.store.newStationsCount++;
|
|
||||||
const newSt: SceneryRowItem = {
|
|
||||||
name: `${this.store.newStationsCount}_Sceneria`,
|
|
||||||
url: '',
|
|
||||||
lines: '',
|
|
||||||
project: null,
|
|
||||||
reqLevel: 0,
|
|
||||||
signalType: '',
|
|
||||||
controlType: '',
|
|
||||||
SUP: false,
|
|
||||||
routes: '',
|
|
||||||
checkpoints: '',
|
|
||||||
authors: '',
|
|
||||||
availability: 'default',
|
|
||||||
};
|
|
||||||
this.store.stationList.unshift(newSt);
|
|
||||||
},
|
|
||||||
|
|
||||||
getRouteNames(station: SceneryRowItem) {
|
getRouteNames(station: SceneryRowItem) {
|
||||||
if (!station.routes) return '';
|
if (!station.routes) return '';
|
||||||
return station.routes
|
return station.routes
|
||||||
@@ -138,58 +122,64 @@ export default defineComponent({
|
|||||||
|
|
||||||
changeProperty(station: SceneryRowItem, row: number, propertyName: string) {
|
changeProperty(station: SceneryRowItem, row: number, propertyName: string) {
|
||||||
this.store.selectedStationName = station.name;
|
this.store.selectedStationName = station.name;
|
||||||
if (propertyName == 'name') return;
|
|
||||||
if (propertyName == 'checkpoints') {
|
if (propertyName == 'checkpoints') {
|
||||||
this.changeCheckpoints(row);
|
this.changeCheckpoints(row);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (propertyName == 'routes') {
|
if (propertyName == 'routes') {
|
||||||
this.showRoutesModal(station);
|
this.showRoutesModal(station);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const stationListRow = this.store.stationList.findIndex(
|
const stationListRow = this.store.stationList.findIndex(
|
||||||
(station) => station.name == this.sortedStationList[row].name
|
(station) => station.name == this.sortedStationList[row].name
|
||||||
);
|
);
|
||||||
|
|
||||||
if (stationListRow == -1) return;
|
if (stationListRow == -1) return;
|
||||||
const oldValue = (this.store.stationList[stationListRow] as any)[propertyName];
|
const oldValue = (this.store.stationList[stationListRow] as any)[propertyName];
|
||||||
if (typeof oldValue === 'boolean') {
|
if (typeof oldValue === 'boolean') {
|
||||||
(this.store.stationList[stationListRow] as any)[propertyName] = !oldValue;
|
(this.store.stationList[stationListRow] as any)[propertyName] = !oldValue;
|
||||||
// this.$set(this.stationList[stationListRow], propertyName, !oldValue);
|
// this.$set(this.stationList[stationListRow], propertyName, !oldValue);
|
||||||
this.addChange(station.name, propertyName, oldValue, !oldValue);
|
this.addChange(station, propertyName, oldValue, !oldValue);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
let newValue = prompt(`Zmień wartość dla rubryki ${this.headerNameList[propertyName]}`, oldValue);
|
let newValue = prompt(`Zmień wartość dla rubryki ${this.headerNameList[propertyName]}`, oldValue);
|
||||||
if (newValue == null) return;
|
if (newValue == null) return;
|
||||||
(this.store.stationList[stationListRow] as any)[propertyName] =
|
(this.store.stationList[stationListRow] as any)[propertyName] =
|
||||||
typeof oldValue === 'number' ? parseInt(newValue) : newValue;
|
typeof oldValue === 'number' ? parseInt(newValue) : newValue;
|
||||||
// this.$set(this.stationList[stationListRow], propertyName, parseInt(newValue));
|
// this.$set(this.stationList[stationListRow], propertyName, parseInt(newValue));
|
||||||
this.addChange(
|
this.addChange(station, propertyName, oldValue, typeof oldValue === 'number' ? parseInt(newValue) : newValue);
|
||||||
station.name,
|
|
||||||
propertyName,
|
|
||||||
oldValue,
|
|
||||||
typeof oldValue === 'number' ? parseInt(newValue) : newValue
|
|
||||||
);
|
|
||||||
},
|
},
|
||||||
|
|
||||||
changeCheckpoints(row: number) {
|
changeCheckpoints(row: number) {
|
||||||
const stationListRow = this.store.stationList.findIndex(
|
const stationListRow = this.store.stationList.findIndex(
|
||||||
(station) => station.name == this.sortedStationList[row].name
|
(station) => station.name == this.sortedStationList[row].name
|
||||||
);
|
);
|
||||||
|
|
||||||
if (stationListRow == -1) return;
|
if (stationListRow == -1) return;
|
||||||
const oldCheckpoints = this.store.stationList[stationListRow].checkpoints;
|
const oldCheckpoints = this.store.stationList[stationListRow].checkpoints;
|
||||||
const newCheckpoints = prompt('Wpisz posterunki (oddzielone średnikiem):', oldCheckpoints);
|
const newCheckpoints = prompt('Wpisz posterunki (oddzielone średnikiem):', oldCheckpoints);
|
||||||
if (newCheckpoints === null) return;
|
if (newCheckpoints === null) return;
|
||||||
|
|
||||||
this.store.stationList[stationListRow]['checkpoints'] = newCheckpoints;
|
this.store.stationList[stationListRow]['checkpoints'] = newCheckpoints;
|
||||||
this.addChange(this.sortedStationList[row].name, 'checkpoints', oldCheckpoints, newCheckpoints);
|
this.addChange(this.sortedStationList[row], 'checkpoints', oldCheckpoints, newCheckpoints);
|
||||||
},
|
},
|
||||||
|
|
||||||
changeAvailability(stationName: string, availability: Availability, e: Event) {
|
changeAvailability(scenery: SceneryRowItem, availability: Availability, e: Event) {
|
||||||
const selectedAvailability: Availability = (e.target as HTMLSelectElement).value as Availability;
|
const selectedAvailability: Availability = (e.target as HTMLSelectElement).value as Availability;
|
||||||
this.addChange(stationName, 'availability', availability, selectedAvailability);
|
this.addChange(scenery, 'availability', availability, selectedAvailability);
|
||||||
},
|
},
|
||||||
|
|
||||||
showRoutesModal(station: SceneryRowItem) {
|
removeStation(scenery: SceneryRowItem) {
|
||||||
this.store.currentStation = station;
|
this.store.stationList = this.store.stationList.filter(({ id }) => id != scenery.id);
|
||||||
|
this.addRemovalChange(scenery);
|
||||||
|
},
|
||||||
|
|
||||||
|
showRoutesModal(scenery: SceneryRowItem) {
|
||||||
|
this.store.currentStation = scenery;
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
@@ -250,4 +240,9 @@ table tr td {
|
|||||||
overflow: auto;
|
overflow: auto;
|
||||||
text-overflow: ellipsis;
|
text-overflow: ellipsis;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
td img {
|
||||||
|
height: 1.45em;
|
||||||
|
vertical-align: middle;
|
||||||
|
}
|
||||||
</style>
|
</style>
|
||||||
|
|||||||
Reference in New Issue
Block a user