teamlead-dashboard/src/TUI/Controls/Containers/DependenciesContainer.cs

89 lines
2.5 KiB
C#
Raw Normal View History

2024-03-21 20:06:32 +00:00
using TUI.Controls.Common;
using TUI.Controls.Components;
using TUI.Domain;
2024-06-14 11:02:21 +00:00
using TUI.Engine;
2024-03-21 20:06:32 +00:00
using TUI.Engine.Attributes;
using TUI.Engine.Attributes.Alignments;
using TUI.Engine.Attributes.Orientations;
using TUI.Engine.Components;
using TUI.Engine.Containers;
using TUI.Engine.Nodes;
using TUI.Engine.Theme;
namespace TUI.Controls.Containers;
public class DependenciesContainer : ContainerBase
{
2024-06-14 11:02:21 +00:00
public readonly Project? Project;
2024-03-21 20:06:32 +00:00
private const int VersionColumnWidth = 10;
2024-06-14 11:02:21 +00:00
2024-04-01 13:37:40 +00:00
private const int TitleColumnWidth = 25;
2024-06-14 11:02:21 +00:00
2024-03-21 20:06:32 +00:00
private readonly Nodes _dependencies = new();
2024-06-14 11:02:21 +00:00
public DependenciesContainer()
{
}
public DependenciesContainer(Project project)
{
Project = project;
}
2024-03-21 20:06:32 +00:00
public void AddTitleStub()
{
var size = new Size(TitleColumnWidth, 1);
var title = new StubComponent(size);
title.SetPadding(Level.Normal);
2024-06-14 11:02:21 +00:00
2024-03-21 20:06:32 +00:00
_dependencies.Add(title);
}
2024-06-14 11:02:21 +00:00
2024-03-21 20:06:32 +00:00
public void AddTitle(IComponent title)
{
title.SetPadding(Level.Normal);
title.SetFixed(Orientation.Horizontal, TitleColumnWidth);
2024-04-01 13:37:40 +00:00
title.SetAlignment(Horizontal.Left);
2024-06-14 11:02:21 +00:00
if (Project is not null && Project.Legacy)
{
title.StyleContext = new StyleContext(Palette.DisableColor);
}
2024-03-21 20:06:32 +00:00
_dependencies.Add(title);
}
2024-06-14 11:02:21 +00:00
public void AddDependencyStub()
2024-03-21 20:06:32 +00:00
{
2024-06-14 11:02:21 +00:00
var size = new Size(VersionColumnWidth, 1);
var stub = new StubComponent(size, Symbols.NotFound.Hint());
stub.SetPadding(Level.Normal);
stub.SetAlignment(Horizontal.Right);
stub.SetFixed(Orientation.Horizontal, VersionColumnWidth);
if (Project is not null && Project.Legacy)
{
stub.StyleContext = new StyleContext(Palette.DisableColor);
}
_dependencies.Add(stub);
}
public void AddDependency(Dependency dependency, VersionStatus status = VersionStatus.BeNice)
{
var version = new VersionComponent(dependency.Version, dependency.Brand, status, dependency.Type);
2024-03-21 20:06:32 +00:00
version.SetPadding(Level.Normal);
version.SetAlignment(Horizontal.Right);
version.SetFixed(Orientation.Horizontal, VersionColumnWidth);
2024-06-14 11:02:21 +00:00
if (Project is not null && Project.Legacy)
{
version.StyleContext = new StyleContext(Palette.DisableColor);
}
2024-03-21 20:06:32 +00:00
_dependencies.Add(version);
}
2024-06-14 11:02:21 +00:00
2024-03-21 20:06:32 +00:00
public override Nodes GetNodes() => _dependencies;
}