mirror of
https://github.com/Spythere/station-manager-2.0.git
synced 2026-05-03 13:38:13 +00:00
Migracja projektu na Vite
This commit is contained in:
@@ -0,0 +1,86 @@
|
||||
<template>
|
||||
<div class="bg-dimmer"></div>
|
||||
<div class="popup-card">
|
||||
<div class="card_content">
|
||||
<p>{{ store.alertMessage || store.confirmMessage }}</p>
|
||||
</div>
|
||||
|
||||
<div class="card_actions">
|
||||
<span v-if="store.alertMessage">
|
||||
<button @click="closeCard">OK!</button>
|
||||
</span>
|
||||
|
||||
<span v-else-if="store.confirmMessage">
|
||||
<button @click="confirm">OK!</button>
|
||||
<button @click="closeCard">Anuluj</button>
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script lang="ts">
|
||||
import { defineComponent } from 'vue';
|
||||
import { useStore } from '../store';
|
||||
|
||||
export default defineComponent({
|
||||
emits: ['confirm'],
|
||||
|
||||
setup() {
|
||||
return {
|
||||
store: useStore(),
|
||||
};
|
||||
},
|
||||
|
||||
methods: {
|
||||
closeCard() {
|
||||
this.store.alertMessage = '';
|
||||
this.store.confirmMessage = '';
|
||||
},
|
||||
|
||||
confirm() {
|
||||
this.$emit('confirm');
|
||||
this.closeCard();
|
||||
},
|
||||
},
|
||||
});
|
||||
</script>
|
||||
|
||||
<style lang="scss" scoped>
|
||||
.bg-dimmer {
|
||||
position: fixed;
|
||||
z-index: 998;
|
||||
top: 0;
|
||||
left: 0;
|
||||
width: 100vw;
|
||||
height: 100vh;
|
||||
|
||||
background-color: #0000004f;
|
||||
}
|
||||
.popup-card {
|
||||
position: fixed;
|
||||
z-index: 999;
|
||||
top: 50%;
|
||||
left: 50%;
|
||||
transform: translate(-50%, -50%);
|
||||
|
||||
width: 80%;
|
||||
max-width: 350px;
|
||||
|
||||
padding: 0.5em 1em;
|
||||
margin-top: 1em;
|
||||
|
||||
font-size: 1.35em;
|
||||
|
||||
background-color: #2a2a2a;
|
||||
box-shadow: 2px 0 10px 2px #1f1f1f;
|
||||
}
|
||||
|
||||
.card_content {
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.card_actions {
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
}
|
||||
</style>
|
||||
@@ -0,0 +1,340 @@
|
||||
<template>
|
||||
<div class="routes-modal" v-if="store.currentStation">
|
||||
<div class="exit" @click="closeRoutesModal">
|
||||
<img src="/icon-exit.svg" alt="exit icon" />
|
||||
</div>
|
||||
|
||||
<div class="modal-wrapper">
|
||||
<h1>Szlaki na scenerii {{ store.currentStation.name }}</h1>
|
||||
|
||||
<ul class="route-list">
|
||||
<li class="route" v-for="(route, i) in computedRouteList" :key="route.routeName + i">
|
||||
<img @click="removeRoute(i)" class="route-delete" src="/icon-trash.svg" alt="icon trash" />
|
||||
|
||||
<form>
|
||||
<div>Szlak: <input type="text" v-model="route.routeName" /></div>
|
||||
<div>
|
||||
<input
|
||||
type="checkbox"
|
||||
:name="`${route.routeName}-internal`"
|
||||
:id="`${route.routeName}-internal`"
|
||||
v-model="route.routeIsInternal"
|
||||
/>
|
||||
<label :for="`${route.routeName}-internal`">Szlak wewnętrzny</label>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<span>Liczba torów: </span>
|
||||
<input
|
||||
type="radio"
|
||||
:name="`${route.routeName}-tracks`"
|
||||
:id="`${route.routeName}-track1`"
|
||||
:value="Number(1)"
|
||||
:checked="route.routeTracks == 1"
|
||||
v-model="route.routeTracks"
|
||||
/>
|
||||
<label :for="`${route.routeName}-track1`">1</label>
|
||||
|
||||
<input
|
||||
type="radio"
|
||||
:name="`${route.routeName}-tracks`"
|
||||
:id="`${route.routeName}-track2`"
|
||||
:value="Number(2)"
|
||||
:checked="route.routeTracks == 2"
|
||||
v-model="route.routeTracks"
|
||||
/>
|
||||
<label :for="`${route.routeName}-track2`">2</label>
|
||||
</div>
|
||||
<div>
|
||||
<span>Elektryfikacja: </span>
|
||||
|
||||
<input
|
||||
type="radio"
|
||||
:name="`${route.routeName}-electr`"
|
||||
:id="`${route.routeName}-E`"
|
||||
:checked="route.routeElectrification == 'E'"
|
||||
value="E"
|
||||
v-model="route.routeElectrification"
|
||||
/>
|
||||
<label :for="`${route.routeName}-E`">Tak</label>
|
||||
|
||||
<input
|
||||
type="radio"
|
||||
:name="`${route.routeName}-electr`"
|
||||
:id="`${route.routeName}-N`"
|
||||
:checked="route.routeElectrification == 'N'"
|
||||
value="N"
|
||||
v-model="route.routeElectrification"
|
||||
/>
|
||||
<label :for="`${route.routeName}-N`">Nie</label>
|
||||
</div>
|
||||
<div>
|
||||
<span>Typ blokady: </span>
|
||||
|
||||
<input
|
||||
type="radio"
|
||||
:name="`${route.routeName}-block`"
|
||||
:id="`${route.routeName}-PBL`"
|
||||
:checked="route.routeBlockType == 'P'"
|
||||
value="P"
|
||||
v-model="route.routeBlockType"
|
||||
/>
|
||||
<label :for="`${route.routeName}-PBL`">PBL</label>
|
||||
|
||||
<input
|
||||
type="radio"
|
||||
:name="`${route.routeName}-block`"
|
||||
:id="`${route.routeName}-SBL`"
|
||||
:checked="route.routeBlockType == 'S'"
|
||||
value="S"
|
||||
v-model="route.routeBlockType"
|
||||
/>
|
||||
<label :for="`${route.routeName}-SBL`">SBL</label>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<span>Blokada dwukierunkowa: </span>
|
||||
|
||||
<input
|
||||
type="radio"
|
||||
:name="`${route.routeName}-2twb`"
|
||||
:id="`${route.routeName}-twb`"
|
||||
:checked="route.routeHasTwoWayBlock"
|
||||
:value="true"
|
||||
v-model="route.routeHasTwoWayBlock"
|
||||
/>
|
||||
<label :for="`${route.routeName}-twb`">Tak</label>
|
||||
|
||||
<input
|
||||
type="radio"
|
||||
:name="`${route.routeName}-2twb`"
|
||||
:id="`${route.routeName}-notwb`"
|
||||
:checked="!route.routeHasTwoWayBlock"
|
||||
:value="false"
|
||||
v-model="route.routeHasTwoWayBlock"
|
||||
/>
|
||||
<label :for="`${route.routeName}-notwb`">Nie</label>
|
||||
</div>
|
||||
</form>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
|
||||
<div class="routes-actions">
|
||||
<button @click="saveRoutes">Zapisz</button>
|
||||
<button @click="addNewRoute">Dodaj szlak</button>
|
||||
<button @click="closeRoutesModal">Zamknij</button>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script lang="ts">import { defineComponent } from 'vue';
|
||||
import changeMixin from '../mixins/changeMixin';
|
||||
import { useStore } from '../store';
|
||||
|
||||
|
||||
export default defineComponent({
|
||||
setup() {
|
||||
return {
|
||||
store: useStore(),
|
||||
};
|
||||
},
|
||||
|
||||
mixins: [changeMixin],
|
||||
|
||||
data: () => ({
|
||||
currentRoutes: '',
|
||||
routeBackup: '',
|
||||
}),
|
||||
|
||||
computed: {
|
||||
computedRouteList() {
|
||||
if (!this.store.currentStation) return [];
|
||||
|
||||
if (this.currentRoutes.length == 0) return [];
|
||||
|
||||
return this.currentRoutes.split(';').map((route) => {
|
||||
/*
|
||||
Route: !Oc_2EPB
|
||||
! - szlak wewnętrzny (! - tak, brak wykrzyknika - nie)
|
||||
Oc - nazwa scenerii
|
||||
2 - liczba torów (1 lub 2)
|
||||
E - elektryfikacja (E - tak, N - nie)
|
||||
P - rodzaj blokady (P - PBL, S - SBL)
|
||||
B - blokada dwukierunkowa (B - tak, brak litery - nie)
|
||||
*/
|
||||
const routeProps = route.split('_');
|
||||
const routeIsInternal = routeProps[0].startsWith('!');
|
||||
const routeName = routeIsInternal ? routeProps[0].replace('!', '') : routeProps[0];
|
||||
|
||||
const routeSpecs = routeProps[1];
|
||||
return {
|
||||
routeName,
|
||||
routeTracks: Number(routeSpecs[0]),
|
||||
routeElectrification: routeSpecs[1],
|
||||
routeBlockType: routeSpecs[2],
|
||||
routeHasTwoWayBlock: routeSpecs[3] ? true : false,
|
||||
routeIsInternal,
|
||||
};
|
||||
});
|
||||
},
|
||||
},
|
||||
|
||||
mounted() {
|
||||
if (this.store.currentStation) {
|
||||
this.currentRoutes = this.store.currentStation.routes;
|
||||
this.routeBackup = this.currentRoutes;
|
||||
}
|
||||
// console.log(this.currentRoutes + " git");
|
||||
|
||||
},
|
||||
|
||||
methods: {
|
||||
closeRoutesModal() {
|
||||
this.store.currentStation = null;
|
||||
this.currentRoutes = '';
|
||||
},
|
||||
|
||||
addNewRoute() {
|
||||
this.currentRoutes += (this.currentRoutes.length != 0 ? ';' : '') + `-_1EP`;
|
||||
this.saveRoutes();
|
||||
},
|
||||
|
||||
removeRoute(index: number) {
|
||||
this.currentRoutes = this.currentRoutes
|
||||
.split(';')
|
||||
.filter((_, i) => i != index)
|
||||
.join(';');
|
||||
|
||||
this.saveRoutes();
|
||||
},
|
||||
|
||||
saveRoutes() {
|
||||
const index = this.store.stationList.findIndex((station) => station.name === this.store.currentStation?.name);
|
||||
|
||||
if (index == -1) return;
|
||||
|
||||
const routeString = this.computedRouteList
|
||||
.map(
|
||||
(route) =>
|
||||
`${route.routeIsInternal ? '!' : ''}${route.routeName.trim()}_${route.routeTracks}${
|
||||
route.routeElectrification
|
||||
}${route.routeBlockType}${route.routeHasTwoWayBlock ? 'B' : ''}`
|
||||
)
|
||||
.join(';');
|
||||
|
||||
this.store.stationList[index]['routes'] = routeString;
|
||||
this.currentRoutes = routeString;
|
||||
|
||||
this.addChange(this.store.currentStation!.name, 'routes', this.routeBackup, routeString);
|
||||
},
|
||||
},
|
||||
});
|
||||
</script>
|
||||
|
||||
<style lang="scss" scoped>
|
||||
.routes-modal {
|
||||
position: fixed;
|
||||
top: 50%;
|
||||
left: 50%;
|
||||
|
||||
width: 90%;
|
||||
max-width: 800px;
|
||||
|
||||
height: 95%;
|
||||
overflow: hidden;
|
||||
padding: 0.5em 0;
|
||||
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
|
||||
transform: translate(-50%, -50%);
|
||||
z-index: 100;
|
||||
|
||||
background-color: #333;
|
||||
}
|
||||
|
||||
.modal-wrapper {
|
||||
overflow: auto;
|
||||
flex-grow: 2;
|
||||
}
|
||||
|
||||
.routes-modal h1 {
|
||||
position: sticky;
|
||||
top: 0;
|
||||
|
||||
z-index: 100;
|
||||
|
||||
background-color: #333;
|
||||
padding: 0.5em 2em;
|
||||
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.routes-modal label {
|
||||
padding: 0;
|
||||
}
|
||||
|
||||
.routes-modal .exit {
|
||||
position: absolute;
|
||||
top: 0;
|
||||
right: 0;
|
||||
z-index: 101;
|
||||
|
||||
cursor: pointer;
|
||||
margin: 0.5em 1.5em;
|
||||
}
|
||||
|
||||
.exit img {
|
||||
width: 2.5em;
|
||||
}
|
||||
|
||||
.routes-modal input {
|
||||
display: inline;
|
||||
padding: 0;
|
||||
margin: 0.5em 0;
|
||||
|
||||
color: black;
|
||||
font-size: 1em;
|
||||
|
||||
max-width: 120px;
|
||||
}
|
||||
|
||||
ul {
|
||||
list-style: none;
|
||||
padding: 0 1em;
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
ul li {
|
||||
padding: 0.65em;
|
||||
margin: 0.5em 0;
|
||||
|
||||
position: relative;
|
||||
|
||||
background-color: #222;
|
||||
}
|
||||
|
||||
.route-delete {
|
||||
position: absolute;
|
||||
top: 0;
|
||||
right: 0;
|
||||
margin: 0.5em;
|
||||
width: 1.15em;
|
||||
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
.routes-actions {
|
||||
background-color: #333;
|
||||
width: 100%;
|
||||
|
||||
margin-top: 0.5em;
|
||||
padding: 0.5em 0;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.routes-actions button {
|
||||
font-size: 1.2em;
|
||||
}
|
||||
</style>
|
||||
@@ -0,0 +1,279 @@
|
||||
<template>
|
||||
<div class="table-actions">
|
||||
<div class="pane info-pane">
|
||||
<div>
|
||||
<span v-if="store.user">
|
||||
Zalogowany jako <b>{{ store.user.name }}</b>
|
||||
</span>
|
||||
•
|
||||
<span class="info-file" :class="store.dataState">
|
||||
<span v-if="store.dataState == 'LOADING'">Ładowanie danych...</span>
|
||||
<span v-if="store.dataState == 'LOADED'">Załadowano dane z bazy!</span>
|
||||
<span v-if="store.dataState == 'ERROR'">Błąd podczas pobierania danych!</span>
|
||||
</span>
|
||||
//
|
||||
<span class="file-changes" style="color: salmon" v-if="store.unsavedChanges">Niezapisane zmiany!</span>
|
||||
<span class="file-changes" style="color: #aaa" v-else>Brak niezapisanych zmian</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="pane actions-pane">
|
||||
<button @click="addNewStation">Dodaj nową stację</button>
|
||||
<button @click="confirmLoadData">Odśwież dane</button>
|
||||
|
||||
<button @click="confirmUpdateList" :data-disabled="!store.unsavedChanges" :disabled="!store.unsavedChanges">
|
||||
Zapisz zmiany
|
||||
</button>
|
||||
<button @click="signOut">Wyloguj się</button>
|
||||
</div>
|
||||
|
||||
<div class="pane notify-pane">
|
||||
<label id="notify">
|
||||
<input
|
||||
type="checkbox"
|
||||
v-model="store.notifyDiscord"
|
||||
@input="onNotifyCheckboxChange(($event.target as HTMLInputElement)!.checked)"
|
||||
/>
|
||||
<span>
|
||||
Powiadom o zmianach: <b>{{ store.notifyDiscord ? 'TAK' : 'NIE' }}</b>
|
||||
</span>
|
||||
</label>
|
||||
</div>
|
||||
|
||||
<div class="pane search-pane">
|
||||
<input
|
||||
class="search"
|
||||
ref="search"
|
||||
type="text"
|
||||
v-model="store.searchedSceneryName"
|
||||
placeholder="Wpisz nazwę scenerii..."
|
||||
width="350"
|
||||
/>
|
||||
|
||||
<button style="margin-left: 0.5em" @click="clearInput">Wyczyść</button>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script lang="ts">
|
||||
import axios from 'axios';
|
||||
import { defineComponent } from 'vue';
|
||||
import dataMixin from '../mixins/dataMixin';
|
||||
import { useStore } from '../store';
|
||||
import { SceneryRowItem } from '../types/types';
|
||||
|
||||
export default defineComponent({
|
||||
setup() {
|
||||
return {
|
||||
store: useStore(),
|
||||
};
|
||||
},
|
||||
|
||||
mixins: [dataMixin],
|
||||
|
||||
methods: {
|
||||
confirmLoadData() {
|
||||
const confirmed = confirm('Czy na pewno chcesz odświeżyć dane? Wszelkie niezapisane zmiany zostaną utracone!');
|
||||
|
||||
if (confirmed) this.loadData();
|
||||
},
|
||||
|
||||
confirmRestoreList() {
|
||||
const confirmed = confirm(
|
||||
'Czy na pewno chcesz zresetować listę do ustawień z pliku? Wszelkie niezapisane zmiany zostaną utracone!'
|
||||
);
|
||||
|
||||
if (confirmed) this.restoreList();
|
||||
},
|
||||
|
||||
confirmUpdateList() {
|
||||
const confirmed = confirm('Czy na pewno chcesz wprowadzić obecne zmiany?');
|
||||
|
||||
if (confirmed) this.updateListToDb();
|
||||
},
|
||||
|
||||
signOut() {
|
||||
this.store.token = null;
|
||||
this.store.isAuthorized = false;
|
||||
|
||||
window.localStorage.removeItem('auth-token');
|
||||
window.localStorage.removeItem('user');
|
||||
|
||||
this.$router.push('/login');
|
||||
},
|
||||
|
||||
onNotifyCheckboxChange(value: boolean) {
|
||||
window.localStorage.setItem('notifyDiscord', Number(value).toString());
|
||||
},
|
||||
|
||||
async updateListToDb() {
|
||||
try {
|
||||
const mappedChangeList = Object.entries(this.store.changeList).map(([k, v]) => {
|
||||
return { name: k, ...v };
|
||||
});
|
||||
|
||||
await axios.post(
|
||||
`${this.API_URL}/manager/updateSceneryList`,
|
||||
{
|
||||
changeList: mappedChangeList,
|
||||
token: this.store.token,
|
||||
notify: this.store.notifyDiscord,
|
||||
},
|
||||
{
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
Authorization: `Bearer ${this.store.token}`,
|
||||
},
|
||||
}
|
||||
);
|
||||
|
||||
alert('Zapisano do bazy!');
|
||||
this.loadData();
|
||||
} catch (error) {
|
||||
this.store.alertMessage = 'Ups! Wystąpił błąd podczas zapisywania danych!';
|
||||
}
|
||||
},
|
||||
|
||||
addNewStation() {
|
||||
const name = prompt('Nazwa nowej scenerii');
|
||||
if (!name) return;
|
||||
|
||||
if (
|
||||
this.store.stationList.some(
|
||||
(station) => station.name.toLocaleLowerCase('pl-PL') == name.toLocaleLowerCase('pl-PL')
|
||||
)
|
||||
) {
|
||||
this.store.alertMessage = 'Sceneria o takiej nazwie już istnieje!';
|
||||
return;
|
||||
}
|
||||
|
||||
this.store.newStationsCount++;
|
||||
|
||||
const newSt: SceneryRowItem = {
|
||||
name,
|
||||
url: '',
|
||||
lines: '',
|
||||
project: null,
|
||||
reqLevel: -1,
|
||||
signalType: 'współczesna',
|
||||
controlType: 'SCS',
|
||||
SUP: false,
|
||||
routes: 'Test_1EPB"',
|
||||
checkpoints: '',
|
||||
authors: '',
|
||||
availability: 'default',
|
||||
};
|
||||
|
||||
this.store.changeList[name] = { ...newSt };
|
||||
this.store.changeBackupList[name] = null;
|
||||
this.store.searchedSceneryName = name;
|
||||
|
||||
this.store.unsavedChanges = true;
|
||||
|
||||
this.store.stationList.unshift(newSt);
|
||||
},
|
||||
|
||||
restoreList() {
|
||||
if (this.store.backupList.length == 0) return;
|
||||
|
||||
this.store.stationList = JSON.parse(this.store.backupList);
|
||||
this.store.changeList = {};
|
||||
this.store.changeBackupList = {};
|
||||
this.store.stationsToRemove = [];
|
||||
this.store.unsavedChanges = false;
|
||||
this.store.searchedSceneryName = '';
|
||||
},
|
||||
|
||||
clearInput() {
|
||||
this.store.searchedSceneryName = '';
|
||||
},
|
||||
},
|
||||
});
|
||||
</script>
|
||||
|
||||
<style lang="scss" scoped>
|
||||
button {
|
||||
&[data-disabled='true'] {
|
||||
user-select: none;
|
||||
-moz-user-select: none;
|
||||
-webkit-user-select: none;
|
||||
|
||||
color: #999;
|
||||
}
|
||||
}
|
||||
|
||||
.info-file {
|
||||
color: greenyellow;
|
||||
}
|
||||
|
||||
.info-file.LOADING {
|
||||
color: #aaa;
|
||||
}
|
||||
|
||||
.info-file.ERROR {
|
||||
color: salmon;
|
||||
}
|
||||
|
||||
#notify-checkbox:checked + label {
|
||||
color: gold;
|
||||
}
|
||||
|
||||
.search {
|
||||
color: black;
|
||||
|
||||
border: 1px solid white;
|
||||
outline: none;
|
||||
appearance: none;
|
||||
|
||||
padding: 0.35em 0.4em;
|
||||
}
|
||||
|
||||
.pane {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
.actions-pane {
|
||||
margin-top: 1em;
|
||||
|
||||
button {
|
||||
margin: 0.5em 0.5em 0 0;
|
||||
}
|
||||
}
|
||||
|
||||
.notify-pane {
|
||||
margin: 1em 0;
|
||||
}
|
||||
|
||||
.search-pane {
|
||||
margin-top: 0.5em;
|
||||
}
|
||||
|
||||
label#notify {
|
||||
cursor: pointer;
|
||||
text-align: center;
|
||||
|
||||
color: #000;
|
||||
|
||||
span {
|
||||
padding: 0.3em 0.25em;
|
||||
background-color: salmon;
|
||||
}
|
||||
|
||||
input {
|
||||
display: none;
|
||||
|
||||
&:checked + span {
|
||||
background-color: lightblue;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@media screen and (max-width: 550px) {
|
||||
.pane {
|
||||
justify-content: center;
|
||||
text-align: center;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
Reference in New Issue
Block a user