mirror of
https://github.com/Stefan-5422/-T5-Elektrifikatsiya.git
synced 2026-09-10 07:36:02 +02:00
Merge remote-tracking branch 'origin/feature-DeviceRegistration' into feature-DeviceRegistration
This commit is contained in:
@@ -1,6 +1,8 @@
|
|||||||
using System.ComponentModel.DataAnnotations;
|
using System.ComponentModel.DataAnnotations;
|
||||||
using System.ComponentModel.DataAnnotations.Schema;
|
using System.ComponentModel.DataAnnotations.Schema;
|
||||||
using System.Net;
|
using System.Net;
|
||||||
|
using Microsoft.AspNetCore.Razor.TagHelpers;
|
||||||
|
using Microsoft.AspNetCore.Server.IIS.Core;
|
||||||
|
|
||||||
namespace Elektrifikatsiya.Models;
|
namespace Elektrifikatsiya.Models;
|
||||||
|
|
||||||
@@ -35,5 +37,17 @@ public class Device
|
|||||||
Room = room;
|
Room = room;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static Device CopyDevice(Device device) => new Device(device.MacAddress, device.Name, device.IpAddress, device.User, device.Room);
|
||||||
|
|
||||||
|
public void OverwiteDevice(Device overwriter)
|
||||||
|
{
|
||||||
|
this.Room = overwriter.Room;
|
||||||
|
this.Available = overwriter.Available;
|
||||||
|
this.PowerUsage = overwriter.PowerUsage;
|
||||||
|
this.Name = overwriter.Name;
|
||||||
|
this.User = overwriter.User;
|
||||||
|
this.MacAddress = overwriter.MacAddress;
|
||||||
|
this.IpAddress = overwriter.IpAddress;
|
||||||
|
}
|
||||||
private Device(){}
|
private Device(){}
|
||||||
}
|
}
|
||||||
@@ -5,6 +5,7 @@
|
|||||||
@using Elektrifikatsiya.Services
|
@using Elektrifikatsiya.Services
|
||||||
@using Elektrifikatsiya.Utilities
|
@using Elektrifikatsiya.Utilities
|
||||||
@using System.Diagnostics
|
@using System.Diagnostics
|
||||||
|
@using Elektrifikatsiya.Services.Implementations
|
||||||
@inject IVersionProvider VersionProvider
|
@inject IVersionProvider VersionProvider
|
||||||
|
|
||||||
@inject IDeviceStatusService DeviceStatusService;
|
@inject IDeviceStatusService DeviceStatusService;
|
||||||
|
|||||||
@@ -2,6 +2,13 @@
|
|||||||
@using Blazorise.Components;
|
@using Blazorise.Components;
|
||||||
@using Elektrifikatsiya.Models;
|
@using Elektrifikatsiya.Models;
|
||||||
@using System.Net
|
@using System.Net
|
||||||
|
@using System.Text.Json
|
||||||
|
@using Elektrifikatsiya.Services.Implementations
|
||||||
|
@using Elektrifikatsiya.Services;
|
||||||
|
@using FluentResults
|
||||||
|
|
||||||
|
@inject IDeviceManagmentService DeviceManagmentService
|
||||||
|
|
||||||
<Div>
|
<Div>
|
||||||
<Row Style="width: 100%; height: 100%" Margin="Margin.Is3.FromTop.OnMobile" Padding="Padding.Is4.FromStart.OnMobile">
|
<Row Style="width: 100%; height: 100%" Margin="Margin.Is3.FromTop.OnMobile" Padding="Padding.Is4.FromStart.OnMobile">
|
||||||
<Div Display="Display.Flex.Row.OnDesktop" Margin=" Margin.Is3.FromBottom" Width="Width.Is100">
|
<Div Display="Display.Flex.Row.OnDesktop" Margin=" Margin.Is3.FromBottom" Width="Width.Is100">
|
||||||
@@ -34,7 +41,7 @@
|
|||||||
</Row>
|
</Row>
|
||||||
<Row>
|
<Row>
|
||||||
<Column>
|
<Column>
|
||||||
<Small>User: @context.Item.User</Small>
|
<Small>User: @context.Item.User.Name</Small>
|
||||||
<br />
|
<br />
|
||||||
<Small>Room: @context.Item.Room</Small>
|
<Small>Room: @context.Item.Room</Small>
|
||||||
</Column>
|
</Column>
|
||||||
@@ -43,14 +50,14 @@
|
|||||||
|
|
||||||
<Column ColumnSize="ColumnSize.Is4.OnDesktop.Is7.OnMobile">
|
<Column ColumnSize="ColumnSize.Is4.OnDesktop.Is7.OnMobile">
|
||||||
<Button Position="Position.Absolute.Top.Is50.Start.Is50.Translate.Middle" Color="Color.Dark" Outline>
|
<Button Position="Position.Absolute.Top.Is50.Start.Is50.Translate.Middle" Color="Color.Dark" Outline>
|
||||||
<BarIcon IconName="IconName.Delete" />
|
<BarIcon @onclick="() => Delete(context.Item)" IconName="IconName.Delete" />
|
||||||
</Button>
|
</Button>
|
||||||
</Column>
|
</Column>
|
||||||
<br />
|
<br />
|
||||||
<br />
|
<br />
|
||||||
<Row>
|
<Row>
|
||||||
<Column ColumnSize="ColumnSize.Is1.OnDesktop">
|
<Column ColumnSize="ColumnSize.Is1.OnDesktop">
|
||||||
<Button @onclick="Toggle" Position="Position.Absolute.Top.Is50.Start.Is100.Translate.Middle" Color="Color.Dark" Outline>
|
<Button @onclick="() => Toggle(context.Item)" Position="Position.Absolute.Top.Is50.Start.Is100.Translate.Middle" Color="Color.Dark" Outline>
|
||||||
<BarIcon IconName="IconName.Pen" />
|
<BarIcon IconName="IconName.Pen" />
|
||||||
</Button>
|
</Button>
|
||||||
</Column>
|
</Column>
|
||||||
@@ -62,6 +69,9 @@
|
|||||||
</ListView>
|
</ListView>
|
||||||
</Column>
|
</Column>
|
||||||
<Column ColumnSize="ColumnSize.Is6.OnDesktop.Is12.OnMobile" Margin="Margin.Is3.FromTop.OnMobile" Padding="Padding.Is4.FromStart.OnMobile">
|
<Column ColumnSize="ColumnSize.Is6.OnDesktop.Is12.OnMobile" Margin="Margin.Is3.FromTop.OnMobile" Padding="Padding.Is4.FromStart.OnMobile">
|
||||||
|
|
||||||
|
@if (DeviceCopy is not null)
|
||||||
|
{
|
||||||
<Div hidden="@hideButtonSettings">
|
<Div hidden="@hideButtonSettings">
|
||||||
<Field>
|
<Field>
|
||||||
<FieldLabel>
|
<FieldLabel>
|
||||||
@@ -79,7 +89,7 @@
|
|||||||
Here you can change the name of your plug
|
Here you can change the name of your plug
|
||||||
</Paragraph>
|
</Paragraph>
|
||||||
</FieldLabel>
|
</FieldLabel>
|
||||||
<TextEdit Placeholder="Enter Name" />
|
<TextEdit @bind-Text="@DeviceCopy.Name" Placeholder="Enter Name" />
|
||||||
</Field>
|
</Field>
|
||||||
<br />
|
<br />
|
||||||
<br />
|
<br />
|
||||||
@@ -93,6 +103,7 @@
|
|||||||
</Paragraph>
|
</Paragraph>
|
||||||
</FieldLabel>
|
</FieldLabel>
|
||||||
<TextEdit Placeholder="Enter Max Output" />
|
<TextEdit Placeholder="Enter Max Output" />
|
||||||
|
<!--TODO: What is this?-->
|
||||||
</Field>
|
</Field>
|
||||||
<br />
|
<br />
|
||||||
<br />
|
<br />
|
||||||
@@ -105,19 +116,10 @@
|
|||||||
Here you select or change the room the plug belongs to.
|
Here you select or change the room the plug belongs to.
|
||||||
</Paragraph>
|
</Paragraph>
|
||||||
</FieldLabel>
|
</FieldLabel>
|
||||||
<br />
|
<TextEdit @bind-text="@DeviceCopy.Room" Placeholder="Enter the name of the room here"/>
|
||||||
<Dropdown Display="Display.InlineBlock">
|
|
||||||
<DropdownToggle Color="Color.Primary" Width="Width.Is100">Rooms</DropdownToggle>
|
|
||||||
<DropdownMenu>
|
|
||||||
<DropdownItem>Room 1</DropdownItem>
|
|
||||||
<DropdownDivider />
|
|
||||||
<DropdownItem>Room 2</DropdownItem>
|
|
||||||
<DropdownDivider />
|
|
||||||
<DropdownItem>Room 3</DropdownItem>
|
|
||||||
</DropdownMenu>
|
|
||||||
</Dropdown>
|
|
||||||
</Field>
|
</Field>
|
||||||
</Div>
|
</Div>
|
||||||
|
}
|
||||||
<Div hidden="@(!hideButtonSettings)">
|
<Div hidden="@(!hideButtonSettings)">
|
||||||
<Field>
|
<Field>
|
||||||
<FieldLabel>
|
<FieldLabel>
|
||||||
@@ -139,20 +141,55 @@
|
|||||||
</Field>
|
</Field>
|
||||||
</Div>
|
</Div>
|
||||||
<Column ColumnSize="ColumnSize.IsFull" TextAlignment="TextAlignment.End">
|
<Column ColumnSize="ColumnSize.IsFull" TextAlignment="TextAlignment.End">
|
||||||
<Button Color="Color.Primary">Save</Button>
|
<Button @onclick="OnSave" Color="Color.Primary">Save</Button>
|
||||||
</Column>
|
</Column>
|
||||||
</Column>
|
</Column>
|
||||||
</Div>
|
</Div>
|
||||||
</Row>
|
</Row>
|
||||||
</Div>
|
</Div>
|
||||||
|
|
||||||
|
|
||||||
@code {
|
@code {
|
||||||
List<Device> plugs = new List<Device>() { 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"), };
|
List<Device> plugs = new List<Device>();
|
||||||
|
|
||||||
private bool hideButtonSettings = true;
|
private bool hideButtonSettings = true;
|
||||||
|
|
||||||
private void Toggle()
|
Device? SelectedDevice = null;
|
||||||
|
Device? DeviceCopy = null;
|
||||||
|
|
||||||
|
protected override void OnInitialized()
|
||||||
|
{
|
||||||
|
Result<List<Device>> getDevicesResult = DeviceManagmentService.GetDevices();
|
||||||
|
|
||||||
|
if (getDevicesResult.IsSuccess)
|
||||||
|
{
|
||||||
|
plugs = getDevicesResult.Value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void Toggle(Device device)
|
||||||
{
|
{
|
||||||
hideButtonSettings = !hideButtonSettings;
|
hideButtonSettings = !hideButtonSettings;
|
||||||
|
SelectedDevice = device;
|
||||||
|
DeviceCopy = Device.CopyDevice(device);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void OnSave()
|
||||||
|
{
|
||||||
|
if (hideButtonSettings || DeviceCopy is null)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
SelectedDevice.OverwiteDevice(DeviceCopy);
|
||||||
|
DeviceManagmentService.UpdateDevice(SelectedDevice);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void Delete(Device contextItem)
|
||||||
|
{
|
||||||
|
DeviceManagmentService.UnregisterDevice(contextItem.MacAddress);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user