mirror of
https://github.com/Spythere/station-manager-2.0.git
synced 2026-05-03 05:28:13 +00:00
zmiana endpointów; poprawki designu
This commit is contained in:
@@ -1,3 +1,3 @@
|
|||||||
VITE_API_URL="https://stacjownik.spythere.pl"
|
VITE_API_URL="https://stacjownik.spythere.eu"
|
||||||
VITE_API_URL_DEV="http://localhost:3001"
|
VITE_API_URL_DEV="http://localhost:3001"
|
||||||
VITE_API_DEV="0"
|
VITE_API_DEV=0
|
||||||
+4
-13
@@ -8,11 +8,10 @@
|
|||||||
import { defineComponent } from 'vue';
|
import { defineComponent } from 'vue';
|
||||||
import PopUpCard from './components/PopUpCard.vue';
|
import PopUpCard from './components/PopUpCard.vue';
|
||||||
import { RouterView } from 'vue-router';
|
import { RouterView } from 'vue-router';
|
||||||
import { AuthState } from './types/types';
|
import { useStore } from './store';
|
||||||
import { baseURL, useStore } from './store';
|
|
||||||
import useLocalStorage from './mixins/useLocalStorage';
|
import useLocalStorage from './mixins/useLocalStorage';
|
||||||
import axios from 'axios';
|
|
||||||
import { IUser } from './types/types';
|
import { IUser } from './types/types';
|
||||||
|
import client from './common/http';
|
||||||
|
|
||||||
export default defineComponent({
|
export default defineComponent({
|
||||||
components: { PopUpCard },
|
components: { PopUpCard },
|
||||||
@@ -33,14 +32,7 @@ export default defineComponent({
|
|||||||
try {
|
try {
|
||||||
this.tokenLoading = true;
|
this.tokenLoading = true;
|
||||||
|
|
||||||
const response = await axios.post<IUser>(
|
const response = await client.post<IUser>('/auth/token');
|
||||||
'/auth/token',
|
|
||||||
{},
|
|
||||||
{
|
|
||||||
baseURL,
|
|
||||||
withCredentials: true,
|
|
||||||
}
|
|
||||||
);
|
|
||||||
|
|
||||||
this.store.setUserData(response.data);
|
this.store.setUserData(response.data);
|
||||||
this.$router.push('/');
|
this.$router.push('/');
|
||||||
@@ -96,7 +88,7 @@ button {
|
|||||||
outline: none;
|
outline: none;
|
||||||
border: none;
|
border: none;
|
||||||
|
|
||||||
background-color: #000000;
|
background-color: #0066ff;
|
||||||
color: white;
|
color: white;
|
||||||
|
|
||||||
padding: 0.5rem 0.75rem;
|
padding: 0.5rem 0.75rem;
|
||||||
@@ -164,4 +156,3 @@ button {
|
|||||||
background: #aaa;
|
background: #aaa;
|
||||||
}
|
}
|
||||||
</style>
|
</style>
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,8 @@
|
|||||||
|
import axios from 'axios';
|
||||||
|
|
||||||
|
const client = axios.create({
|
||||||
|
baseURL: import.meta.env['VITE_API_URL'],
|
||||||
|
withCredentials: true,
|
||||||
|
});
|
||||||
|
|
||||||
|
export default client;
|
||||||
@@ -21,19 +21,13 @@
|
|||||||
<button @click="addNewStation">Dodaj nową stację</button>
|
<button @click="addNewStation">Dodaj nową stację</button>
|
||||||
<button @click="confirmLoadData">Odśwież dane</button>
|
<button @click="confirmLoadData">Odśwież dane</button>
|
||||||
|
|
||||||
<button @click="confirmUpdateList" :data-disabled="!store.unsavedChanges" :disabled="!store.unsavedChanges">
|
<button @click="confirmUpdateList" :data-disabled="!store.unsavedChanges" :disabled="!store.unsavedChanges">Zapisz zmiany</button>
|
||||||
Zapisz zmiany
|
|
||||||
</button>
|
|
||||||
<button @click="signOut">Wyloguj się</button>
|
<button @click="signOut">Wyloguj się</button>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="pane notify-pane">
|
<div class="pane notify-pane">
|
||||||
<label id="notify">
|
<label id="notify">
|
||||||
<input
|
<input type="checkbox" v-model="store.notifyDiscord" @input="onNotifyCheckboxChange(($event.target as HTMLInputElement)!.checked)" />
|
||||||
type="checkbox"
|
|
||||||
v-model="store.notifyDiscord"
|
|
||||||
@input="onNotifyCheckboxChange(($event.target as HTMLInputElement)!.checked)"
|
|
||||||
/>
|
|
||||||
<span>
|
<span>
|
||||||
Powiadom o zmianach: <b>{{ store.notifyDiscord ? 'TAK' : 'NIE' }}</b>
|
Powiadom o zmianach: <b>{{ store.notifyDiscord ? 'TAK' : 'NIE' }}</b>
|
||||||
</span>
|
</span>
|
||||||
@@ -41,14 +35,7 @@
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="pane search-pane">
|
<div class="pane search-pane">
|
||||||
<input
|
<input class="search" ref="search" type="text" v-model="store.searchedSceneryName" placeholder="Wpisz nazwę scenerii..." width="350" />
|
||||||
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>
|
<button style="margin-left: 0.5em" @click="clearInput">Wyczyść</button>
|
||||||
</div>
|
</div>
|
||||||
@@ -66,9 +53,7 @@
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="pane">
|
<div class="pane">
|
||||||
<button @click="changelogVisible = !changelogVisible">
|
<button @click="changelogVisible = !changelogVisible">{{ changelogVisible ? 'Ukryj' : 'Pokaż' }} changelog</button>
|
||||||
{{ changelogVisible ? 'Ukryj' : 'Pokaż' }} changelog
|
|
||||||
</button>
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="changelog" v-if="changelogVisible">
|
<div class="changelog" v-if="changelogVisible">
|
||||||
@@ -82,10 +67,11 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import { defineComponent } from 'vue';
|
import { defineComponent } from 'vue';
|
||||||
import routesMixin from '../mixins/routesMixin';
|
import routesMixin from '../mixins/routesMixin';
|
||||||
import { useStore, baseURL } from '../store';
|
import { useStore } from '../store';
|
||||||
import { AuthState, Availability, ChangeProp, HeaderTypes, SceneryRoutesInfo, SceneryRowItem } from '../types/types';
|
import { AuthState, Availability, ChangeProp, HeaderTypes, SceneryRoutesInfo, SceneryRowItem } from '../types/types';
|
||||||
import { getAvailabilityValue } from '../types/typeUitls';
|
import { getAvailabilityValue } from '../types/typeUitls';
|
||||||
import axios from 'axios';
|
import axios from 'axios';
|
||||||
|
import client from '../common/http';
|
||||||
|
|
||||||
export default defineComponent({
|
export default defineComponent({
|
||||||
setup() {
|
setup() {
|
||||||
@@ -115,12 +101,7 @@ export default defineComponent({
|
|||||||
|
|
||||||
if (/id|name/.test(propChange)) continue;
|
if (/id|name/.test(propChange)) continue;
|
||||||
|
|
||||||
let value =
|
let value = typeof changeItem[propChange] === 'boolean' ? (changeItem[propChange] ? 'TAK' : 'NIE') : changeItem[propChange];
|
||||||
typeof changeItem[propChange] === 'boolean'
|
|
||||||
? changeItem[propChange]
|
|
||||||
? 'TAK'
|
|
||||||
: 'NIE'
|
|
||||||
: changeItem[propChange];
|
|
||||||
|
|
||||||
if (propChange == 'availability') value = getAvailabilityValue(changeItem[propChange] as Availability);
|
if (propChange == 'availability') value = getAvailabilityValue(changeItem[propChange] as Availability);
|
||||||
if (propChange == 'routesInfo') value = this.getRouteNames(changeItem[propChange] as SceneryRoutesInfo[]);
|
if (propChange == 'routesInfo') value = this.getRouteNames(changeItem[propChange] as SceneryRoutesInfo[]);
|
||||||
@@ -142,9 +123,7 @@ export default defineComponent({
|
|||||||
},
|
},
|
||||||
|
|
||||||
confirmRestoreList() {
|
confirmRestoreList() {
|
||||||
const confirmed = confirm(
|
const confirmed = confirm('Czy na pewno chcesz zresetować listę do ustawień z pliku? Wszelkie niezapisane zmiany zostaną utracone!');
|
||||||
'Czy na pewno chcesz zresetować listę do ustawień z pliku? Wszelkie niezapisane zmiany zostaną utracone!'
|
|
||||||
);
|
|
||||||
|
|
||||||
if (confirmed) this.restoreList();
|
if (confirmed) this.restoreList();
|
||||||
},
|
},
|
||||||
@@ -156,7 +135,7 @@ export default defineComponent({
|
|||||||
},
|
},
|
||||||
|
|
||||||
async signOut() {
|
async signOut() {
|
||||||
await axios.post('/auth/logout', {}, { baseURL, withCredentials: true });
|
await client.post('/auth/logout');
|
||||||
|
|
||||||
this.$router.push('/login');
|
this.$router.push('/login');
|
||||||
this.store.removeUserData();
|
this.store.removeUserData();
|
||||||
@@ -182,6 +161,7 @@ export default defineComponent({
|
|||||||
this.store.fetchSceneriesData();
|
this.store.fetchSceneriesData();
|
||||||
} 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!';
|
||||||
|
console.error(error);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
@@ -189,11 +169,7 @@ export default defineComponent({
|
|||||||
const name = prompt('Nazwa nowej scenerii');
|
const name = prompt('Nazwa nowej scenerii');
|
||||||
if (!name) return;
|
if (!name) return;
|
||||||
|
|
||||||
if (
|
if (this.store.stationList.some((station) => station.name.toLocaleLowerCase('pl-PL') == name.toLocaleLowerCase('pl-PL'))) {
|
||||||
this.store.stationList.some(
|
|
||||||
(station) => station.name.toLocaleLowerCase('pl-PL') == name.toLocaleLowerCase('pl-PL')
|
|
||||||
)
|
|
||||||
) {
|
|
||||||
this.store.alertMessage = 'Sceneria o takiej nazwie już istnieje!';
|
this.store.alertMessage = 'Sceneria o takiej nazwie już istnieje!';
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|||||||
+20
-30
@@ -1,8 +1,7 @@
|
|||||||
import { defineStore } from 'pinia';
|
import { defineStore } from 'pinia';
|
||||||
import { AuthState, ILoginResponse, IStore, IUser, SceneryRowItem } from './types/types';
|
import { AuthState, ILoginResponse, IStore, IUser, SceneryRowItem } from './types/types';
|
||||||
import axios from 'axios';
|
import axios from 'axios';
|
||||||
|
import client from './common/http';
|
||||||
export const baseURL = import.meta.env['VITE_API_URL'];
|
|
||||||
|
|
||||||
export const useStore = defineStore('store', {
|
export const useStore = defineStore('store', {
|
||||||
state: () =>
|
state: () =>
|
||||||
@@ -33,42 +32,33 @@ export const useStore = defineStore('store', {
|
|||||||
} as IStore),
|
} as IStore),
|
||||||
|
|
||||||
actions: {
|
actions: {
|
||||||
fetchSceneriesData() {
|
async fetchSceneriesData() {
|
||||||
this.dataState = 'LOADING';
|
this.dataState = 'LOADING';
|
||||||
|
|
||||||
const data = axios.get<SceneryRowItem[]>(`api/getSceneries`, {
|
try {
|
||||||
baseURL,
|
const data = (await client.get<SceneryRowItem[]>(`api/getSceneries`)).data;
|
||||||
});
|
this.dataState = 'LOADED';
|
||||||
|
this.backupList = JSON.parse(JSON.stringify(data));
|
||||||
data
|
this.stationList = data;
|
||||||
.then((res) => {
|
this.unsavedChanges = false;
|
||||||
this.dataState = 'LOADED';
|
this.changeList = [];
|
||||||
this.backupList = JSON.parse(JSON.stringify(res.data));
|
} catch (error: any) {
|
||||||
this.stationList = res.data;
|
this.dataState = 'ERROR';
|
||||||
this.unsavedChanges = false;
|
console.error('Błąd podczas ładowania danych: ', error?.response || error);
|
||||||
this.changeList = [];
|
}
|
||||||
})
|
|
||||||
.catch(() => {
|
|
||||||
this.dataState = 'ERROR';
|
|
||||||
});
|
|
||||||
},
|
},
|
||||||
|
|
||||||
async updateSceneriesData(mappedChangeList: any[]) {
|
async updateSceneriesData(mappedChangeList: any[]) {
|
||||||
console.log(mappedChangeList);
|
try {
|
||||||
|
const response = await client.post('manager/updateSceneryList', {
|
||||||
const response = await axios.post(
|
|
||||||
'/manager/updateSceneryList',
|
|
||||||
{
|
|
||||||
changeList: mappedChangeList,
|
changeList: mappedChangeList,
|
||||||
notify: this.notifyDiscord,
|
notify: this.notifyDiscord,
|
||||||
},
|
});
|
||||||
{
|
|
||||||
baseURL,
|
|
||||||
withCredentials: true,
|
|
||||||
}
|
|
||||||
);
|
|
||||||
|
|
||||||
return response;
|
return response;
|
||||||
|
} catch (error) {
|
||||||
|
throw error;
|
||||||
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
setUserData(responseData: IUser) {
|
setUserData(responseData: IUser) {
|
||||||
|
|||||||
+9
-12
@@ -14,7 +14,7 @@
|
|||||||
<br />
|
<br />
|
||||||
<input type="password" id="password" v-model="password" />
|
<input type="password" id="password" v-model="password" />
|
||||||
<br />
|
<br />
|
||||||
<button>{{ loginState == LoginState.LOADING ? 'Logowanie...' : 'Zaloguj się' }}</button>
|
<button>{{ isLoading ? 'Logowanie...' : 'Zaloguj się' }}</button>
|
||||||
</form>
|
</form>
|
||||||
<p style="color: yellow; height: 25px">{{ errorMessage }}</p>
|
<p style="color: yellow; height: 25px">{{ errorMessage }}</p>
|
||||||
</div>
|
</div>
|
||||||
@@ -22,9 +22,9 @@
|
|||||||
|
|
||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import { defineComponent } from 'vue';
|
import { defineComponent } from 'vue';
|
||||||
import { useStore, baseURL } from '../store';
|
import { useStore } from '../store';
|
||||||
import { AuthState, IUser } from '../types/types';
|
import { AuthState, IUser } from '../types/types';
|
||||||
import axios from 'axios';
|
import client from '../common/http';
|
||||||
|
|
||||||
enum LoginState {
|
enum LoginState {
|
||||||
INITIALIZED = 0,
|
INITIALIZED = 0,
|
||||||
@@ -38,6 +38,7 @@ export default defineComponent({
|
|||||||
return {
|
return {
|
||||||
errorMessage: '',
|
errorMessage: '',
|
||||||
loginState: LoginState.INITIALIZED,
|
loginState: LoginState.INITIALIZED,
|
||||||
|
isLoading: false,
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
|
|
||||||
@@ -55,21 +56,15 @@ export default defineComponent({
|
|||||||
methods: {
|
methods: {
|
||||||
async signIn(e: Event) {
|
async signIn(e: Event) {
|
||||||
this.loginState = LoginState.LOADING;
|
this.loginState = LoginState.LOADING;
|
||||||
|
this.isLoading = true;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const response = await axios.post<IUser>(
|
const response = await client.post<IUser>('auth/login', { username: this.name, password: this.password });
|
||||||
'auth/login',
|
|
||||||
{ username: this.name, password: this.password },
|
|
||||||
{
|
|
||||||
baseURL,
|
|
||||||
withCredentials: true,
|
|
||||||
}
|
|
||||||
);
|
|
||||||
|
|
||||||
|
this.$router.push('/');
|
||||||
this.store.setUserData(response.data);
|
this.store.setUserData(response.data);
|
||||||
|
|
||||||
this.loginState = LoginState.LOADED;
|
this.loginState = LoginState.LOADED;
|
||||||
this.$router.push('/');
|
|
||||||
} catch (e: any) {
|
} catch (e: any) {
|
||||||
this.loginState = LoginState.ERROR;
|
this.loginState = LoginState.ERROR;
|
||||||
this.store.removeUserData();
|
this.store.removeUserData();
|
||||||
@@ -89,6 +84,8 @@ export default defineComponent({
|
|||||||
|
|
||||||
this.errorMessage = 'Wystąpił błąd podczas łączenia z serwerem!';
|
this.errorMessage = 'Wystąpił błąd podczas łączenia z serwerem!';
|
||||||
return false;
|
return false;
|
||||||
|
} finally {
|
||||||
|
this.isLoading = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
|||||||
@@ -19,9 +19,7 @@
|
|||||||
<tr v-for="(station, row) in store.sortedStationList" tabindex="0">
|
<tr v-for="(station, row) in store.sortedStationList" tabindex="0">
|
||||||
<td v-for="(value, propName) in headerNameList" @click="changeProperty(station, row, propName as string)">
|
<td v-for="(value, propName) in headerNameList" @click="changeProperty(station, row, propName as string)">
|
||||||
<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 === 'projectUrl'" :style="station.projectUrl ? 'color: gold' : 'color: gray;'"
|
<span v-else-if="propName === 'projectUrl'" :style="station.projectUrl ? 'color: gold' : 'color: gray;'">URL</span>
|
||||||
>URL</span
|
|
||||||
>
|
|
||||||
|
|
||||||
<span v-else-if="propName === 'checkpoints'">{{ station[propName] ? 'POKAŻ' : 'DODAJ' }}</span>
|
<span v-else-if="propName === 'checkpoints'">{{ station[propName] ? 'POKAŻ' : 'DODAJ' }}</span>
|
||||||
|
|
||||||
@@ -119,9 +117,7 @@ export default defineComponent({
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const stationListRow = this.store.stationList.findIndex(
|
const stationListRow = this.store.stationList.findIndex((station) => station.name == this.store.sortedStationList[row].name);
|
||||||
(station) => station.name == this.store.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];
|
||||||
@@ -134,16 +130,13 @@ export default defineComponent({
|
|||||||
|
|
||||||
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(station, propertyName, oldValue, typeof oldValue === 'number' ? parseInt(newValue) : newValue);
|
this.addChange(station, 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.store.sortedStationList[row].name);
|
||||||
(station) => station.name == this.store.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;
|
||||||
@@ -234,4 +227,8 @@ td img {
|
|||||||
height: 1.45em;
|
height: 1.45em;
|
||||||
vertical-align: middle;
|
vertical-align: middle;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
button {
|
||||||
|
color: black;
|
||||||
|
}
|
||||||
</style>
|
</style>
|
||||||
|
|||||||
Reference in New Issue
Block a user