Files
CartriX/CartriX.Web/Pages/AddPrinterDialog.razor
T

126 lines
4.8 KiB
Plaintext

@using CartriX.Shared.DTOs.Printer
<RadzenStack Gap="16px">
<RadzenStack Orientation="Orientation.Horizontal" AlignItems="AlignItems.Center" Wrap="FlexWrap.Wrap">
<RadzenLabel Text="IP Адрес принтера:" />
<RadzenTextBox Placeholder="123.255.255.255" Style="flex: 1; min-width: 200px;" @bind-Value="printerIpOrHostname" />
</RadzenStack>
<RadzenButton Text="Опросить" Icon="content_paste_search" BusyText="Опрашиваем" IsBusy="processingQueryToPrinter" Click="@(() => OnQueryPrinter())" />
<RadzenTable>
<RadzenTableHeader>
<RadzenTableHeaderRow>
<RadzenTableHeaderCell ColSpan="2">
Результат запроса принтера
</RadzenTableHeaderCell>
</RadzenTableHeaderRow>
</RadzenTableHeader>
<RadzenTableBody>
<RadzenTableRow>
<RadzenTableCell>Имя хоста</RadzenTableCell>
<RadzenTableCell>
@if (processingQueryToPrinter)
{
<RadzenSkeleton Animation="SkeletonAnimation.Wave" Style="width: 100%;" />
}
else if (queryPrinterToAdd is not null)
{
@queryPrinterToAdd.hostname;
}
else
{
<RadzenSkeleton Animation="SkeletonAnimation.None" Style="width: 100%;" />
}
</RadzenTableCell>
</RadzenTableRow>
<RadzenTableRow>
<RadzenTableCell>IP Адрес</RadzenTableCell>
<RadzenTableCell>
@if (processingQueryToPrinter)
{
<RadzenSkeleton Animation="SkeletonAnimation.Wave" Style="width: 100%;" />
}
else if (queryPrinterToAdd is not null)
{
@queryPrinterToAdd.ipAddress;
}
else
{
<RadzenSkeleton Animation="SkeletonAnimation.None" Style="width: 100%;" />
}
</RadzenTableCell>
</RadzenTableRow>
<RadzenTableRow>
<RadzenTableCell>Модель принтера</RadzenTableCell>
<RadzenTableCell>
@if (processingQueryToPrinter)
{
<RadzenSkeleton Animation="SkeletonAnimation.Wave" Style="width: 100%;" />
}
else if (queryPrinterToAdd is not null)
{
@queryPrinterToAdd.model;
}
else
{
<RadzenSkeleton Animation="SkeletonAnimation.None" Style="width: 100%;" />
}
</RadzenTableCell>
</RadzenTableRow>
<RadzenTableRow>
<RadzenTableCell>Местоположение</RadzenTableCell>
<RadzenTableCell>
@if (processingQueryToPrinter)
{
<RadzenSkeleton Animation="SkeletonAnimation.Wave" Style="width: 100%;" />
}
else if (queryPrinterToAdd is not null)
{
@queryPrinterToAdd.location;
}
else
{
<RadzenSkeleton Animation="SkeletonAnimation.None" Style="width: 100%;" />
}
</RadzenTableCell>
</RadzenTableRow>
</RadzenTableBody>
</RadzenTable>
<RadzenStack>
<RadzenButton Text="Добавить" Disabled="true" />
</RadzenStack>
</RadzenStack>
@code {
private string printerIpOrHostname = "";
private bool processingQueryToPrinter = false;
QueryPrinterToAdd queryPrinterToAdd = null!;
private async Task OnQueryPrinter()
{
if (string.IsNullOrWhiteSpace(printerIpOrHostname))
return;
processingQueryToPrinter = true;
try
{
HttpClient client = new();
var response = await client.GetAsync($"http://localhost:5197/api/Printer/GetSNMP/{printerIpOrHostname}");
if (response.IsSuccessStatusCode)
{
var result = JsonConvert.DeserializeObject<QueryPrinterToAdd>(await response.Content.ReadAsStringAsync());
queryPrinterToAdd = result!;
}
}
catch (Exception ex)
{
Console.WriteLine($"Ошибка: {ex.Message}");
}
finally
{
processingQueryToPrinter = false;
}
}
}