From 5571595fbec95e1142c55f8f7200e24edee80aa4 Mon Sep 17 00:00:00 2001 From: Nyra Sama <83142634+NyraSama@users.noreply.github.com> Date: Tue, 28 May 2024 14:18:17 +0200 Subject: [PATCH] feat(statistic_preview): Read CSV from the back to display a table that preview the content (#1455) --- yaki_admin/src/services/statistics.service.ts | 21 +++ yaki_admin/src/ui/components/PreviewTable.vue | 159 ++++++++++++++++++ yaki_admin/src/ui/views/StatisticsView.vue | 24 +++ 3 files changed, 204 insertions(+) create mode 100644 yaki_admin/src/ui/components/PreviewTable.vue diff --git a/yaki_admin/src/services/statistics.service.ts b/yaki_admin/src/services/statistics.service.ts index b08f9b950..42d203260 100644 --- a/yaki_admin/src/services/statistics.service.ts +++ b/yaki_admin/src/services/statistics.service.ts @@ -44,6 +44,27 @@ class StatisticsService { return "javascript:void(0)"; } }; + + getStatisticsArray = async ( + customerId: number, + teamId: number, + statisticType: STATISTICTYPE, + periodStart: string, + periodEnd: string, + ): Promise>> => { + const data = await this.getStatisticsCsv( + customerId, + teamId, + statisticType, + periodStart, + periodEnd, + ); + + const response = await fetch(data); + const csvText = await response.text(); + + return csvText.split("\n").map((row) => row.split(",")); + }; } export const statisticsService = Object.freeze(new StatisticsService()); diff --git a/yaki_admin/src/ui/components/PreviewTable.vue b/yaki_admin/src/ui/components/PreviewTable.vue new file mode 100644 index 000000000..afe895593 --- /dev/null +++ b/yaki_admin/src/ui/components/PreviewTable.vue @@ -0,0 +1,159 @@ + + + + + diff --git a/yaki_admin/src/ui/views/StatisticsView.vue b/yaki_admin/src/ui/views/StatisticsView.vue index a830287ad..7b3a6371a 100644 --- a/yaki_admin/src/ui/views/StatisticsView.vue +++ b/yaki_admin/src/ui/views/StatisticsView.vue @@ -2,6 +2,7 @@ import PageContentHeader from "@/ui/components/PageContentHeader.vue"; import PageContentLayout from "@/ui/layouts/PageContentLayout.vue"; import buttonPrimary from "@/ui/components/buttons/ButtonPrimary.vue"; +import PreviewTable from "@/ui/components/PreviewTable.vue"; import { statisticsService } from "@/services/statistics.service"; import { useSelectedRoleStore } from "@/stores/selectedRole"; @@ -24,6 +25,7 @@ const periodStartSelected = ref( new Date(Date.now() - 30 * 24 * 60 * 60 * 1000).toISOString().split("T")[0], ); const periodEndSelected = ref(new Date().toISOString().split("T")[0]); +const statisticsPreview = ref>>([[""]]); onMounted(() => { if (roleStore.getCustomersIdWhereIgotRights.length === 0) { @@ -60,12 +62,29 @@ const downloadCsv = async () => { } }; +const loadPreview = async () => { + const customerId = selectedRoleStore.getCustomerIdSelected; + try { + statisticsPreview.value = await statisticsService.getStatisticsArray( + customerId, + teamSelected.value, + statisticTypeSelected.value, + periodStartSelected.value, + periodEndSelected.value, + ); + } catch (error) { + console.error("Error while getting preview :", error); + } +}; + const onSelectTeam = (e: Event) => { teamSelected.value = parseInt((e.target as HTMLSelectElement).value); + loadPreview(); }; const onSelectStatisticType = (e: Event) => { statisticTypeSelected.value = (e.target as HTMLSelectElement).value as STATISTICTYPE; + loadPreview(); }; const onSelectPeriodStart = (e: Event) => { @@ -73,6 +92,7 @@ const onSelectPeriodStart = (e: Event) => { if (new Date((e.target as HTMLInputElement).value) > new Date(periodEndSelected.value)) { periodEndSelected.value = (e.target as HTMLInputElement).value; } + loadPreview(); }; const onSelectPeriodEnd = (e: Event) => { @@ -80,6 +100,7 @@ const onSelectPeriodEnd = (e: Event) => { if (new Date((e.target as HTMLInputElement).value) < new Date(periodStartSelected.value)) { periodStartSelected.value = (e.target as HTMLInputElement).value; } + loadPreview(); }; @@ -173,6 +194,9 @@ const onSelectPeriodEnd = (e: Event) => { @click.prevent="downloadCsv" /> +
+ +