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';
186207import { isInBlackList } from ' ../compositions/black-list' ;
187208import { isDomainEquals } from ' ../utils/common' ;
188209import { 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
190214const notification = useNotification ();
191215
@@ -197,6 +221,10 @@ const allowDeferringBlock = ref<boolean>();
197221const whiteList = ref <string []>();
198222const darkMode = ref <boolean >();
199223
224+ const selectedDate = ref <Date []>();
225+
226+ const presetRanges = ranges ();
227+
200228const newWebsiteForWhiteList = ref <string >();
201229
202230onMounted (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
219248async function save(storageParam : StorageParams , value : any ) {
@@ -245,6 +274,28 @@ function deleteFromWhiteList(url: string) {
245274function 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 >
0 commit comments