|
| 1 | +<template> |
| 2 | + <div class="settings-item"> |
| 3 | + <label class="setting-header"> |
| 4 | + <input |
| 5 | + type="checkbox" |
| 6 | + class="filled-in" |
| 7 | + id="viewTimeInBadge" |
| 8 | + v-model="viewTimeInBadge" |
| 9 | + @change="onChange(StorageParams.VIEW_TIME_IN_BADGE, $event.target.checked)" |
| 10 | + /> |
| 11 | + <span>Display time tracker in icon</span> |
| 12 | + <p class="description"> |
| 13 | + You can see current spent time in short format in the icon of extension |
| 14 | + </p> |
| 15 | + </label> |
| 16 | + </div> |
| 17 | + <div class="settings-item"> |
| 18 | + <label class="setting-header"> |
| 19 | + <input |
| 20 | + type="checkbox" |
| 21 | + class="filled-in" |
| 22 | + id="blockDeferral" |
| 23 | + v-model="allowDeferringBlock" |
| 24 | + @change="onChange(StorageParams.BLOCK_DEFERRAL, $event.target.checked)" |
| 25 | + /> |
| 26 | + <span>Allow deferring block for 5 minutes</span> |
| 27 | + <p class="description"> |
| 28 | + After the site is blocked, you can postpone the blocking for 5 minutes |
| 29 | + </p> |
| 30 | + </label> |
| 31 | + </div> |
| 32 | + <div class="settings-item"> |
| 33 | + <label class="setting-header"> |
| 34 | + <input |
| 35 | + type="checkbox" |
| 36 | + class="filled-in" |
| 37 | + id="darkMode" |
| 38 | + v-model="darkMode" |
| 39 | + @change="onChange(StorageParams.DARK_MODE, $event.target.checked)" |
| 40 | + /> |
| 41 | + <span>Dark mode</span> |
| 42 | + <p class="description">Dark theme</p> |
| 43 | + </label> |
| 44 | + </div> |
| 45 | + <div class="settings-item"> |
| 46 | + <label class="setting-header d-inline-block" |
| 47 | + >Stop tracking if there is no activity during: |
| 48 | + </label> |
| 49 | + <div class="d-inline-block ml-10"> |
| 50 | + <select |
| 51 | + class="option" |
| 52 | + v-model="intervalInactivity" |
| 53 | + @change="onChange(StorageParams.INTERVAL_INACTIVITY, $event.target.value)" |
| 54 | + > |
| 55 | + <option :value="InactivityInterval.Seconds_30">30 seconds</option> |
| 56 | + <option :value="InactivityInterval.Seconds_45">45 seconds</option> |
| 57 | + <option :value="InactivityInterval.Min_1">1 min</option> |
| 58 | + <option :value="InactivityInterval.Min_2">2 min</option> |
| 59 | + <option :value="InactivityInterval.Min_5">5 mins</option> |
| 60 | + <option :value="InactivityInterval.Min_10">10 mins</option> |
| 61 | + <option :value="InactivityInterval.Min_20">20 mins</option> |
| 62 | + <option :value="InactivityInterval.Min_30">30 mins</option> |
| 63 | + </select> |
| 64 | + </div> |
| 65 | + <p class="description">These are any actions with the mouse or keyboard</p> |
| 66 | + </div> |
| 67 | + <div class="settings-item"> |
| 68 | + <label class="setting-header d-inline-block">Exporting your web activity data to CSV </label> |
| 69 | + <p class="description">You can export your web activity for any date range</p> |
| 70 | + <div class="export-block"> |
| 71 | + <VueDatePicker |
| 72 | + range |
| 73 | + :enable-time-picker="false" |
| 74 | + class="date-picker" |
| 75 | + v-model="selectedDate" |
| 76 | + :preset-ranges="presetRanges" |
| 77 | + @update:model-value="handleDate" |
| 78 | + > |
| 79 | + <template #yearly="{ label, range, presetDateRange }"> |
| 80 | + <span @click="presetDateRange(range)">{{ label }}</span> |
| 81 | + </template> |
| 82 | + </VueDatePicker> |
| 83 | + <input type="button" value="Export to CSV" @click="exportToCsv()" /> |
| 84 | + </div> |
| 85 | + </div> |
| 86 | +</template> |
| 87 | + |
| 88 | +<script lang="ts"> |
| 89 | +export default { |
| 90 | + name: 'GeneralSettings', |
| 91 | +}; |
| 92 | +</script> |
| 93 | + |
| 94 | +<script lang="ts" setup> |
| 95 | +import { onMounted, ref } from 'vue'; |
| 96 | +import { injecStorage } from '../storage/inject-storage'; |
| 97 | +import { useNotification } from '@kyvg/vue3-notification'; |
| 98 | +import { |
| 99 | + BLOCK_DEFERRAL_DEFAULT, |
| 100 | + DARK_MODE_DEFAULT, |
| 101 | + INTERVAL_INACTIVITY_DEFAULT, |
| 102 | + StorageParams, |
| 103 | + VIEW_TIME_IN_BADGE_DEFAULT, |
| 104 | + InactivityInterval, |
| 105 | +} from '../storage/storage-params'; |
| 106 | +import { ranges, ThisWeekRange } from '../utils/date'; |
| 107 | +import { useImportToCsv } from '../compositions/toCsv'; |
| 108 | +import { FileType, useFile } from '../compositions/loadFile'; |
| 109 | +
|
| 110 | +const settingsStorage = injecStorage(); |
| 111 | +const notification = useNotification(); |
| 112 | +
|
| 113 | +const viewTimeInBadge = ref<boolean>(); |
| 114 | +const intervalInactivity = ref<InactivityInterval>(); |
| 115 | +const allowDeferringBlock = ref<boolean>(); |
| 116 | +const darkMode = ref<boolean>(); |
| 117 | +const selectedDate = ref<Date[]>(); |
| 118 | +
|
| 119 | +const presetRanges = ranges(); |
| 120 | +
|
| 121 | +onMounted(async () => { |
| 122 | + viewTimeInBadge.value = await settingsStorage.getValue( |
| 123 | + StorageParams.VIEW_TIME_IN_BADGE, |
| 124 | + VIEW_TIME_IN_BADGE_DEFAULT, |
| 125 | + ); |
| 126 | + intervalInactivity.value = await settingsStorage.getValue( |
| 127 | + StorageParams.INTERVAL_INACTIVITY, |
| 128 | + INTERVAL_INACTIVITY_DEFAULT, |
| 129 | + ); |
| 130 | + darkMode.value = await settingsStorage.getValue(StorageParams.DARK_MODE, DARK_MODE_DEFAULT); |
| 131 | + allowDeferringBlock.value = await settingsStorage.getValue( |
| 132 | + StorageParams.BLOCK_DEFERRAL, |
| 133 | + BLOCK_DEFERRAL_DEFAULT, |
| 134 | + ); |
| 135 | + selectedDate.value = ThisWeekRange; |
| 136 | +}); |
| 137 | +
|
| 138 | +async function onChange(storageParam: StorageParams, value: any) { |
| 139 | + await save(storageParam, value); |
| 140 | +} |
| 141 | +
|
| 142 | +async function save(storageParam: StorageParams, value: any) { |
| 143 | + if (value != undefined) await settingsStorage.saveValue(storageParam, value); |
| 144 | +} |
| 145 | +
|
| 146 | +async function handleDate(modelData: Date[]) { |
| 147 | + selectedDate.value = modelData; |
| 148 | +} |
| 149 | +
|
| 150 | +async function exportToCsv() { |
| 151 | + const dateFrom = selectedDate.value?.[0] as Date; |
| 152 | + const dateTo = selectedDate.value?.[1] as Date; |
| 153 | + if (dateFrom == undefined || dateTo == undefined) { |
| 154 | + notification.notify({ |
| 155 | + title: 'No time period selected', |
| 156 | + type: 'warn', |
| 157 | + }); |
| 158 | + } else { |
| 159 | + const csv = await useImportToCsv(dateFrom, dateTo); |
| 160 | + useFile( |
| 161 | + csv, |
| 162 | + FileType.CSV, |
| 163 | + `websites_${dateFrom.toLocaleDateString()}-${dateTo.toLocaleDateString()}.csv`, |
| 164 | + ); |
| 165 | + } |
| 166 | +} |
| 167 | +</script> |
| 168 | + |
| 169 | +<style scoped> |
| 170 | +.export-block { |
| 171 | + display: flex; |
| 172 | + justify-content: start; |
| 173 | +} |
| 174 | +
|
| 175 | +.export-block .date-picker { |
| 176 | + width: 250px; |
| 177 | + margin-right: 15px; |
| 178 | +} |
| 179 | +</style> |
0 commit comments