-
-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1601 from pkuehnel/develop
Develop
- Loading branch information
Showing
16 changed files
with
507 additions
and
134 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
442 changes: 336 additions & 106 deletions
442
TeslaSolarCharger/Client/Components/GenericInput.razor
Large diffs are not rendered by default.
Oops, something went wrong.
55 changes: 55 additions & 0 deletions
55
TeslaSolarCharger/Client/Components/PowerBufferComponent.razor
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
@using TeslaSolarCharger.Shared.Dtos | ||
@using TeslaSolarCharger.Shared.Dtos.IndexRazor.PvValues | ||
|
||
@inject HttpClient HttpClient | ||
@inject ISnackbar Snackbar | ||
|
||
|
||
@if(_displayValue && _pvValues != default) | ||
{ | ||
<div style="max-width: 200px; margin: 0 auto;"> | ||
<GenericInput T="int?" | ||
For="() => _pvValues.PowerBuffer" | ||
PostfixButtonStartIcon="@Icons.Material.Filled.Save" | ||
OnButtonClicked="UpdatePowerBuffer"></GenericInput> | ||
</div> | ||
} | ||
|
||
|
||
@code { | ||
private DtoPvValues? _pvValues; | ||
private bool _displayValue; | ||
|
||
protected override async Task OnInitializedAsync() | ||
{ | ||
var result = await HttpClient.GetFromJsonAsync<DtoValue<bool>>("api/BaseConfiguration/AllowPowerBufferChangeOnHome").ConfigureAwait(false); | ||
if(result == default) | ||
{ | ||
return; | ||
} | ||
_displayValue = result.Value; | ||
if(_displayValue) | ||
{ | ||
_pvValues = await HttpClient.GetFromJsonAsync<DtoPvValues>("api/Index/GetPvValues").ConfigureAwait(false); | ||
} | ||
|
||
} | ||
|
||
private async Task UpdatePowerBuffer() | ||
{ | ||
if(_pvValues == default) | ||
{ | ||
return; | ||
} | ||
var response = await HttpClient.GetAsync($"api/BaseConfiguration/UpdatePowerBuffer?powerBuffer={_pvValues.PowerBuffer ?? 0}").ConfigureAwait(false); | ||
if (response.IsSuccessStatusCode) | ||
{ | ||
Snackbar.Add("Power Buffer updated", Severity.Success); | ||
} | ||
else | ||
{ | ||
Snackbar.Add("Failed to update Power Buffer", Severity.Error); | ||
} | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
9 changes: 9 additions & 0 deletions
9
TeslaSolarCharger/Client/Helper/Contracts/IJavaScriptWrapper.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
namespace Lysando.LabStorageV2.UiHelper.Wrapper.Contracts; | ||
|
||
public interface IJavaScriptWrapper | ||
{ | ||
Task<bool> SetFocusToElementById(string elementId); | ||
Task<bool> RemoveFocusFromElementById(string elementId); | ||
Task OpenUrlInNewTab(string url); | ||
Task<bool> IsIosDevice(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
using Lysando.LabStorageV2.UiHelper.Wrapper.Contracts; | ||
using Microsoft.JSInterop; | ||
|
||
namespace Lysando.LabStorageV2.UiHelper.Wrapper; | ||
|
||
public class JavaScriptWrapper(IJSRuntime jsRuntime) : IJavaScriptWrapper | ||
{ | ||
/// <summary> | ||
/// Sets the focus to an element with a specific ID | ||
/// </summary> | ||
/// <param name="elementId">ID to set the focus on</param> | ||
/// <returns>Was the ID set successfully</returns> | ||
public async Task<bool> SetFocusToElementById(string elementId) | ||
{ | ||
try | ||
{ | ||
return await jsRuntime.InvokeAsync<bool>("setFocus", elementId); | ||
} | ||
catch (Exception) | ||
{ | ||
return false; | ||
} | ||
} | ||
|
||
public async Task<bool> RemoveFocusFromElementById(string elementId) | ||
{ | ||
try | ||
{ | ||
return await jsRuntime.InvokeAsync<bool>("removeFocus", elementId); | ||
} | ||
catch (Exception) | ||
{ | ||
return false; | ||
} | ||
} | ||
|
||
public async Task OpenUrlInNewTab(string url) | ||
{ | ||
await jsRuntime.InvokeVoidAsync("openInNewTab", url); | ||
} | ||
|
||
public async Task<bool> IsIosDevice() | ||
{ | ||
try | ||
{ | ||
var device = await jsRuntime.InvokeAsync<string>("detectDevice"); | ||
return device == "iOS"; | ||
} | ||
catch (Exception) | ||
{ | ||
return false; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
30 changes: 30 additions & 0 deletions
30
TeslaSolarCharger/Client/wwwroot/js/javaScriptWrapperFunctions.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
function setFocus(elementId) { | ||
const element = document.getElementById(elementId); | ||
if (element) { | ||
element.focus(); | ||
return true; | ||
} | ||
return false; | ||
} | ||
|
||
function removeFocus(elementId) { | ||
const element = document.getElementById(elementId); | ||
if (element) { | ||
element.blur(); | ||
return true; | ||
} | ||
return false; | ||
} | ||
|
||
function openInNewTab(url) { | ||
window.open(url, '_blank'); | ||
} | ||
|
||
function detectDevice() { | ||
var ua = navigator.userAgent || navigator.vendor || window.opera; | ||
// iOS detection | ||
if (/iPad|iPhone|iPod/.test(ua) && !window.MSStream) { | ||
return "iOS"; | ||
} | ||
return "Other"; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters