diff --git a/src/Elektrifikatsiya/Elektrifikatsiya/Components/Layout/SideMenu.razor b/src/Elektrifikatsiya/Elektrifikatsiya/Components/Layout/SideMenu.razor index c96b81f..956a1a0 100644 --- a/src/Elektrifikatsiya/Elektrifikatsiya/Components/Layout/SideMenu.razor +++ b/src/Elektrifikatsiya/Elektrifikatsiya/Components/Layout/SideMenu.razor @@ -23,6 +23,12 @@ Admin + + + + Settings + + @@ -32,9 +38,9 @@ - - - Settings + + + Logout @@ -42,7 +48,5 @@ @code { private bool pagesBarVisible = true; - - //TODO: replace logo png with transparent background one RenderFragment customIcon =@; } \ No newline at end of file diff --git a/src/Elektrifikatsiya/Elektrifikatsiya/DeviceManagement.sqlite b/src/Elektrifikatsiya/Elektrifikatsiya/DeviceManagement.sqlite new file mode 100644 index 0000000..b7a73e2 Binary files /dev/null and b/src/Elektrifikatsiya/Elektrifikatsiya/DeviceManagement.sqlite differ diff --git a/src/Elektrifikatsiya/Elektrifikatsiya/DeviceManagement.sqlite-shm b/src/Elektrifikatsiya/Elektrifikatsiya/DeviceManagement.sqlite-shm new file mode 100644 index 0000000..fe9ac28 Binary files /dev/null and b/src/Elektrifikatsiya/Elektrifikatsiya/DeviceManagement.sqlite-shm differ diff --git a/src/Elektrifikatsiya/Elektrifikatsiya/DeviceManagement.sqlite-wal b/src/Elektrifikatsiya/Elektrifikatsiya/DeviceManagement.sqlite-wal new file mode 100644 index 0000000..e69de29 diff --git a/src/Elektrifikatsiya/Elektrifikatsiya/Elektrifikatsiya.csproj b/src/Elektrifikatsiya/Elektrifikatsiya/Elektrifikatsiya.csproj index c19f966..72696db 100644 --- a/src/Elektrifikatsiya/Elektrifikatsiya/Elektrifikatsiya.csproj +++ b/src/Elektrifikatsiya/Elektrifikatsiya/Elektrifikatsiya.csproj @@ -37,6 +37,7 @@ + diff --git a/src/Elektrifikatsiya/Elektrifikatsiya/Layouts/LoginLayout.razor b/src/Elektrifikatsiya/Elektrifikatsiya/Layouts/LoginLayout.razor index 83982b9..091b551 100644 --- a/src/Elektrifikatsiya/Elektrifikatsiya/Layouts/LoginLayout.razor +++ b/src/Elektrifikatsiya/Elektrifikatsiya/Layouts/LoginLayout.razor @@ -1,40 +1,17 @@ @using System.Diagnostics; -@using FluentResults -@inject Elektrifikatsiya.Services.IAuthenticationService AuthenticationService -@inject NavigationManager NavigationManager @inherits LayoutComponentBase - - - - - - - + + + + + + + + + @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; - } - } -} - - \ No newline at end of file + +} \ No newline at end of file diff --git a/src/Elektrifikatsiya/Elektrifikatsiya/Pages/AddPlug.razor b/src/Elektrifikatsiya/Elektrifikatsiya/Pages/AddPlug.razor index e3c034f..37fee70 100644 --- a/src/Elektrifikatsiya/Elektrifikatsiya/Pages/AddPlug.razor +++ b/src/Elektrifikatsiya/Elektrifikatsiya/Pages/AddPlug.razor @@ -11,144 +11,122 @@ @inject IAuthenticationService AuthenticationService @inject IMessageService MessageService -
- - - - - - - Add a plug via wifi - - - - - - - - - - - - IP: @context.Item - - - - - - - - - - - - - - - - - - - - - Add a plug via IP - - - - -
- - - - - - Please enter a ip address. - Ip address is valid. - Ip address is not valid! - - -
- -
-
-
-
-
-
-
- -
-
-
+@inject IAuthenticationService AuthenticationService + + + + + + + + + Add a plug via wifi + + + + + + + + + + + + + + + + + IP: @context.Item + + + + + + + + + + + + + + + + + + + + + Add a plug via IP + + + + +
+ + + +
+ +
+
+
+
+
+
+ +
+
@code { List ipAddresses = new List(); - Validation? ipValidation; + List ipAddresses = new List(); - string ipText = null!; + bool visible = false; - protected override void OnInitialized() - { - MdnsDiscovery.OnDeviceFound += async ipAddress => - { - if (!ipAddresses.Contains(ipAddress)) - { - ipAddresses.Add(ipAddress); - await InvokeAsync(StateHasChanged); - } - }; + DateTime time = DateTime.UtcNow; - MdnsDiscovery.FetchChachedDevices(); - } + protected override void OnInitialized() + { + ipAddresses.AddRange(MdnsDiscovery.GetChachedDevices()); - private async Task RegisterDevice(IPAddress ipAddress) - { - Result result = await DeviceManagmentService.RegisterDevice(ipAddress, (await AuthenticationService.GetUserAsync()).ValueOrDefault); + System.Timers.Timer aTimer = new System.Timers.Timer(1000); + aTimer.Elapsed += (_, _) => { + DateTime dateTime = DateTime.UtcNow; + if(dateTime >= time.AddSeconds(3)) + { + visible = false; + InvokeAsync(StateHasChanged); + } + }; + aTimer.Start(); - if (result.IsSuccess) - { - await MessageService.Success("Device added!"); - } - else - { - await MessageService.Error(string.Join(',', result.Errors.Select(e => e.Message)), "Adding device failed!"); - } - } + MdnsDiscovery.OnDeviceFound += address => + { + visible = true; + + ipAddresses.Add(address); + InvokeAsync(StateHasChanged); - public void ValidateIPv4(ValidatorEventArgs e) - { - string? input = Convert.ToString(e.Value); - - if (string.IsNullOrWhiteSpace(input)) - { - e.Status = ValidationStatus.None; - return; - } - - string[] splitValues = input.Split('.'); - if (splitValues.Length != 4) - { - e.Status = ValidationStatus.Error; - return; - } - - e.Status = splitValues.All(r => byte.TryParse(r, out _)) ? ValidationStatus.Success : ValidationStatus.Error; - } -} + time = DateTime.UtcNow; + }; + } diff --git a/src/Elektrifikatsiya/Elektrifikatsiya/Pages/Admin.razor b/src/Elektrifikatsiya/Elektrifikatsiya/Pages/Admin.razor new file mode 100644 index 0000000..af079a3 --- /dev/null +++ b/src/Elektrifikatsiya/Elektrifikatsiya/Pages/Admin.razor @@ -0,0 +1,28 @@ +@page "/admin" +@using Blazorise.Components +@using Elektrifikatsiya.Models; +@using System.Net +
+ +
+ + + + Users + + + + + + +
+
+
+@code { +} diff --git a/src/Elektrifikatsiya/Elektrifikatsiya/Pages/Dashboard.razor b/src/Elektrifikatsiya/Elektrifikatsiya/Pages/Dashboard.razor index 77373e1..a2b1a5e 100644 --- a/src/Elektrifikatsiya/Elektrifikatsiya/Pages/Dashboard.razor +++ b/src/Elektrifikatsiya/Elektrifikatsiya/Pages/Dashboard.razor @@ -1,113 +1,103 @@ -@page "/" +@page "/" @using Blazorise.Components; @using Elektrifikatsiya.Models; @using System.Net -@using Elektrifikatsiya.Services -@using Elektrifikatsiya.Utilities -@using System.Diagnostics @inject IVersionProvider VersionProvider -@inject IDeviceStatusService DeviceStatusService - -
- - - - Plugs - - - - - - - - - - @context.Item.Name - - - - - User: @context.Item.User.Name -
- Room: @context.Item.Room -
- - @context.Item.PowerUsage W - -
-
- - - -
-
-
-
-
- - - - Logs - - - - -
- @context.Item.EventName - @context.Item.Date -
- @context.Item.Description -
-
+
+ +
+ + + + Plugs + + + + + + + + + + @context.Item.Name + + + + + User: @context.Item.User +
+ Room: @context.Item.Room +
+ + @context.Item.PowerUsage W + +
+
+ + + +
+
+
+
+
+ + + + Logs + + + + +
+ @context.Item.EventName + @context.Item.Date +
+ @context.Item.Description +
+
+
+
+
+ + + + -
- - - - - - - + +
+ @code { //TODO: insert new event here if plug produces one - List events = new List() { new Event("Placeholder", "Placeholder", DateTime.Now), new Event("Placeholder", "Placeholder", DateTime.Now), new Event("Placeholder", "Placeholder", DateTime.Now) }; + List events = new List() { new Event("Placeholder", "Event", DateTime.Now), new Event("Placeholder", "Event", DateTime.Now), new Event("Placeholder", "Event", DateTime.Now) }; //TODO: insert new Device here if user adds one - List plugs = new List(); + List plugs = new List() { new Device("ffff:ffff:ffff:ffff", "Josne", IPAddress.Broadcast, new User("Joe", "qiowruioewjfopa", Role.Admin), "Raum"), new Device("ffff:ffff:ffff:ffff", "Josne", IPAddress.Broadcast, new User("Joe", "Josne", Role.Admin), "Raum"), new Device("ffff:ffff:ffff:ffff", "Josne", IPAddress.Broadcast, new User("Joe", "qiowruioewjfopa", Role.Admin), "Raum"), }; //code for graph LineChart lineChart; - protected override void OnInitialized() - { - plugs = DeviceStatusService.GetDevices().ValueOrDefault ?? new List(); - - DeviceStatusService.OnDeviceStatusChanged += (_, e) => - { - InvokeAsync(StateHasChanged); - }; - } - protected override async Task OnAfterRenderAsync(bool firstRender) { if (firstRender) @@ -118,47 +108,50 @@ async Task HandleRedraw() { - labels.Clear(); await lineChart.Clear(); - await lineChart.AddLabelsDatasetsAndUpdate(labels, await GetLineChartDataset()); + + await lineChart.AddLabelsDatasetsAndUpdate(Labels, GetLineChartDataset()); } //TODO: insert dataset of current and last voltage usages - async Task> GetLineChartDataset() + LineChartDataset GetLineChartDataset() { return new LineChartDataset { - Label = "Wattage", - Data = await RandomizeData(), + Label = "# of random number in thousands", + Data = RandomizeData(), + BackgroundColor = backgroundColors, + BorderColor = borderColors, Fill = true, PointRadius = 3, CubicInterpolationMode = "monotone", }; } - List labels = new List(); + string[] Labels = { "Red", "Blue", "Yellow", "Green", "Purple", "Orange" }; + List backgroundColors = new List { ChartColor.FromRgba(255, 99, 132, 0.2f), ChartColor.FromRgba(54, 162, 235, 0.2f), ChartColor.FromRgba(255, 206, 86, 0.2f), ChartColor.FromRgba(75, 192, 192, 0.2f), ChartColor.FromRgba(153, 102, 255, 0.2f), ChartColor.FromRgba(255, 159, 64, 0.2f) }; + List borderColors = new List { ChartColor.FromRgba(255, 99, 132, 1f), ChartColor.FromRgba(54, 162, 235, 1f), ChartColor.FromRgba(255, 206, 86, 1f), ChartColor.FromRgba(75, 192, 192, 1f), ChartColor.FromRgba(153, 102, 255, 1f), ChartColor.FromRgba(255, 159, 64, 1f) }; - async Task> RandomizeData() + List RandomizeData() { - PrometheusQuery promQueryer = new PrometheusQuery("http://localhost:9090"); - - string plugnames = ""; - foreach (Device device in plugs) - { - plugnames += $"shellyplug-s-{device.MacAddress}/relay/0|"; - } - plugnames = plugnames[0..^1]; - - Debug.WriteLine($$"""sum(power{sensor=~"{{plugnames}}"})[1h:1m]"""); - - PrometheusDataWrapper? deviceData = (await promQueryer.Query($$"""sum(power{sensor=~"{{plugnames}}"})[1h:1m]"""))?.Data; - var r = new Random(DateTime.Now.Millisecond); - return deviceData?.MatrixTypeToTimestampFloatTuple().ValueOrDefault?.Select(x => - { - labels.Add(DateTimeOffset.FromUnixTimeSeconds(long.Parse($"1{x.Item1}0")).UtcDateTime.ToLocalTime().ToShortTimeString()); - return x.Item2; - }).ToList() ?? new List(); + return new List { + r.Next( 3, 50 ) * r.NextDouble(), + r.Next( 3, 50 ) * r.NextDouble(), + r.Next( 3, 50 ) * r.NextDouble(), + r.Next( 3, 50 ) * r.NextDouble(), + r.Next( 3, 50 ) * r.NextDouble(), + r.Next( 3, 50 ) * r.NextDouble() }; } -} \ No newline at end of file + + //private Background buttonColor = Background.Primary; + + private void ChangeButtonColor() + { + //device.on = !device.on; + } + + +} + diff --git a/src/Elektrifikatsiya/Elektrifikatsiya/Pages/Dashboard.razor.cs b/src/Elektrifikatsiya/Elektrifikatsiya/Pages/Dashboard.razor.cs index ed25e93..fa4bbf2 100644 --- a/src/Elektrifikatsiya/Elektrifikatsiya/Pages/Dashboard.razor.cs +++ b/src/Elektrifikatsiya/Elektrifikatsiya/Pages/Dashboard.razor.cs @@ -18,11 +18,6 @@ namespace Elektrifikatsiya.Pages { public partial class Dashboard { - string bgcolor { get; set; } = "00f"; // (starting value) - void SetColor() - { - bgcolor = "#fd7"; - StateHasChanged(); // may not be required, but I'm at work right now, so can't check - } + } } \ No newline at end of file diff --git a/src/Elektrifikatsiya/Elektrifikatsiya/Pages/Settings.razor b/src/Elektrifikatsiya/Elektrifikatsiya/Pages/Settings.razor index 336dd20..46f8278 100644 --- a/src/Elektrifikatsiya/Elektrifikatsiya/Pages/Settings.razor +++ b/src/Elektrifikatsiya/Elektrifikatsiya/Pages/Settings.razor @@ -2,61 +2,157 @@ @using Blazorise.Components; @using Elektrifikatsiya.Models; @using System.Net - - - - - Plugs - - - - - - - +
+ +
+ + + + Plugs + + + + + - - @context.Item.Name - - - - - User: @context.Item.User -
- Room: @context.Item.Room -
- - @context.Item.PowerUsage W - -
-
- - - - - - - - - + + + + @context.Item.Name + + + + + User: @context.Item.User +
+ Room: @context.Item.Room +
+
+
+ + + + +
+
+ + + + + + + + + + + + + + + + + + +
+
+
@code { + List plugs = new List() { new Device("ffff:ffff:ffff:ffff", "Josne", IPAddress.Broadcast, new User("Joe", "qiowruioewjfopa", Role.Admin), "Raum"), new Device("ffff:ffff:ffff:ffff", "Josne", IPAddress.Broadcast, new User("Joe", "Josne", Role.Admin), "Raum"), new Device("ffff:ffff:ffff:ffff", "Josne", IPAddress.Broadcast, new User("Joe", "qiowruioewjfopa", Role.Admin), "Raum"), }; + private bool hideButtonSettings = true; - List plugs = new List() { new Device("ffff:ffff:ffff:ffff", "Josne", IPAddress.Broadcast, new User("Joe", "qiowruioewjfopa", Role.Admin), "Raum"), new Device("ffff:ffff:ffff:ffff", "Josne", IPAddress.Broadcast, new User("Joe", "Josne", Role.Admin), "Raum"), new Device("ffff:ffff:ffff:ffff", "Josne", IPAddress.Broadcast, new User("Joe", "qiowruioewjfopa", Role.Admin), "Raum"), }; - -} + private void Toggle() + { + hideButtonSettings = !hideButtonSettings; + } +} \ No newline at end of file diff --git a/src/Elektrifikatsiya/Elektrifikatsiya/Pages/_Host.cshtml b/src/Elektrifikatsiya/Elektrifikatsiya/Pages/_Host.cshtml index 3e71a2d..6f92073 100644 --- a/src/Elektrifikatsiya/Elektrifikatsiya/Pages/_Host.cshtml +++ b/src/Elektrifikatsiya/Elektrifikatsiya/Pages/_Host.cshtml @@ -6,3 +6,4 @@ } + \ No newline at end of file diff --git a/src/Elektrifikatsiya/Elektrifikatsiya/_Imports.razor b/src/Elektrifikatsiya/Elektrifikatsiya/_Imports.razor index 971248a..9dc4cde 100644 --- a/src/Elektrifikatsiya/Elektrifikatsiya/_Imports.razor +++ b/src/Elektrifikatsiya/Elektrifikatsiya/_Imports.razor @@ -10,3 +10,4 @@ @using Elektrifikatsiya @using Blazorise @using Blazorise.Charts +@using Blazorise.LoadingIndicator