mirror of
https://github.com/Spythere/stacjownik.git
synced 2026-05-03 05:18:11 +00:00
refactor typów danych
This commit is contained in:
@@ -36,16 +36,14 @@ import axios from 'axios';
|
||||
|
||||
import JournalOptions from '../components/JournalView/JournalOptions.vue';
|
||||
import { URLs } from '../scripts/utils/apiURLs';
|
||||
import { DataStatus } from '../scripts/enums/DataStatus';
|
||||
import { useStore } from '../store/store';
|
||||
import { useStore } from '../store/mainStore';
|
||||
import JournalDispatchersList from '../components/JournalView/JournalDispatchersList.vue';
|
||||
import {
|
||||
JournalDispatcherSearcher,
|
||||
JournalDispatcherSorter
|
||||
} from '../scripts/types/JournalDispatcherTypes';
|
||||
import { DispatcherHistory } from '../scripts/interfaces/api/DispatchersAPIData';
|
||||
|
||||
import JournalHeader from '../components/JournalView/JournalHeader.vue';
|
||||
import { LocationQuery } from 'vue-router';
|
||||
import { Journal } from '../components/JournalView/typings';
|
||||
import { API } from '../typings/api';
|
||||
import { Status } from '../typings/common';
|
||||
|
||||
const DISPATCHERS_API_URL = `${URLs.stacjownikAPI}/api/getDispatchers`;
|
||||
|
||||
@@ -81,21 +79,20 @@ export default defineComponent({
|
||||
statsCardOpen: false,
|
||||
currentOptionsActive: false,
|
||||
|
||||
dataStatus: DataStatus.Loading,
|
||||
DataStatus,
|
||||
dataStatus: Status.Data.Loading,
|
||||
|
||||
historyList: [] as DispatcherHistory[]
|
||||
historyList: [] as API.DispatcherHistory.Response
|
||||
}),
|
||||
|
||||
setup() {
|
||||
const sorterActive: JournalDispatcherSorter = reactive({ id: 'timestampFrom', dir: -1 });
|
||||
const sorterActive: Journal.DispatcherSorter = reactive({ id: 'timestampFrom', dir: -1 });
|
||||
const journalFilterActive = ref({});
|
||||
|
||||
const searchersValues = reactive({
|
||||
'search-dispatcher': '',
|
||||
'search-station': '',
|
||||
'search-date': ''
|
||||
} as JournalDispatcherSearcher);
|
||||
} as Journal.DispatcherSearcher);
|
||||
|
||||
const countFromIndex = ref(0);
|
||||
const countLimit = 15;
|
||||
@@ -153,7 +150,7 @@ export default defineComponent({
|
||||
const scrollTop = listElement.scrollTop;
|
||||
const elementHeight = listElement.scrollHeight - listElement.offsetHeight;
|
||||
|
||||
if (!this.scrollDataLoaded || this.scrollNoMoreData || this.dataStatus != DataStatus.Loaded)
|
||||
if (!this.scrollDataLoaded || this.scrollNoMoreData || this.dataStatus != Status.Data.Loaded)
|
||||
return;
|
||||
|
||||
if (scrollTop > elementHeight * 0.85) this.addHistoryData();
|
||||
@@ -185,7 +182,7 @@ export default defineComponent({
|
||||
|
||||
this.countFromIndex = this.historyList.length;
|
||||
|
||||
const responseData: DispatcherHistory[] = await (
|
||||
const responseData: API.DispatcherHistory.Response = await (
|
||||
await axios.get(
|
||||
`${DISPATCHERS_API_URL}?${this.currentQuery}&countFrom=${this.countFromIndex}`
|
||||
)
|
||||
@@ -226,20 +223,20 @@ export default defineComponent({
|
||||
|
||||
queries.push('countLimit=30');
|
||||
|
||||
if (this.currentQuery != queries.join('&')) this.dataStatus = DataStatus.Loading;
|
||||
if (this.currentQuery != queries.join('&')) this.dataStatus = Status.Data.Loading;
|
||||
|
||||
this.currentQuery = queries.join('&');
|
||||
this.currentQueryArray = queries;
|
||||
|
||||
try {
|
||||
if (reset) this.dataStatus = DataStatus.Loading;
|
||||
if (reset) this.dataStatus = Status.Data.Loading;
|
||||
|
||||
const responseData: DispatcherHistory[] = await (
|
||||
const responseData: API.DispatcherHistory.Response = await (
|
||||
await axios.get(`${DISPATCHERS_API_URL}?${this.currentQuery}`)
|
||||
).data;
|
||||
|
||||
if (!responseData) {
|
||||
this.dataStatus = DataStatus.Error;
|
||||
this.dataStatus = Status.Data.Error;
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -255,9 +252,9 @@ export default defineComponent({
|
||||
: '';
|
||||
|
||||
this.dataRefreshedAt = new Date();
|
||||
this.dataStatus = DataStatus.Loaded;
|
||||
this.dataStatus = Status.Data.Loaded;
|
||||
} catch (error) {
|
||||
this.dataStatus = DataStatus.Error;
|
||||
this.dataStatus = Status.Data.Error;
|
||||
}
|
||||
|
||||
this.scrollNoMoreData = false;
|
||||
|
||||
@@ -45,24 +45,84 @@ import JournalOptions from '../components/JournalView/JournalOptions.vue';
|
||||
import JournalStats from '../components/JournalView/JournalStats.vue';
|
||||
import JournalHeader from '../components/JournalView/JournalHeader.vue';
|
||||
|
||||
import { DataStatus } from '../scripts/enums/DataStatus';
|
||||
import { TimetableHistory } from '../scripts/interfaces/api/TimetablesAPIData';
|
||||
import { URLs } from '../scripts/utils/apiURLs';
|
||||
import { useStore } from '../store/store';
|
||||
import { useStore } from '../store/mainStore';
|
||||
|
||||
import { LocationQuery } from 'vue-router';
|
||||
import { TimetablesQueryParams } from '../scripts/interfaces/api/TimetablesQueryParams';
|
||||
import { JournalFilterType } from '../scripts/enums/JournalFilterType';
|
||||
import {
|
||||
JournalFilter,
|
||||
JournalTimetableSearchType,
|
||||
JournalTimetableSorter
|
||||
} from '../scripts/types/JournalTimetablesTypes';
|
||||
import { journalTimetableFilters } from '../constants/Journal/JournalTimetablesConsts';
|
||||
|
||||
import JournalTimetablesList from '../components/JournalView/JournalTimetables/JournalTimetablesList.vue';
|
||||
import { Journal } from '../components/JournalView/typings';
|
||||
import { Status } from '../typings/common';
|
||||
import { API } from '../typings/api';
|
||||
|
||||
const TIMETABLES_API_URL = `${URLs.stacjownikAPI}/api/getTimetables`;
|
||||
|
||||
export const journalTimetableFilters: Journal.TimetableFilter[] = [
|
||||
{
|
||||
id: Journal.TimetableFilterId.ALL,
|
||||
filterSection: Journal.FilterSection.TIMETABLE_STATUS,
|
||||
isActive: true
|
||||
},
|
||||
|
||||
{
|
||||
id: Journal.TimetableFilterId.ACTIVE,
|
||||
filterSection: Journal.FilterSection.TIMETABLE_STATUS,
|
||||
isActive: false
|
||||
},
|
||||
|
||||
{
|
||||
id: Journal.TimetableFilterId.FULFILLED,
|
||||
filterSection: Journal.FilterSection.TIMETABLE_STATUS,
|
||||
isActive: false
|
||||
},
|
||||
|
||||
{
|
||||
id: Journal.TimetableFilterId.ABANDONED,
|
||||
filterSection: Journal.FilterSection.TIMETABLE_STATUS,
|
||||
isActive: false
|
||||
},
|
||||
|
||||
{
|
||||
id: Journal.TimetableFilterId.TWR_SKR,
|
||||
filterSection: Journal.FilterSection.TWRSKR,
|
||||
isActive: true
|
||||
},
|
||||
|
||||
{
|
||||
id: Journal.TimetableFilterId.TWR,
|
||||
filterSection: Journal.FilterSection.TWRSKR,
|
||||
isActive: false
|
||||
},
|
||||
|
||||
{
|
||||
id: Journal.TimetableFilterId.SKR,
|
||||
filterSection: Journal.FilterSection.TWRSKR,
|
||||
isActive: false
|
||||
}
|
||||
];
|
||||
|
||||
interface TimetablesQueryParams {
|
||||
driverName?: string;
|
||||
trainNo?: string;
|
||||
timetableId?: string;
|
||||
|
||||
authorName?: string;
|
||||
timestampFrom?: number;
|
||||
timestampTo?: number;
|
||||
issuedFrom?: string;
|
||||
|
||||
countFrom?: number;
|
||||
countLimit?: number;
|
||||
|
||||
fulfilled?: number;
|
||||
terminated?: number;
|
||||
|
||||
twr?: number;
|
||||
skr?: number;
|
||||
|
||||
sortBy?: Journal.TimetableSorter['id'];
|
||||
}
|
||||
|
||||
export default defineComponent({
|
||||
components: {
|
||||
JournalOptions,
|
||||
@@ -91,22 +151,20 @@ export default defineComponent({
|
||||
statsCardOpen: false,
|
||||
currentOptionsActive: false,
|
||||
|
||||
timetableHistory: [] as TimetableHistory[],
|
||||
timetableHistory: [] as API.TimetableHistory.Response,
|
||||
journalTimetableFilters,
|
||||
|
||||
dataStatus: DataStatus.Loading,
|
||||
dataErrorMessage: '',
|
||||
|
||||
DataStatus
|
||||
dataStatus: Status.Data.Loading,
|
||||
dataErrorMessage: ''
|
||||
}),
|
||||
|
||||
setup() {
|
||||
const sorterActive: JournalTimetableSorter = reactive({ id: 'timetableId', dir: 'desc' });
|
||||
const sorterActive: Journal.TimetableSorter = reactive({ id: 'timetableId', dir: 'desc' });
|
||||
// const journalFilterActive = ref(journalTimetableFilters[0]);
|
||||
const initFilters: readonly JournalFilter[] = JSON.parse(
|
||||
const initFilters: readonly Journal.TimetableFilter[] = JSON.parse(
|
||||
JSON.stringify(journalTimetableFilters)
|
||||
);
|
||||
const filterList: JournalFilter[] = reactive(JSON.parse(JSON.stringify(initFilters)));
|
||||
const filterList: Journal.TimetableFilter[] = reactive(JSON.parse(JSON.stringify(initFilters)));
|
||||
|
||||
const searchersValues = reactive({
|
||||
'search-train': '',
|
||||
@@ -114,7 +172,7 @@ export default defineComponent({
|
||||
'search-dispatcher': '',
|
||||
'search-issuedFrom': '',
|
||||
'search-date': ''
|
||||
} as JournalTimetableSearchType);
|
||||
} as Journal.TimetableSearchType);
|
||||
|
||||
const countFromIndex = ref(0);
|
||||
const countLimit = 15;
|
||||
@@ -163,7 +221,7 @@ export default defineComponent({
|
||||
const scrollTop = listElement.scrollTop;
|
||||
const elementHeight = listElement.scrollHeight - listElement.offsetHeight;
|
||||
|
||||
if (!this.scrollDataLoaded || this.scrollNoMoreData || this.dataStatus != DataStatus.Loaded)
|
||||
if (!this.scrollDataLoaded || this.scrollNoMoreData || this.dataStatus != Status.Data.Loaded)
|
||||
return;
|
||||
|
||||
if (scrollTop > elementHeight * 0.85) this.addHistoryData();
|
||||
@@ -213,7 +271,7 @@ export default defineComponent({
|
||||
|
||||
this.currentQueryParams['countFrom'] = this.timetableHistory.length;
|
||||
|
||||
const responseData: TimetableHistory[] = await (
|
||||
const responseData: API.TimetableHistory.Response = await (
|
||||
await axios.get(`${TIMETABLES_API_URL}`, {
|
||||
params: { ...this.currentQueryParams }
|
||||
})
|
||||
@@ -248,37 +306,37 @@ export default defineComponent({
|
||||
.filter((f) => f.isActive)
|
||||
.forEach((f) => {
|
||||
switch (f.id) {
|
||||
case JournalFilterType.ABANDONED:
|
||||
case Journal.TimetableFilterId.ABANDONED:
|
||||
queryParams['fulfilled'] = 0;
|
||||
queryParams['terminated'] = 1;
|
||||
break;
|
||||
|
||||
case JournalFilterType.ACTIVE:
|
||||
case Journal.TimetableFilterId.ACTIVE:
|
||||
queryParams['fulfilled'] = undefined;
|
||||
queryParams['terminated'] = 0;
|
||||
break;
|
||||
|
||||
case JournalFilterType.FULFILLED:
|
||||
case Journal.TimetableFilterId.FULFILLED:
|
||||
queryParams['terminated'] = undefined;
|
||||
queryParams['fulfilled'] = 1;
|
||||
break;
|
||||
|
||||
case JournalFilterType.ALL:
|
||||
case Journal.TimetableFilterId.ALL:
|
||||
queryParams['terminated'] = undefined;
|
||||
queryParams['fulfilled'] = undefined;
|
||||
break;
|
||||
|
||||
case JournalFilterType.TWR_SKR:
|
||||
case Journal.TimetableFilterId.TWR_SKR:
|
||||
queryParams['twr'] = undefined;
|
||||
queryParams['skr'] = undefined;
|
||||
break;
|
||||
|
||||
case JournalFilterType.TWR:
|
||||
case Journal.TimetableFilterId.TWR:
|
||||
queryParams['twr'] = 1;
|
||||
queryParams['skr'] = undefined;
|
||||
break;
|
||||
|
||||
case JournalFilterType.SKR:
|
||||
case Journal.TimetableFilterId.SKR:
|
||||
queryParams['twr'] = undefined;
|
||||
queryParams['skr'] = 1;
|
||||
break;
|
||||
@@ -301,19 +359,19 @@ export default defineComponent({
|
||||
this.sorterActive.id != 'timetableId' ? this.sorterActive.id : undefined;
|
||||
|
||||
if (JSON.stringify(this.currentQueryParams) != JSON.stringify(queryParams))
|
||||
this.dataStatus = DataStatus.Loading;
|
||||
this.dataStatus = Status.Data.Loading;
|
||||
|
||||
this.currentQueryParams = queryParams;
|
||||
|
||||
try {
|
||||
const responseData: TimetableHistory[] = await (
|
||||
const responseData: API.TimetableHistory.Response = await (
|
||||
await axios.get(`${TIMETABLES_API_URL}`, {
|
||||
params: this.currentQueryParams
|
||||
})
|
||||
).data;
|
||||
|
||||
if (!responseData) {
|
||||
this.dataStatus = DataStatus.Error;
|
||||
this.dataStatus = Status.Data.Error;
|
||||
this.dataErrorMessage = 'Brak danych!';
|
||||
return;
|
||||
}
|
||||
@@ -329,10 +387,10 @@ export default defineComponent({
|
||||
? this.timetableHistory[0].driverName
|
||||
: '';
|
||||
|
||||
this.dataStatus = DataStatus.Loaded;
|
||||
this.dataStatus = Status.Data.Loaded;
|
||||
this.dataRefreshedAt = new Date();
|
||||
} catch (error) {
|
||||
this.dataStatus = DataStatus.Error;
|
||||
this.dataStatus = Status.Data.Error;
|
||||
this.dataErrorMessage = 'Ups! Coś poszło nie tak!';
|
||||
}
|
||||
|
||||
|
||||
@@ -50,7 +50,7 @@
|
||||
import { computed, defineComponent } from 'vue';
|
||||
import { useRoute } from 'vue-router';
|
||||
import routerMixin from '../mixins/routerMixin';
|
||||
import { useStore } from '../store/store';
|
||||
import { useStore } from '../store/mainStore';
|
||||
|
||||
import SceneryInfo from '../components/SceneryView/SceneryInfo.vue';
|
||||
import SceneryHeader from '../components/SceneryView/SceneryHeader.vue';
|
||||
|
||||
@@ -21,7 +21,7 @@ import { defineComponent } from 'vue';
|
||||
import StationTable from '../components/StationsView/StationTable.vue';
|
||||
import StationFilterCard from '../components/StationsView/StationFilterCard.vue';
|
||||
import { useStationFiltersStore } from '../store/stationFiltersStore';
|
||||
import { useStore } from '../store/store';
|
||||
import { useStore } from '../store/mainStore';
|
||||
|
||||
export default defineComponent({
|
||||
components: {
|
||||
@@ -38,7 +38,6 @@ export default defineComponent({
|
||||
store: useStore()
|
||||
}),
|
||||
|
||||
|
||||
computed: {
|
||||
computedStationList() {
|
||||
return this.filterStore.filteredStationList;
|
||||
|
||||
@@ -15,12 +15,11 @@
|
||||
import { computed, ComputedRef, defineComponent, provide, reactive, ref, watch } from 'vue';
|
||||
import TrainOptions from '../components/TrainsView/TrainOptions.vue';
|
||||
import TrainTable from '../components/TrainsView/TrainTable.vue';
|
||||
import { trainFilters } from '../constants/Trains/TrainOptionsConsts';
|
||||
import modalTrainMixin from '../mixins/modalTrainMixin';
|
||||
import Train from '../scripts/interfaces/Train';
|
||||
import { filteredTrainList } from '../scripts/managers/trainFilterManager';
|
||||
import { useStore } from '../store/store';
|
||||
import { TrainFilter } from '../scripts/interfaces/Trains/TrainFilter';
|
||||
import { useStore } from '../store/mainStore';
|
||||
import { TrainFilter, trainFilters } from '../components/TrainsView/typings';
|
||||
import { filteredTrainList } from '../managers/trainFilterManager';
|
||||
|
||||
export default defineComponent({
|
||||
components: {
|
||||
|
||||
Reference in New Issue
Block a user