1
0
mirror of https://github.com/amir20/dozzle.git synced 2025-12-21 13:23:07 +01:00

feat: allows for date format to be overriden with locale. fixes #2665 (#2671)

This commit is contained in:
Amir Raminfar
2024-01-08 14:36:08 -08:00
committed by GitHub
parent 7038bb35b2
commit 8b183e98ff
6 changed files with 44 additions and 16 deletions

View File

@@ -40,6 +40,7 @@ declare global {
const createTemplatePromise: typeof import('@vueuse/core')['createTemplatePromise'] const createTemplatePromise: typeof import('@vueuse/core')['createTemplatePromise']
const createUnrefFn: typeof import('@vueuse/core')['createUnrefFn'] const createUnrefFn: typeof import('@vueuse/core')['createUnrefFn']
const customRef: typeof import('vue')['customRef'] const customRef: typeof import('vue')['customRef']
const dateLocale: typeof import('./stores/settings')['dateLocale']
const debouncedRef: typeof import('@vueuse/core')['debouncedRef'] const debouncedRef: typeof import('@vueuse/core')['debouncedRef']
const debouncedWatch: typeof import('@vueuse/core')['debouncedWatch'] const debouncedWatch: typeof import('@vueuse/core')['debouncedWatch']
const defineAsyncComponent: typeof import('vue')['defineAsyncComponent'] const defineAsyncComponent: typeof import('vue')['defineAsyncComponent']
@@ -393,6 +394,7 @@ declare module 'vue' {
readonly createTemplatePromise: UnwrapRef<typeof import('@vueuse/core')['createTemplatePromise']> readonly createTemplatePromise: UnwrapRef<typeof import('@vueuse/core')['createTemplatePromise']>
readonly createUnrefFn: UnwrapRef<typeof import('@vueuse/core')['createUnrefFn']> readonly createUnrefFn: UnwrapRef<typeof import('@vueuse/core')['createUnrefFn']>
readonly customRef: UnwrapRef<typeof import('vue')['customRef']> readonly customRef: UnwrapRef<typeof import('vue')['customRef']>
readonly dateLocale: UnwrapRef<typeof import('./stores/settings')['dateLocale']>
readonly debouncedRef: UnwrapRef<typeof import('@vueuse/core')['debouncedRef']> readonly debouncedRef: UnwrapRef<typeof import('@vueuse/core')['debouncedRef']>
readonly debouncedWatch: UnwrapRef<typeof import('@vueuse/core')['debouncedWatch']> readonly debouncedWatch: UnwrapRef<typeof import('@vueuse/core')['debouncedWatch']>
readonly defineAsyncComponent: UnwrapRef<typeof import('vue')['defineAsyncComponent']> readonly defineAsyncComponent: UnwrapRef<typeof import('vue')['defineAsyncComponent']>
@@ -738,6 +740,7 @@ declare module '@vue/runtime-core' {
readonly createTemplatePromise: UnwrapRef<typeof import('@vueuse/core')['createTemplatePromise']> readonly createTemplatePromise: UnwrapRef<typeof import('@vueuse/core')['createTemplatePromise']>
readonly createUnrefFn: UnwrapRef<typeof import('@vueuse/core')['createUnrefFn']> readonly createUnrefFn: UnwrapRef<typeof import('@vueuse/core')['createUnrefFn']>
readonly customRef: UnwrapRef<typeof import('vue')['customRef']> readonly customRef: UnwrapRef<typeof import('vue')['customRef']>
readonly dateLocale: UnwrapRef<typeof import('./stores/settings')['dateLocale']>
readonly debouncedRef: UnwrapRef<typeof import('@vueuse/core')['debouncedRef']> readonly debouncedRef: UnwrapRef<typeof import('@vueuse/core')['debouncedRef']>
readonly debouncedWatch: UnwrapRef<typeof import('@vueuse/core')['debouncedWatch']> readonly debouncedWatch: UnwrapRef<typeof import('@vueuse/core')['debouncedWatch']>
readonly defineAsyncComponent: UnwrapRef<typeof import('vue')['defineAsyncComponent']> readonly defineAsyncComponent: UnwrapRef<typeof import('vue')['defineAsyncComponent']>

View File

@@ -10,13 +10,21 @@ const props = defineProps<{
date: Date; date: Date;
}>(); }>();
const dateFormatter = new Intl.DateTimeFormat(undefined, { day: "2-digit", month: "2-digit", year: "numeric" }); const dateOverride = computed(() => (dateLocale.value === "auto" ? undefined : dateLocale.value));
const use12Hour = $computed(() => ({ auto: undefined, "12": true, "24": false })[hourStyle.value]); const dateFormatter = computed(
const timeFormatter = $computed( () => new Intl.DateTimeFormat(dateOverride.value, { day: "2-digit", month: "2-digit", year: "numeric" }),
);
const use12Hour = computed(() => ({ auto: undefined, "12": true, "24": false })[hourStyle.value]);
const timeFormatter = computed(
() => () =>
new Intl.DateTimeFormat(undefined, { hour: "2-digit", minute: "2-digit", second: "2-digit", hour12: use12Hour }), new Intl.DateTimeFormat(undefined, {
hour: "2-digit",
minute: "2-digit",
second: "2-digit",
hour12: use12Hour.value,
}),
); );
const dateStr = $computed(() => dateFormatter.format(props.date)); const dateStr = computed(() => dateFormatter.value.format(props.date));
const timeStr = $computed(() => timeFormatter.format(props.date)); const timeStr = computed(() => timeFormatter.value.format(props.date));
</script> </script>

View File

@@ -31,17 +31,29 @@
<labeled-input> <labeled-input>
<template #label> <template #label>
{{ $t("settings.12-24-format") }} {{ $t("settings.datetime-format") }}
</template> </template>
<template #input> <template #input>
<dropdown-menu <div class="flex gap-2">
v-model="hourStyle" <dropdown-menu
:options="[ v-model="dateLocale"
{ label: 'Auto', value: 'auto' }, :options="[
{ label: '12', value: '12' }, { label: 'Auto', value: 'auto' },
{ label: '24', value: '24' }, { label: 'MM/DD/YYYY', value: 'en-US' },
]" { label: 'DD/MM/YYYY', value: 'en-GB' },
/> { label: 'DD.MM.YYYY', value: 'de-DE' },
{ label: 'YYYY-MM-DD', value: 'en-CA' },
]"
/>
<dropdown-menu
v-model="hourStyle"
:options="[
{ label: 'Auto', value: 'auto' },
{ label: '12', value: '12' },
{ label: '24', value: '24' },
]"
/>
</div>
</template> </template>
</labeled-input> </labeled-input>
@@ -113,6 +125,7 @@ import { ComplexLogEntry, SimpleLogEntry } from "@/models/LogEntry";
import { import {
automaticRedirect, automaticRedirect,
hourStyle, hourStyle,
dateLocale,
lightTheme, lightTheme,
search, search,
showAllContainers, showAllContainers,

View File

@@ -10,6 +10,7 @@ export type Settings = {
showAllContainers: boolean; showAllContainers: boolean;
lightTheme: "auto" | "dark" | "light"; lightTheme: "auto" | "dark" | "light";
hourStyle: "auto" | "24" | "12"; hourStyle: "auto" | "24" | "12";
dateLocale: "auto" | "en-US" | "en-GB" | "de-DE" | "en-CA";
softWrap: boolean; softWrap: boolean;
collapseNav: boolean; collapseNav: boolean;
automaticRedirect: boolean; automaticRedirect: boolean;
@@ -24,6 +25,7 @@ export const DEFAULT_SETTINGS: Settings = {
showAllContainers: false, showAllContainers: false,
lightTheme: "auto", lightTheme: "auto",
hourStyle: "auto", hourStyle: "auto",
dateLocale: "auto",
softWrap: true, softWrap: true,
collapseNav: false, collapseNav: false,
automaticRedirect: true, automaticRedirect: true,
@@ -35,6 +37,7 @@ export const {
collapseNav, collapseNav,
softWrap, softWrap,
hourStyle, hourStyle,
dateLocale,
lightTheme, lightTheme,
showAllContainers, showAllContainers,
showTimestamp, showTimestamp,

View File

@@ -32,6 +32,7 @@ type Settings struct {
Size string `json:"size,omitempty"` Size string `json:"size,omitempty"`
LightTheme string `json:"lightTheme,omitempty"` LightTheme string `json:"lightTheme,omitempty"`
HourStyle string `json:"hourStyle,omitempty"` HourStyle string `json:"hourStyle,omitempty"`
DateLocale string `json:"dateLocale,omitempty"`
} }
type Profile struct { type Profile struct {

View File

@@ -68,7 +68,7 @@ settings:
small-scrollbars: Use smaller scrollbars small-scrollbars: Use smaller scrollbars
show-timesamps: Show timestamps show-timesamps: Show timestamps
soft-wrap: Soft wrap lines soft-wrap: Soft wrap lines
12-24-format: Time format datetime-format: Override date and time format
font-size: Font size to use for logs font-size: Font size to use for logs
color-scheme: Color scheme color-scheme: Color scheme
options: Options options: Options