@using RackPeek.Domain.Resources.Servers @using RackPeek.Domain.Resources.SubResources @using RackPeek.Domain.UseCases.Cpus @using RackPeek.Domain.UseCases.Drives @using RackPeek.Domain.UseCases.Gpus @using RackPeek.Domain.UseCases.Ports @using Shared.Rcl.Hardware @inject IAddCpuUseCase AddCpuUseCase @inject IRemoveCpuUseCase RemoveCpuUseCase @inject IUpdateCpuUseCase UpdateCpuUseCase @inject IAddDriveUseCase AddDriveUseCase @inject IUpdateDriveUseCase UpdateDriveUseCase @inject IRemoveDriveUseCase RemoveDriveUseCase @inject IAddPortUseCase AddNicUseCase @inject IUpdatePortUseCase UpdateNicUseCase @inject IRemovePortUseCase RemoveNicUseCase @inject IAddGpuUseCase AddGpuUseCase @inject IUpdateGpuUseCase UpdateGpuUseCase @inject IRemoveGpuUseCase RemoveGpuUseCase @inject IGetResourceByNameUseCase GetByNameUseCase @inject UpdateServerUseCase UpdateUseCase @inject IDeleteResourceUseCase DeleteUseCase @inject ICloneResourceUseCase CloneUseCase @inject IRenameResourceUseCase RenameUseCase @inject NavigationManager Nav
@Server.Name
CPU
@if (Server.Cpus?.Any() == true) { @foreach (var cpu in Server.Cpus) {
} }
RAM @if (Server.Ram is null) { }
@if (Server.Ram is not null) {
}
Drives
@if (Server.Drives?.Any() == true) { @foreach (var drive in Server.Drives) {
} }
GPUs
@if (Server.Gpus?.Any() == true) { @foreach (var gpu in Server.Gpus) {
} }
Notes
@if (!_editingNotes) { } else { }
Are you sure you want to delete @Server.Name?
This will detach all dependent systems.
@code { [Parameter] [EditorRequired] public Server Server { get; set; } = default!; #region RAM private bool _isRamModalOpen; private void EditRam() { _isRamModalOpen = true; } private async Task HandleRamSubmit(Ram? value) { _isRamModalOpen = false; await UpdateUseCase.ExecuteAsync(Server.Name, value?.Size ?? 0, value?.Mts ?? 0, Server.Ipmi); Server = await GetByNameUseCase.ExecuteAsync(Server.Name); } #endregion #region CPU bool _cpuModalOpen; int _editingCpuIndex; Cpu? _editingCpu; void OpenAddCpu() { _editingCpuIndex = -1; _editingCpu = null; _cpuModalOpen = true; } void OpenEditCpu(Cpu cpu) { _editingCpu = cpu; Server.Cpus ??= new List(); _editingCpuIndex = Server.Cpus.IndexOf(cpu); ; _cpuModalOpen = true; } async Task HandleCpuSubmit(Cpu cpu) { Server.Cpus ??= new List(); if (_editingCpuIndex < 0) { await AddCpuUseCase.ExecuteAsync(Server.Name, cpu.Model, cpu.Cores, cpu.Threads); } else { await UpdateCpuUseCase.ExecuteAsync(Server.Name, _editingCpuIndex, cpu.Model, cpu.Cores, cpu.Threads); } Server = await GetByNameUseCase.ExecuteAsync(Server.Name); } async Task HandleCpuDelete(Cpu cpu) { await RemoveCpuUseCase.ExecuteAsync(Server.Name, _editingCpuIndex); Server = await GetByNameUseCase.ExecuteAsync(Server.Name); } #endregion #region Drives bool _driveModalOpen; int _editingDriveIndex; Drive? _editingDrive; void OpenAddDrive() { _editingDriveIndex = -1; _editingDrive = null; _driveModalOpen = true; } void OpenEditDrives(Drive drive) { _editingDrive = drive; Server.Drives ??= new List(); _editingDriveIndex = Server.Drives.IndexOf(drive); ; _driveModalOpen = true; } async Task HandleDriveSubmit(Drive drive) { Server.Drives ??= new List(); if (_editingDriveIndex < 0) { await AddDriveUseCase.ExecuteAsync(Server.Name, drive.Type, drive.Size); } else { await UpdateDriveUseCase.ExecuteAsync(Server.Name, _editingDriveIndex, drive.Type, drive.Size); } Server = await GetByNameUseCase.ExecuteAsync(Server.Name); StateHasChanged(); } async Task HandleDriveDelete(Drive drive) { await RemoveDriveUseCase.ExecuteAsync(Server.Name, _editingDriveIndex); Server = await GetByNameUseCase.ExecuteAsync(Server.Name); StateHasChanged(); } #endregion #region GPUs bool _gpuModalOpen; int _editingGpuIndex; Gpu? _editingGpu; void OpenAddGpu() { _editingGpuIndex = -1; _editingGpu = null; _gpuModalOpen = true; } void OpenEditGpu(Gpu gpu) { Server.Gpus ??= new List(); _editingGpuIndex = Server.Gpus.IndexOf(gpu); _editingGpu = gpu; _gpuModalOpen = true; } async Task HandleGpuSubmit(Gpu gpu) { Server.Gpus ??= new List(); if (_editingGpuIndex < 0) { await AddGpuUseCase.ExecuteAsync( Server.Name, gpu.Model, gpu.Vram); } else { await UpdateGpuUseCase.ExecuteAsync( Server.Name, _editingGpuIndex, gpu.Model, gpu.Vram); } Server = await GetByNameUseCase.ExecuteAsync(Server.Name); } async Task HandleGpuDelete(Gpu gpu) { await RemoveGpuUseCase.ExecuteAsync(Server.Name, _editingGpuIndex); Server = await GetByNameUseCase.ExecuteAsync(Server.Name); } #endregion } @code { private bool _confirmDeleteOpen; [Parameter] public EventCallback OnDeleted { get; set; } void ConfirmDelete() { _confirmDeleteOpen = true; } async Task DeleteServer() { _confirmDeleteOpen = false; await DeleteUseCase.ExecuteAsync(Server.Name); if (OnDeleted.HasDelegate) await OnDeleted.InvokeAsync(Server.Name); } } @code { bool _renameOpen; void OpenRename() { _renameOpen = true; } async Task HandleRenameSubmit(string newName) { await RenameUseCase.ExecuteAsync(Server.Name, newName); Nav.NavigateTo($"resources/hardware/{Uri.EscapeDataString(newName)}"); } } @code { bool _cloneOpen; void OpenClone() { _cloneOpen = true; } async Task HandleCloneSubmit(string newName) { await CloneUseCase.ExecuteAsync(Server.Name, newName); Nav.NavigateTo($"resources/hardware/{Uri.EscapeDataString(newName)}"); } } @code { bool _editingNotes; string? _notesDraft; void BeginNotesEdit() { _editingNotes = true; _notesDraft = Server.Notes; // draft buffer } void CancelNotesEdit() { _editingNotes = false; _notesDraft = null; // discard } async Task SaveNotes() { _editingNotes = false; await UpdateUseCase.ExecuteAsync( Server.Name, Server.Ram?.Size, Server.Ram?.Mts, Server.Ipmi, _notesDraft); Server = await GetByNameUseCase.ExecuteAsync(Server.Name); _notesDraft = null; } }