-
Notifications
You must be signed in to change notification settings - Fork 31
Expand file tree
/
Copy pathLogSearch.vue
More file actions
100 lines (89 loc) · 2.51 KB
/
LogSearch.vue
File metadata and controls
100 lines (89 loc) · 2.51 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
<!--
SPDX-FileCopyrightText: 2023 Nextcloud Gmbh and Nextcloud contributors
SPDX-License-Identifier: AGPL-3.0-or-later
-->
<template>
<NcActions
v-model:open="isOpen"
forceMenu
:aria-label="t('logreader', 'Search log entries')"
:type="buttonType">
<template #icon>
<IconTextSearch :size="20" />
</template>
<template #default>
<NcActionInput
:modelValue="currentQuery"
:label="t('logreader', 'Search log entries')"
:showTrailingButton="false"
@submit="isOpen = false"
@input="onSearchInput">
{{ t('logreader', 'Search log entries') }}
<template #icon>
<IconMagnify :size="20" />
</template>
</NcActionInput>
</template>
</NcActions>
</template>
<script setup lang="ts">
import { translate as t } from '@nextcloud/l10n'
import { computed, onMounted, onUnmounted, ref } from 'vue'
import NcActionInput from '@nextcloud/vue/components/NcActionInput'
import NcActions from '@nextcloud/vue/components/NcActions'
import IconMagnify from 'vue-material-design-icons/Magnify.vue'
import IconTextSearch from 'vue-material-design-icons/TextSearch.vue'
import { useLogStore } from '../store/logging'
declare global {
interface Window {
OCP: Nextcloud.v27.OCP
}
}
const logStore = useLogStore()
/**
* State of the search input popover
*/
const isOpen = ref(false)
/**
* The button type, forced to `primary` when filter is active
*/
const buttonType = computed(() => logStore.query ? 'primary' : 'tertiary-no-background')
/**
* Current active search query
*/
const currentQuery = computed(() => logStore.query)
/**
* Handle changes of the search query
*
* @param param0 The InputEvent
* @param param0.target The input element
*/
function onSearchInput({ target }: InputEvent) {
logStore.searchLogs((target as HTMLInputElement).value)
}
/**
* Listen for common search shortcut, open menu if requested and stop the event to prevent unified search from opening
*
* @param event The keydown event
*/
function keyboardListener(event: KeyboardEvent) {
if (event.ctrlKey && event.key === 'f') {
isOpen.value = true
event.preventDefault()
event.stopPropagation()
}
}
/**
* Intercept search requestes to filter log entries
*
* Notice the `true` so we intercept keydown on the bubble in -> intercept before unified search can handle it.
*/
onMounted(() => {
if (!window.OCP.Accessibility.disableKeyboardShortcuts()) {
document.addEventListener('keydown', keyboardListener, true)
}
})
onUnmounted(() => {
document.removeEventListener('keydown', keyboardListener, true)
})
</script>