mirror of
https://github.com/Spythere/stacjownik.git
synced 2026-05-04 13:58:12 +00:00
ulepszone zapamiętywanie zakładek statystyk w dzienniku
This commit is contained in:
+4
-2
@@ -139,8 +139,10 @@ import { API } from '../../typings/api';
|
|||||||
import { Status } from '../../typings/common';
|
import { Status } from '../../typings/common';
|
||||||
|
|
||||||
export default defineComponent({
|
export default defineComponent({
|
||||||
|
name: 'journal-daily-stats',
|
||||||
|
|
||||||
mixins: [dateMixin],
|
mixins: [dateMixin],
|
||||||
emits: ['toggleStatsOpen'],
|
// emits: ['toggleStatsOpen'],
|
||||||
|
|
||||||
data() {
|
data() {
|
||||||
return {
|
return {
|
||||||
@@ -154,7 +156,7 @@ export default defineComponent({
|
|||||||
|
|
||||||
activated() {
|
activated() {
|
||||||
this.startFetchingDailyStats();
|
this.startFetchingDailyStats();
|
||||||
this.$emit('toggleStatsOpen', true);
|
// this.$emit('toggleStatsOpen', true);
|
||||||
},
|
},
|
||||||
|
|
||||||
deactivated() {
|
deactivated() {
|
||||||
@@ -59,6 +59,8 @@ import { useStore } from '../../store/mainStore';
|
|||||||
import { Status } from '../../typings/common';
|
import { Status } from '../../typings/common';
|
||||||
|
|
||||||
export default defineComponent({
|
export default defineComponent({
|
||||||
|
name: 'journal-driver-stats',
|
||||||
|
|
||||||
data() {
|
data() {
|
||||||
return {
|
return {
|
||||||
store: useStore(),
|
store: useStore(),
|
||||||
|
|||||||
@@ -184,8 +184,6 @@ export default defineComponent({
|
|||||||
watch: {
|
watch: {
|
||||||
async 'store.driverStatsName'() {
|
async 'store.driverStatsName'() {
|
||||||
await this.fetchDriverStats();
|
await this.fetchDriverStats();
|
||||||
|
|
||||||
// if (value) this.store.currentStatsTab = 'driver';
|
|
||||||
},
|
},
|
||||||
|
|
||||||
async 'searchersValues.search-driver'(value: string | undefined) {
|
async 'searchersValues.search-driver'(value: string | undefined) {
|
||||||
|
|||||||
@@ -1,27 +1,26 @@
|
|||||||
<template>
|
<template>
|
||||||
<div class="journal-stats" v-if="!store.isOffline">
|
<div class="journal-stats" v-if="!store.isOffline">
|
||||||
<div class="tabs">
|
<div class="stats-buttons">
|
||||||
<button
|
<button
|
||||||
v-for="tab in data.tabs"
|
v-for="button in data.statsButtons"
|
||||||
:key="tab.name"
|
:key="button.name"
|
||||||
class="btn--filled"
|
class="btn--filled btn--image"
|
||||||
:data-selected="tab.name == store.currentStatsTab && areStatsOpen"
|
:data-selected="button.name == currentStatsTab"
|
||||||
:data-inactive="tab.inactive"
|
@click="onTabButtonClick(button.name)"
|
||||||
:data-disabled="tab.inactive"
|
|
||||||
:disabled="tab.inactive"
|
|
||||||
@click="onTabButtonClick(tab.name)"
|
|
||||||
>
|
>
|
||||||
{{ $t(tab.titlePath) }}
|
<img
|
||||||
|
v-if="button.iconName"
|
||||||
|
:src="`/images/icon-${button.iconName}.svg`"
|
||||||
|
:alt="button.iconName"
|
||||||
|
/>
|
||||||
|
{{ $t(button.localeKey) }}
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="stats-tab" v-show="areStatsOpen">
|
<div class="stats-tab" v-show="currentStatsTab !== null">
|
||||||
<keep-alive>
|
<keep-alive>
|
||||||
<JournalDailyStats
|
<JournalDailyStats v-if="currentStatsTab == 'journal-daily-stats'" />
|
||||||
v-if="store.currentStatsTab == 'daily'"
|
<JournalDriverStats v-else-if="currentStatsTab == 'journal-driver-stats'" />
|
||||||
@toggleStatsOpen="toggleStatsOpen"
|
|
||||||
/>
|
|
||||||
<JournalDriverStats v-else-if="store.currentStatsTab == 'driver'" />
|
|
||||||
</keep-alive>
|
</keep-alive>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@@ -30,67 +29,49 @@
|
|||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import { computed, onMounted, reactive, Ref, ref, watch } from 'vue';
|
import { computed, onMounted, reactive, Ref, ref, watch } from 'vue';
|
||||||
import { useStore } from '../../store/mainStore';
|
import { useStore } from '../../store/mainStore';
|
||||||
import JournalDailyStats from './DailyStats.vue';
|
import JournalDailyStats from './JournalDailyStats.vue';
|
||||||
import JournalDriverStats from './JournalDriverStats.vue';
|
import JournalDriverStats from './JournalDriverStats.vue';
|
||||||
import StorageManager from '../../managers/storageManager';
|
import StorageManager from '../../managers/storageManager';
|
||||||
|
|
||||||
// Types
|
export type JournalStatsTab = 'journal-driver-stats' | 'journal-daily-stats';
|
||||||
type TStatTab = 'daily' | 'driver';
|
|
||||||
|
|
||||||
// Variables
|
|
||||||
const store = useStore();
|
const store = useStore();
|
||||||
|
const currentStatsTab: Ref<JournalStatsTab | null> = ref(null);
|
||||||
const lastDailyStatsOpen = ref(false);
|
|
||||||
const areStatsOpen = ref(false);
|
|
||||||
const lastClickedTab: Ref<'daily' | 'driver' | null> = ref(null);
|
|
||||||
|
|
||||||
let data = reactive({
|
let data = reactive({
|
||||||
tabs: [
|
statsButtons: [
|
||||||
{
|
{
|
||||||
name: 'daily',
|
name: 'journal-daily-stats',
|
||||||
titlePath: 'journal.daily-stats-title'
|
localeKey: 'journal.daily-stats-title',
|
||||||
|
iconName: 'stats'
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: 'driver',
|
name: 'journal-driver-stats',
|
||||||
titlePath: 'journal.driver-stats-title'
|
localeKey: 'journal.driver-stats-title',
|
||||||
// inactive: true,
|
iconName: 'user'
|
||||||
}
|
}
|
||||||
] as { name: TStatTab; titlePath: string; inactive?: boolean }[]
|
] as { name: JournalStatsTab; localeKey: string; iconName?: string }[]
|
||||||
});
|
});
|
||||||
|
|
||||||
// Methods
|
function onTabButtonClick(tab: JournalStatsTab) {
|
||||||
function onTabButtonClick(tab: TStatTab) {
|
currentStatsTab.value = tab == currentStatsTab.value ? null : tab;
|
||||||
if (lastClickedTab.value == tab || !lastClickedTab.value || !areStatsOpen.value)
|
StorageManager.setStringValue('journalStatsTab', currentStatsTab.value ?? '');
|
||||||
areStatsOpen.value = !areStatsOpen.value;
|
|
||||||
|
|
||||||
if (tab == 'daily') {
|
|
||||||
StorageManager.setBooleanValue('dailyStatsOpen', areStatsOpen.value);
|
|
||||||
lastDailyStatsOpen.value = areStatsOpen.value;
|
|
||||||
}
|
|
||||||
|
|
||||||
store.currentStatsTab = tab;
|
|
||||||
lastClickedTab.value = tab;
|
|
||||||
|
|
||||||
if (areStatsOpen.value == false) store.currentStatsTab = null;
|
|
||||||
}
|
|
||||||
|
|
||||||
function toggleStatsOpen(open: boolean) {
|
|
||||||
areStatsOpen.value = open;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
watch(
|
watch(
|
||||||
computed(() => store.driverStatsData),
|
computed(() => store.driverStatsData),
|
||||||
(statsData) => {
|
(newData, prevData) => {
|
||||||
store.currentStatsTab = statsData ? 'driver' : lastClickedTab.value;
|
currentStatsTab.value =
|
||||||
areStatsOpen.value = statsData ? true : lastClickedTab.value !== null;
|
JSON.stringify(prevData) !== JSON.stringify(newData) && newData !== undefined
|
||||||
|
? 'journal-driver-stats'
|
||||||
|
: currentStatsTab.value;
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
onMounted(() => {
|
onMounted(() => {
|
||||||
if (StorageManager.getBooleanValue('dailyStatsOpen')) {
|
const storedTab = StorageManager.getStringValue('journalStatsTab');
|
||||||
areStatsOpen.value = true;
|
|
||||||
store.currentStatsTab = 'daily';
|
if (storedTab && storedTab !== '') currentStatsTab.value = storedTab as JournalStatsTab;
|
||||||
}
|
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
@@ -98,7 +79,7 @@ onMounted(() => {
|
|||||||
@import '../../styles/JournalStats.scss';
|
@import '../../styles/JournalStats.scss';
|
||||||
@import '../../styles/variables.scss';
|
@import '../../styles/variables.scss';
|
||||||
|
|
||||||
.tabs {
|
.stats-buttons {
|
||||||
position: relative;
|
position: relative;
|
||||||
|
|
||||||
display: flex;
|
display: flex;
|
||||||
|
|||||||
@@ -51,8 +51,6 @@ export const useStore = defineStore('store', {
|
|||||||
trains: Status.Data.Loading
|
trains: Status.Data.Loading
|
||||||
},
|
},
|
||||||
|
|
||||||
currentStatsTab: null,
|
|
||||||
|
|
||||||
blockScroll: false,
|
blockScroll: false,
|
||||||
listenerLaunched: false,
|
listenerLaunched: false,
|
||||||
modalLastClickedTarget: null,
|
modalLastClickedTarget: null,
|
||||||
|
|||||||
@@ -41,8 +41,6 @@ export interface StoreState {
|
|||||||
|
|
||||||
chosenModalTrainId?: string;
|
chosenModalTrainId?: string;
|
||||||
|
|
||||||
currentStatsTab: 'daily' | 'driver' | null;
|
|
||||||
|
|
||||||
dataStatuses: {
|
dataStatuses: {
|
||||||
connection: Status.Data;
|
connection: Status.Data;
|
||||||
sceneries: Status.Data;
|
sceneries: Status.Data;
|
||||||
|
|||||||
Reference in New Issue
Block a user