-
Notifications
You must be signed in to change notification settings - Fork 31
Expand file tree
/
Copy pathSettingsLogLevels.vue
More file actions
62 lines (53 loc) · 1.71 KB
/
SettingsLogLevels.vue
File metadata and controls
62 lines (53 loc) · 1.71 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
<!--
SPDX-FileCopyrightText: 2023 Nextcloud Gmbh and Nextcloud contributors
SPDX-License-Identifier: AGPL-3.0-or-later
-->
<template>
<div>
<fieldset>
<legend>{{ t('logreader', 'Filter logging levels') }}</legend>
<NcCheckboxRadioSwitch
v-for="(levelName, levelId) in LOGGING_LEVEL_NAMES"
:key="levelId"
:modelValue="shownLevels[levelId]"
@update:modelValue="setShowLevels(levelId)">
{{ levelName }}
</NcCheckboxRadioSwitch>
</fieldset>
</div>
</template>
<script setup lang="ts">
import type { IAppSettings } from '../../interfaces'
import { showError } from '@nextcloud/dialogs'
import { translate as t } from '@nextcloud/l10n'
import { computed } from 'vue'
import NcCheckboxRadioSwitch from '@nextcloud/vue/components/NcCheckboxRadioSwitch'
import { LOGGING_LEVEL_NAMES } from '../../constants'
import { useSettingsStore } from '../../store/settings'
import { debounce } from '../../utils/debounce'
const settingsStore = useSettingsStore()
/**
* Get shown logging levels (to allow filter levels)
*/
const shownLevels = computed(() => {
return Object.fromEntries(Object.keys(LOGGING_LEVEL_NAMES).map((level) => {
return [level, settingsStore.shownLevels.includes(parseInt(level))]
}))
})
const setShowLevels = debounce((level: number) => {
const newShownLevels = {
...shownLevels.value,
[level]: !shownLevels.value[level],
}
const numericLevels = Object.keys(newShownLevels)
.filter((level) => newShownLevels[level])
.map((level) => parseInt(level)) as IAppSettings['shownLevels']
settingsStore.setSetting('shownLevels', numericLevels)
.catch(() => showError(t('logreader', 'Could not set logging levels to show')))
}, 200)
</script>
<style scoped>
fieldset {
padding: 6px;
}
</style>