| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252 |
- @using RackPeek.Domain.Resources.Hardware.UpsUnits
- @using RackPeek.Domain.Resources.Models
- @using Shared.Rcl.Modals
- @inject UpdateUpsUseCase UpdateUpsUseCase
- @inject GetUpsUnitUseCase GetUpsUseCase
- @inject DeleteUpsUseCase DeleteUseCase
- @inject RenameUpsUseCase RenameUpsUseCase
- @inject CloneUpsUseCase CloneUseCase
- @inject NavigationManager Nav
- <div class="border border-zinc-800 rounded p-4 bg-zinc-900">
- <div class="flex justify-between items-center mb-3">
- <div class="text-zinc-100 hover:text-emerald-300">
- <NavLink href="@($"resources/hardware/{Ups.Name}")" class="block">
- @Ups.Name
- </NavLink>
- </div>
- <div class="flex gap-3 text-xs">
- @if (!_isEditing)
- {
- <button class="text-zinc-400 hover:text-zinc-200"
- @onclick="BeginEdit">
- Edit
- </button>
- <button class="text-xs text-blue-400 hover:text-blue-300 transition"
- title="Rename service"
- @onclick="OpenRename">
- Rename
- </button>
- <button
- class="text-xs text-emerald-400 hover:text-emerald-300 transition"
- title="Clone service"
- @onclick="OpenClone">
- Clone
- </button>
- <button class="text-red-400 hover:text-red-300 transition"
- title="Delete UPS"
- @onclick="ConfirmDelete">
- Delete
- </button>
- }
- else
- {
- <button class="text-emerald-400 hover:text-emerald-300"
- @onclick="Save">
- Save
- </button>
- <button class="text-zinc-500 hover:text-zinc-300"
- @onclick="Cancel">
- Cancel
- </button>
- }
- </div>
- </div>
- <div class="grid grid-cols-1 md:grid-cols-2 gap-3 text-sm">
- <!-- Model -->
- <div>
- <div class="text-zinc-400 mb-1">Model</div>
- @if (_isEditing)
- {
- <input
- class="w-full px-3 py-2 rounded-md
- bg-zinc-800 text-zinc-100
- border border-zinc-600
- placeholder-zinc-500
- focus:outline-none focus:ring-2 focus:ring-blue-500 focus:border-blue-500
- hover:border-zinc-400
- transition-colors duration-150
- cursor-text"
- @bind="_edit.Model"/>
- }
- else if (!string.IsNullOrWhiteSpace(Ups.Model))
- {
- <div class="text-zinc-300">@Ups.Model</div>
- }
- </div>
- <!-- Capacity -->
- <div>
- <div class="text-zinc-400 mb-1">Capacity</div>
- @if (_isEditing)
- {
- <input type="number"
- class="w-full px-3 py-2 rounded-md
- bg-zinc-800 text-zinc-100
- border border-zinc-600
- placeholder-zinc-500
- focus:outline-none focus:ring-2 focus:ring-blue-500 focus:border-blue-500
- hover:border-zinc-400
- transition-colors duration-150
- cursor-text"
- @bind="_edit.Va"/>
- }
- else if (Ups.Va is not null)
- {
- <div class="text-zinc-300">@Ups.Va VA</div>
- }
- </div>
- <ResourceTagEditor Resource="Ups" />
- <div class="md:col-span-2">
- <div class="text-zinc-400 mb-1">Notes</div>
- @if (_isEditing)
- {
- <MarkdownEditor
- @bind-Value="_edit.Notes"
- ShowActionButtons="false" />
- }
- else
- {
- <MarkdownViewer
- Value="@Ups.Notes"
- ShowEditButton="false" />
- }
- </div>
- </div>
- </div>
- <ConfirmModal
- IsOpen="_confirmDeleteOpen"
- IsOpenChanged="v => _confirmDeleteOpen = v"
- Title="Delete UPS"
- ConfirmText="Delete"
- ConfirmClass="bg-red-600 hover:bg-red-500"
- OnConfirm="DeleteUps">
- Are you sure you want to delete <strong>@Ups.Name</strong>?
- </ConfirmModal>
- <StringValueModal
- IsOpen="_renameOpen"
- IsOpenChanged="v => _renameOpen = v"
- Title="Rename Ups"
- Description="Enter a new name for this Ups"
- Label="New Ups name"
- Value="@Ups.Name"
- OnSubmit="HandleRenameSubmit" />
- <StringValueModal
- IsOpen="_cloneOpen"
- IsOpenChanged="v => _cloneOpen = v"
- Title="Clone resource"
- Description="Enter a name for the cloned resource"
- Label="New resource name"
- Value="@($"{Ups.Name}-copy")"
- OnSubmit="HandleCloneSubmit" />
- @code {
- [Parameter][EditorRequired] public Ups Ups { get; set; } = default!;
- [Parameter] public EventCallback<string> OnDeleted { get; set; }
- bool _isEditing;
- bool _confirmDeleteOpen;
- UpsEditModel _edit = new();
- void BeginEdit()
- {
- _edit = UpsEditModel.From(Ups);
- _isEditing = true;
- }
- async Task Save()
- {
- _isEditing = false;
- await UpdateUpsUseCase.ExecuteAsync(
- Ups.Name,
- _edit.Model,
- _edit.Va,
- _edit.Notes);
- Ups = await GetUpsUseCase.ExecuteAsync(Ups.Name);
- }
- void Cancel()
- {
- _isEditing = false;
- }
- void ConfirmDelete()
- {
- _confirmDeleteOpen = true;
- }
- async Task DeleteUps()
- {
- _confirmDeleteOpen = false;
- await DeleteUseCase.ExecuteAsync(Ups.Name);
- if (OnDeleted.HasDelegate)
- await OnDeleted.InvokeAsync(Ups.Name);
- }
- public class UpsEditModel
- {
- public string? Model { get; set; }
- public int? Va { get; set; }
- public string? Notes { get; set; }
- public static UpsEditModel From(Ups ups)
- {
- return new UpsEditModel
- {
- Model = ups.Model,
- Va = ups.Va,
- Notes = ups.Notes
- };
- }
- }
- }
- @code
- {
- bool _renameOpen;
- void OpenRename()
- {
- _renameOpen = true;
- }
- async Task HandleRenameSubmit(string newName)
- {
- await RenameUpsUseCase.ExecuteAsync(Ups.Name, newName);
- Nav.NavigateTo($"resources/hardware/{newName}");
- }
- }
- @code
- {
- bool _cloneOpen;
- void OpenClone()
- {
- _cloneOpen = true;
- }
- async Task HandleCloneSubmit(string newName)
- {
- await CloneUseCase.ExecuteAsync(Ups.Name, newName);
- Nav.NavigateTo($"resources/hardware/{newName}");
- }
- }
|