Skip to content

Commit

Permalink
Merge pull request #1600 from pkuehnel/fix/decimalNumbericInput
Browse files Browse the repository at this point in the history
fix(GenericInput): use decimal for numeric values
  • Loading branch information
pkuehnel authored Nov 6, 2024
2 parents 88289bb + d1a1f99 commit 2fdda04
Show file tree
Hide file tree
Showing 6 changed files with 410 additions and 111 deletions.
424 changes: 313 additions & 111 deletions TeslaSolarCharger/Client/Components/GenericInput.razor

Large diffs are not rendered by default.

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();
}
54 changes: 54 additions & 0 deletions TeslaSolarCharger/Client/Helper/JavaScriptWrapper.cs
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;
}
}
}
3 changes: 3 additions & 0 deletions TeslaSolarCharger/Client/Program.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
using Lysando.LabStorageV2.UiHelper.Wrapper;
using Lysando.LabStorageV2.UiHelper.Wrapper.Contracts;
using Microsoft.AspNetCore.Components.Web;
using Microsoft.AspNetCore.Components.WebAssembly.Hosting;
using MudBlazor;
Expand All @@ -21,6 +23,7 @@
builder.Services.AddScoped<INodePatternTypeHelper, NodePatternTypeHelper>();
builder.Services.AddScoped<IDateTimeProvider, DateTimeProvider>();
builder.Services.AddScoped<IDialogHelper, DialogHelper>();
builder.Services.AddScoped<IJavaScriptWrapper, JavaScriptWrapper>();
builder.Services.AddScoped<IHttpClientHelper, HttpClientHelper>();
builder.Services.AddSingleton<ToolTipTextKeys>();
builder.Services.AddSharedDependencies();
Expand Down
1 change: 1 addition & 0 deletions TeslaSolarCharger/Client/wwwroot/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
<script src="js/fileDownload.js"></script>
<script src="js/textAreaLineCount.js"></script>
<script src="js/copyToClipboard.js"></script>
<script src="js/javaScriptWrapperFunctions.js"></script>
<script src="_framework/blazor.webassembly.js"></script>
<script>navigator.serviceWorker.register('service-worker.js');</script>
<script src="_content/MudBlazor/MudBlazor.min.js"></script>
Expand Down
30 changes: 30 additions & 0 deletions TeslaSolarCharger/Client/wwwroot/js/javaScriptWrapperFunctions.js
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";
}

0 comments on commit 2fdda04

Please sign in to comment.