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
<template lang='pug'>
q-page.admin-api
.row.q-pa-md.items-center
.col-auto
img.admin-icon.animated.fadeInLeft(src='/_assets/icons/fluent-graph.svg')
.col.q-pl-md
.text-h5.text-primary.animated.fadeInLeft {{ t('admin.metrics.title') }}
.text-subtitle1.text-grey.animated.fadeInLeft.wait-p2s {{ t('admin.metrics.subtitle') }}
.col
.flex.items-center
template(v-if='state.enabled')
q-spinner-rings.q-mr-sm(color='green', size='md')
.text-caption.text-green {{t('admin.metrics.enabled')}}
template(v-else)
q-spinner-rings.q-mr-sm(color='red', size='md')
.text-caption.text-red {{t('admin.metrics.disabled')}}
.col-auto
q-btn.q-mr-sm.q-ml-md.acrylic-btn(
icon='las la-question-circle'
flat
color='grey'
:aria-label='t(`common.actions.viewDocs`)'
:href='siteStore.docsBase + `/system/metrics`'
target='_blank'
type='a'
)
q-tooltip {{ t(`common.actions.viewDocs`) }}
q-btn.acrylic-btn.q-mr-sm(
icon='las la-redo-alt'
flat
color='secondary'
:loading='state.loading > 0'
:aria-label='t(`common.actions.refresh`)'
@click='refresh'
)
q-tooltip {{ t(`common.actions.refresh`) }}
q-btn.q-mr-sm(
unelevated
icon='las la-power-off'
:label='!state.enabled ? t(`common.actions.activate`) : t(`common.actions.deactivate`)'
:color='!state.enabled ? `positive` : `negative`'
@click='globalSwitch'
:loading='state.isToggleLoading'
:disabled='state.loading > 0'
)
q-separator(inset)
.row.q-pa-md.q-col-gutter-md
.col-12
q-card.rounded-borders(
flat
:class='$q.dark.isActive ? `bg-dark-5 text-white` : `bg-grey-3 text-dark`'
)
q-card-section.items-center(horizontal)
q-card-section.col-auto.q-pr-none
q-icon(name='las la-info-circle', size='sm')
q-card-section
i18n-t(tag='span', keypath='admin.metrics.endpoint', scope='global')
template(#endpoint)
strong.font-robotomono /metrics
.text-caption {{ t('admin.metrics.endpointWarning') }}
q-card.rounded-borders.q-mt-md(
flat
:class='$q.dark.isActive ? `bg-dark-5 text-white` : `bg-grey-3 text-dark`'
)
q-card-section.items-center(horizontal)
q-card-section.col-auto.q-pr-none
q-icon(name='las la-key', size='sm')
q-card-section
i18n-t(tag='span', keypath='admin.metrics.auth', scope='global')
template(#headerName)
strong.font-robotomono Authorization
template(#tokenType)
strong.font-robotomono Bearer
template(#permission)
strong.font-robotomono read:metrics
.text-caption.font-robotomono Authorization: Bearer API-KEY-VALUE
</template>
<script setup>
import gql from 'graphql-tag'
import { cloneDeep } from 'lodash-es'
import { useI18n } from 'vue-i18n'
import { useMeta, useQuasar } from 'quasar'
import { computed, onMounted, reactive, watch } from 'vue'
import { useAdminStore } from '@/stores/admin'
import { useSiteStore } from '@/stores/site'
// QUASAR
const $q = useQuasar()
// STORES
const adminStore = useAdminStore()
const siteStore = useSiteStore()
// I18N
const { t } = useI18n()
// META
useMeta({
title: t('admin.metrics.title')
})
// DATA
const state = reactive({
enabled: false,
loading: 0,
isToggleLoading: false
})
// METHODS
async function load () {
state.loading++
$q.loading.show()
const resp = await APOLLO_CLIENT.query({
query: gql`
query getMetricsState {
metricsState
}
`,
fetchPolicy: 'network-only'
})
state.enabled = resp?.data?.metricsState === true
adminStore.info.isMetricsEnabled = state.enabled
$q.loading.hide()
state.loading--
}
async function refresh () {
await load()
$q.notify({
type: 'positive',
message: t('admin.metrics.refreshSuccess')
})
}
async function globalSwitch () {
state.isToggleLoading = true
try {
const resp = await APOLLO_CLIENT.mutate({
mutation: gql`
mutation ($enabled: Boolean!) {
setMetricsState (enabled: $enabled) {
operation {
succeeded
message
}
}
}
`,
variables: {
enabled: !state.enabled
}
})
if (resp?.data?.setMetricsState?.operation?.succeeded) {
$q.notify({
type: 'positive',
message: state.enabled ? t('admin.metrics.toggleStateDisabledSuccess') : t('admin.metrics.toggleStateEnabledSuccess')
})
await load()
} else {
throw new Error(resp?.data?.setMetricsState?.operation?.message || 'An unexpected error occurred.')
}
} catch (err) {
$q.notify({
type: 'negative',
message: 'Failed to switch metrics endpoint state.',
caption: err.message
})
}
state.isToggleLoading = false
}
// MOUNTED
onMounted(load)
</script>
<style lang='scss'>
</style>