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
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
using RackPeek.Domain.Resources.Services;
using RackPeek.Domain.Resources.Switches;
using RackPeek.Domain.Resources.SystemResources;
using RackPeek.Domain.Resources.OtherHardware;
using RackPeek.Domain.Resources.UpsUnits;
using YamlDotNet.Serialization;
using YamlDotNet.Serialization.NamingConventions;
Expand Down Expand Up @@ -45,6 +46,7 @@ public RackPeekConfigMigrationDeserializer(IServiceProvider serviceProvider,
{ Laptop.KindLabel, typeof(Laptop) },
{ AccessPoint.KindLabel, typeof(AccessPoint) },
{ Ups.KindLabel, typeof(Ups) },
{ Other.KindLabel, typeof(Other) },
{ SystemResource.KindLabel, typeof(SystemResource) },
{ Service.KindLabel, typeof(Service) }
});
Expand Down
2 changes: 2 additions & 0 deletions RackPeek.Domain/Persistence/Yaml/YamlResourceCollection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
using RackPeek.Domain.Resources.Services;
using RackPeek.Domain.Resources.Switches;
using RackPeek.Domain.Resources.SystemResources;
using RackPeek.Domain.Resources.OtherHardware;
using RackPeek.Domain.Resources.UpsUnits;
using YamlDotNet.Core;
using YamlDotNet.Serialization;
Expand Down Expand Up @@ -368,6 +369,7 @@ private string GetKind(Resource resource)
Laptop => "Laptop",
AccessPoint => "AccessPoint",
Ups => "Ups",
Other => "Other",
SystemResource => "System",
Service => "Service",
_ => throw new InvalidOperationException($"Unknown resource type: {resource.GetType().Name}")
Expand Down
31 changes: 31 additions & 0 deletions RackPeek.Domain/Resources/OtherHardware/DescribeOtherUseCase.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
using RackPeek.Domain.Helpers;
using RackPeek.Domain.Persistence;

namespace RackPeek.Domain.Resources.OtherHardware;

public record OtherDescription(
string Name,
string? Model,
string? Description,
Dictionary<string, string> Labels
);

public class DescribeOtherUseCase(IResourceCollection repository) : IUseCase
{
public async Task<OtherDescription> ExecuteAsync(string name)
{
name = Normalize.HardwareName(name);
ThrowIfInvalid.ResourceName(name);

var other = await repository.GetByNameAsync(name) as Other;
if (other == null)
throw new NotFoundException($"Other hardware '{name}' not found.");

return new OtherDescription(
other.Name,
other.Model,
other.Description,
other.Labels
);
}
}
8 changes: 8 additions & 0 deletions RackPeek.Domain/Resources/OtherHardware/Other.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
namespace RackPeek.Domain.Resources.OtherHardware;

public class Other : Hardware.Hardware
{
public const string KindLabel = "Other";
public string? Model { get; set; }
public string? Description { get; set; }
}
29 changes: 29 additions & 0 deletions RackPeek.Domain/Resources/OtherHardware/OtherHardwareReport.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
using RackPeek.Domain.Persistence;

namespace RackPeek.Domain.Resources.OtherHardware;

public record OtherHardwareReport(
IReadOnlyList<OtherHardwareRow> Others
);

public record OtherHardwareRow(
string Name,
string Model,
string Description
);

public class OtherHardwareReportUseCase(IResourceCollection repository) : IUseCase
{
public async Task<OtherHardwareReport> ExecuteAsync()
{
var others = await repository.GetAllOfTypeAsync<Other>();

var rows = others.Select(o => new OtherHardwareRow(
o.Name,
o.Model ?? "Unknown",
o.Description ?? ""
)).ToList();

return new OtherHardwareReport(rows);
}
}
31 changes: 31 additions & 0 deletions RackPeek.Domain/Resources/OtherHardware/UpdateOtherUseCase.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
using RackPeek.Domain.Helpers;
using RackPeek.Domain.Persistence;

namespace RackPeek.Domain.Resources.OtherHardware;

public class UpdateOtherUseCase(IResourceCollection repository) : IUseCase
{
public async Task ExecuteAsync(
string name,
string? model = null,
string? description = null,
string? notes = null
)
{
name = Normalize.HardwareName(name);
ThrowIfInvalid.ResourceName(name);

var other = await repository.GetByNameAsync(name) as Other;
if (other == null)
throw new InvalidOperationException($"Other hardware '{name}' not found.");

if (!string.IsNullOrWhiteSpace(model))
other.Model = model;

if (description != null)
other.Description = description;

if (notes != null) other.Notes = notes;
await repository.UpdateAsync(other);
}
}
5 changes: 4 additions & 1 deletion RackPeek.Domain/Resources/Resource.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,15 @@
using RackPeek.Domain.Resources.Services;
using RackPeek.Domain.Resources.Switches;
using RackPeek.Domain.Resources.SystemResources;
using RackPeek.Domain.Resources.OtherHardware;
using RackPeek.Domain.Resources.UpsUnits;

namespace RackPeek.Domain.Resources;

public abstract class Resource
{
private static readonly string[] HardwareTypes =
["server", "switch", "firewall", "router", "accesspoint", "desktop", "laptop", "ups"];
["server", "switch", "firewall", "router", "accesspoint", "desktop", "laptop", "ups", "other"];

public static bool IsHardware(string kind)
{
Expand Down Expand Up @@ -52,6 +53,7 @@ public static string GetResourceUrl(string kind, string name)
{ "desktop", "desktops" },
{ "laptop", "laptops" },
{ "ups", "ups" },
{ "other", "other" },
{ "system", "systems" },
{ "service", "services" }
};
Expand All @@ -67,6 +69,7 @@ public static string GetResourceUrl(string kind, string name)
{ typeof(Desktop), "Desktop" },
{ typeof(Laptop), "Laptop" },
{ typeof(Ups), "Ups" },
{ typeof(Other), "Other" },
{ typeof(SystemResource), "System" },
{ typeof(Service), "Service" }
};
Expand Down
6 changes: 6 additions & 0 deletions Shared.Rcl/Hardware/HardwareDetailsPage.razor
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
@using RackPeek.Domain.Resources.Servers
@using RackPeek.Domain.Resources.Switches
@using RackPeek.Domain.Resources.SystemResources
@using RackPeek.Domain.Resources.OtherHardware
@using RackPeek.Domain.Resources.UpsUnits
@using Shared.Rcl.AccessPoints
@using Shared.Rcl.Desktops
Expand All @@ -18,6 +19,7 @@
@using Shared.Rcl.Servers
@using Shared.Rcl.Switches
@using Shared.Rcl.Ups
@using Shared.Rcl.OtherHardware
@using Router = RackPeek.Domain.Resources.Routers.Router
@inject IResourceCollection Repo
@inject GetHardwareSystemTreeUseCase GetHardwareSystemTreeUseCase
Expand Down Expand Up @@ -77,6 +79,10 @@
{
<UpsCardComponent Ups="ups" OnDeleted="DeleteCallback"/>
}
else if (_hardware is Other other)
{
<OtherCardComponent Other="other" OnDeleted="DeleteCallback"/>
}
else
{
<div class="text-zinc-400">
Expand Down
1 change: 1 addition & 0 deletions Shared.Rcl/Hardware/HardwareTreePage.razor
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
<NavLink href="ups/list" data-testid="nav-ups">Ups</NavLink>
<NavLink href="desktops/list" data-testid="nav-desktops">Desktops</NavLink>
<NavLink href="laptops/list" data-testid="nav-laptops">Laptops</NavLink>
<NavLink href="other/list" data-testid="nav-other">Other</NavLink>
</nav>

@if (_tree is null)
Expand Down
Loading