mirror of
https://github.com/Spythere/station-manager-2.0.git
synced 2026-05-03 05:28:13 +00:00
refactor: code organization
This commit is contained in:
+18
-142
@@ -1,17 +1,18 @@
|
||||
<template>
|
||||
<PopUpCard v-if="store.alertMessage || store.confirmMessage" />
|
||||
<PopUpCard />
|
||||
|
||||
<router-view v-if="!tokenLoading"></router-view>
|
||||
<router-view></router-view>
|
||||
</template>
|
||||
|
||||
<script lang="ts">
|
||||
import { defineComponent } from 'vue';
|
||||
import PopUpCard from './components/PopUpCard.vue';
|
||||
import { RouterView } from 'vue-router';
|
||||
import { useStore } from './store';
|
||||
import useLocalStorage from './mixins/useLocalStorage';
|
||||
import { IUser } from './types/types';
|
||||
import client from './common/http';
|
||||
import { IUser } from './types/auth.types';
|
||||
import { LoadingState } from './types/common.types';
|
||||
import { useAuthStore } from './stores/auth.store';
|
||||
import { useSceneriesStore } from './stores/sceneries.store';
|
||||
|
||||
export default defineComponent({
|
||||
components: { PopUpCard },
|
||||
@@ -22,26 +23,26 @@ export default defineComponent({
|
||||
setupStorage();
|
||||
|
||||
return {
|
||||
store: useStore(),
|
||||
tokenLoading: false,
|
||||
authStore: useAuthStore(),
|
||||
sceneriesStore: useSceneriesStore(),
|
||||
|
||||
tokenState: LoadingState.LOADING,
|
||||
LoadingState,
|
||||
};
|
||||
},
|
||||
|
||||
methods: {
|
||||
async autoLogin() {
|
||||
try {
|
||||
this.tokenLoading = true;
|
||||
|
||||
this.tokenState = LoadingState.LOADING;
|
||||
const response = await client.post<IUser>('/auth/token');
|
||||
|
||||
this.store.setUserData(response.data);
|
||||
// this.$router.push('/');
|
||||
this.authStore.setUserData(response.data);
|
||||
this.tokenState = LoadingState.SUCCESS;
|
||||
} catch (error) {
|
||||
this.store.removeUserData();
|
||||
this.authStore.removeUserData();
|
||||
this.$router.push('/login');
|
||||
this.tokenState = LoadingState.ERROR;
|
||||
}
|
||||
|
||||
this.tokenLoading = false;
|
||||
},
|
||||
},
|
||||
|
||||
@@ -49,138 +50,13 @@ export default defineComponent({
|
||||
this.autoLogin();
|
||||
|
||||
if (window.localStorage.getItem('notifyDiscord') !== null) {
|
||||
this.store.notifyDiscord = Boolean(Number(window.localStorage.getItem('notifyDiscord')));
|
||||
this.sceneriesStore.notifyDiscord = Boolean(Number(window.localStorage.getItem('notifyDiscord')));
|
||||
}
|
||||
},
|
||||
});
|
||||
</script>
|
||||
|
||||
<style lang="scss">
|
||||
@import './styles/global.scss';
|
||||
@import url('https://fonts.googleapis.com/css2?family=Inter:wght@500;600&display=swap');
|
||||
|
||||
a {
|
||||
color: white;
|
||||
text-decoration: none;
|
||||
}
|
||||
|
||||
a:visited {
|
||||
color: rgb(124, 164, 218);
|
||||
}
|
||||
|
||||
* {
|
||||
font-family: 'Inter', sans-serif;
|
||||
}
|
||||
|
||||
body,
|
||||
html {
|
||||
padding: 0 0.25em;
|
||||
margin: 0;
|
||||
background-color: #1e2341;
|
||||
color: white;
|
||||
|
||||
@media screen and (max-width: 700px) {
|
||||
font-size: calc(0.7vw + 0.7rem);
|
||||
}
|
||||
|
||||
font-size: 16px;
|
||||
}
|
||||
|
||||
button,
|
||||
select,
|
||||
input {
|
||||
font-size: inherit;
|
||||
}
|
||||
|
||||
button {
|
||||
appearance: none;
|
||||
outline: none;
|
||||
border: none;
|
||||
|
||||
background-color: #3c5a89;
|
||||
color: white;
|
||||
|
||||
padding: 0.5em 0.5em;
|
||||
|
||||
font-weight: bold;
|
||||
font-size: 0.9em;
|
||||
|
||||
cursor: pointer;
|
||||
transition: all 75ms;
|
||||
|
||||
&:hover:not([data-disabled='true']),
|
||||
&:focus-visible {
|
||||
background-color: lighten($color: #3c5a89, $amount: 10%);
|
||||
}
|
||||
|
||||
&[data-disabled='true'] {
|
||||
user-select: none;
|
||||
-moz-user-select: none;
|
||||
-webkit-user-select: none;
|
||||
|
||||
color: #999;
|
||||
}
|
||||
|
||||
&.btn--icon {
|
||||
background-color: transparent;
|
||||
padding: 0;
|
||||
}
|
||||
|
||||
&:focus-visible {
|
||||
outline: 1px solid gold;
|
||||
}
|
||||
}
|
||||
|
||||
// Text
|
||||
.text {
|
||||
&--accent {
|
||||
color: gold;
|
||||
}
|
||||
}
|
||||
|
||||
// Card modal
|
||||
.g-card {
|
||||
position: fixed;
|
||||
z-index: 999;
|
||||
top: 50%;
|
||||
left: 50%;
|
||||
transform: translate(-50%, -50%);
|
||||
|
||||
width: 90vw;
|
||||
max-width: 550px;
|
||||
|
||||
padding: 0.5em 1em;
|
||||
|
||||
border-radius: 1em;
|
||||
|
||||
background-color: #1d1c33;
|
||||
box-shadow: 0 0 6px 1px #414141;
|
||||
}
|
||||
|
||||
// Scrollbar
|
||||
/* width */
|
||||
::-webkit-scrollbar {
|
||||
width: 7px;
|
||||
height: 7px;
|
||||
}
|
||||
|
||||
/* Track */
|
||||
::-webkit-scrollbar-track {
|
||||
background: #333;
|
||||
}
|
||||
|
||||
/* Corner */
|
||||
::-webkit-scrollbar-corner {
|
||||
background: #333;
|
||||
}
|
||||
|
||||
/* Handle */
|
||||
::-webkit-scrollbar-thumb {
|
||||
background: #888;
|
||||
border-radius: 1rem;
|
||||
}
|
||||
|
||||
/* Handle on hover */
|
||||
::-webkit-scrollbar-thumb:hover {
|
||||
background: #aaa;
|
||||
}
|
||||
</style>
|
||||
|
||||
@@ -40,22 +40,22 @@
|
||||
|
||||
<script lang="ts">
|
||||
import { defineComponent } from 'vue';
|
||||
import { useStore } from '../store';
|
||||
import { Availability, HeaderTypes } from '../types/types';
|
||||
import { getAvailabilityValue } from '../types/typeUitls';
|
||||
import RouteList from './RouteList.vue';
|
||||
import { Availability, AvailabilityTypes, HeaderTypes } from '../types/sceneries.types';
|
||||
import { useSceneriesStore } from '../stores/sceneries.store';
|
||||
|
||||
export default defineComponent({
|
||||
components: { RouteList },
|
||||
data() {
|
||||
return {
|
||||
store: useStore(),
|
||||
getAvailabilityValue,
|
||||
sceneriesStore: useSceneriesStore(),
|
||||
HeaderTypes,
|
||||
};
|
||||
},
|
||||
|
||||
computed: {
|
||||
changeList() {
|
||||
return this.store.changeList.map((changeItem) => {
|
||||
return this.sceneriesStore.changeList.map((changeItem) => {
|
||||
return {
|
||||
name: changeItem.name,
|
||||
toRemove: changeItem.toRemove,
|
||||
@@ -66,7 +66,12 @@ export default defineComponent({
|
||||
});
|
||||
},
|
||||
},
|
||||
components: { RouteList },
|
||||
|
||||
methods: {
|
||||
getAvailabilityValue(availability: Availability) {
|
||||
return AvailabilityTypes[availability];
|
||||
},
|
||||
},
|
||||
});
|
||||
</script>
|
||||
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
<template>
|
||||
<div class="changes-modal">
|
||||
<transition name="modal-anim">
|
||||
<div class="content g-card" v-if="store.changesResponse.length > 0">
|
||||
<div class="content g-card" v-if="sceneriesStore.changesResponse.length > 0">
|
||||
<h2>Wprowadzone zmiany</h2>
|
||||
<div>
|
||||
<ul class="changelog">
|
||||
<li v-for="change in store.changesResponse">{{ change }}</li>
|
||||
<li v-for="change in sceneriesStore.changesResponse">{{ change }}</li>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
@@ -15,12 +15,12 @@
|
||||
|
||||
<script lang="ts">
|
||||
import { defineComponent } from 'vue';
|
||||
import { useStore } from '../store';
|
||||
import { useSceneriesStore } from '../stores/sceneries.store';
|
||||
|
||||
export default defineComponent({
|
||||
setup() {
|
||||
return {
|
||||
store: useStore(),
|
||||
sceneriesStore: useSceneriesStore(),
|
||||
};
|
||||
},
|
||||
});
|
||||
|
||||
@@ -1,40 +1,42 @@
|
||||
<template>
|
||||
<div class="bg-dimmer"></div>
|
||||
<div class="g-card popup-card">
|
||||
<div class="card_content">
|
||||
<p>{{ store.alertMessage || store.confirmMessage }}</p>
|
||||
</div>
|
||||
<div v-if="globalStore.alertMessage || globalStore.confirmMessage">
|
||||
<div class="bg-dimmer"></div>
|
||||
<div class="g-card popup-card">
|
||||
<div class="card_content">
|
||||
<p>{{ globalStore.alertMessage || globalStore.confirmMessage }}</p>
|
||||
</div>
|
||||
|
||||
<div class="card_actions">
|
||||
<span v-if="store.alertMessage">
|
||||
<button @click="closeCard">OK!</button>
|
||||
</span>
|
||||
<div class="card_actions">
|
||||
<span v-if="globalStore.alertMessage">
|
||||
<button @click="closeCard">OK!</button>
|
||||
</span>
|
||||
|
||||
<span v-else-if="store.confirmMessage">
|
||||
<button @click="confirm">OK!</button>
|
||||
<button @click="closeCard">Anuluj</button>
|
||||
</span>
|
||||
<span v-else-if="globalStore.confirmMessage">
|
||||
<button @click="confirm">OK!</button>
|
||||
<button @click="closeCard">Anuluj</button>
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script lang="ts">
|
||||
import { defineComponent } from 'vue';
|
||||
import { useStore } from '../store';
|
||||
import { useGlobalStore } from '../stores/global.store';
|
||||
|
||||
export default defineComponent({
|
||||
emits: ['confirm'],
|
||||
|
||||
setup() {
|
||||
return {
|
||||
store: useStore(),
|
||||
globalStore: useGlobalStore(),
|
||||
};
|
||||
},
|
||||
|
||||
methods: {
|
||||
closeCard() {
|
||||
this.store.alertMessage = '';
|
||||
this.store.confirmMessage = '';
|
||||
this.globalStore.alertMessage = '';
|
||||
this.globalStore.confirmMessage = '';
|
||||
},
|
||||
|
||||
confirm() {
|
||||
|
||||
@@ -18,7 +18,7 @@
|
||||
|
||||
<script lang="ts">
|
||||
import { PropType, defineComponent } from 'vue';
|
||||
import { SceneryRoutesInfo } from '../types/types';
|
||||
import { SceneryRoutesInfo } from '../types/sceneries.types';
|
||||
|
||||
export default defineComponent({
|
||||
props: {
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
<template>
|
||||
<div class="bg" @click="closeRoutesModal"></div>
|
||||
<div class="routes-modal" v-if="store.currentStation" @keydown.esc="closeRoutesModal" tabindex="0" ref="modal">
|
||||
<div class="routes-modal" v-if="sceneriesStore.currentStation" @keydown.esc="closeRoutesModal" tabindex="0" ref="modal">
|
||||
<div class="modal-content">
|
||||
<div class="modal-wrapper">
|
||||
<h1>
|
||||
Szlaki na scenerii {{ store.currentStation.name }}
|
||||
Szlaki na scenerii {{ sceneriesStore.currentStation.name }}
|
||||
<div class="exit" @click="closeRoutesModal">
|
||||
<img src="/icon-exit.svg" alt="exit icon" />
|
||||
</div>
|
||||
@@ -103,17 +103,17 @@
|
||||
<script lang="ts">
|
||||
import { Ref, computed, defineComponent, ref } from 'vue';
|
||||
import changeMixin from '../mixins/changeMixin';
|
||||
import { useStore } from '../store';
|
||||
import { SceneryRoutesInfo } from '../types/types';
|
||||
import { SceneryRoutesInfo } from '../types/sceneries.types';
|
||||
import { useSceneriesStore } from '../stores/sceneries.store';
|
||||
|
||||
export default defineComponent({
|
||||
setup() {
|
||||
const store = useStore();
|
||||
const sceneriesStore = useSceneriesStore();
|
||||
const currentRoutes: Ref<SceneryRoutesInfo[]> = ref([]);
|
||||
const routeBackup: Ref<SceneryRoutesInfo[]> = ref([]);
|
||||
|
||||
return {
|
||||
store,
|
||||
sceneriesStore,
|
||||
routeBackup,
|
||||
currentRoutes,
|
||||
};
|
||||
@@ -121,13 +121,11 @@ export default defineComponent({
|
||||
|
||||
mixins: [changeMixin],
|
||||
|
||||
data: () => ({}),
|
||||
|
||||
mounted() {
|
||||
if (this.store.currentStation) {
|
||||
if (this.sceneriesStore.currentStation) {
|
||||
// unrefed copy of routesInfo object
|
||||
this.currentRoutes = JSON.parse(JSON.stringify(this.store.currentStation.routesInfo));
|
||||
this.routeBackup = [...this.store.currentStation.routesInfo];
|
||||
this.currentRoutes = JSON.parse(JSON.stringify(this.sceneriesStore.currentStation.routesInfo));
|
||||
this.routeBackup = [...this.sceneriesStore.currentStation.routesInfo];
|
||||
|
||||
(this.$refs['modal'] as HTMLElement).focus();
|
||||
}
|
||||
@@ -135,7 +133,7 @@ export default defineComponent({
|
||||
|
||||
methods: {
|
||||
closeRoutesModal() {
|
||||
this.store.currentStation = null;
|
||||
this.sceneriesStore.currentStation = null;
|
||||
},
|
||||
|
||||
addNewRoute() {
|
||||
@@ -157,7 +155,7 @@ export default defineComponent({
|
||||
},
|
||||
|
||||
parseRoutes() {
|
||||
const routeString = this.store.currentStation?.routesInfo
|
||||
const routeString = this.sceneriesStore.currentStation?.routesInfo
|
||||
.map(
|
||||
(route) =>
|
||||
`${route.isInternal ? '!' : ''}${route.routeName.trim()}_${route.routeTracks}${route.isElectric ? 'E' : 'N'}${
|
||||
@@ -170,14 +168,12 @@ export default defineComponent({
|
||||
},
|
||||
|
||||
saveRoutes() {
|
||||
const index = this.store.stationList.findIndex((station) => station.name === this.store.currentStation?.name);
|
||||
const index = this.sceneriesStore.stationList.findIndex((station) => station.name === this.sceneriesStore.currentStation?.name);
|
||||
|
||||
if (index == -1) return;
|
||||
|
||||
// const routeString = this.parseRoutes();
|
||||
|
||||
this.addChange(this.store.currentStation!, 'routesInfo', this.routeBackup, this.currentRoutes);
|
||||
this.store.stationList[index]['routesInfo'] = this.currentRoutes;
|
||||
this.addChange(this.sceneriesStore.currentStation!, 'routesInfo', this.routeBackup, this.currentRoutes);
|
||||
this.sceneriesStore.stationList[index]['routesInfo'] = this.currentRoutes;
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
@@ -8,19 +8,19 @@
|
||||
<div>
|
||||
<div style="font-size: 0.75em; color: #ccc">v{{ packageVersion }}</div>
|
||||
<div>
|
||||
<span v-if="store.user">
|
||||
Zalogowany jako <b>{{ store.user.name }}</b>
|
||||
<span v-if="authStore.user != null">
|
||||
Zalogowany jako <b>{{ authStore.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 class="info-file" :class="sceneriesStore.dataState">
|
||||
<span v-if="sceneriesStore.dataState == LoadingState.LOADING">Ładowanie danych...</span>
|
||||
<span v-if="sceneriesStore.dataState == LoadingState.SUCCESS">Załadowano dane z bazy!</span>
|
||||
<span v-if="sceneriesStore.dataState == LoadingState.ERROR">Błąd podczas pobierania danych!</span>
|
||||
</span>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<span class="file-changes" style="color: salmon" v-if="store.unsavedChanges">Niezapisane zmiany!</span>
|
||||
<span class="file-changes" style="color: salmon" v-if="sceneriesStore.unsavedChanges">Niezapisane zmiany!</span>
|
||||
<span class="file-changes" style="color: #aaa" v-else>Brak niezapisanych zmian</span>
|
||||
</div>
|
||||
</div>
|
||||
@@ -29,40 +29,42 @@
|
||||
<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="confirmUpdateList" :data-disabled="!sceneriesStore.unsavedChanges" :disabled="!sceneriesStore.unsavedChanges">
|
||||
Zapisz zmiany
|
||||
</button>
|
||||
<button @click="signOut">Wyloguj się</button>
|
||||
</div>
|
||||
|
||||
<div class="pane notify-pane">
|
||||
<label class="notify">
|
||||
<input type="checkbox" v-model="store.notifyDiscord" @input="onNotifyCheckboxChange(($event.target as HTMLInputElement)!.checked)" />
|
||||
<input type="checkbox" v-model="sceneriesStore.notifyDiscord" @input="onNotifyCheckboxChange(($event.target as HTMLInputElement)!.checked)" />
|
||||
<span>
|
||||
Powiadom o zmianach: <b>{{ store.notifyDiscord ? 'TAK' : 'NIE' }}</b>
|
||||
Powiadom o zmianach: <b>{{ sceneriesStore.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" />
|
||||
<input class="search" ref="search" type="text" v-model="sceneriesStore.searchedSceneryName" placeholder="Wpisz nazwę scenerii..." width="350" />
|
||||
|
||||
<button @click="clearInput">Wyczyść</button>
|
||||
</div>
|
||||
|
||||
<div class="pane">
|
||||
Pokazuj maks.
|
||||
<input type="number" min="1" v-model="store.maxVisibleResults" style="width: 3em; margin: 0 0.5em" />
|
||||
<input type="number" min="1" v-model="sceneriesStore.maxVisibleResults" style="width: 3em; margin: 0 0.5em" />
|
||||
wyników
|
||||
</div>
|
||||
|
||||
<div class="pane">
|
||||
Obecnie pokazane scenerie:
|
||||
{{ Math.min(store.maxVisibleResults, store.stationList.length, store.sortedStationList.length) }} /
|
||||
{{ store.stationList.length }}
|
||||
{{ Math.min(sceneriesStore.maxVisibleResults, sceneriesStore.stationList.length, sceneriesStore.sortedStationList.length) }} /
|
||||
{{ sceneriesStore.stationList.length }}
|
||||
</div>
|
||||
|
||||
<div class="pane">
|
||||
<button @click="changelogVisible = !changelogVisible">
|
||||
{{ changelogVisible ? 'Ukryj' : 'Pokaż' }} changelog ({{ store.changeList.length }})
|
||||
{{ changelogVisible ? 'Ukryj' : 'Pokaż' }} changelog ({{ sceneriesStore.changeList.length }})
|
||||
</button>
|
||||
</div>
|
||||
|
||||
@@ -72,17 +74,24 @@
|
||||
|
||||
<script lang="ts">
|
||||
import { defineComponent } from 'vue';
|
||||
import { useStore } from '../store';
|
||||
import { SceneryRowItem } from '../types/types';
|
||||
import client from '../common/http';
|
||||
|
||||
import { version } from '../../package.json';
|
||||
import Changelog from './Changelog.vue';
|
||||
import { useSceneriesStore } from '../stores/sceneries.store';
|
||||
import { LoadingState } from '../types/common.types';
|
||||
import { SceneryRowItem } from '../types/sceneries.types';
|
||||
import { useGlobalStore } from '../stores/global.store';
|
||||
import { useAuthStore } from '../stores/auth.store';
|
||||
|
||||
export default defineComponent({
|
||||
setup() {
|
||||
return {
|
||||
store: useStore(),
|
||||
sceneriesStore: useSceneriesStore(),
|
||||
globalStore: useGlobalStore(),
|
||||
authStore: useAuthStore(),
|
||||
|
||||
LoadingState,
|
||||
};
|
||||
},
|
||||
data() {
|
||||
@@ -94,48 +103,54 @@ export default defineComponent({
|
||||
methods: {
|
||||
confirmLoadData() {
|
||||
const confirmed = confirm('Czy na pewno chcesz odświeżyć dane? Wszelkie niezapisane zmiany zostaną utracone!');
|
||||
if (confirmed) this.store.fetchSceneriesData();
|
||||
if (confirmed) this.sceneriesStore.fetchSceneriesData();
|
||||
},
|
||||
|
||||
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();
|
||||
},
|
||||
|
||||
async signOut() {
|
||||
await client.post('/auth/logout');
|
||||
this.$router.push('/login');
|
||||
this.store.removeUserData();
|
||||
this.authStore.removeUserData();
|
||||
},
|
||||
|
||||
onNotifyCheckboxChange(value: boolean) {
|
||||
window.localStorage.setItem('notifyDiscord', Number(value).toString());
|
||||
},
|
||||
|
||||
async updateListToDb() {
|
||||
try {
|
||||
const mappedChangeList = this.store.changeList.map((v) => {
|
||||
const mappedChangeList = this.sceneriesStore.changeList.map((v) => {
|
||||
if (/^#/.test(v.id.toString())) {
|
||||
return { ...v, id: undefined };
|
||||
}
|
||||
return { ...v };
|
||||
});
|
||||
const updateResData = (await this.store.updateSceneriesData(mappedChangeList)).data;
|
||||
this.store.changesResponse = updateResData;
|
||||
this.store.fetchSceneriesData();
|
||||
const updateResData = (await this.sceneriesStore.updateSceneriesData(mappedChangeList)).data;
|
||||
this.sceneriesStore.changesResponse = updateResData;
|
||||
this.sceneriesStore.fetchSceneriesData();
|
||||
} catch (error) {
|
||||
this.store.alertMessage = 'Ups! Wystąpił błąd podczas zapisywania danych!';
|
||||
this.globalStore.alertMessage = 'Ups! Wystąpił błąd podczas zapisywania danych!';
|
||||
console.error(error);
|
||||
}
|
||||
},
|
||||
|
||||
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!';
|
||||
if (this.sceneriesStore.stationList.some((station) => station.name.toLocaleLowerCase('pl-PL') == name.toLocaleLowerCase('pl-PL'))) {
|
||||
this.globalStore.alertMessage = 'Sceneria o takiej nazwie już istnieje!';
|
||||
return;
|
||||
}
|
||||
this.store.newStationsCount++;
|
||||
this.sceneriesStore.newStationsCount++;
|
||||
const newSt: SceneryRowItem = {
|
||||
name,
|
||||
abbr: name.slice(0, 2),
|
||||
@@ -167,20 +182,20 @@ export default defineComponent({
|
||||
availability: 'default',
|
||||
id: `#${Math.random().toString(32).substring(2)}`,
|
||||
};
|
||||
this.store.changeList.push({ ...newSt });
|
||||
this.sceneriesStore.changeList.push({ ...newSt });
|
||||
// this.store.changeBackupList[newSt.id] = null;
|
||||
this.store.searchedSceneryName = name;
|
||||
this.store.stationList.unshift(newSt);
|
||||
this.sceneriesStore.searchedSceneryName = name;
|
||||
this.sceneriesStore.stationList.unshift(newSt);
|
||||
},
|
||||
restoreList() {
|
||||
if (this.store.backupList.length == 0) return;
|
||||
this.store.stationList = JSON.parse(JSON.stringify(this.store.backupList));
|
||||
this.store.changeList = [];
|
||||
this.store.stationsToRemove = [];
|
||||
this.store.searchedSceneryName = '';
|
||||
if (this.sceneriesStore.backupList.length == 0) return;
|
||||
this.sceneriesStore.stationList = JSON.parse(JSON.stringify(this.sceneriesStore.backupList));
|
||||
this.sceneriesStore.changeList = [];
|
||||
this.sceneriesStore.stationsToRemove = [];
|
||||
this.sceneriesStore.searchedSceneryName = '';
|
||||
},
|
||||
clearInput() {
|
||||
this.store.searchedSceneryName = '';
|
||||
this.sceneriesStore.searchedSceneryName = '';
|
||||
},
|
||||
},
|
||||
components: { Changelog },
|
||||
|
||||
@@ -21,18 +21,15 @@
|
||||
|
||||
<script lang="ts">
|
||||
import { defineComponent } from 'vue';
|
||||
import { useStore } from '../store';
|
||||
|
||||
import { useSceneriesStore } from '../stores/sceneries.store';
|
||||
export default defineComponent({
|
||||
setup() {
|
||||
return {
|
||||
store: useStore(),
|
||||
};
|
||||
},
|
||||
data: () => ({
|
||||
sceneriesStore: useSceneriesStore(),
|
||||
}),
|
||||
|
||||
computed: {
|
||||
changesResponseComp() {
|
||||
return this.store.changesResponse.map((ch) => ({
|
||||
return this.sceneriesStore.changesResponse.map((ch) => ({
|
||||
resolved: ch.split(' ')[0] == 'v',
|
||||
message: ch.replace(/^[v|x] /, ''),
|
||||
}));
|
||||
@@ -41,7 +38,7 @@ export default defineComponent({
|
||||
|
||||
methods: {
|
||||
closeCard() {
|
||||
this.store.changesResponse.length = 0;
|
||||
this.sceneriesStore.changesResponse.length = 0;
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
+5
-17
@@ -4,26 +4,14 @@ import App from './App.vue';
|
||||
import router from './router';
|
||||
|
||||
import { createPinia } from 'pinia';
|
||||
import { useStore } from './store';
|
||||
import { createRouteGuard } from './routeGuard';
|
||||
|
||||
const pinia = createPinia();
|
||||
const app = createApp(App);
|
||||
|
||||
app.use(pinia).use(router);
|
||||
app.use(pinia);
|
||||
app.use(router);
|
||||
app.mount('#app');
|
||||
|
||||
router.beforeEach((to, from, next) => {
|
||||
const store = useStore();
|
||||
|
||||
if (to.meta.protected && !store.user && !window.localStorage.getItem('user')) {
|
||||
next('/login');
|
||||
return;
|
||||
}
|
||||
|
||||
if (to.meta.loginPage && window.localStorage.getItem('user')) {
|
||||
next('/');
|
||||
return;
|
||||
}
|
||||
|
||||
next();
|
||||
});
|
||||
// Route guard
|
||||
createRouteGuard(router);
|
||||
|
||||
+12
-14
@@ -1,13 +1,11 @@
|
||||
import { defineComponent } from 'vue';
|
||||
import { useStore } from '../store';
|
||||
import { ChangeProp, SceneryRowItem } from '../types/types';
|
||||
import { useSceneriesStore } from '../stores/sceneries.store';
|
||||
import { ChangeProp, SceneryRowItem } from '../types/sceneries.types';
|
||||
|
||||
export default defineComponent({
|
||||
setup() {
|
||||
return {
|
||||
store: useStore(),
|
||||
};
|
||||
},
|
||||
data: () => ({
|
||||
sceneriesStore: useSceneriesStore(),
|
||||
}),
|
||||
|
||||
methods: {
|
||||
addChange(sceneryData: SceneryRowItem, propName: string, oldValue: any, newValue: any) {
|
||||
@@ -17,22 +15,22 @@ export default defineComponent({
|
||||
|
||||
const sceneryId = sceneryData.id;
|
||||
|
||||
let changeItem = this.store.changeList.find((item) => item.id == sceneryId);
|
||||
let changeItem = this.sceneriesStore.changeList.find((item) => item.id == sceneryId);
|
||||
|
||||
if (!changeItem) {
|
||||
changeItem = { id: sceneryId, name: sceneryData.name };
|
||||
this.store.changeList.push(changeItem);
|
||||
this.sceneriesStore.changeList.push(changeItem);
|
||||
}
|
||||
|
||||
changeItem[changePropName] = newValue;
|
||||
|
||||
const sceneryBackup = this.store.backupList.find((scenery) => scenery.id == sceneryId);
|
||||
const sceneryBackup = this.sceneriesStore.backupList.find((scenery) => scenery.id == sceneryId);
|
||||
if (!sceneryBackup) return;
|
||||
|
||||
if (sceneryBackup && sceneryBackup[changePropName] == changeItem[changePropName]) delete changeItem[changePropName];
|
||||
|
||||
if (Object.keys(changeItem).length == 2 && changeItem.id)
|
||||
this.store.changeList = this.store.changeList.filter((item) => changeItem?.id != item.id);
|
||||
this.sceneriesStore.changeList = this.sceneriesStore.changeList.filter((item) => changeItem?.id != item.id);
|
||||
},
|
||||
|
||||
addRemovalChange(sceneryData: SceneryRowItem) {
|
||||
@@ -40,13 +38,13 @@ export default defineComponent({
|
||||
|
||||
// Sceneria niewpisana do bazy danych (id stworzone przez stronę)
|
||||
if (sceneryId.toString().startsWith('#')) {
|
||||
this.store.changeList = this.store.changeList.filter((item) => item.id != sceneryId);
|
||||
this.sceneriesStore.changeList = this.sceneriesStore.changeList.filter((item) => item.id != sceneryId);
|
||||
return;
|
||||
}
|
||||
|
||||
let changeItem = this.store.changeList.find((item) => item.id == sceneryId);
|
||||
let changeItem = this.sceneriesStore.changeList.find((item) => item.id == sceneryId);
|
||||
|
||||
if (!changeItem) this.store.changeList.push({ id: sceneryId, name: sceneryData.name, toRemove: true });
|
||||
if (!changeItem) this.sceneriesStore.changeList.push({ id: sceneryId, name: sceneryData.name, toRemove: true });
|
||||
else changeItem['toRemove'] = true;
|
||||
},
|
||||
},
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { defineComponent } from 'vue';
|
||||
import { SceneryRowItem } from '../types/types';
|
||||
import { SceneryRowItem } from '../types/sceneries.types';
|
||||
|
||||
export default defineComponent({
|
||||
methods: {
|
||||
|
||||
@@ -1,16 +1,16 @@
|
||||
import { computed, watch } from 'vue';
|
||||
import { useStore } from '../store';
|
||||
import { useSceneriesStore } from '../stores/sceneries.store';
|
||||
|
||||
export default () => {
|
||||
const store = useStore();
|
||||
const sceneriesStore = useSceneriesStore();
|
||||
|
||||
const setupStorage = () => {
|
||||
// On mounted
|
||||
store.maxVisibleResults = Number(window.localStorage.getItem('maxVisibleResults')) || 30;
|
||||
sceneriesStore.maxVisibleResults = Number(window.localStorage.getItem('maxVisibleResults')) || 30;
|
||||
|
||||
// Max vis. results
|
||||
watch(
|
||||
computed(() => store.maxVisibleResults),
|
||||
computed(() => sceneriesStore.maxVisibleResults),
|
||||
(v) => {
|
||||
window.localStorage.setItem('maxVisibleResults', v.toString());
|
||||
}
|
||||
@@ -21,4 +21,3 @@ export default () => {
|
||||
setupStorage,
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
@@ -0,0 +1,23 @@
|
||||
import { Router } from 'vue-router';
|
||||
import { useAuthStore } from './stores/auth.store';
|
||||
|
||||
export function createRouteGuard(router: Router) {
|
||||
router.beforeEach((to, from, next) => {
|
||||
const authStore = useAuthStore();
|
||||
|
||||
console.log(to);
|
||||
|
||||
|
||||
if (to.meta.protected && !authStore.user && !window.localStorage.getItem('user')) {
|
||||
next('/login');
|
||||
return;
|
||||
}
|
||||
|
||||
if (to.meta.loginPage && window.localStorage.getItem('user')) {
|
||||
next('/');
|
||||
return;
|
||||
}
|
||||
|
||||
next();
|
||||
});
|
||||
}
|
||||
@@ -17,6 +17,14 @@ const routes: Array<RouteRecordRaw> = [
|
||||
},
|
||||
component: () => import('./views/LoginView.vue'),
|
||||
},
|
||||
{
|
||||
path: '/vehicles',
|
||||
name: 'VehiclesManagerView',
|
||||
meta: {
|
||||
protected: true,
|
||||
},
|
||||
component: () => import('./views/VehiclesManagerView.vue'),
|
||||
},
|
||||
];
|
||||
|
||||
const router = createRouter({
|
||||
|
||||
@@ -1,86 +0,0 @@
|
||||
import { defineStore } from 'pinia';
|
||||
import { AuthState, IStore, IUser, SceneryRowItem } from './types/types';
|
||||
import client from './common/http';
|
||||
|
||||
export const useStore = defineStore('store', {
|
||||
state: () =>
|
||||
({
|
||||
dataState: 'LOADING',
|
||||
authState: AuthState.LOADING,
|
||||
|
||||
stationList: [],
|
||||
backupList: [],
|
||||
stationsToRemove: [],
|
||||
changeList: [],
|
||||
newStationsCount: 0,
|
||||
routesModalVisible: true,
|
||||
currentStation: null,
|
||||
searchedSceneryName: '',
|
||||
selectedStationName: '',
|
||||
|
||||
user: null,
|
||||
notifyDiscord: true,
|
||||
|
||||
alertMessage: '',
|
||||
confirmMessage: '',
|
||||
|
||||
maxVisibleResults: 15,
|
||||
|
||||
changesResponse: [],
|
||||
} as IStore),
|
||||
|
||||
actions: {
|
||||
async fetchSceneriesData() {
|
||||
this.dataState = 'LOADING';
|
||||
|
||||
try {
|
||||
const data = (await client.get<SceneryRowItem[]>(`api/getSceneries?t=${Date.now()}`)).data;
|
||||
this.dataState = 'LOADED';
|
||||
this.backupList = JSON.parse(JSON.stringify(data));
|
||||
this.stationList = data;
|
||||
this.changeList = [];
|
||||
} catch (error: any) {
|
||||
this.dataState = 'ERROR';
|
||||
console.error('Błąd podczas ładowania danych: ', error?.response || error);
|
||||
}
|
||||
},
|
||||
|
||||
async updateSceneriesData(mappedChangeList: any[]) {
|
||||
try {
|
||||
const response = await client.post('manager/updateSceneryList', {
|
||||
changeList: mappedChangeList,
|
||||
notify: this.notifyDiscord,
|
||||
});
|
||||
|
||||
return response;
|
||||
} catch (error) {
|
||||
throw error;
|
||||
}
|
||||
},
|
||||
|
||||
setUserData(responseData: IUser) {
|
||||
this.authState = AuthState.AUTHORIZED;
|
||||
this.user = responseData;
|
||||
window.localStorage.setItem('user', JSON.stringify(responseData));
|
||||
},
|
||||
|
||||
removeUserData() {
|
||||
this.authState = AuthState.UNAUTHORIZED;
|
||||
this.user = null;
|
||||
window.localStorage.removeItem('user');
|
||||
},
|
||||
},
|
||||
|
||||
getters: {
|
||||
sortedStationList(state) {
|
||||
return state.stationList
|
||||
.filter((station) => station.name.toLowerCase().startsWith(state.searchedSceneryName.toLowerCase()))
|
||||
.sort((a, b) => (a.name > b.name ? 1 : -1))
|
||||
.filter((_, i) => i < state.maxVisibleResults);
|
||||
},
|
||||
|
||||
unsavedChanges(state) {
|
||||
return Object.keys(state.changeList).length != 0;
|
||||
},
|
||||
},
|
||||
});
|
||||
@@ -0,0 +1,23 @@
|
||||
import { defineStore } from 'pinia';
|
||||
import { AuthState, IUser } from '../types/auth.types';
|
||||
|
||||
export const useAuthStore = defineStore('authStore', {
|
||||
state: () => ({
|
||||
authState: AuthState.LOADING,
|
||||
user: null as IUser | null,
|
||||
}),
|
||||
|
||||
actions: {
|
||||
setUserData(responseData: IUser) {
|
||||
this.authState = AuthState.AUTHORIZED;
|
||||
this.user = responseData;
|
||||
window.localStorage.setItem('user', JSON.stringify(responseData));
|
||||
},
|
||||
|
||||
removeUserData() {
|
||||
this.authState = AuthState.UNAUTHORIZED;
|
||||
this.user = null;
|
||||
window.localStorage.removeItem('user');
|
||||
},
|
||||
},
|
||||
});
|
||||
@@ -0,0 +1,8 @@
|
||||
import { defineStore } from 'pinia';
|
||||
|
||||
export const useGlobalStore = defineStore('globalStore', {
|
||||
state: () => ({
|
||||
alertMessage: '',
|
||||
confirmMessage: '',
|
||||
}),
|
||||
});
|
||||
@@ -0,0 +1,73 @@
|
||||
import { defineStore } from 'pinia';
|
||||
import client from '../common/http';
|
||||
import { ChangeItem, SceneryRowItem } from '../types/sceneries.types';
|
||||
import { LoadingState } from '../types/common.types';
|
||||
|
||||
export const useSceneriesStore = defineStore('sceneriesStore', {
|
||||
state: () => ({
|
||||
dataState: LoadingState.INIT,
|
||||
|
||||
stationList: [] as SceneryRowItem[],
|
||||
backupList: [] as SceneryRowItem[],
|
||||
changeList: [] as ChangeItem[],
|
||||
stationsToRemove: [] as string[],
|
||||
|
||||
newStationsCount: 0,
|
||||
routesModalVisible: true,
|
||||
|
||||
currentStation: null as SceneryRowItem | null,
|
||||
searchedSceneryName: '',
|
||||
selectedStationName: '',
|
||||
|
||||
notifyDiscord: true,
|
||||
|
||||
|
||||
|
||||
maxVisibleResults: 15,
|
||||
|
||||
changesResponse: [] as string[],
|
||||
}),
|
||||
|
||||
actions: {
|
||||
async fetchSceneriesData() {
|
||||
this.dataState = LoadingState.LOADING;
|
||||
|
||||
try {
|
||||
const data = (await client.get<SceneryRowItem[]>(`api/getSceneries?t=${Date.now()}`)).data;
|
||||
this.dataState = LoadingState.SUCCESS;
|
||||
this.backupList = JSON.parse(JSON.stringify(data));
|
||||
this.stationList = data;
|
||||
this.changeList = [];
|
||||
} catch (error: any) {
|
||||
this.dataState = LoadingState.ERROR;
|
||||
console.error('Błąd podczas ładowania danych: ', error?.response || error);
|
||||
}
|
||||
},
|
||||
|
||||
async updateSceneriesData(mappedChangeList: any[]) {
|
||||
try {
|
||||
const response = await client.post('manager/updateSceneryList', {
|
||||
changeList: mappedChangeList,
|
||||
notify: this.notifyDiscord,
|
||||
});
|
||||
|
||||
return response;
|
||||
} catch (error) {
|
||||
throw error;
|
||||
}
|
||||
},
|
||||
},
|
||||
|
||||
getters: {
|
||||
sortedStationList(state) {
|
||||
return state.stationList
|
||||
.filter((station) => station.name.toLowerCase().startsWith(state.searchedSceneryName.toLowerCase()))
|
||||
.sort((a, b) => (a.name > b.name ? 1 : -1))
|
||||
.filter((_, i) => i < state.maxVisibleResults);
|
||||
},
|
||||
|
||||
unsavedChanges(state) {
|
||||
return Object.keys(state.changeList).length != 0;
|
||||
},
|
||||
},
|
||||
});
|
||||
@@ -0,0 +1,30 @@
|
||||
import { defineStore } from 'pinia';
|
||||
import client from '../common/http';
|
||||
import { IVehicle, IVehicleTableRow, VehicleAPIResponse } from '../types/vehicles.types';
|
||||
import { LoadingState } from '../types/common.types';
|
||||
|
||||
export const useVehiclesStore = defineStore('vehiclesStore', {
|
||||
state: () => ({
|
||||
vehicles: [] as IVehicle[],
|
||||
dataState: LoadingState.INIT,
|
||||
|
||||
vehiclesTable: [] as IVehicleTableRow[],
|
||||
}),
|
||||
|
||||
actions: {
|
||||
async fetchVehicles() {
|
||||
try {
|
||||
this.dataState = LoadingState.LOADING;
|
||||
|
||||
const vehiclesResponseData = (await client.get<VehicleAPIResponse>(`api/getVehicles`)).data;
|
||||
this.vehicles = vehiclesResponseData;
|
||||
this.vehiclesTable = vehiclesResponseData.map((v) => ({ vehicleRef: v, pendingChanges: {} }));
|
||||
|
||||
this.dataState = LoadingState.SUCCESS;
|
||||
} catch (error) {
|
||||
console.error('Wystąpił błąd podczas pobierania danych o pojazdach!', error);
|
||||
this.dataState = LoadingState.ERROR;
|
||||
}
|
||||
},
|
||||
},
|
||||
});
|
||||
@@ -0,0 +1,130 @@
|
||||
body,
|
||||
html {
|
||||
margin: 0;
|
||||
background-color: #1e2341;
|
||||
color: white;
|
||||
box-sizing: border-box;
|
||||
|
||||
@media screen and (max-width: 700px) {
|
||||
font-size: calc(0.7vw + 0.7rem);
|
||||
}
|
||||
|
||||
font-size: 16px;
|
||||
}
|
||||
|
||||
#app {
|
||||
padding: 0 0.25em;
|
||||
}
|
||||
|
||||
a {
|
||||
color: white;
|
||||
text-decoration: none;
|
||||
}
|
||||
|
||||
a:visited {
|
||||
color: rgb(124, 164, 218);
|
||||
}
|
||||
|
||||
* {
|
||||
font-family: 'Inter', sans-serif;
|
||||
box-sizing: inherit;
|
||||
}
|
||||
|
||||
button,
|
||||
select,
|
||||
input {
|
||||
font-size: inherit;
|
||||
}
|
||||
|
||||
button {
|
||||
appearance: none;
|
||||
outline: none;
|
||||
border: none;
|
||||
|
||||
background-color: #3c5a89;
|
||||
color: white;
|
||||
|
||||
padding: 0.5em 0.5em;
|
||||
|
||||
font-weight: bold;
|
||||
font-size: 0.9em;
|
||||
|
||||
cursor: pointer;
|
||||
transition: all 75ms;
|
||||
|
||||
&:hover:not([data-disabled='true']),
|
||||
&:focus-visible {
|
||||
background-color: lighten($color: #3c5a89, $amount: 10%);
|
||||
}
|
||||
|
||||
&[data-disabled='true'] {
|
||||
user-select: none;
|
||||
-moz-user-select: none;
|
||||
-webkit-user-select: none;
|
||||
|
||||
color: #999;
|
||||
}
|
||||
|
||||
&.btn--icon {
|
||||
background-color: transparent;
|
||||
padding: 0;
|
||||
}
|
||||
|
||||
&:focus-visible {
|
||||
outline: 1px solid gold;
|
||||
}
|
||||
}
|
||||
|
||||
// Text
|
||||
.text {
|
||||
&--accent {
|
||||
color: gold;
|
||||
}
|
||||
}
|
||||
|
||||
// Card modal
|
||||
.g-card {
|
||||
position: fixed;
|
||||
z-index: 999;
|
||||
top: 50%;
|
||||
left: 50%;
|
||||
transform: translate(-50%, -50%);
|
||||
|
||||
width: 90vw;
|
||||
max-width: 550px;
|
||||
|
||||
padding: 0.5em 1em;
|
||||
|
||||
border-radius: 1em;
|
||||
|
||||
background-color: #1d1c33;
|
||||
box-shadow: 0 0 6px 1px #414141;
|
||||
}
|
||||
|
||||
// Scrollbar
|
||||
/* width */
|
||||
::-webkit-scrollbar {
|
||||
width: 7px;
|
||||
height: 7px;
|
||||
}
|
||||
|
||||
/* Track */
|
||||
::-webkit-scrollbar-track {
|
||||
background: #333;
|
||||
}
|
||||
|
||||
/* Corner */
|
||||
::-webkit-scrollbar-corner {
|
||||
background: #333;
|
||||
}
|
||||
|
||||
/* Handle */
|
||||
::-webkit-scrollbar-thumb {
|
||||
background: #888;
|
||||
border-radius: 1rem;
|
||||
}
|
||||
|
||||
/* Handle on hover */
|
||||
::-webkit-scrollbar-thumb:hover {
|
||||
background: #aaa;
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
export enum AuthState {
|
||||
'LOADING' = 0,
|
||||
'AUTHORIZED' = 1,
|
||||
'UNAUTHORIZED' = 2,
|
||||
}
|
||||
|
||||
export interface IUser {
|
||||
name: string;
|
||||
id: number;
|
||||
iat?: number;
|
||||
}
|
||||
|
||||
export interface ILoginResponse {
|
||||
token: string;
|
||||
user: IUser;
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
export enum LoadingState {
|
||||
LOADING = 0,
|
||||
SUCCESS = 1,
|
||||
ERROR = 2,
|
||||
INIT = 3,
|
||||
}
|
||||
@@ -1,129 +1,114 @@
|
||||
export type Availability = 'default' | 'unavailable' | 'nonPublic' | 'abandoned' | 'nonDefault';
|
||||
export type ChangeProp =
|
||||
| 'name'
|
||||
| 'hash'
|
||||
| 'url'
|
||||
| 'lines'
|
||||
| 'project'
|
||||
| 'projectUrl'
|
||||
| 'reqLevel'
|
||||
| 'signalType'
|
||||
| 'controlType'
|
||||
| 'SUP'
|
||||
| 'ASDEK'
|
||||
| 'routesInfo'
|
||||
| 'checkpoints'
|
||||
| 'authors'
|
||||
| 'availability'
|
||||
| 'hidden';
|
||||
|
||||
export enum HeaderTypes {
|
||||
name = 'Nazwa',
|
||||
abbr = 'Skrót posterunku',
|
||||
url = 'URL',
|
||||
hash = 'Hash',
|
||||
lines = 'Linie',
|
||||
project = 'Projekt',
|
||||
projectUrl = 'URL projektu',
|
||||
reqLevel = 'Wym. poziom',
|
||||
signalType = 'Sygnalizacja',
|
||||
controlType = 'Sterowanie',
|
||||
SUP = 'SUP',
|
||||
ASDEK = 'ASDEK',
|
||||
authors = 'Autorzy',
|
||||
routesInfo = 'Szlaki',
|
||||
checkpoints = 'Posterunki',
|
||||
availability = 'Dostępność',
|
||||
hidden = 'Ukryty',
|
||||
toRemove = 'Usuń',
|
||||
}
|
||||
|
||||
export enum AvailabilityTypes {
|
||||
'default' = 'w paczce',
|
||||
'nonDefault' = 'poza paczką',
|
||||
'nonPublic' = 'niepubliczna',
|
||||
'abandoned' = 'wycofana',
|
||||
'unavailable' = 'niedostępna',
|
||||
}
|
||||
|
||||
export interface SceneryRoutesInfo {
|
||||
routeName: string;
|
||||
isElectric: boolean;
|
||||
isRouteSBL: boolean;
|
||||
isInternal: boolean;
|
||||
routeSpeed: number;
|
||||
routeLength: number;
|
||||
routeTracks: number;
|
||||
hidden?: boolean;
|
||||
}
|
||||
|
||||
export interface SceneryRowItem {
|
||||
id: string | number;
|
||||
hash: string;
|
||||
name: string;
|
||||
abbr: string;
|
||||
url: string;
|
||||
lines: string;
|
||||
project: string | null;
|
||||
projectUrl: string | null;
|
||||
reqLevel: number;
|
||||
signalType: string;
|
||||
controlType: string;
|
||||
SUP: boolean;
|
||||
ASDEK: boolean;
|
||||
hidden: boolean;
|
||||
routesInfo: SceneryRoutesInfo[];
|
||||
checkpoints: string;
|
||||
authors: string;
|
||||
availability: Availability;
|
||||
}
|
||||
|
||||
export type ChangeItem = {
|
||||
[key in ChangeProp]?: any;
|
||||
} & {
|
||||
id: string | number;
|
||||
name: string;
|
||||
|
||||
toRemove?: boolean;
|
||||
};
|
||||
|
||||
export enum AuthState {
|
||||
'LOADING' = 0,
|
||||
'AUTHORIZED' = 1,
|
||||
'UNAUTHORIZED' = 2,
|
||||
}
|
||||
|
||||
export interface IUser {
|
||||
name: string;
|
||||
id: number;
|
||||
iat?: number;
|
||||
}
|
||||
|
||||
export interface IStore {
|
||||
dataState: string;
|
||||
authState: AuthState;
|
||||
|
||||
stationList: SceneryRowItem[];
|
||||
backupList: SceneryRowItem[];
|
||||
stationsToRemove: string[];
|
||||
searchedSceneryName: string;
|
||||
changeList: ChangeItem[];
|
||||
newStationsCount: number;
|
||||
routesModalVisible: boolean;
|
||||
currentStation: SceneryRowItem | null;
|
||||
selectedStationName: string;
|
||||
// token: string | null;
|
||||
user: IUser | null;
|
||||
notifyDiscord: boolean;
|
||||
alertMessage: string;
|
||||
confirmMessage: string;
|
||||
|
||||
maxVisibleResults: number;
|
||||
|
||||
changesResponse: string[];
|
||||
}
|
||||
|
||||
export interface ILoginResponse {
|
||||
token: string;
|
||||
user: IUser;
|
||||
}
|
||||
import { AuthState, IUser } from './auth.types';
|
||||
|
||||
export interface ISceneriesStore {
|
||||
dataState: string;
|
||||
authState: AuthState;
|
||||
|
||||
stationList: SceneryRowItem[];
|
||||
backupList: SceneryRowItem[];
|
||||
stationsToRemove: string[];
|
||||
searchedSceneryName: string;
|
||||
changeList: ChangeItem[];
|
||||
newStationsCount: number;
|
||||
routesModalVisible: boolean;
|
||||
currentStation: SceneryRowItem | null;
|
||||
selectedStationName: string;
|
||||
// token: string | null;
|
||||
user: IUser | null;
|
||||
notifyDiscord: boolean;
|
||||
alertMessage: string;
|
||||
confirmMessage: string;
|
||||
|
||||
maxVisibleResults: number;
|
||||
|
||||
changesResponse: string[];
|
||||
}
|
||||
|
||||
export type Availability = 'default' | 'unavailable' | 'nonPublic' | 'abandoned' | 'nonDefault';
|
||||
export type ChangeProp =
|
||||
| 'name'
|
||||
| 'hash'
|
||||
| 'url'
|
||||
| 'lines'
|
||||
| 'project'
|
||||
| 'projectUrl'
|
||||
| 'reqLevel'
|
||||
| 'signalType'
|
||||
| 'controlType'
|
||||
| 'SUP'
|
||||
| 'ASDEK'
|
||||
| 'routesInfo'
|
||||
| 'checkpoints'
|
||||
| 'authors'
|
||||
| 'availability'
|
||||
| 'hidden';
|
||||
|
||||
export enum HeaderTypes {
|
||||
name = 'Nazwa',
|
||||
abbr = 'Skrót posterunku',
|
||||
url = 'URL',
|
||||
hash = 'Hash',
|
||||
lines = 'Linie',
|
||||
project = 'Projekt',
|
||||
projectUrl = 'URL projektu',
|
||||
reqLevel = 'Wym. poziom',
|
||||
signalType = 'Sygnalizacja',
|
||||
controlType = 'Sterowanie',
|
||||
SUP = 'SUP',
|
||||
ASDEK = 'ASDEK',
|
||||
authors = 'Autorzy',
|
||||
routesInfo = 'Szlaki',
|
||||
checkpoints = 'Posterunki',
|
||||
availability = 'Dostępność',
|
||||
hidden = 'Ukryty',
|
||||
toRemove = 'Usuń',
|
||||
}
|
||||
|
||||
export enum AvailabilityTypes {
|
||||
'default' = 'w paczce',
|
||||
'nonDefault' = 'poza paczką',
|
||||
'nonPublic' = 'niepubliczna',
|
||||
'abandoned' = 'wycofana',
|
||||
'unavailable' = 'niedostępna',
|
||||
}
|
||||
|
||||
export interface SceneryRoutesInfo {
|
||||
routeName: string;
|
||||
isElectric: boolean;
|
||||
isRouteSBL: boolean;
|
||||
isInternal: boolean;
|
||||
routeSpeed: number;
|
||||
routeLength: number;
|
||||
routeTracks: number;
|
||||
hidden?: boolean;
|
||||
}
|
||||
|
||||
export interface SceneryRowItem {
|
||||
id: string | number;
|
||||
hash: string;
|
||||
name: string;
|
||||
abbr: string;
|
||||
url: string;
|
||||
lines: string;
|
||||
project: string | null;
|
||||
projectUrl: string | null;
|
||||
reqLevel: number;
|
||||
signalType: string;
|
||||
controlType: string;
|
||||
SUP: boolean;
|
||||
ASDEK: boolean;
|
||||
hidden: boolean;
|
||||
routesInfo: SceneryRoutesInfo[];
|
||||
checkpoints: string;
|
||||
authors: string;
|
||||
availability: Availability;
|
||||
}
|
||||
|
||||
export type ChangeItem = {
|
||||
[key in ChangeProp]?: any;
|
||||
} & {
|
||||
id: string | number;
|
||||
name: string;
|
||||
|
||||
toRemove?: boolean;
|
||||
};
|
||||
@@ -1,5 +0,0 @@
|
||||
import { Availability, AvailabilityTypes } from './types';
|
||||
|
||||
export function getAvailabilityValue(availability: Availability) {
|
||||
return AvailabilityTypes[availability];
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
export type VehicleAPIResponse = IVehicle[];
|
||||
|
||||
export interface IVehicle {
|
||||
id: number;
|
||||
name: string;
|
||||
type: string;
|
||||
cabinName?: string;
|
||||
restrictions?: IVehicleRestrictions;
|
||||
vehicleGroupsId: number;
|
||||
group: IVehicleGroup;
|
||||
}
|
||||
|
||||
export interface IVehicleRestrictions {
|
||||
sponsorOnly?: number;
|
||||
teamOnly?: boolean;
|
||||
}
|
||||
|
||||
export interface IVehicleGroup {
|
||||
id: number;
|
||||
name: string;
|
||||
speed: number;
|
||||
length: number;
|
||||
weight: number;
|
||||
cargoTypes?: IVehicleCargoType[];
|
||||
locoProps?: IVehicleLocoProps;
|
||||
}
|
||||
|
||||
export interface IVehicleCargoType {
|
||||
id: string;
|
||||
weight: number;
|
||||
}
|
||||
|
||||
export interface IVehicleLocoProps {
|
||||
coldStart: boolean;
|
||||
doubleManned: boolean;
|
||||
}
|
||||
|
||||
export interface IVehicleTableRow {
|
||||
vehicleRef: IVehicle;
|
||||
pendingChanges: Partial<IVehicle>;
|
||||
}
|
||||
|
||||
export enum VehicleEditRowKey {
|
||||
NAME = 'name',
|
||||
TYPE = 'type',
|
||||
CABIN = 'cabinName',
|
||||
|
||||
}
|
||||
|
||||
export enum VehicleEditRestrictionKey {
|
||||
SPONSOR_ONLY = "sponsorOnly",
|
||||
TEAM_ONLY = "teamOnly"
|
||||
}
|
||||
+79
-60
@@ -1,73 +1,77 @@
|
||||
<template>
|
||||
<div class="login">
|
||||
<div class="login-header">
|
||||
<img src="/icon-logo.svg" alt="logo" />
|
||||
<h1>Stacjownik Station Manager</h1>
|
||||
</div>
|
||||
<div class="login-view">
|
||||
<div class="login-wrapper">
|
||||
<div class="login-header">
|
||||
<img src="/icon-logo.svg" alt="logo" />
|
||||
<h1>
|
||||
Stacjownik Station <br />
|
||||
Manager <sup>v{{ version }}</sup>
|
||||
</h1>
|
||||
</div>
|
||||
|
||||
<form @submit.prevent="signIn">
|
||||
<label for="name">Nick</label>
|
||||
<br />
|
||||
<input type="text" id="name" v-model="name" />
|
||||
<br />
|
||||
<label for="password">Hasło</label>
|
||||
<br />
|
||||
<input type="password" id="password" v-model="password" />
|
||||
<br />
|
||||
<button>{{ isLoading ? 'Logowanie...' : 'Zaloguj się' }}</button>
|
||||
</form>
|
||||
<p style="color: yellow; height: 25px">{{ errorMessage }}</p>
|
||||
<form class="login-form" @submit.prevent="signIn">
|
||||
<div class="login-input-box">
|
||||
<label for="name">Nick</label>
|
||||
<input type="text" id="name" v-model="name" />
|
||||
</div>
|
||||
|
||||
<div class="login-input-box">
|
||||
<label for="password">Hasło</label>
|
||||
<input type="password" id="password" v-model="password" />
|
||||
</div>
|
||||
|
||||
<button class="login-button" :disabled="loginState == LoadingState.LOADING" :data-disabled="loginState == LoadingState.LOADING">
|
||||
{{ loginState == LoadingState.LOADING ? 'Logowanie...' : loginState == LoadingState.SUCCESS ? 'Zalogowano!' : 'Zaloguj się' }}
|
||||
</button>
|
||||
</form>
|
||||
|
||||
<div class="login-warning-box" v-if="errorMessage">{{ errorMessage }}</div>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script lang="ts">
|
||||
import { defineComponent } from 'vue';
|
||||
import { useStore } from '../store';
|
||||
import { AuthState, IUser } from '../types/types';
|
||||
import client from '../common/http';
|
||||
|
||||
enum LoginState {
|
||||
INITIALIZED = 0,
|
||||
LOADING = 1,
|
||||
LOADED = 2,
|
||||
ERROR = 3,
|
||||
}
|
||||
import { LoadingState } from '../types/common.types';
|
||||
import { AuthState, IUser } from '../types/auth.types';
|
||||
import { useAuthStore } from '../stores/auth.store';
|
||||
import { version } from '../../package.json';
|
||||
|
||||
export default defineComponent({
|
||||
data() {
|
||||
return {
|
||||
errorMessage: '',
|
||||
loginState: LoginState.INITIALIZED,
|
||||
isLoading: false,
|
||||
loginState: LoadingState.INIT,
|
||||
version,
|
||||
};
|
||||
},
|
||||
|
||||
setup() {
|
||||
return {
|
||||
LoginState,
|
||||
LoadingState,
|
||||
AuthState,
|
||||
|
||||
name: '',
|
||||
password: '',
|
||||
store: useStore(),
|
||||
authStore: useAuthStore(),
|
||||
};
|
||||
},
|
||||
|
||||
methods: {
|
||||
async signIn(e: Event) {
|
||||
this.loginState = LoginState.LOADING;
|
||||
this.isLoading = true;
|
||||
this.loginState = LoadingState.LOADING;
|
||||
|
||||
try {
|
||||
const response = await client.post<IUser>('auth/login', { username: this.name, password: this.password });
|
||||
|
||||
this.$router.push('/');
|
||||
this.store.setUserData(response.data);
|
||||
this.authStore.setUserData(response.data);
|
||||
|
||||
this.loginState = LoginState.LOADED;
|
||||
this.loginState = LoadingState.SUCCESS;
|
||||
} catch (e: any) {
|
||||
this.loginState = LoginState.ERROR;
|
||||
this.store.removeUserData();
|
||||
this.loginState = LoadingState.ERROR;
|
||||
this.authStore.removeUserData();
|
||||
|
||||
if (!e.response || e.response.status === undefined) {
|
||||
this.errorMessage = 'Wystąpił błąd podczas łączenia z serwerem!';
|
||||
@@ -84,8 +88,6 @@ export default defineComponent({
|
||||
|
||||
this.errorMessage = 'Wystąpił błąd podczas łączenia z serwerem!';
|
||||
return false;
|
||||
} finally {
|
||||
this.isLoading = false;
|
||||
}
|
||||
|
||||
return true;
|
||||
@@ -95,42 +97,59 @@ export default defineComponent({
|
||||
</script>
|
||||
|
||||
<style lang="scss" scoped>
|
||||
.login {
|
||||
.login-view {
|
||||
padding: 0 1em;
|
||||
min-height: 100vh;
|
||||
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
|
||||
flex-direction: column;
|
||||
height: 100vh;
|
||||
|
||||
&-header {
|
||||
text-align: center;
|
||||
}
|
||||
}
|
||||
|
||||
img {
|
||||
width: 8em;
|
||||
.login-wrapper {
|
||||
background-color: #2a304f;
|
||||
border-radius: 0.5em;
|
||||
padding: 2em 0.5em;
|
||||
}
|
||||
|
||||
input {
|
||||
font-size: 1.2rem;
|
||||
margin: 0.5rem 0;
|
||||
.login-header {
|
||||
display: flex;
|
||||
gap: 1em;
|
||||
align-items: center;
|
||||
margin-bottom: 1em;
|
||||
}
|
||||
|
||||
.login-header img {
|
||||
width: 7em;
|
||||
}
|
||||
|
||||
.login-header sup {
|
||||
font-size: 0.5em;
|
||||
color: #ccc;
|
||||
}
|
||||
|
||||
.login-input-box input {
|
||||
font-size: 1.2em;
|
||||
margin: 0.5em 0;
|
||||
padding: 0.25em 0.3em;
|
||||
color: black;
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
h2 {
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
label {
|
||||
.login-input-box label {
|
||||
text-align: left;
|
||||
}
|
||||
|
||||
button {
|
||||
.login-button {
|
||||
width: 100%;
|
||||
margin: 1rem 0;
|
||||
padding: 0.5rem 0;
|
||||
font-size: 1rem;
|
||||
padding: 0.5em 0;
|
||||
font-size: 1em;
|
||||
margin-top: 4em;
|
||||
}
|
||||
|
||||
.login-warning-box {
|
||||
text-align: center;
|
||||
color: gold;
|
||||
margin-top: 1em;
|
||||
}
|
||||
</style>
|
||||
|
||||
+25
-27
@@ -1,7 +1,7 @@
|
||||
<template>
|
||||
<div class="manager" v-if="store.user">
|
||||
<RoutesModal v-if="store.currentStation" />
|
||||
<UpdateCard v-if="store.changesResponse.length > 0" />
|
||||
<div class="manager-view" v-if="authStore.user != null">
|
||||
<RoutesModal v-if="sceneriesStore.currentStation" />
|
||||
<UpdateCard v-if="sceneriesStore.changesResponse.length > 0" />
|
||||
|
||||
<hr color="white" />
|
||||
<TableActions />
|
||||
@@ -16,7 +16,7 @@
|
||||
</thead>
|
||||
|
||||
<tbody>
|
||||
<tr v-for="(station, row) in store.sortedStationList" tabindex="0">
|
||||
<tr v-for="(station, row) in sceneriesStore.sortedStationList" tabindex="0">
|
||||
<td v-for="(_, propName) in headerNameList" @click="changeProperty(station, row, propName as string)" :class="propName">
|
||||
<span v-if="propName === 'url'" :style="station.url ? 'color: gold' : 'color: gray;'">URL</span>
|
||||
<span v-else-if="propName === 'projectUrl'" :style="station.projectUrl ? 'color: gold' : 'color: gray;'">URL</span>
|
||||
@@ -39,8 +39,8 @@
|
||||
<select
|
||||
name="availability"
|
||||
:id="`select-${row}`"
|
||||
v-model="store.sortedStationList[row]['availability']"
|
||||
@input="(e) => changeAvailability(station, store.sortedStationList[row]['availability'], e)"
|
||||
v-model="sceneriesStore.sortedStationList[row]['availability']"
|
||||
@input="(e) => changeAvailability(station, sceneriesStore.sortedStationList[row]['availability'], e)"
|
||||
>
|
||||
<option value="default">dostępna (w paczce)</option>
|
||||
<option value="nonDefault">dostępna (poza paczką)</option>
|
||||
@@ -61,18 +61,23 @@
|
||||
<script lang="ts">
|
||||
import { defineComponent } from 'vue';
|
||||
import changeMixin from '../mixins/changeMixin';
|
||||
import { useStore } from '../store';
|
||||
import { SceneryRowItem, Availability, AuthState } from '../types/types';
|
||||
import RoutesModal from '../components/RoutesModal.vue';
|
||||
import TableActions from '../components/TableActions.vue';
|
||||
import UpdateCard from '../components/UpdateCard.vue';
|
||||
import RouteList from '../components/RouteList.vue';
|
||||
import { AuthState } from '../types/auth.types';
|
||||
import { SceneryRowItem, Availability } from '../types/sceneries.types';
|
||||
import { useSceneriesStore } from '../stores/sceneries.store';
|
||||
import { useAuthStore } from '../stores/auth.store';
|
||||
|
||||
export default defineComponent({
|
||||
components: { RoutesModal, TableActions, UpdateCard, RouteList },
|
||||
mixins: [changeMixin],
|
||||
|
||||
data: () => ({
|
||||
sceneriesStore: useSceneriesStore(),
|
||||
authStore: useAuthStore(),
|
||||
|
||||
AuthState,
|
||||
headerNameList: {
|
||||
name: 'Nazwa',
|
||||
@@ -96,20 +101,13 @@ export default defineComponent({
|
||||
},
|
||||
}),
|
||||
|
||||
setup() {
|
||||
const store = useStore();
|
||||
return {
|
||||
store,
|
||||
};
|
||||
},
|
||||
|
||||
mounted() {
|
||||
this.store.fetchSceneriesData();
|
||||
this.sceneriesStore.fetchSceneriesData();
|
||||
},
|
||||
|
||||
methods: {
|
||||
changeProperty(station: SceneryRowItem, row: number, propertyName: string) {
|
||||
this.store.selectedStationName = station.name;
|
||||
this.sceneriesStore.selectedStationName = station.name;
|
||||
|
||||
if (propertyName == 'checkpoints') {
|
||||
this.changeCheckpoints(row);
|
||||
@@ -121,12 +119,12 @@ export default defineComponent({
|
||||
return;
|
||||
}
|
||||
|
||||
const stationListRow = this.store.stationList.findIndex((station) => station.name == this.store.sortedStationList[row].name);
|
||||
const stationListRow = this.sceneriesStore.stationList.findIndex((station) => station.name == this.sceneriesStore.sortedStationList[row].name);
|
||||
|
||||
if (stationListRow == -1) return;
|
||||
const oldValue = (this.store.stationList[stationListRow] as any)[propertyName];
|
||||
const oldValue = (this.sceneriesStore.stationList[stationListRow] as any)[propertyName];
|
||||
if (typeof oldValue === 'boolean') {
|
||||
(this.store.stationList[stationListRow] as any)[propertyName] = !oldValue;
|
||||
(this.sceneriesStore.stationList[stationListRow] as any)[propertyName] = !oldValue;
|
||||
// this.$set(this.stationList[stationListRow], propertyName, !oldValue);
|
||||
this.addChange(station, propertyName, oldValue, !oldValue);
|
||||
return;
|
||||
@@ -134,21 +132,21 @@ export default defineComponent({
|
||||
|
||||
let newValue = prompt(`Zmień wartość dla rubryki ${this.headerNameList[propertyName]}`, oldValue || '');
|
||||
if (newValue == null) return;
|
||||
(this.store.stationList[stationListRow] as any)[propertyName] = typeof oldValue === 'number' ? parseInt(newValue) : newValue;
|
||||
(this.sceneriesStore.stationList[stationListRow] as any)[propertyName] = typeof oldValue === 'number' ? parseInt(newValue) : newValue;
|
||||
// this.$set(this.stationList[stationListRow], propertyName, parseInt(newValue));
|
||||
this.addChange(station, propertyName, oldValue, typeof oldValue === 'number' ? parseInt(newValue) : newValue);
|
||||
},
|
||||
|
||||
changeCheckpoints(row: number) {
|
||||
const stationListRow = this.store.stationList.findIndex((station) => station.name == this.store.sortedStationList[row].name);
|
||||
const stationListRow = this.sceneriesStore.stationList.findIndex((station) => station.name == this.sceneriesStore.sortedStationList[row].name);
|
||||
|
||||
if (stationListRow == -1) return;
|
||||
const oldCheckpoints = this.store.stationList[stationListRow].checkpoints;
|
||||
const oldCheckpoints = this.sceneriesStore.stationList[stationListRow].checkpoints;
|
||||
const newCheckpoints = prompt('Wpisz posterunki (oddzielone średnikiem):', oldCheckpoints);
|
||||
if (newCheckpoints === null) return;
|
||||
|
||||
this.store.stationList[stationListRow]['checkpoints'] = newCheckpoints;
|
||||
this.addChange(this.store.sortedStationList[row], 'checkpoints', oldCheckpoints, newCheckpoints);
|
||||
this.sceneriesStore.stationList[stationListRow]['checkpoints'] = newCheckpoints;
|
||||
this.addChange(this.sceneriesStore.sortedStationList[row], 'checkpoints', oldCheckpoints, newCheckpoints);
|
||||
},
|
||||
|
||||
changeAvailability(scenery: SceneryRowItem, availability: Availability, e: Event) {
|
||||
@@ -161,12 +159,12 @@ export default defineComponent({
|
||||
|
||||
if (!confirmRemove) return;
|
||||
|
||||
this.store.stationList = this.store.stationList.filter(({ id }) => id != scenery.id);
|
||||
this.sceneriesStore.stationList = this.sceneriesStore.stationList.filter(({ id }) => id != scenery.id);
|
||||
this.addRemovalChange(scenery);
|
||||
},
|
||||
|
||||
showRoutesModal(scenery: SceneryRowItem) {
|
||||
this.store.currentStation = scenery;
|
||||
this.sceneriesStore.currentStation = scenery;
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
@@ -0,0 +1,252 @@
|
||||
<template>
|
||||
<div class="manager-view">
|
||||
<div class="view-wrapper">
|
||||
<div class="top-bar">
|
||||
<div class="brand">
|
||||
<img class="brand-image" src="/icon-logo.svg" alt="logo" />
|
||||
<h3>Edytor pojazdów</h3>
|
||||
</div>
|
||||
|
||||
<div class="search-box">
|
||||
<input type="text" placeholder="Wyszukaj pojazd..." v-model="vehicleSearchValue" />
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="table-wrapper">
|
||||
<table>
|
||||
<thead>
|
||||
<tr>
|
||||
<th style="width: 50px">#</th>
|
||||
<th style="width: 300px">Nazwa</th>
|
||||
<th style="width: 200px">Typ</th>
|
||||
<th style="width: 150px">Kabina (lok.)</th>
|
||||
<th style="width: 150px">Grupa</th>
|
||||
<th style="width: 150px">Tylko sponsorzy do</th>
|
||||
<th style="width: 150px">Tylko zespół</th>
|
||||
</tr>
|
||||
</thead>
|
||||
|
||||
<tbody>
|
||||
<tr v-for="row in vehiclesTableComp" :key="row.vehicleRef.id">
|
||||
<td>{{ row.vehicleRef.id }}</td>
|
||||
<td
|
||||
class="editable"
|
||||
:data-pending="row.pendingChanges.name !== undefined && row.pendingChanges.name !== row.vehicleRef.name"
|
||||
@click="editRowPrimitive(row, VehicleEditRowKey.NAME)"
|
||||
>
|
||||
{{ row.pendingChanges.name ?? row.vehicleRef.name }}
|
||||
</td>
|
||||
<td
|
||||
class="editable"
|
||||
:data-pending="row.pendingChanges.type !== undefined && row.pendingChanges.type !== row.vehicleRef.type"
|
||||
@click="editRowPrimitive(row, VehicleEditRowKey.TYPE)"
|
||||
>
|
||||
{{ row.pendingChanges.type ?? row.vehicleRef.type }}
|
||||
</td>
|
||||
|
||||
<td
|
||||
class="editable"
|
||||
:data-pending="row.pendingChanges.cabinName !== undefined && row.pendingChanges.cabinName !== row.vehicleRef.cabinName"
|
||||
@click="editRowPrimitive(row, VehicleEditRowKey.CABIN)"
|
||||
>
|
||||
{{ row.pendingChanges.cabinName ?? row.vehicleRef.cabinName }}
|
||||
</td>
|
||||
|
||||
<td class="editable">{{ row.vehicleRef.group.name }}</td>
|
||||
<td
|
||||
class="editable"
|
||||
:data-pending="
|
||||
row.pendingChanges.restrictions?.sponsorOnly !== undefined &&
|
||||
row.pendingChanges.restrictions.sponsorOnly !== row.vehicleRef.restrictions?.sponsorOnly
|
||||
"
|
||||
@click="editRowRestrictions(row, VehicleEditRestrictionKey.SPONSOR_ONLY)"
|
||||
>
|
||||
<span v-if="row.pendingChanges.restrictions?.sponsorOnly !== undefined">
|
||||
{{ new Date(row.pendingChanges.restrictions.sponsorOnly).toLocaleString() }}
|
||||
</span>
|
||||
|
||||
<span v-else-if="row.vehicleRef.restrictions?.sponsorOnly !== undefined">
|
||||
{{ new Date(row.vehicleRef.restrictions.sponsorOnly).toLocaleString() }}
|
||||
</span>
|
||||
|
||||
<span v-else>❌</span>
|
||||
</td>
|
||||
<td
|
||||
class="editable"
|
||||
:data-pending="
|
||||
row.pendingChanges.restrictions?.teamOnly !== undefined &&
|
||||
row.pendingChanges.restrictions.teamOnly !== row.vehicleRef.restrictions?.teamOnly
|
||||
"
|
||||
@click="editRowRestrictions(row, VehicleEditRestrictionKey.TEAM_ONLY)"
|
||||
>
|
||||
<span v-if="row.pendingChanges.restrictions?.teamOnly !== undefined">
|
||||
{{ row.pendingChanges.restrictions.teamOnly ? '✔️' : '❌' }}
|
||||
</span>
|
||||
|
||||
<span v-else-if="row.vehicleRef.restrictions?.teamOnly !== undefined">
|
||||
{{ row.vehicleRef.restrictions.teamOnly ? '✔️' : '❌' }}
|
||||
</span>
|
||||
|
||||
<span v-else>❌</span>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script lang="ts">
|
||||
import { defineComponent } from 'vue';
|
||||
import { useVehiclesStore } from '../stores/vehicles.store';
|
||||
import { VehicleEditRowKey, IVehicleTableRow, VehicleEditRestrictionKey } from '../types/vehicles.types';
|
||||
import { IVehicle } from '../types/vehicles.types';
|
||||
|
||||
export default defineComponent({
|
||||
data: () => ({
|
||||
vehiclesStore: useVehiclesStore(),
|
||||
vehicleSearchValue: '',
|
||||
VehicleEditRowKey,
|
||||
VehicleEditRestrictionKey,
|
||||
}),
|
||||
|
||||
mounted() {
|
||||
this.vehiclesStore.fetchVehicles();
|
||||
},
|
||||
|
||||
computed: {
|
||||
vehiclesTableComp() {
|
||||
return this.vehiclesStore.vehiclesTable
|
||||
.filter((row) => row.vehicleRef.name.toLowerCase().startsWith(this.vehicleSearchValue.trim().toLowerCase()))
|
||||
.sort((r1, r2) => {
|
||||
//v1.name.localeCompare(v2.name, 'pl-PL')
|
||||
|
||||
return r1.vehicleRef.id - r2.vehicleRef.id;
|
||||
});
|
||||
},
|
||||
},
|
||||
|
||||
methods: {
|
||||
editRowPrimitive(row: IVehicleTableRow, editKey: VehicleEditRowKey) {
|
||||
if (!(editKey in row.vehicleRef)) return;
|
||||
|
||||
const promptValue = prompt('Zmień wartość:', row.vehicleRef[editKey]);
|
||||
if (promptValue == null) return;
|
||||
|
||||
let changedVehileObj: Partial<IVehicle> = {};
|
||||
|
||||
changedVehileObj[editKey] = promptValue;
|
||||
|
||||
if (row.vehicleRef[editKey] === promptValue) {
|
||||
delete row.pendingChanges[editKey];
|
||||
} else row.pendingChanges = { ...row.pendingChanges, ...changedVehileObj };
|
||||
},
|
||||
|
||||
editRowRestrictions(row: IVehicleTableRow, editKey: VehicleEditRestrictionKey) {
|
||||
let changedVehileObj: Partial<IVehicle> = {};
|
||||
|
||||
if (editKey == VehicleEditRestrictionKey.TEAM_ONLY) {
|
||||
let nextTeamOnly = true;
|
||||
|
||||
if (row.pendingChanges.restrictions?.teamOnly !== undefined) nextTeamOnly = !row.pendingChanges.restrictions.teamOnly;
|
||||
else if (row.vehicleRef.restrictions?.teamOnly !== undefined) nextTeamOnly = !row.vehicleRef.restrictions.teamOnly;
|
||||
|
||||
changedVehileObj['restrictions'] = {
|
||||
teamOnly: nextTeamOnly,
|
||||
};
|
||||
|
||||
if (row.vehicleRef.restrictions?.teamOnly === changedVehileObj.restrictions.teamOnly) delete changedVehileObj['restrictions']['teamOnly'];
|
||||
}
|
||||
|
||||
if (editKey == VehicleEditRestrictionKey.SPONSOR_ONLY) {
|
||||
const promptValue = prompt('Zmień wartość (timestamp):', row.vehicleRef.restrictions?.sponsorOnly?.toString() ?? Date.now().toString());
|
||||
|
||||
if (promptValue == null) return;
|
||||
|
||||
if (promptValue.trim() == '') {
|
||||
changedVehileObj['restrictions'] = { sponsorOnly: undefined };
|
||||
} else if (!isNaN(parseInt(promptValue))) {
|
||||
const timestampPromptValue = parseInt(promptValue);
|
||||
|
||||
changedVehileObj['restrictions'] = { sponsorOnly: timestampPromptValue };
|
||||
}
|
||||
}
|
||||
|
||||
row.pendingChanges = { ...row.pendingChanges, ...changedVehileObj };
|
||||
|
||||
console.log(this.vehiclesStore.vehiclesTable.filter((v) => Object.keys(v.pendingChanges).length > 0));
|
||||
},
|
||||
|
||||
getTableValueHTML(pendingValue: any, originalValue: any) {
|
||||
if (pendingValue === undefined) return `${originalValue ?? '-'}`;
|
||||
|
||||
return `<s>${originalValue ?? '-'}</s> ${pendingValue}`;
|
||||
},
|
||||
},
|
||||
});
|
||||
</script>
|
||||
|
||||
<style lang="scss" scoped>
|
||||
.view-wrapper {
|
||||
display: grid;
|
||||
grid-template-rows: auto 1fr;
|
||||
max-height: 100vh;
|
||||
padding: 0.5em;
|
||||
}
|
||||
|
||||
.brand {
|
||||
display: flex;
|
||||
gap: 0.5em;
|
||||
}
|
||||
|
||||
img.brand-image {
|
||||
max-width: 4em;
|
||||
}
|
||||
|
||||
.search-box {
|
||||
margin-top: 1em;
|
||||
}
|
||||
|
||||
.table-wrapper {
|
||||
overflow: auto;
|
||||
margin-top: 1em;
|
||||
}
|
||||
|
||||
table {
|
||||
border-collapse: collapse;
|
||||
text-align: center;
|
||||
table-layout: fixed;
|
||||
|
||||
thead {
|
||||
position: sticky;
|
||||
top: 0;
|
||||
}
|
||||
|
||||
th {
|
||||
background-color: #2b2b2b;
|
||||
}
|
||||
|
||||
tr:nth-child(odd) {
|
||||
background-color: #3b3b3b;
|
||||
}
|
||||
|
||||
tr:nth-child(even) {
|
||||
background-color: #4c4c4c;
|
||||
}
|
||||
|
||||
td.editable {
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
td[data-pending='true'] {
|
||||
background-color: lightgreen;
|
||||
color: black;
|
||||
}
|
||||
|
||||
th,
|
||||
td {
|
||||
padding: 0.5em;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
Reference in New Issue
Block a user