Skip to content

Commit ac15cbc

Browse files
committed
Export to csv from settings
1 parent 2d03a8c commit ac15cbc

File tree

3 files changed

+64
-1
lines changed

3 files changed

+64
-1
lines changed

src/compositions/toCsv.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { DayTabs } from '../dto/tabListSummary';
22
import { useTabListByDays } from './tab-list-by-days';
33

4-
const CSV_HEADER = 'date,website,time(sec),sessions\r\n';
4+
const CSV_HEADER = 'Date,WebSite,Time(sec),Sessions\r\n';
55

66
export async function useImportToCsvWithData(days: DayTabs[] | undefined): Promise<string> {
77
return getCsv(days);

src/pages/Settings.vue

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,27 @@
7575
</div>
7676
<p class="description">These are any actions with the mouse or keyboard</p>
7777
</div>
78+
<div class="settings-item">
79+
<label class="setting-header d-inline-block"
80+
>Exporting your web activity data to CSV
81+
</label>
82+
<p class="description">You can export your web activity for any date range</p>
83+
<div class="export-block">
84+
<VueDatePicker
85+
range
86+
:enable-time-picker="false"
87+
class="date-picker"
88+
v-model="selectedDate"
89+
:preset-ranges="presetRanges"
90+
@update:model-value="handleDate"
91+
>
92+
<template #yearly="{ label, range, presetDateRange }">
93+
<span @click="presetDateRange(range)">{{ label }}</span>
94+
</template></VueDatePicker
95+
>
96+
<input type="button" value="Export to CSV" @click="exportToCsv()" />
97+
</div>
98+
</div>
7899
</div>
79100
</div>
80101

@@ -186,6 +207,9 @@ import { InactivityInterval } from '../storage/storage-params';
186207
import { isInBlackList } from '../compositions/black-list';
187208
import { isDomainEquals } from '../utils/common';
188209
import { extractHostname } from '../compositions/extract-hostname';
210+
import { ranges, ThisWeekRange } from '../utils/date';
211+
import { useImportToCsv } from '../compositions/toCsv';
212+
import { FileType, useFile } from '../compositions/loadFile';
189213
190214
const notification = useNotification();
191215
@@ -197,6 +221,10 @@ const allowDeferringBlock = ref<boolean>();
197221
const whiteList = ref<string[]>();
198222
const darkMode = ref<boolean>();
199223
224+
const selectedDate = ref<Date[]>();
225+
226+
const presetRanges = ranges();
227+
200228
const newWebsiteForWhiteList = ref<string>();
201229
202230
onMounted(async () => {
@@ -214,6 +242,7 @@ onMounted(async () => {
214242
BLOCK_DEFERRAL_DEFAULT,
215243
);
216244
whiteList.value = Object.values(await settingsStorage.getValue(StorageParams.BLACK_LIST, []));
245+
selectedDate.value = ThisWeekRange;
217246
});
218247
219248
async function save(storageParam: StorageParams, value: any) {
@@ -245,6 +274,28 @@ function deleteFromWhiteList(url: string) {
245274
function onChange(storageParam: StorageParams, value: any) {
246275
save(storageParam, value);
247276
}
277+
278+
async function handleDate(modelData: Date[]) {
279+
selectedDate.value = modelData;
280+
}
281+
282+
async function exportToCsv() {
283+
const dateFrom = selectedDate.value?.[0] as Date;
284+
const dateTo = selectedDate.value?.[1] as Date;
285+
if (dateFrom == undefined || dateTo == undefined) {
286+
notification.notify({
287+
title: 'No time period selected',
288+
type: 'warn',
289+
});
290+
} else {
291+
const csv = await useImportToCsv(dateFrom, dateTo);
292+
useFile(
293+
csv,
294+
FileType.CSV,
295+
`websites_${dateFrom.toLocaleDateString()}-${dateTo.toLocaleDateString()}.csv`,
296+
);
297+
}
298+
}
248299
</script>
249300

250301
<style scoped>
@@ -262,4 +313,13 @@ function onChange(storageParam: StorageParams, value: any) {
262313
margin-right: 10px;
263314
cursor: pointer;
264315
}
316+
.export-block {
317+
display: flex;
318+
justify-content: start;
319+
}
320+
321+
.export-block .date-picker {
322+
width: 250px;
323+
margin-right: 15px;
324+
}
265325
</style>

src/settings.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
import Settings from './pages/Settings.vue';
22
import Notifications from '@kyvg/vue3-notification';
3+
import VueDatePicker from '@vuepic/vue-datepicker';
4+
import '@vuepic/vue-datepicker/dist/main.css';
35
import { createApp } from 'vue';
46

57
const app = createApp(Settings);
68
app.use(Notifications);
9+
app.component('VueDatePicker', VueDatePicker);
710
app.mount('body');

0 commit comments

Comments
 (0)