Skip to content

Commit 581089d

Browse files
committed
Fix filter tab list by days (and export)
1 parent 239486f commit 581089d

File tree

2 files changed

+65
-38
lines changed

2 files changed

+65
-38
lines changed

src/components/ByDaysChart.vue

Lines changed: 54 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -23,55 +23,74 @@ import {
2323
} from 'chart.js';
2424
import { convertSummaryTimeToString } from '../utils/converter';
2525
import { TabListByDays } from '../dto/tabListSummary';
26+
import { ref, watch } from 'vue';
27+
import { log } from '../compositions/logger';
2628
2729
const props = defineProps<{
2830
data: TabListByDays;
2931
}>();
3032
3133
ChartJS.register(CategoryScale, LinearScale, BarElement, Title, Tooltip, Legend);
32-
const labelsForChart = props.data.days.map(x => x.day);
33-
const dataForChart = props.data.days.map(x => x.time);
34-
const tickStep = Math.round(dataForChart[0] / 5 / 600) * 600;
3534
36-
const data = {
37-
labels: labelsForChart,
38-
datasets: [
39-
{
40-
backgroundColor: ['#5668e2'],
41-
data: dataForChart,
42-
},
43-
],
44-
};
35+
const labelsForChart = ref<string[]>();
36+
const dataForChart = ref<number[]>();
37+
const data = ref<any>();
38+
const options = ref<any>();
4539
46-
const options = {
47-
responsive: true,
48-
maintainAspectRatio: false,
49-
plugins: {
50-
legend: {
51-
position: 'none',
52-
},
53-
legendDistance: {
54-
padding: 50,
55-
},
56-
tooltip: {
57-
callbacks: {
58-
label: function (context: any) {
59-
return convertSummaryTimeToString(context.raw);
40+
watch(
41+
() => props.data,
42+
() => {
43+
refreshChart();
44+
},
45+
);
46+
47+
refreshChart();
48+
49+
function refreshChart() {
50+
labelsForChart.value = props.data.days.map(x => x.day);
51+
dataForChart.value = props.data.days.map(x => x.time);
52+
const tickStep = Math.round(dataForChart.value[0] / 5 / 600) * 600;
53+
54+
data.value = {
55+
labels: labelsForChart.value,
56+
datasets: [
57+
{
58+
backgroundColor: ['#5668e2'],
59+
data: dataForChart.value,
60+
},
61+
],
62+
};
63+
64+
options.value = {
65+
responsive: true,
66+
maintainAspectRatio: false,
67+
plugins: {
68+
legend: {
69+
position: 'none',
70+
},
71+
legendDistance: {
72+
padding: 50,
73+
},
74+
tooltip: {
75+
callbacks: {
76+
label: function (context: any) {
77+
return convertSummaryTimeToString(context.raw);
78+
},
6079
},
6180
},
6281
},
63-
},
64-
scales: {
65-
y: {
66-
ticks: {
67-
stepSize: tickStep,
68-
callback: function (value: any, index: number, ticks: number) {
69-
return convertSummaryTimeToString(value);
82+
scales: {
83+
y: {
84+
ticks: {
85+
stepSize: tickStep,
86+
callback: function (value: any, index: number, ticks: number) {
87+
return convertSummaryTimeToString(value);
88+
},
7089
},
7190
},
7291
},
73-
},
74-
};
92+
};
93+
}
7594
</script>
7695

7796
<style scoped>

src/compositions/tab-list-by-days.ts

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { CurrentTabItem } from '../dto/currentTabItem';
22
import { DayTabs, TabListByDays } from '../dto/tabListSummary';
33
import { injectTabsRepository } from '../repository/inject-tabs-repository';
4+
import { isSameDay } from 'date-fns';
45

56
export async function useTabListByDays(
67
dateFrom: Date,
@@ -12,8 +13,12 @@ export async function useTabListByDays(
1213

1314
if (unSortedTabs.length == 0) return null;
1415

15-
const unSortedTabsByDays = unSortedTabs.filter(
16-
x => x.days.find(s => new Date(s.date) >= dateFrom && new Date(s.date) <= dateTo) != undefined,
16+
const isTheSameDay = isSameDay(dateFrom, dateTo);
17+
18+
const unSortedTabsByDays = unSortedTabs.filter(x =>
19+
isTheSameDay
20+
? x.days.find(s => isSameDay(new Date(s.date), dateFrom)) != undefined
21+
: x.days.find(s => new Date(s.date) >= dateFrom && new Date(s.date) <= dateTo) != undefined,
1722
);
1823

1924
if (unSortedTabsByDays.length == 0)
@@ -25,7 +30,10 @@ export async function useTabListByDays(
2530

2631
unSortedTabsByDays.forEach(tab => {
2732
tab.days.forEach(day => {
28-
if (new Date(day.date) >= dateFrom && new Date(day.date) <= dateTo) {
33+
if (
34+
(new Date(day.date) >= dateFrom && new Date(day.date) <= dateTo) ||
35+
(isTheSameDay && isSameDay(new Date(day.date), dateFrom))
36+
) {
2937
let dayTab = daysTabs.find(x => x.day == day.date);
3038
if (dayTab == undefined) {
3139
dayTab = {

0 commit comments

Comments
 (0)