-
Notifications
You must be signed in to change notification settings - Fork 30
Expand file tree
/
Copy pathApp.vue
More file actions
192 lines (169 loc) Β· 4.89 KB
/
App.vue
File metadata and controls
192 lines (169 loc) Β· 4.89 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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
<!--
SPDX-FileCopyrightText: 2023 Nextcloud Gmbh and Nextcloud contributors
SPDX-License-Identifier: AGPL-3.0-or-later
-->
<template>
<div class="logreader-container">
<div class="logreader-container__header">
<h2>{{ t('logreader', 'Log reader') }}</h2>
<!-- Setting toggle -->
<NcButton
:aria-label="t('logreader', 'Open log reader settings')"
class="settings-toggle"
variant="tertiary"
@click="areSettingsShown = true">
<template #icon>
<IconCog :size="20" />
</template>
{{ t('logreader', 'Log reader settings') }}
</NcButton>
</div>
<!-- Show information / warning message -->
<NcNoteCard v-if="settingsStore.localFile" type="info" class="info-note">
<div class="info-note__content">
<p>{{ t('logreader', 'Currently the log file {file} is shown', { file: settingsStore.localFileName }) }}</p>
<NcButton variant="secondary" @click="onShowServerLog">
{{ t('logreader', 'Show server log') }}
</NcButton>
</div>
</NcNoteCard>
<NcNoteCard v-else-if="!settingsStore.liveLog" type="info" class="info-note">
<p>{{ t('logreader', 'Live view is disabled') }}</p>
</NcNoteCard>
<!-- Show the log file table -->
<LogTable v-if="settingsStore.enabled" :rows="entries" />
<NcEmptyContent v-else :name="t('logreader', 'No log file')">
<template #icon>
<IconFormatList :size="20" />
</template>
<template #description>
{{ t('logreader', 'File-based logging must be enabled to access logs from the Web UI.') }}
<br>
<!-- eslint-disable-next-line vue/no-v-html -->
<span v-html="noLogDescription" />
</template>
</NcEmptyContent>
<!-- App settings dialog will be mounted on page body -->
<AppSettingsDialog v-model:open="areSettingsShown" />
</div>
</template>
<script lang="ts" setup>
import { translate as t } from '@nextcloud/l10n'
import { computed, onMounted, onUnmounted, ref, watchEffect } from 'vue'
import NcButton from '@nextcloud/vue/components/NcButton'
import NcEmptyContent from '@nextcloud/vue/components/NcEmptyContent'
import NcNoteCard from '@nextcloud/vue/components/NcNoteCard'
import IconCog from 'vue-material-design-icons/CogOutline.vue'
import IconFormatList from 'vue-material-design-icons/FormatListBulletedSquare.vue'
import AppSettingsDialog from './components/settings/AppSettingsDialog.vue'
import LogTable from './components/table/LogTable.vue'
import { useLogStore } from './store/logging'
import { useSettingsStore } from './store/settings'
import '@nextcloud/dialogs/style.css'
/** If currently showing the settings modal */
const areSettingsShown = ref(false)
/** Store with app settings */
const settingsStore = useSettingsStore()
/** Store handling all log retrieval */
const loggingStore = useLogStore()
const entries = computed(() => loggingStore.entries)
/**
*
*/
function onShowServerLog() {
settingsStore.localFile = undefined
// remove local entries
loggingStore.allEntries = []
loggingStore.loadMore()
}
/**
* Handle paste events with log entries
*
* @param event The keyboard event
*/
function onHandlePaste(event: ClipboardEvent) {
event.preventDefault()
if (event.clipboardData) {
const paste = event.clipboardData.getData('text')
loggingStore.loadText(paste)
}
}
// Add / remove event listeners
onMounted(() => window.addEventListener('paste', onHandlePaste))
onUnmounted(() => window.removeEventListener('paste', onHandlePaste))
/**
* Toggle polling if live log is dis- / enabled
*/
watchEffect(() => {
if (settingsStore.liveLog && settingsStore.isEnabled) {
loggingStore.startPolling()
} else {
loggingStore.stopPolling()
}
})
onMounted(() => {
loggingStore.loadMore()
})
onUnmounted(() => {
loggingStore.stopPolling()
})
/** Translated description what to check in case no log can be loaded */
const noLogDescription = t(
'logreader',
'If you feel this is an error, please verify {setting} in your {config} and check the Nextcloud Administration Manual.',
{
setting: '<code>log_type</code>',
config: '<code>config.php</code>',
},
0,
{
sanitize: false,
escape: false,
},
)
</script>
<style lang="scss" scoped>
legend {
font-weight: bold;
}
.logreader-container {
// Ensure max 100% is used and the table itself will be scrollable
display: flex;
flex-direction: column;
height: 100%;
.info-note {
margin-block: 4px;
margin-inline: 1rem;
&__content {
display: flex;
gap: 12px;
align-items: center;
justify-content: space-between;
}
}
&__header {
padding-inline-start: 1rem; // Align with info note
display: flex;
flex-direction: row;
align-items: center;
justify-content: space-between;
h2 {
// Handled by container
margin: 0;
padding: 0;
}
.settings-toggle {
// 2px to show outline when focus-visible
margin: 2px;
}
}
}
:deep(.empty-content) {
text-align: center;
}
@media only screen and (max-width: 1023px) {
.logreader-container__header {
padding-inline-start: 48px; // app sidebar toggle
}
}
</style>