mirror of
https://github.com/Spythere/stacjownik.git
synced 2026-05-03 05:18:11 +00:00
feature: nieskończona lista historii dr/rj scenerii
This commit is contained in:
@@ -2,7 +2,7 @@
|
|||||||
<section class="scenery-dispatchers-history scenery-section">
|
<section class="scenery-dispatchers-history scenery-section">
|
||||||
<Loading v-if="dataStatus != 2" />
|
<Loading v-if="dataStatus != 2" />
|
||||||
|
|
||||||
<table class="scenery-history-table" v-else-if="dispatcherHistoryList.length">
|
<table class="scenery-history-table" v-else-if="historyList.length">
|
||||||
<thead>
|
<thead>
|
||||||
<!-- <th>{{ $t('scenery.timetables-history-id') }}</th>
|
<!-- <th>{{ $t('scenery.timetables-history-id') }}</th>
|
||||||
<th>{{ $t('scenery.timetables-history-number') }}</th>
|
<th>{{ $t('scenery.timetables-history-number') }}</th>
|
||||||
@@ -19,7 +19,7 @@
|
|||||||
</thead>
|
</thead>
|
||||||
|
|
||||||
<tbody>
|
<tbody>
|
||||||
<tr v-for="historyItem in dispatcherHistoryList">
|
<tr v-for="historyItem in historyList">
|
||||||
<td>#{{ historyItem.stationHash }}</td>
|
<td>#{{ historyItem.stationHash }}</td>
|
||||||
<td>
|
<td>
|
||||||
<router-link :to="`/journal/dispatchers?dispatcherName=${historyItem.dispatcherName}`">
|
<router-link :to="`/journal/dispatchers?dispatcherName=${historyItem.dispatcherName}`">
|
||||||
@@ -57,6 +57,7 @@
|
|||||||
</table>
|
</table>
|
||||||
|
|
||||||
<div class="no-history" v-else>{{ $t('scenery.history-list-empty') }}</div>
|
<div class="no-history" v-else>{{ $t('scenery.history-list-empty') }}</div>
|
||||||
|
<div ref="bottomDiv"></div>
|
||||||
</section>
|
</section>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
@@ -70,24 +71,35 @@ import Station from '../../scripts/interfaces/Station';
|
|||||||
import { URLs } from '../../scripts/utils/apiURLs';
|
import { URLs } from '../../scripts/utils/apiURLs';
|
||||||
import Loading from '../Global/Loading.vue';
|
import Loading from '../Global/Loading.vue';
|
||||||
import styleMixin from '../../mixins/styleMixin';
|
import styleMixin from '../../mixins/styleMixin';
|
||||||
|
import listObserverMixin from '../../mixins/listObserverMixin';
|
||||||
|
|
||||||
export default defineComponent({
|
export default defineComponent({
|
||||||
name: 'SceneryDispatchersHistory',
|
name: 'SceneryDispatchersHistory',
|
||||||
mixins: [dateMixin, styleMixin],
|
mixins: [dateMixin, styleMixin, listObserverMixin],
|
||||||
props: {
|
props: {
|
||||||
station: {
|
station: {
|
||||||
type: Object as PropType<Station>,
|
type: Object as PropType<Station>,
|
||||||
required: true,
|
required: true,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
||||||
data() {
|
data() {
|
||||||
return {
|
return {
|
||||||
dispatcherHistoryList: [] as DispatcherHistory[],
|
historyList: [] as DispatcherHistory[],
|
||||||
dataStatus: DataStatus.Loading,
|
dataStatus: DataStatus.Loading,
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
|
|
||||||
|
mounted() {
|
||||||
|
this.mountObserver(this.fireObserverAction, this.$refs['bottomDiv'] as Element);
|
||||||
|
},
|
||||||
|
|
||||||
|
unmounted() {
|
||||||
|
this.unmountObserver();
|
||||||
|
},
|
||||||
|
|
||||||
activated() {
|
activated() {
|
||||||
this.fetchAPIData();
|
if (this.historyList.length == 0) this.fetchAPIData();
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
async fetchAPIData(countFrom = 0, countLimit = 30) {
|
async fetchAPIData(countFrom = 0, countLimit = 30) {
|
||||||
@@ -95,12 +107,17 @@ export default defineComponent({
|
|||||||
const requestString = `${URLs.stacjownikAPI}/api/getDispatchers?stationName=${this.station.name}&countFrom=${countFrom}&countLimit=${countLimit}`;
|
const requestString = `${URLs.stacjownikAPI}/api/getDispatchers?stationName=${this.station.name}&countFrom=${countFrom}&countLimit=${countLimit}`;
|
||||||
const historyAPIData: DispatcherHistory[] = await (await axios.get(requestString)).data;
|
const historyAPIData: DispatcherHistory[] = await (await axios.get(requestString)).data;
|
||||||
|
|
||||||
this.dispatcherHistoryList = historyAPIData;
|
this.historyList.push(...historyAPIData);
|
||||||
this.dataStatus = DataStatus.Loaded;
|
this.dataStatus = DataStatus.Loaded;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error(error);
|
console.error(error);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
fireObserverAction() {
|
||||||
|
if (this.historyList.length > 0 && this.dataStatus == DataStatus.Loaded)
|
||||||
|
this.fetchAPIData(this.historyList.length);
|
||||||
|
},
|
||||||
},
|
},
|
||||||
components: { Loading },
|
components: { Loading },
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
<section class="scenery-timetables-history scenery-section">
|
<section class="scenery-timetables-history scenery-section">
|
||||||
<Loading v-if="dataStatus != 2" />
|
<Loading v-if="dataStatus != 2" />
|
||||||
|
|
||||||
<table class="scenery-history-table" v-else-if="sceneryHistoryList.length">
|
<table class="scenery-history-table" v-else-if="historyList.length">
|
||||||
<thead>
|
<thead>
|
||||||
<th>{{ $t('scenery.timetables-history-id') }}</th>
|
<th>{{ $t('scenery.timetables-history-id') }}</th>
|
||||||
<th>{{ $t('scenery.timetables-history-number') }}</th>
|
<th>{{ $t('scenery.timetables-history-number') }}</th>
|
||||||
@@ -13,7 +13,7 @@
|
|||||||
</thead>
|
</thead>
|
||||||
|
|
||||||
<tbody>
|
<tbody>
|
||||||
<tr v-for="historyItem in sceneryHistoryList">
|
<tr v-for="historyItem in historyList">
|
||||||
<td>
|
<td>
|
||||||
<router-link :to="`/journal/timetables?timetableId=${historyItem.id}`">#{{ historyItem.id }}</router-link>
|
<router-link :to="`/journal/timetables?timetableId=${historyItem.id}`">#{{ historyItem.id }}</router-link>
|
||||||
</td>
|
</td>
|
||||||
@@ -40,6 +40,7 @@
|
|||||||
</table>
|
</table>
|
||||||
|
|
||||||
<div class="no-history" v-else>{{ $t('scenery.history-list-empty') }}</div>
|
<div class="no-history" v-else>{{ $t('scenery.history-list-empty') }}</div>
|
||||||
|
<div ref="bottomDiv"></div>
|
||||||
</section>
|
</section>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
@@ -52,37 +53,54 @@ import { TimetableHistory, SceneryTimetableHistory } from '../../scripts/interfa
|
|||||||
import Station from '../../scripts/interfaces/Station';
|
import Station from '../../scripts/interfaces/Station';
|
||||||
import { URLs } from '../../scripts/utils/apiURLs';
|
import { URLs } from '../../scripts/utils/apiURLs';
|
||||||
import Loading from '../Global/Loading.vue';
|
import Loading from '../Global/Loading.vue';
|
||||||
|
import listObserverMixin from '../../mixins/listObserverMixin';
|
||||||
|
|
||||||
export default defineComponent({
|
export default defineComponent({
|
||||||
name: 'SceneryTimetablesHistory',
|
name: 'SceneryTimetablesHistory',
|
||||||
mixins: [dateMixin],
|
mixins: [dateMixin, listObserverMixin],
|
||||||
props: {
|
props: {
|
||||||
station: {
|
station: {
|
||||||
type: Object as PropType<Station>,
|
type: Object as PropType<Station>,
|
||||||
required: true,
|
required: true,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
||||||
data() {
|
data() {
|
||||||
return {
|
return {
|
||||||
sceneryHistoryList: [] as TimetableHistory[],
|
historyList: [] as TimetableHistory[],
|
||||||
dataStatus: DataStatus.Loading,
|
dataStatus: DataStatus.Loading,
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
activated() {
|
|
||||||
this.fetchAPIData();
|
mounted() {
|
||||||
|
this.mountObserver(this.fireObserverAction, this.$refs['bottomDiv'] as Element);
|
||||||
},
|
},
|
||||||
|
|
||||||
|
unmounted() {
|
||||||
|
this.unmountObserver();
|
||||||
|
},
|
||||||
|
|
||||||
|
activated() {
|
||||||
|
if (this.historyList.length == 0) this.fetchAPIData();
|
||||||
|
},
|
||||||
|
|
||||||
methods: {
|
methods: {
|
||||||
async fetchAPIData(countFrom = 0, countLimit = 15) {
|
async fetchAPIData(countFrom = 0, countLimit = 15) {
|
||||||
try {
|
try {
|
||||||
const requestString = `${URLs.stacjownikAPI}/api/getIssuedTimetables?name=${this.station.name}&countFrom=${countFrom}&countLimit=${countLimit}`;
|
const requestString = `${URLs.stacjownikAPI}/api/getIssuedTimetables?name=${this.station.name}&countFrom=${countFrom}&countLimit=${countLimit}`;
|
||||||
const historyAPIData: SceneryTimetableHistory = await (await axios.get(requestString)).data;
|
const historyAPIData: SceneryTimetableHistory = await (await axios.get(requestString)).data;
|
||||||
|
|
||||||
this.sceneryHistoryList = historyAPIData.timetables;
|
this.historyList.push(...historyAPIData.timetables);
|
||||||
this.dataStatus = DataStatus.Loaded;
|
this.dataStatus = DataStatus.Loaded;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error(error);
|
console.error(error);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
fireObserverAction() {
|
||||||
|
if (this.historyList.length > 0 && this.dataStatus == DataStatus.Loaded)
|
||||||
|
this.fetchAPIData(this.historyList.length);
|
||||||
|
},
|
||||||
},
|
},
|
||||||
components: { Loading },
|
components: { Loading },
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -0,0 +1,24 @@
|
|||||||
|
import { defineComponent } from 'vue';
|
||||||
|
|
||||||
|
export default defineComponent({
|
||||||
|
data: () => ({
|
||||||
|
observer: null as IntersectionObserver | null,
|
||||||
|
observerTarget: null as Element | null,
|
||||||
|
}),
|
||||||
|
|
||||||
|
methods: {
|
||||||
|
mountObserver(actionFunction: () => void, target: Element) {
|
||||||
|
this.observer = new IntersectionObserver((entries) => {
|
||||||
|
if (entries[0].intersectionRatio > 0) actionFunction();
|
||||||
|
});
|
||||||
|
|
||||||
|
this.observer.observe(target);
|
||||||
|
},
|
||||||
|
|
||||||
|
unmountObserver() {
|
||||||
|
if (!this.observerTarget) return;
|
||||||
|
|
||||||
|
this.observer?.unobserve(this.observerTarget);
|
||||||
|
},
|
||||||
|
},
|
||||||
|
});
|
||||||
Reference in New Issue
Block a user