red delete button settings page

This commit is contained in:
Aldin296
2023-06-07 10:25:03 +02:00
parent b9fed85a8c
commit 2b108e09b9
@@ -52,62 +52,67 @@
</Column> </Column>
<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 class="btn1" Position="Position.Absolute.Top.Is50.Start.Is50.Translate.Middle" Color="Color.Dark" Outline>
<BarIcon @onclick="() => Delete(context.Item)" IconName="IconName.Delete" /> <BarIcon @onclick="() => Delete(context.Item)" IconName="IconName.Delete" />
</Button> </Button>
<style>
.btn1:hover {
background: #E50000;
}
</style>
</Column> </Column>
<br /> <br />
<br /> <br />
<Row> <Row>
<Column ColumnSize="ColumnSize.Is1.OnDesktop"> <Column ColumnSize="ColumnSize.Is1.OnDesktop">
<Button @onclick="() => Toggle(context.Item)" 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>
</Row> </Row>
</Row> </Row>
</ListGroupItem> </ListGroupItem>
</ItemTemplate> </ItemTemplate>
</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) @if (DeviceCopy is not null)
{ {
<Div hidden="@hideButtonSettings"> <Div hidden="@hideButtonSettings">
<Field> <Field>
<FieldLabel> <FieldLabel>
<h2> <h2>
Plug Settings Plug Settings
</h2> </h2>
</FieldLabel> </FieldLabel>
</Field> </Field>
<Field> <Field>
<FieldLabel> <FieldLabel>
<h5> <h5>
Plug Name Plug Name
</h5> </h5>
<Paragraph> <Paragraph>
Here you can change the name of your plug Here you can change the name of your plug
</Paragraph> </Paragraph>
</FieldLabel> </FieldLabel>
<TextEdit MaxLength="20" @bind-Text="@DeviceCopy.Name" Placeholder="Enter Name" /> <TextEdit MaxLength="20" @bind-Text="@DeviceCopy.Name" Placeholder="Enter Name" />
</Field> </Field>
<br /> <br />
<br /> <br />
<Field> <Field>
<FieldLabel> <FieldLabel>
<h5> <h5>
Select Room Select Room
</h5> </h5>
<Paragraph> <Paragraph>
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>
<TextEdit MaxLength="30" @bind-text="@DeviceCopy.Room" Placeholder="Enter the name of the room here" /> <TextEdit MaxLength="30" @bind-text="@DeviceCopy.Room" Placeholder="Enter the name of the room here" />
</Field> </Field>
</Div> </Div>
} }
<Div hidden="@(!hideButtonSettings)"> <Div hidden="@(!hideButtonSettings)">
<Field> <Field>
@@ -145,6 +150,7 @@
bool hideButtonSettings = true; bool hideButtonSettings = true;
int clicks = 0; int clicks = 0;
bool test = false;
double electricityPrice = 0; double electricityPrice = 0;
@@ -160,11 +166,12 @@
plugs = getDevicesResult.Value; plugs = getDevicesResult.Value;
} }
electricityPrice = MainDatabaseContext.EnergyPriceChanges.OrderByDescending(e=>e.DateTime).FirstOrDefault()?.EnergyPrice ?? 0; electricityPrice = MainDatabaseContext.EnergyPriceChanges.OrderByDescending(e => e.DateTime).FirstOrDefault()?.EnergyPrice ?? 0;
} }
private void Toggle(Device device) private void Toggle(Device device)
{ {
if (device == SelectedDevice || clicks == 0) if (device == SelectedDevice || clicks == 0)
{ {
hideButtonSettings = !hideButtonSettings; hideButtonSettings = !hideButtonSettings;
@@ -176,7 +183,9 @@
{ {
SelectedDevice = device; SelectedDevice = device;
DeviceCopy = device.CopyDevice(); DeviceCopy = device.CopyDevice();
clicks = 0;
} }
} }
private async void OnSave() private async void OnSave()
@@ -184,10 +193,10 @@
if (hideButtonSettings) if (hideButtonSettings)
{ {
MainDatabaseContext.ChangeTracker.Clear(); MainDatabaseContext.ChangeTracker.Clear();
MainDatabaseContext.EnergyPriceChanges.Add(new EnergyPriceChange(electricityPrice)); MainDatabaseContext.EnergyPriceChanges.Add(new EnergyPriceChange(electricityPrice));
await MainDatabaseContext.SaveChangesAsync(); await MainDatabaseContext.SaveChangesAsync();
} }
else if(DeviceCopy is not null && SelectedDevice is not null) else if (DeviceCopy is not null && SelectedDevice is not null)
{ {
SelectedDevice.OverwiteDevice(DeviceCopy); SelectedDevice.OverwiteDevice(DeviceCopy);
@@ -197,18 +206,18 @@
private async Task Delete(Device contextItem) private async Task Delete(Device contextItem)
{ {
bool succ = await MessageService.Confirm($"Do you really want to delete the device \"{contextItem.Name}\"?"); bool succ = await MessageService.Confirm($"Do you really want to delete the device \"{contextItem.Name}\"?");
if(!succ) if (!succ)
{ {
return; return;
} }
await DeviceManagmentService.UnregisterDevice(contextItem.MacAddress); await DeviceManagmentService.UnregisterDevice(contextItem.MacAddress);
int index = plugs.FindIndex(x => x.MacAddress == contextItem.MacAddress); int index = plugs.FindIndex(x => x.MacAddress == contextItem.MacAddress);
if(index != -1) if (index != -1)
{ {
plugs.RemoveAt(index); plugs.RemoveAt(index);
} }