mirror of
https://github.com/Stefan-5422/-T5-Elektrifikatsiya.git
synced 2026-09-04 00:45:58 +02:00
Fix formatting and other stuff
whoopsie
This commit is contained in:
@@ -1,74 +0,0 @@
|
|||||||
using Blazorise;
|
|
||||||
|
|
||||||
using Elektrifikatsiya.Components.TodoApp;
|
|
||||||
|
|
||||||
using Microsoft.AspNetCore.Components;
|
|
||||||
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
|
|
||||||
namespace Elektrifikatsiya.Components.TodoApp;
|
|
||||||
public abstract class BaseTodoItems : ComponentBase
|
|
||||||
{
|
|
||||||
protected Validations validations;
|
|
||||||
|
|
||||||
protected string description;
|
|
||||||
|
|
||||||
protected Filter filter = Filter.All;
|
|
||||||
|
|
||||||
protected List<Todo> todos = new()
|
|
||||||
{
|
|
||||||
new() { Description = "Buy milk" },
|
|
||||||
new() { Description = "Call John regarding the meeting" },
|
|
||||||
new() { Description = "Walk a dog" },
|
|
||||||
};
|
|
||||||
|
|
||||||
protected IEnumerable<Todo> Todos
|
|
||||||
{
|
|
||||||
get
|
|
||||||
{
|
|
||||||
var query = from t in todos select t;
|
|
||||||
|
|
||||||
if (filter == Filter.Active)
|
|
||||||
query = from q in query where !q.Completed select q;
|
|
||||||
|
|
||||||
if (filter == Filter.Completed)
|
|
||||||
query = from q in query where q.Completed select q;
|
|
||||||
|
|
||||||
return query;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
protected void SetFilter(Filter filter)
|
|
||||||
{
|
|
||||||
this.filter = filter;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected void OnCheckAll(bool isChecked)
|
|
||||||
{
|
|
||||||
todos.ForEach(x => x.Completed = isChecked);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected async Task OnAddTodo()
|
|
||||||
{
|
|
||||||
if (await validations.ValidateAll())
|
|
||||||
{
|
|
||||||
todos.Add(new() { Description = description });
|
|
||||||
description = null;
|
|
||||||
|
|
||||||
await validations.ClearAll();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
protected void OnClearCompleted()
|
|
||||||
{
|
|
||||||
todos.RemoveAll(x => x.Completed);
|
|
||||||
filter = Filter.All;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected Task OnTodoStatusChanged(bool isChecked)
|
|
||||||
{
|
|
||||||
return InvokeAsync(StateHasChanged);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,8 +0,0 @@
|
|||||||
namespace Elektrifikatsiya.Components.TodoApp;
|
|
||||||
|
|
||||||
public enum Filter
|
|
||||||
{
|
|
||||||
All,
|
|
||||||
Active,
|
|
||||||
Completed,
|
|
||||||
}
|
|
||||||
@@ -1,8 +0,0 @@
|
|||||||
namespace Elektrifikatsiya.Components.TodoApp;
|
|
||||||
|
|
||||||
public class Todo
|
|
||||||
{
|
|
||||||
public bool Completed { get; set; }
|
|
||||||
|
|
||||||
public string Description { get; set; }
|
|
||||||
}
|
|
||||||
@@ -1,22 +0,0 @@
|
|||||||
<ListGroupItem>
|
|
||||||
<Field Horizontal Padding="Padding.IsAuto.OnAll">
|
|
||||||
<FieldBody ColumnSize="ColumnSize.Is1">
|
|
||||||
<Check TValue="bool" Checked="@Todo.Completed" CheckedChanged="@OnCheckedChanged"></Check>
|
|
||||||
</FieldBody>
|
|
||||||
<FieldBody ColumnSize="ColumnSize.Is11">
|
|
||||||
@Todo.Description
|
|
||||||
</FieldBody>
|
|
||||||
</Field>
|
|
||||||
</ListGroupItem>
|
|
||||||
@code{
|
|
||||||
Task OnCheckedChanged( bool isChecked )
|
|
||||||
{
|
|
||||||
Todo.Completed = isChecked;
|
|
||||||
|
|
||||||
return StatusChanged?.Invoke( isChecked );
|
|
||||||
}
|
|
||||||
|
|
||||||
[Parameter] public Todo Todo { get; set; }
|
|
||||||
|
|
||||||
[Parameter] public Func<bool, Task> StatusChanged { get; set; }
|
|
||||||
}
|
|
||||||
@@ -1,57 +0,0 @@
|
|||||||
@inherits BaseTodoItems
|
|
||||||
<Container Fluid>
|
|
||||||
<Row>
|
|
||||||
<Column>
|
|
||||||
<Card>
|
|
||||||
<CardHeader Padding="Padding.Is1.FromBottom">
|
|
||||||
<CardTitle Size="4">Todo List</CardTitle>
|
|
||||||
</CardHeader>
|
|
||||||
<CardBody Padding="Padding.Is0.FromBottom">
|
|
||||||
<Fields>
|
|
||||||
<Column ColumnSize="ColumnSize.Is1">
|
|
||||||
<Check TValue="bool" Checked="@Todos.All(x=>x.Completed)" CheckedChanged="@OnCheckAll">All</Check>
|
|
||||||
</Column>
|
|
||||||
<Column ColumnSize="ColumnSize.Is11">
|
|
||||||
<Addons>
|
|
||||||
<Addon AddonType="AddonType.Body">
|
|
||||||
<Validations @ref="validations" Mode="ValidationMode.Manual">
|
|
||||||
<Validation Validator="@ValidationRule.IsNotEmpty">
|
|
||||||
<TextEdit @bind-Text="@description" Placeholder="What needs to be done?"></TextEdit>
|
|
||||||
</Validation>
|
|
||||||
</Validations>
|
|
||||||
</Addon>
|
|
||||||
<Addon AddonType="AddonType.End">
|
|
||||||
<Button Color="Color.Primary" Clicked="@OnAddTodo">
|
|
||||||
<Icon Name="IconName.Add" />Add
|
|
||||||
</Button>
|
|
||||||
</Addon>
|
|
||||||
</Addons>
|
|
||||||
</Column>
|
|
||||||
</Fields>
|
|
||||||
</CardBody>
|
|
||||||
<CardBody Padding="Padding.Is0.OnY">
|
|
||||||
<ListGroup Flush>
|
|
||||||
@foreach ( var todo in Todos )
|
|
||||||
{
|
|
||||||
<TodoItem Todo="@todo" StatusChanged="@OnTodoStatusChanged" />
|
|
||||||
}
|
|
||||||
</ListGroup>
|
|
||||||
</CardBody>
|
|
||||||
<CardFooter Padding="Padding.Is3.FromBottom">
|
|
||||||
<Field Horizontal>
|
|
||||||
<FieldBody ColumnSize="ColumnSize.Is10">
|
|
||||||
<Buttons Role="ButtonsRole.Addons">
|
|
||||||
<Button Color="Color.Info" Clicked="@(() => SetFilter( Filter.All ))" Active="@(filter == Filter.All)">All</Button>
|
|
||||||
<Button Color="Color.Info" Clicked="@(() => SetFilter( Filter.Active ))" Active="@(filter == Filter.Active)">Active</Button>
|
|
||||||
<Button Color="Color.Info" Clicked="@(() => SetFilter( Filter.Completed ))" Active="@(filter == Filter.Completed)">Completed</Button>
|
|
||||||
</Buttons>
|
|
||||||
</FieldBody>
|
|
||||||
<FieldBody ColumnSize="ColumnSize.Is2">
|
|
||||||
<Button Color="Color.Warning" Float="Float.End" Clicked="@OnClearCompleted" Display="@(todos.Any(x=>x.Completed) ? Display.Always : Display.None)">Clear Completed</Button>
|
|
||||||
</FieldBody>
|
|
||||||
</Field>
|
|
||||||
</CardFooter>
|
|
||||||
</Card>
|
|
||||||
</Column>
|
|
||||||
</Row>
|
|
||||||
</Container>
|
|
||||||
@@ -1,17 +1,42 @@
|
|||||||
@using System.Diagnostics;
|
@using System.Diagnostics;
|
||||||
|
@using FluentResults;
|
||||||
|
|
||||||
|
@inject Elektrifikatsiya.Services.IAuthenticationService AuthenticationService
|
||||||
|
@inject NavigationManager NavigationManager
|
||||||
|
|
||||||
@inherits LayoutComponentBase
|
@inherits LayoutComponentBase
|
||||||
<Image Source="logo.png" Width="Width.Is50" Height="Height.Is50"> </Image>
|
<Image Source="logo.png" Width="Width.Is50" Height="Height.Is50"> </Image>
|
||||||
<Card Width="Width.Is50" Position="Position.Absolute.Top.Is50.Start.Is50.Translate.Middle" Padding="Padding.Is5">
|
<Card Width="Width.Is50" Position="Position.Absolute.Top.Is50.Start.Is50.Translate.Middle" Padding="Padding.Is5">
|
||||||
<Column ColumnSize="ColumnSize.Is6.OnDesktop.Is12.Is3.WithOffset">
|
<Column ColumnSize="ColumnSize.Is6.OnDesktop.Is12.Is3.WithOffset">
|
||||||
<Field Position="Position.Relative.Top.Is50.Start.Is50.Translate.Middle">
|
<Field Position="Position.Relative.Top.Is50.Start.Is50.Translate.Middle">
|
||||||
<TextEdit Placeholder="Username" />
|
<TextEdit @bind-Text="username" Placeholder="Username" />
|
||||||
</Field>
|
</Field>
|
||||||
<Field Position="Position.Relative.Top.Is50.Start.Is50.Translate.Middle">
|
<Field Position="Position.Relative.Top.Is50.Start.Is50.Translate.Middle">
|
||||||
<TextEdit Role="TextRole.Password" Placeholder="Password" />
|
<TextEdit @bind-Text="password" Role="TextRole.Password" Placeholder="Password" />
|
||||||
</Field>
|
</Field>
|
||||||
<Button Color="Color.Primary" Position="Position.Relative.Bottom.Is50.Start.Is50.Translate.MiddleX">Login</Button>
|
<Button Width="Width.Is25" Disabled="disabled" Color="color" Clicked="Clicked" Position="Position.Relative.Bottom.Is50.Start.Is50.Translate.MiddleX">Login</Button>
|
||||||
</Column>
|
</Column>
|
||||||
</Card>
|
</Card>
|
||||||
@code {
|
@code {
|
||||||
|
private string username = string.Empty;
|
||||||
|
private string password = string.Empty;
|
||||||
|
private Color color = Color.Primary;
|
||||||
|
private bool disabled;
|
||||||
|
private async Task Clicked()
|
||||||
|
{
|
||||||
|
color = Color.Primary;
|
||||||
|
disabled = true;
|
||||||
|
|
||||||
|
Result loginResult = await AuthenticationService.LoginUserAsync(username, password);
|
||||||
|
|
||||||
|
if (loginResult.IsSuccess)
|
||||||
|
{
|
||||||
|
NavigationManager.NavigateTo("/", true);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
color = Color.Danger;
|
||||||
|
disabled = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
|
using System.Globalization;
|
||||||
using System.Text.Json.Serialization;
|
using System.Text.Json.Serialization;
|
||||||
using Microsoft.AspNetCore.Mvc.Diagnostics;
|
|
||||||
|
|
||||||
namespace Elektrifikatsiya.Models;
|
namespace Elektrifikatsiya.Models;
|
||||||
|
|
||||||
@@ -47,51 +47,50 @@ public class PrometheusDataWrapper
|
|||||||
ResultType = resultType;
|
ResultType = resultType;
|
||||||
Result = result;
|
Result = result;
|
||||||
}
|
}
|
||||||
|
|
||||||
public FluentResults.Result<List<(double, double)>> MatrixTypeToTimestampFloatTuple()
|
public FluentResults.Result<List<(double, double)>> MatrixTypeToTimestampFloatTuple()
|
||||||
{
|
{
|
||||||
if (ResultType != ResultType.Matrix)
|
if (ResultType != ResultType.Matrix)
|
||||||
{
|
{
|
||||||
return FluentResults.Result.Fail("The response did not have the Matrix Type");
|
return FluentResults.Result.Fail("The response did not have the Matrix Type");
|
||||||
}
|
}
|
||||||
|
|
||||||
List<(double, double)> result = new List<(double, double)>();
|
List<(double, double)> result = new List<(double, double)>();
|
||||||
|
|
||||||
if (Result.Count == 0 || Result[0]?.Values is null || Result[0]?.Values?[0] is null)
|
if (Result.Count == 0 || Result[0]?.Values is null || Result[0]?.Values?[0] is null)
|
||||||
{
|
{
|
||||||
return FluentResults.Result.Fail("There was no result in the Response Body");
|
return FluentResults.Result.Fail("There was no result in the Response Body");
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach (object value in Result[0]!.Values!)
|
foreach (object value in Result[0]!.Values!)
|
||||||
{
|
{
|
||||||
|
|
||||||
string[] segment = value.ToString()!.Split(",");
|
string[] segment = value.ToString()!.Split(",");
|
||||||
|
|
||||||
result.Add((Convert.ToDouble(segment[0][2..^1]), Convert.ToDouble(segment[1][1..^2])));
|
result.Add((Convert.ToDouble(segment[0][2..^1], CultureInfo.InvariantCulture), Convert.ToDouble(segment[1][1..^2], CultureInfo.InvariantCulture)));
|
||||||
}
|
}
|
||||||
Debug.WriteLine(result);
|
Debug.WriteLine(result);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
public FluentResults.Result<(double, double)> VectorTypeToTimestampFloatTuple()
|
public FluentResults.Result<(double, double)> VectorTypeToTimestampFloatTuple()
|
||||||
{
|
{
|
||||||
if (ResultType != ResultType.Vector)
|
if (ResultType != ResultType.Vector)
|
||||||
{
|
{
|
||||||
return FluentResults.Result.Fail("The response did not have the Vector Type");
|
return FluentResults.Result.Fail("The response did not have the Vector Type");
|
||||||
}
|
}
|
||||||
|
|
||||||
string[]? segment = Result.FirstOrDefault()?.Value.ToString()?.Split(",") ?? null;
|
string[]? segment = Result.FirstOrDefault()?.Value?.ToString()?.Split(",");
|
||||||
|
|
||||||
if (segment is null)
|
if (segment is null)
|
||||||
{
|
{
|
||||||
return FluentResults.Result.Fail("There was no result in the Response Body");
|
return FluentResults.Result.Fail("There was no result in the Response Body");
|
||||||
}
|
}
|
||||||
|
|
||||||
return((Convert.ToDouble(segment[0][2..^1]), Convert.ToDouble(segment[1][1..^2])));
|
return (Convert.ToDouble(segment[0][2..^1]), Convert.ToDouble(segment[1][1..^2], CultureInfo.InvariantCulture));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public class PrometheusDataMetric
|
public class PrometheusDataMetric
|
||||||
{
|
{
|
||||||
[JsonPropertyName("__name__")] public string Name { get; set; }
|
[JsonPropertyName("__name__")] public string Name { get; set; }
|
||||||
|
|||||||
@@ -14,144 +14,155 @@
|
|||||||
|
|
||||||
|
|
||||||
<Row Style="height:50%; width:100%" Padding="Padding.Is3.OnDesktop.Is5.FromStart.OnMobile">
|
<Row Style="height:50%; width:100%" Padding="Padding.Is3.OnDesktop.Is5.FromStart.OnMobile">
|
||||||
<Row Style="height:90%; width:100%">
|
<Row Style="height:90%; width:100%">
|
||||||
<Column ColumnSize="ColumnSize.Is4.OnDesktop.Is1"></Column>
|
<Column ColumnSize="ColumnSize.Is4.OnDesktop.Is1"></Column>
|
||||||
<Column ColumnSize="ColumnSize.Is4.OnDesktop.Is12">
|
<Column ColumnSize="ColumnSize.Is4.OnDesktop.Is12">
|
||||||
<Bar Breakpoint="Breakpoint.Desktop"
|
<Bar Breakpoint="Breakpoint.Desktop"
|
||||||
Background="Background.White"
|
Background="Background.White"
|
||||||
ThemeContrast="ThemeContrast.None"
|
ThemeContrast="ThemeContrast.None"
|
||||||
Shadow="Shadow.Remove"
|
Shadow="Shadow.Remove"
|
||||||
Border="Border.Is1.RoundedTop">
|
Border="Border.Is1.RoundedTop">
|
||||||
<BarBrand>
|
<BarBrand>
|
||||||
<Column ColumnSize="ColumnSize.Is9">
|
<Column ColumnSize="ColumnSize.Is9">
|
||||||
Add a plug via wifi
|
Add a plug via wifi
|
||||||
</Column>
|
</Column>
|
||||||
<Column ColumnSize="ColumnSize.Is3.Is6.WithOffset">
|
<Column ColumnSize="ColumnSize.Is3.Is6.WithOffset">
|
||||||
<LoadingIndicator @bind-Visible="@visible"/>
|
<LoadingIndicator @bind-Visible="@visible" />
|
||||||
|
|
||||||
</Column>
|
</Column>
|
||||||
</BarBrand>
|
</BarBrand>
|
||||||
</Bar>
|
</Bar>
|
||||||
<ListView Class="w-100"
|
<ListView Class="w-100"
|
||||||
TItem="IPAddress"
|
TItem="IPAddress"
|
||||||
Data="@ipAddresses"
|
Data="@ipAddresses"
|
||||||
TextField="@((_)=>(""))"
|
TextField="@((_)=>(""))"
|
||||||
ValueField="@((_)=>(""))"
|
ValueField="@((_)=>(""))"
|
||||||
Mode="ListGroupMode.Static"
|
Mode="ListGroupMode.Static"
|
||||||
Style="border-radius: 0px 0px">
|
Style="border-radius: 0px 0px">
|
||||||
<ItemTemplate>
|
<ItemTemplate>
|
||||||
<ListGroupItem>
|
<ListGroupItem>
|
||||||
<Row>
|
<Row>
|
||||||
<Column ColumnSize="ColumnSize.Is8">
|
<Column ColumnSize="ColumnSize.Is8">
|
||||||
<Row>
|
<Row>
|
||||||
</Row>
|
</Row>
|
||||||
<Row Width="Width.Is100">
|
<Row Width="Width.Is100">
|
||||||
<Column>
|
<Column>
|
||||||
<Small>IP: @context.Item</Small>
|
<Small>IP: @context.Item</Small>
|
||||||
</Column>
|
</Column>
|
||||||
</Row>
|
</Row>
|
||||||
</Column>
|
</Column>
|
||||||
<Column ColumnSize="ColumnSize.Is4">
|
<Column ColumnSize="ColumnSize.Is4">
|
||||||
<Button Position="Position.Absolute.Top.Is50.Start.Is50.Translate.Middle" Color="Color.Dark" Clicked="@(async () => await DeviceManagmentService.RegisterDevice(context.Item,(await AuthenticationService.GetUserAsync()).ValueOrDefault))" Outline>
|
<Button Disabled="disabled" Position="Position.Absolute.Top.Is50.Start.Is50.Translate.Middle" Color="Color.Dark" Clicked="@(async () => await RegisterDevice(context.Item))" Outline>
|
||||||
<BarIcon IconName="IconName.Add" />
|
<BarIcon IconName="IconName.Add" />
|
||||||
</Button>
|
</Button>
|
||||||
</Column>
|
</Column>
|
||||||
</Row>
|
</Row>
|
||||||
</ListGroupItem>
|
</ListGroupItem>
|
||||||
</ItemTemplate>
|
</ItemTemplate>
|
||||||
</ListView>
|
</ListView>
|
||||||
</Column>
|
</Column>
|
||||||
</Row>
|
</Row>
|
||||||
</Row>
|
</Row>
|
||||||
<Row Style="height:50%; width:100%; border-top-style:solid; border-top-color:#1a237e" Padding="Padding.Is3.OnDesktop.Is5.FromStart.OnMobile">
|
<Row Style="height:50%; width:100%; border-top-style:solid; border-top-color:#1a237e" Padding="Padding.Is3.OnDesktop.Is5.FromStart.OnMobile">
|
||||||
<Column ColumnSize="ColumnSize.Is4.OnDesktop.Is1"></Column>
|
<Column ColumnSize="ColumnSize.Is4.OnDesktop.Is1"></Column>
|
||||||
<Column ColumnSize="ColumnSize.Is4.OnDesktop.Is12">
|
<Column ColumnSize="ColumnSize.Is4.OnDesktop.Is12">
|
||||||
<Row Style="height:15%; width:100%"></Row>
|
<Row Style="height:15%; width:100%"></Row>
|
||||||
<Row Style="height:10%; width:100%">
|
<Row Style="height:10%; width:100%">
|
||||||
<Bar Breakpoint="Breakpoint.Desktop"
|
<Bar Breakpoint="Breakpoint.Desktop"
|
||||||
Background="Background.White"
|
Background="Background.White"
|
||||||
ThemeContrast="ThemeContrast.None"
|
ThemeContrast="ThemeContrast.None"
|
||||||
Shadow="Shadow.Remove"
|
Shadow="Shadow.Remove"
|
||||||
Border="Border.Is1.RoundedTop"
|
Border="Border.Is1.RoundedTop"
|
||||||
Style="width:100%">
|
Style="width:100%">
|
||||||
<BarBrand>
|
<BarBrand>
|
||||||
Add a plug via IP
|
Add a plug via IP
|
||||||
</BarBrand>
|
</BarBrand>
|
||||||
</Bar>
|
</Bar>
|
||||||
<ListGroup Style="width:100%; border-radius: 0px 0px">
|
<ListGroup Style="width:100%; border-radius: 0px 0px">
|
||||||
<ListGroupItem Color="Color.Default">
|
<ListGroupItem Color="Color.Default">
|
||||||
<Form>
|
<Form>
|
||||||
<Field Horizontal>
|
<Validation @ref="ipValidation" Validator="ValidateIPv4">
|
||||||
<FieldBody ColumnSize="ColumnSize.Is12">
|
<Field Horizontal>
|
||||||
<TextEdit Placeholder="Enter the Device IP here" />
|
<FieldBody ColumnSize="ColumnSize.Is12">
|
||||||
<br>
|
<TextEdit @bind-Text="ipText" Placeholder="Enter the Device IP here">
|
||||||
<Button style="background-color:#1a237e; color:white" Type="ButtonType.Submit" PreventDefaultOnSubmit>CONNECT</Button>
|
<Feedback>
|
||||||
</FieldBody>
|
<ValidationNone>Please enter a ip address.</ValidationNone>
|
||||||
</Field>
|
<ValidationSuccess>Ip address is valid.</ValidationSuccess>
|
||||||
</Form>
|
<ValidationError>Ip address is not valid!</ValidationError>
|
||||||
</ListGroupItem>
|
</Feedback>
|
||||||
</ListGroup>
|
</TextEdit>
|
||||||
</Row>
|
<br>
|
||||||
<Row Style="height:75%; width:100%"></Row>
|
<Button style="background-color:#1a237e; color:white" Type="ButtonType.Submit" Disabled="ipValidation?.Status != ValidationStatus.Success || disabled" Clicked="@(async (_)=> await RegisterDevice(IPAddress.Parse(ipText!)))" PreventDefaultOnSubmit>CONNECT</Button>
|
||||||
</Column>
|
</FieldBody>
|
||||||
|
</Field>
|
||||||
|
</Validation>
|
||||||
|
</Form>
|
||||||
|
</ListGroupItem>
|
||||||
|
</ListGroup>
|
||||||
|
</Row>
|
||||||
|
<Row Style="height:75%; width:100%"></Row>
|
||||||
|
</Column>
|
||||||
</Row>
|
</Row>
|
||||||
|
|
||||||
@code {
|
@code {
|
||||||
List<IPAddress> ipAddresses = new List<IPAddress>();
|
List<IPAddress> ipAddresses = new List<IPAddress>();
|
||||||
|
|
||||||
Validation? ipValidation;
|
Validation? ipValidation;
|
||||||
|
|
||||||
bool visible = true;
|
bool visible = true;
|
||||||
|
bool disabled = false;
|
||||||
|
|
||||||
string ipText = null!;
|
string ipText = null!;
|
||||||
|
|
||||||
protected override void OnInitialized()
|
protected override void OnInitialized()
|
||||||
{
|
{
|
||||||
MdnsDiscovery.OnDeviceFound += async ipAddress =>
|
MdnsDiscovery.OnDeviceFound += async ipAddress =>
|
||||||
{
|
{
|
||||||
visible = false;
|
visible = false;
|
||||||
if (!ipAddresses.Contains(ipAddress))
|
if (!ipAddresses.Contains(ipAddress))
|
||||||
{
|
{
|
||||||
ipAddresses.Add(ipAddress);
|
ipAddresses.Add(ipAddress);
|
||||||
await InvokeAsync(StateHasChanged);
|
await InvokeAsync(StateHasChanged);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
MdnsDiscovery.FetchChachedDevices();
|
MdnsDiscovery.FetchChachedDevices();
|
||||||
}
|
}
|
||||||
|
|
||||||
private async Task RegisterDevice(IPAddress ipAddress)
|
private async Task RegisterDevice(IPAddress ipAddress)
|
||||||
{
|
{
|
||||||
Result<Device> result = await DeviceManagmentService.RegisterDevice(ipAddress, (await AuthenticationService.GetUserAsync()).ValueOrDefault);
|
disabled = true;
|
||||||
|
Result<Device> result = await DeviceManagmentService.RegisterDevice(ipAddress, (await AuthenticationService.GetUserAsync()).ValueOrDefault);
|
||||||
|
|
||||||
if (result.IsSuccess)
|
if (result.IsSuccess)
|
||||||
{
|
{
|
||||||
await MessageService.Success("Device added!");
|
await MessageService.Success("Device added!");
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
await MessageService.Error(string.Join(',', result.Errors.Select(e => e.Message)), "Adding device failed!");
|
await MessageService.Error(string.Join(',', result.Errors.Select(e => e.Message)), "Adding device failed!");
|
||||||
}
|
}
|
||||||
}
|
disabled = false;
|
||||||
|
}
|
||||||
|
|
||||||
public void ValidateIPv4(ValidatorEventArgs e)
|
public void ValidateIPv4(ValidatorEventArgs e)
|
||||||
{
|
{
|
||||||
string? input = Convert.ToString(e.Value);
|
string? input = Convert.ToString(e.Value);
|
||||||
|
|
||||||
if (string.IsNullOrWhiteSpace(input))
|
if (string.IsNullOrWhiteSpace(input))
|
||||||
{
|
{
|
||||||
e.Status = ValidationStatus.None;
|
e.Status = ValidationStatus.None;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
string[] splitValues = input.Split('.');
|
string[] splitValues = input.Split('.');
|
||||||
if (splitValues.Length != 4)
|
if (splitValues.Length != 4)
|
||||||
{
|
{
|
||||||
e.Status = ValidationStatus.Error;
|
e.Status = ValidationStatus.Error;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
e.Status = splitValues.All(r => byte.TryParse(r, out _)) ? ValidationStatus.Success : ValidationStatus.Error;
|
e.Status = splitValues.All(r => byte.TryParse(r, out _)) ? ValidationStatus.Success : ValidationStatus.Error;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -152,6 +152,12 @@
|
|||||||
{
|
{
|
||||||
plugnames += $"shellyplug-s-{device.MacAddress}/relay/0|";
|
plugnames += $"shellyplug-s-{device.MacAddress}/relay/0|";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(string.IsNullOrEmpty(plugnames))
|
||||||
|
{
|
||||||
|
return new();
|
||||||
|
}
|
||||||
|
|
||||||
plugnames = plugnames[0..^1];
|
plugnames = plugnames[0..^1];
|
||||||
|
|
||||||
Debug.WriteLine($$"""sum(power{sensor=~"{{plugnames}}"})[1h:1m]""");
|
Debug.WriteLine($$"""sum(power{sensor=~"{{plugnames}}"})[1h:1m]""");
|
||||||
|
|||||||
@@ -1,3 +0,0 @@
|
|||||||
@using Elektrifikatsiya.Components.TodoApp
|
|
||||||
@page "/apps/todo"
|
|
||||||
<TodoItems />
|
|
||||||
@@ -60,7 +60,7 @@ IAuthenticationService authenticationService = serviceScope.ServiceProvider.GetR
|
|||||||
|
|
||||||
if (!mainDatabase.Users.Any())
|
if (!mainDatabase.Users.Any())
|
||||||
{
|
{
|
||||||
authenticationService.RegisterUserAsync("admin", "admin", Role.Admin);
|
_ = authenticationService.RegisterUserAsync("admin", "admin", Role.Admin);
|
||||||
}
|
}
|
||||||
|
|
||||||
app.Run();
|
app.Run();
|
||||||
|
|||||||
@@ -33,12 +33,12 @@ public class UpdateService : IHostedService, IDisposable
|
|||||||
_ = deviceStatusService.TrackDevice(device);
|
_ = deviceStatusService.TrackDevice(device);
|
||||||
}
|
}
|
||||||
|
|
||||||
timer = new Timer((_) => Update(), null, TimeSpan.Zero, TimeSpan.FromSeconds(15));
|
timer = new Timer(async (_) => await Update(), null, TimeSpan.Zero, TimeSpan.FromSeconds(15));
|
||||||
|
|
||||||
logger.LogInformation("Update service started.");
|
logger.LogInformation("Update service started.");
|
||||||
}
|
}
|
||||||
|
|
||||||
private async void Update()
|
private async Task Update()
|
||||||
{
|
{
|
||||||
Result<List<Device>> getDeviceStatusResult = deviceStatusService.GetDevices();
|
Result<List<Device>> getDeviceStatusResult = deviceStatusService.GetDevices();
|
||||||
|
|
||||||
|
|||||||
Binary file not shown.
@@ -10,18 +10,15 @@ namespace Elektrifikatsiya.Utilities;
|
|||||||
|
|
||||||
public class PrometheusQuery
|
public class PrometheusQuery
|
||||||
{
|
{
|
||||||
private string connectionString;
|
|
||||||
private readonly HttpClient client = new();
|
private readonly HttpClient client = new();
|
||||||
|
|
||||||
public PrometheusQuery(string connectionString)
|
public PrometheusQuery(string connectionString)
|
||||||
{
|
{
|
||||||
this.connectionString = connectionString;
|
|
||||||
client.BaseAddress = new Uri(connectionString);
|
client.BaseAddress = new Uri(connectionString);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Task<PrometheusQueryResult?> Query(string query)
|
public Task<PrometheusQueryResult?> Query(string query)
|
||||||
{
|
{
|
||||||
var res = client.GetStringAsync($"/api/v1/query?query={UrlEncoder.Create().Encode(query)}").Result;
|
|
||||||
return client.GetFromJsonAsync<PrometheusQueryResult>($"/api/v1/query?query={UrlEncoder.Create().Encode(query)}", new JsonSerializerOptions()
|
return client.GetFromJsonAsync<PrometheusQueryResult>($"/api/v1/query?query={UrlEncoder.Create().Encode(query)}", new JsonSerializerOptions()
|
||||||
{
|
{
|
||||||
PropertyNameCaseInsensitive = true,
|
PropertyNameCaseInsensitive = true,
|
||||||
|
|||||||
Reference in New Issue
Block a user