mirror of
https://gitlab.com/Hukuta47/cartrix.git
synced 2026-12-04 20:10:55 +00:00
138 lines
4.3 KiB
Plaintext
138 lines
4.3 KiB
Plaintext
@page "/Printer/{PrinterId:int}"
|
|
@inject NavigationManager NavigationManager
|
|
@inject HttpClient http
|
|
@inject IJSRuntime JS
|
|
@using System.Net
|
|
|
|
<style>
|
|
.rz-fabmenu {
|
|
display: none !important;
|
|
}
|
|
|
|
@@media (max-width: 800px) {
|
|
.desktopActionPanel {
|
|
display: none;
|
|
}
|
|
|
|
.rz-fabmenu {
|
|
display: block !important;
|
|
}
|
|
}
|
|
</style>
|
|
|
|
|
|
|
|
|
|
|
|
@if (dataIsLoading)
|
|
{
|
|
<RadzenStack>
|
|
<h1>Получаем информацию...</h1>
|
|
</RadzenStack>
|
|
}
|
|
else if (printer is null)
|
|
{
|
|
|
|
}
|
|
else
|
|
{
|
|
if (pingIsActive)
|
|
{
|
|
<h1>Пингуем...</h1>
|
|
}
|
|
else
|
|
{
|
|
<RadzenFabMenu class="phoneFab" Icon="more_horiz">
|
|
<RadzenFabMenuItem Text="Заменить картридж" Click="ChangeCartridgeClick" />
|
|
<RadzenFabMenuItem Text="Веб конфигурация" Click="WebConfigurationClick" Visible="printer.ConnetctionTypeId == 1" Disabled="!canNetworkActions" />
|
|
</RadzenFabMenu>
|
|
|
|
<RadzenStack Orientation="Orientation.Vertical">
|
|
<RadzenCard>
|
|
<RadzenStack Orientation="Orientation.Horizontal">
|
|
@if (printer.Model.PicturePath is null)
|
|
{
|
|
<img src="/media/product_empty.jpg" width="200" />
|
|
}
|
|
else
|
|
{
|
|
|
|
}
|
|
<RadzenStack>
|
|
<RadzenText Text="@printer.Model.Name" TextStyle="TextStyle.DisplayH4"/>
|
|
<img alt="@printer.Model.Manufacturer.Name" />
|
|
|
|
<RadzenText/>
|
|
<RadzenText/>
|
|
<RadzenText/>
|
|
<RadzenText/>
|
|
</RadzenStack>
|
|
|
|
</RadzenStack>
|
|
</RadzenCard>
|
|
<RadzenCard class="desktopActionPanel">
|
|
<RadzenStack Orientation="Orientation.Horizontal">
|
|
<RadzenButton Text="Заменить картридж" Click="ChangeCartridgeClick" />
|
|
<RadzenButton Text="Веб конфигурация" Visible="printer.ConnetctionTypeId == 1" Click="WebConfigurationClick" Disabled="!canNetworkActions" />
|
|
</RadzenStack>
|
|
</RadzenCard>
|
|
</RadzenStack>
|
|
}
|
|
}
|
|
|
|
@code {
|
|
bool dataIsLoading;
|
|
bool canNetworkActions;
|
|
bool pingIsActive;
|
|
[Parameter] public int PrinterId { get; set; }
|
|
private Models.Printer.PrinterItem? printer = default!;
|
|
|
|
protected async override Task OnInitializedAsync()
|
|
{
|
|
dataIsLoading = true;
|
|
await GetPrinterInfo();
|
|
dataIsLoading = false;
|
|
StateHasChanged();
|
|
await PingPrinter();
|
|
}
|
|
|
|
async Task GetPrinterInfo()
|
|
{
|
|
var responce = await http.GetAsync(ApiRoutes.Printer.Item(PrinterId));
|
|
var json = await responce.Content.ReadAsStringAsync();
|
|
printer = JsonConvert.DeserializeObject<Models.Printer.PrinterItem>(json)!;
|
|
}
|
|
async Task PingPrinter()
|
|
{
|
|
pingIsActive = true;
|
|
await InvokeAsync(StateHasChanged);
|
|
var responce = await http.GetFromJsonAsync<bool>(ApiRoutes.Network.Ping(printer!.IpAddressOrHostname!));
|
|
Console.WriteLine(responce);
|
|
bool pingIsSuccessful = (bool)responce;
|
|
int SetStatusId = (pingIsSuccessful) ? 1 : 2;
|
|
await http.PatchAsJsonAsync(ApiRoutes.Printer.ChangeStatus(PrinterId), SetStatusId);
|
|
await GetPrinterInfo();
|
|
canNetworkActions = pingIsSuccessful;
|
|
pingIsActive = false;
|
|
await InvokeAsync(StateHasChanged);
|
|
}
|
|
async Task ChangeCartridgeClick()
|
|
{
|
|
NavigationManager.NavigateTo($"/printer/{PrinterId}/cartridgereplace");
|
|
}
|
|
async Task WebConfigurationClick()
|
|
{
|
|
string features = "width=1280,height=720,resizable=no,scrollbars=yes";
|
|
|
|
if (IPAddress.TryParse(printer!.IpAddressOrHostname, out IPAddress? address))
|
|
{
|
|
await JS.InvokeVoidAsync("open", $"http://{address.ToString()}", "_blank", features);
|
|
}
|
|
else
|
|
{
|
|
string ipAddress = await http.GetStringAsync(ApiRoutes.Network.GetIpAddressFromHostname(printer.IpAddressOrHostname!));
|
|
await JS.InvokeVoidAsync("open", $"http://{ipAddress}", "_blank", features);
|
|
}
|
|
}
|
|
}
|