Skip to content

Commit

Permalink
Use application name for dashboard page title
Browse files Browse the repository at this point in the history
Resolves #153
  • Loading branch information
smitpatel committed Oct 10, 2023
1 parent 2687492 commit 8a6da08
Show file tree
Hide file tree
Showing 7 changed files with 31 additions and 8 deletions.
6 changes: 4 additions & 2 deletions src/Aspire.Dashboard/Components/Layout/MainLayout.razor
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
@inherits LayoutComponentBase
@using Aspire.Dashboard.Model
@inject IDashboardViewModelService dashboardViewModelService
@inherits LayoutComponentBase

<div>
<FluentLayout>
<FluentHeader Style="margin-bottom:0px">Aspire Dashboard</FluentHeader>
<FluentHeader Style="margin-bottom:0px">@dashboardViewModelService.GetApplicationName() Dashboard</FluentHeader>
<FluentStack Orientation="Orientation.Horizontal" Width="100%">

<FluentNavMenu Width="250" Collapsible="true">
Expand Down
2 changes: 1 addition & 1 deletion src/Aspire.Dashboard/Components/Pages/Containers.razor
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
@implements IDisposable
@inherits ResourcesListBase<ContainerViewModel>

<PageTitle>Microsoft.Aspire Dashboard</PageTitle>
<PageTitle>@DashboardViewModelService.GetApplicationName() Dashboard</PageTitle>

<h1>Containers</h1>

Expand Down
2 changes: 1 addition & 1 deletion src/Aspire.Dashboard/Components/Pages/Executables.razor
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
@implements IDisposable
@inherits ResourcesListBase<ExecutableViewModel>

<PageTitle>Microsoft.Aspire Dashboard</PageTitle>
<PageTitle>@DashboardViewModelService.GetApplicationName() Dashboard</PageTitle>

<h1>Executables</h1>

Expand Down
2 changes: 1 addition & 1 deletion src/Aspire.Dashboard/Components/Pages/Index.razor
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
@implements IDisposable
@inherits ResourcesListBase<ProjectViewModel>

<PageTitle>Microsoft.Aspire Dashboard</PageTitle>
<PageTitle>@DashboardViewModelService.GetApplicationName() Dashboard</PageTitle>

<h1>Projects</h1>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
@using Aspire.Dashboard.Model
@typeparam TResource where TResource : ResourceViewModel

<PageTitle>Microsoft.Aspire @ResourceType Logs</PageTitle>
<PageTitle>@DashboardViewModelService.GetApplicationName() @ResourceType Logs</PageTitle>

<h1>@ResourceType Logs</h1>

Expand Down
1 change: 1 addition & 0 deletions src/Aspire.Dashboard/Model/IDashboardViewModelService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ namespace Aspire.Dashboard.Model;

public interface IDashboardViewModelService
{
public string GetApplicationName();
public Task<List<ContainerViewModel>> GetContainersAsync();
public Task<List<ExecutableViewModel>> GetExecutablesAsync();
public Task<List<ProjectViewModel>> GetProjectsAsync();
Expand Down
24 changes: 22 additions & 2 deletions src/Aspire.Hosting/Dashboard/DashboardViewModelService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,25 @@
using Aspire.Hosting.Dcp;
using Aspire.Hosting.Dcp.Model;
using k8s;
using Microsoft.Extensions.Hosting;
using NamespacedName = Aspire.Dashboard.Model.NamespacedName;

namespace Aspire.Hosting.Dashboard;

public class DashboardViewModelService(DistributedApplicationModel applicationModel) : IDashboardViewModelService, IDisposable
public class DashboardViewModelService : IDashboardViewModelService, IDisposable
{
private readonly DistributedApplicationModel _applicationModel = applicationModel;
private readonly DistributedApplicationModel _applicationModel;
private readonly string _applicationName;
private readonly KubernetesService _kubernetesService = new();

public DashboardViewModelService(DistributedApplicationModel applicationModel, IHostEnvironment hostEnvironment)
{
_applicationModel = applicationModel;
_applicationName = ComputeApplicationName(hostEnvironment.ApplicationName);
}

public string GetApplicationName() => _applicationName;

public async Task<List<ContainerViewModel>> GetContainersAsync()
{
var containers = await _kubernetesService.ListAsync<Container>().ConfigureAwait(false);
Expand Down Expand Up @@ -246,4 +256,14 @@ private static void FillEnvironmentVariables(List<EnvironmentVariableViewModel>

target.Sort((v1, v2) => string.Compare(v1.Name, v2.Name));
}

private static string ComputeApplicationName(string applicationName)
{
if (applicationName.EndsWith(".apphost", StringComparison.OrdinalIgnoreCase))
{
applicationName = applicationName[..^".apphost".Length];
}

return applicationName;
}
}

0 comments on commit 8a6da08

Please sign in to comment.