Implements comprehensive time filtering and visualization improvements: - Adds time range picker with presets from 5min to 24h - Enhances chart visualization with minute-level granularity - Updates globe visualization to respond to time/filter changes - Implements animated event log display - Swaps primary/secondary color scheme for better contrast Improves realtime data handling with automatic updates and proper cleanup on unmount. Includes i18n support for new time picker UI across all supported languages.
30 lines
1,023 B
TypeScript
30 lines
1,023 B
TypeScript
import type { H3Event } from 'h3'
|
|
import { QuerySchema } from '@@/schemas/query'
|
|
import { z } from 'zod'
|
|
|
|
const { select } = SqlBricks
|
|
|
|
const unitMap: { [x: string]: string } = {
|
|
minute: '%H:%M',
|
|
hour: '%Y-%m-%d %H',
|
|
day: '%Y-%m-%d',
|
|
}
|
|
|
|
const ViewsQuerySchema = QuerySchema.extend({
|
|
unit: z.string(),
|
|
clientTimezone: z.string().default('Etc/UTC'),
|
|
})
|
|
|
|
function query2sql(query: z.infer<typeof ViewsQuerySchema>, event: H3Event): string {
|
|
const filter = query2filter(query)
|
|
const { dataset } = useRuntimeConfig(event)
|
|
const sql = select(`formatDateTime(timestamp, '${unitMap[query.unit]}', '${query.clientTimezone}') as time, SUM(_sample_interval) as visits, COUNT(DISTINCT ${logsMap.ip}) as visitors`).from(dataset).where(filter).groupBy('time').orderBy('time')
|
|
appendTimeFilter(sql, query)
|
|
return sql.toString()
|
|
}
|
|
|
|
export default eventHandler(async (event) => {
|
|
const query = await getValidatedQuery(event, ViewsQuerySchema.parse)
|
|
const sql = query2sql(query, event)
|
|
return useWAE(event, sql)
|
|
})
|