Skip to content

Commit 37876ce

Browse files
committed
chore: add logs export and delete buttons to settings page
1 parent 38b49dd commit 37876ce

File tree

1 file changed

+80
-2
lines changed

1 file changed

+80
-2
lines changed

src/components/generalSettings.vue

Lines changed: 80 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
11
<script setup lang="ts">
22
import { Button, Fieldset, Select, ToggleSwitch } from 'primevue'
3+
import { useConfirm } from 'primevue/useconfirm'
34
import { Ref, ref } from 'vue'
45
56
import { i18n } from '#i18n'
67
import TagInput from '@/components/inputs/tagInput.vue'
78
import LogDialog from '@/components/logger/logDialog.vue'
89
import { Settings as GeneralSettings, useSettings as useGeneralSettings } from '@/services/general'
10+
import debugLogger from '@/services/logger/debugLogger'
11+
import nzbLogger from '@/services/logger/nzbLogger'
912
1013
const settings: Ref<GeneralSettings> = await useGeneralSettings()
1114
@@ -18,6 +21,44 @@ const notificationNames = [
1821
i18n.t('settings.general.notifications.showError'),
1922
i18n.t('settings.general.notifications.showNothing'),
2023
]
24+
25+
const exportCSV = (logType: 'nzb' | 'debug') => {
26+
if (logType === 'debug') debugLogger.download()
27+
if (logType === 'nzb') nzbLogger.download()
28+
}
29+
30+
const confirm = useConfirm()
31+
const confirmDelete = (logType: 'nzb' | 'debug'): void => {
32+
const message =
33+
logType === 'nzb'
34+
? i18n.t('logger.nzbLog.confirmDeleteNzblog.message')
35+
: i18n.t('logger.debugLog.confirmDeleteDebuglog.message')
36+
const header =
37+
logType === 'nzb'
38+
? i18n.t('logger.nzbLog.confirmDeleteNzblog.header')
39+
: i18n.t('logger.debugLog.confirmDeleteDebuglog.header')
40+
confirm.require({
41+
message: message,
42+
header: header,
43+
icon: 'pi pi-exclamation-triangle',
44+
rejectProps: {
45+
label: i18n.t('common.cancel'),
46+
severity: 'secondary',
47+
outlined: true,
48+
},
49+
acceptProps: {
50+
label: i18n.t('common.delete'),
51+
severity: 'danger',
52+
},
53+
accept: async () => {
54+
if (logType === 'debug') debugLogger.clear()
55+
if (logType === 'nzb') nzbLogger.clear()
56+
},
57+
reject: () => {
58+
// void
59+
},
60+
})
61+
}
2162
</script>
2263

2364
<template>
@@ -110,8 +151,9 @@ const notificationNames = [
110151
</div>
111152
</Fieldset>
112153
</div>
113-
<Fieldset :legend="i18n.t('settings.general.logs.title')" class="flex align-middle">
114-
<div class="flex items-center mb-4">
154+
<div class="mb-4"></div>
155+
<Fieldset :legend="i18n.t('menu.logger.nzbLog.title')" class="flex align-middle">
156+
<div class="flex items-center">
115157
<ToggleSwitch v-model="settings.nzbLog" />
116158
<label class="label-text pl-4">
117159
{{ i18n.t('settings.general.logs.nzbLog') }}
@@ -123,7 +165,27 @@ const notificationNames = [
123165
:label="i18n.t('menu.logger.nzbLog.title')"
124166
@click="logType = 'nzbLog'"
125167
/>
168+
<Button
169+
:label="i18n.t('logger.exportCSV')"
170+
icon="pi pi-download"
171+
severity="secondary"
172+
size="small"
173+
style="margin-left: 16px"
174+
@click="exportCSV('nzb')"
175+
/>
176+
<Button
177+
:label="i18n.t('logger.clearLog')"
178+
icon="pi pi-trash"
179+
severity="danger"
180+
size="small"
181+
style="margin-left: 16px"
182+
@click="confirmDelete('nzb')"
183+
/>
126184
</div>
185+
</Fieldset>
186+
</div>
187+
<div class="mb-4">
188+
<Fieldset :legend="i18n.t('menu.logger.debugLog.title')" class="flex align-middle">
127189
<div class="flex items-center">
128190
<ToggleSwitch v-model="settings.debug" />
129191
<label class="label-text pl-4">
@@ -136,6 +198,22 @@ const notificationNames = [
136198
:label="i18n.t('menu.logger.debugLog.title')"
137199
@click="logType = 'debugLog'"
138200
/>
201+
<Button
202+
:label="i18n.t('logger.exportCSV')"
203+
icon="pi pi-download"
204+
severity="secondary"
205+
size="small"
206+
style="margin-left: 16px"
207+
@click="exportCSV('debug')"
208+
/>
209+
<Button
210+
:label="i18n.t('logger.clearLog')"
211+
icon="pi pi-trash"
212+
severity="danger"
213+
size="small"
214+
style="margin-left: 16px"
215+
@click="confirmDelete('debug')"
216+
/>
139217
</div>
140218
</Fieldset>
141219
</div>

0 commit comments

Comments
 (0)