POprawiono url do api

This commit is contained in:
2022-05-19 21:30:38 +02:00
parent cb6be0e1f1
commit 0440e47de8
+38 -26
View File
@@ -28,14 +28,16 @@
<!-- <transition name="unfold-anim" @enter="enter" @afterEnter="afterEnter" @leave="leave"> --> <!-- <transition name="unfold-anim" @enter="enter" @afterEnter="afterEnter" @leave="leave"> -->
<!-- <div class="dispatcher-list" v-if="timeline.showTimeline"> --> <!-- <div class="dispatcher-list" v-if="timeline.showTimeline"> -->
<div class="dispatcher-item" v-for="dispatcher in timeline.dispatchers" :key="dispatcher.dispatcherFrom"> <div class="dispatcher-item" v-for="dispatcher in timeline.dispatchers" :key="dispatcher.timestampFrom">
<b>{{ dispatcher.dispatcherName }}</b> <b>{{ dispatcher.dispatcherName }}</b>
<span> <span>
<span class="dispatcher-from text--primary"> <span class="dispatcher-from text--primary">
{{ timestampToString(dispatcher.dispatcherFrom, true) }} {{ timestampToString(dispatcher.timestampFrom, true) }}
</span>
<span class="dispatcher-to text--primary" v-if="dispatcher.timestampTo">
&gt; {{ timestampToString(dispatcher.timestampTo, true) }}
</span> </span>
&gt;
<span class="dispatcher-to text--primary"> {{ timestampToString(dispatcher.dispatcherTo, true) }}</span>
</span> </span>
</div> </div>
<!-- </div> --> <!-- </div> -->
@@ -60,30 +62,32 @@ interface DispatcherTimeline {
interface DispatcherHistory { interface DispatcherHistory {
dispatcherName: string; dispatcherName: string;
dispatcherId: number; dispatcherId: number;
dispatcherFrom: any; timestampFrom: number;
dispatcherTo: any; timestampTo?: number;
} }
interface SceneryHistory { interface SceneryHistoryResponse {
stops: any[];
checkpoints: any[];
stationName: string; stationName: string;
currentDispatcher: string; stationHash: string;
currentDispatcherId: number; region: string;
currentDispatcherFrom: number; dispatcherName: string;
dispatcherHistory: DispatcherHistory[]; dispatcherId: number;
timestampFrom: number;
timestampTo?: number;
currentDuration: number;
isOnline: boolean;
lastOnlineTimestamp: number;
} }
interface HistoryResultAPI { interface HistoryResultAPI {
response: SceneryHistory; response: SceneryHistoryResponse[];
errorMessage?: any; errorMessage?: string;
} }
const API_URL = `${URLs.stacjownikAPI}/api/getSceneryHistory`; const HISTORY_API_URL = `${URLs.stacjownikAPI}/api/getSceneryHistory`;
export default defineComponent({ export default defineComponent({
data: () => ({ data: () => ({
dispatcherHistory: [] as DispatcherHistory[],
dispatcherTimeline: [] as DispatcherTimeline[], dispatcherTimeline: [] as DispatcherTimeline[],
isLoaded: false, isLoaded: false,
@@ -107,19 +111,21 @@ export default defineComponent({
async mounted() { async mounted() {
try { try {
const apiResult: HistoryResultAPI = (await axios.get(`${API_URL}?name=${this.name}&historyCount=100`)).data; const apiResult: HistoryResultAPI = (await axios.get(`${HISTORY_API_URL}?name=${this.name}&historyCount=100`)).data;
if (!apiResult || !apiResult.response) return; if (!apiResult || !apiResult.response) return;
this.isLoaded = true; this.isLoaded = true;
if (apiResult.errorMessage) return; if (apiResult.errorMessage) return;
this.dispatcherHistory = apiResult.response.dispatcherHistory; console.log(apiResult);
this.savedSceneryHistory = this.dispatcherHistory;
this.dispatcherTimeline = this.dispatcherHistory const dispatcherHistoryResult = apiResult.response;
.reduce((acc, dispatcher) => { this.savedSceneryHistory = dispatcherHistoryResult;
const dateStr = new Date(dispatcher.dispatcherFrom).toLocaleDateString('pl-PL').replace(/\./g, '/');
this.dispatcherTimeline = apiResult.response.reduce(
(acc, { timestampFrom, timestampTo, dispatcherId, dispatcherName }) => {
const dateStr = new Date(timestampFrom).toLocaleDateString('pl-PL').replace(/\./g, '/');
const timelineDay = acc.find((timeline) => timeline.date == dateStr) || { const timelineDay = acc.find((timeline) => timeline.date == dateStr) || {
date: dateStr, date: dateStr,
@@ -127,13 +133,19 @@ export default defineComponent({
showTimeline: false, showTimeline: false,
}; };
timelineDay.dispatchers.unshift(dispatcher); timelineDay.dispatchers.unshift({
timestampFrom,
timestampTo,
dispatcherId,
dispatcherName,
});
if (!acc.find((timeline) => timeline.date == dateStr)) acc.push(timelineDay); if (!acc.find((timeline) => timeline.date == dateStr)) acc.push(timelineDay);
return acc; return acc;
}, [] as DispatcherTimeline[]) },
.reverse(); [] as DispatcherTimeline[]
);
} catch (error) { } catch (error) {
console.error(error); console.error(error);
} }