Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions src/Aspire.Dashboard/Components/Dialogs/SettingsDialog.razor
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,17 @@
<p class="setting-subtext">@Loc[nameof(Dialogs.SettingsDialogLanguagePageReloads)]</p>
</div>

<div class="input-container">
<FluentSelect
TOption="TimeFormat"
Label="@Loc[nameof(Dialogs.SettingsDialogTimeFormat)]"
Items="@(Enum.GetValues<TimeFormat>())"
OptionText="@(i => FormatTimeFormatOption(i))"
@bind-SelectedOption="@_timeFormat"
@bind-SelectedOption:after="OnTimeFormatChanged"
Position="SelectPosition.Below" />
</div>

<div>
<span class="setting-title">@Loc[nameof(Dialogs.SettingsDialogDashboardLogsAndTelemetry)]</span>
<div>
Expand Down
29 changes: 29 additions & 0 deletions src/Aspire.Dashboard/Components/Dialogs/SettingsDialog.razor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ public partial class SettingsDialog : IDialogContentComponent, IDisposable
private string? _currentSetting;
private List<CultureInfo> _languageOptions = null!;
private CultureInfo? _selectedUiCulture;
private TimeFormat _timeFormat;

private IDisposable? _themeChangedSubscription;

Expand All @@ -30,6 +31,12 @@ public partial class SettingsDialog : IDialogContentComponent, IDisposable
[Inject]
public required DashboardDialogService DialogService { get; init; }

[Inject]
public required BrowserTimeProvider TimeProvider { get; init; }

[Inject]
public required ILocalStorage LocalStorage { get; init; }

protected override void OnInitialized()
{
_languageOptions = GlobalizationHelpers.OrderedLocalizedCultures;
Expand All @@ -39,6 +46,8 @@ protected override void OnInitialized()
// Otherwise, Blazor has fallen back to a supported language
CultureInfo.CurrentUICulture;

_timeFormat = TimeProvider.TimeFormat;

_currentSetting = ThemeManager.SelectedTheme ?? ThemeManager.ThemeSettingSystem;

// Handle value being changed in a different browser window.
Expand Down Expand Up @@ -99,6 +108,26 @@ private async Task LaunchManageDataAsync()
await DialogService.ShowDialogAsync<ManageDataDialog>(parameters);
}

private async Task OnTimeFormatChanged()
{
TimeProvider.SetTimeFormat(_timeFormat);
await LocalStorage.SetAsync(BrowserStorageKeys.TimeFormat, _timeFormat);

// Reload the page to ensure all components pick up the new format
var uri = new Uri(NavigationManager.Uri)
.GetComponents(UriComponents.PathAndQuery, UriFormat.Unescaped);

NavigationManager.NavigateTo(uri, forceLoad: true);
}

private string FormatTimeFormatOption(TimeFormat format) => format switch
{
TimeFormat.System => Loc[nameof(Dashboard.Resources.Dialogs.SettingsDialogTimeFormatSystem)],
TimeFormat.TwelveHour => Loc[nameof(Dashboard.Resources.Dialogs.SettingsDialogTimeFormatTwelveHour)],
TimeFormat.TwentyFourHour => Loc[nameof(Dashboard.Resources.Dialogs.SettingsDialogTimeFormatTwentyFourHour)],
_ => format.ToString()
};

public void Dispose()
{
_themeChangedSubscription?.Dispose();
Expand Down
6 changes: 6 additions & 0 deletions src/Aspire.Dashboard/Components/Layout/MainLayout.razor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,12 @@ protected override async Task OnInitializedAsync()
TimeProvider.SetBrowserTimeZone(result.TimeZone);
TelemetryContextProvider.SetBrowserUserAgent(result.UserAgent);

var timeFormatResult = await LocalStorage.GetAsync<TimeFormat>(BrowserStorageKeys.TimeFormat);
if (timeFormatResult.Success)
{
TimeProvider.SetTimeFormat(timeFormatResult.Value);
}

await DisplayUnsecuredEndpointsMessageAsync();

_aiDisplayChangedSubscription = AIContextProvider.OnDisplayChanged(() => InvokeAsync(StateHasChanged));
Expand Down
14 changes: 14 additions & 0 deletions src/Aspire.Dashboard/Model/BrowserTimeProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,18 @@ public void SetBrowserTimeZone(string? timeZone)
_logger.LogDebug("Browser time zone set to '{TimeZone}' with UTC offset {UtcOffset}.", timeZoneInfo.Id, timeZoneInfo.BaseUtcOffset);
_browserLocalTimeZone = timeZoneInfo;
}

public TimeFormat TimeFormat { get; private set; } = TimeFormat.System;

public void SetTimeFormat(TimeFormat timeFormat)
{
TimeFormat = timeFormat;
}
}

public enum TimeFormat
{
System,
TwelveHour,
TwentyFourHour
}
36 changes: 36 additions & 0 deletions src/Aspire.Dashboard/Resources/Dialogs.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 13 additions & 1 deletion src/Aspire.Dashboard/Resources/Dialogs.resx
Original file line number Diff line number Diff line change
Expand Up @@ -549,4 +549,16 @@
<data name="ManageDataResource" xml:space="preserve">
<value>Resource</value>
</data>
</root>
<data name="SettingsDialogTimeFormat" xml:space="preserve">
<value>Time Format</value>
</data>
<data name="SettingsDialogTimeFormatSystem" xml:space="preserve">
<value>System</value>
</data>
<data name="SettingsDialogTimeFormatTwelveHour" xml:space="preserve">
<value>12-Hour</value>
</data>
<data name="SettingsDialogTimeFormatTwentyFourHour" xml:space="preserve">
<value>24-Hour</value>
</data>
</root>
20 changes: 20 additions & 0 deletions src/Aspire.Dashboard/Resources/xlf/Dialogs.cs.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 20 additions & 0 deletions src/Aspire.Dashboard/Resources/xlf/Dialogs.de.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 20 additions & 0 deletions src/Aspire.Dashboard/Resources/xlf/Dialogs.es.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 20 additions & 0 deletions src/Aspire.Dashboard/Resources/xlf/Dialogs.fr.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 20 additions & 0 deletions src/Aspire.Dashboard/Resources/xlf/Dialogs.it.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 20 additions & 0 deletions src/Aspire.Dashboard/Resources/xlf/Dialogs.ja.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 20 additions & 0 deletions src/Aspire.Dashboard/Resources/xlf/Dialogs.ko.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 20 additions & 0 deletions src/Aspire.Dashboard/Resources/xlf/Dialogs.pl.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Loading