mirror of
https://github.com/lantean-code/qbtmud.git
synced 2025-10-23 04:52:22 +00:00
Fix slider dialog and add submittable dialog.
This commit is contained in:
@@ -3,28 +3,34 @@
|
||||
<MudGrid>
|
||||
<MudItem xs="12">
|
||||
<MudRadioGroup T="int" Value="ShareRatioType" ValueChanged="ShareRatioTypeChanged">
|
||||
<MudRadio T="int" Value="-2">Use global share limit</MudRadio>
|
||||
<MudRadio T="int" Value="-1">Set no share limit</MudRadio>
|
||||
<MudRadio T="int" Value="0">Set share limit to</MudRadio>
|
||||
<MudItem xs="12">
|
||||
<MudRadio T="int" Value="-2">Use global share limit</MudRadio>
|
||||
</MudItem>
|
||||
<MudItem xs="12">
|
||||
<MudRadio T="int" Value="-1">Set no share limit</MudRadio>
|
||||
</MudItem>
|
||||
<MudItem xs="12">
|
||||
<MudRadio T="int" Value="0">Set share limit to</MudRadio>
|
||||
</MudItem>
|
||||
</MudRadioGroup>
|
||||
</MudItem>
|
||||
<MudItem xs="3">
|
||||
<FieldSwitch Label="Ratio" Value="RatioEnabled" ValueChanged="RatioEnabledChanged" Disabled="@(!CustomEnabled)" />
|
||||
</MudItem>
|
||||
<MudItem xs="9">
|
||||
<MudNumericField T="float" Value="Ratio" ValueChanged="RatioChanged" Disabled="@(!CustomEnabled)" Min="1" Max="1024000" Variant="Variant.Outlined" Adornment="Adornment.End" AdornmentText="KiB" />
|
||||
<MudNumericField T="float" Value="Ratio" ValueChanged="RatioChanged" Disabled="@(!(CustomEnabled && RatioEnabled))" Min="1" Max="1024000" Format="F2" Variant="Variant.Outlined" />
|
||||
</MudItem>
|
||||
<MudItem xs="3">
|
||||
<FieldSwitch Label="Total minutes" Value="TotalMinutesEnabled" ValueChanged="TotalMinutesEnabledChanged" Disabled="@(!CustomEnabled)" />
|
||||
</MudItem>
|
||||
<MudItem xs="9">
|
||||
<MudNumericField T="int" Value="TotalMinutes" ValueChanged="TotalMinutesChanged" Disabled="@(!CustomEnabled)" Min="1" Max="1024000" Variant="Variant.Outlined" Adornment="Adornment.End" AdornmentText="KiB" />
|
||||
<MudNumericField T="int" Value="TotalMinutes" ValueChanged="TotalMinutesChanged" Disabled="@(!(CustomEnabled && TotalMinutesEnabled))" Min="1" Max="1024000" Variant="Variant.Outlined" Adornment="Adornment.End" AdornmentText="minutes" />
|
||||
</MudItem>
|
||||
<MudItem xs="3">
|
||||
<FieldSwitch Label="Inactive minutes" Value="InactiveMinutesEnabled" ValueChanged="InactiveMinutesEnabledChanged" Disabled="@(!CustomEnabled)" />
|
||||
</MudItem>
|
||||
<MudItem xs="9">
|
||||
<MudNumericField T="int" Value="InactiveMinutes" ValueChanged="InactiveMinutesChanged" Disabled="@(!CustomEnabled)" Min="1" Max="1024000" Variant="Variant.Outlined" Adornment="Adornment.End" AdornmentText="KiB" />
|
||||
<MudNumericField T="int" Value="InactiveMinutes" ValueChanged="InactiveMinutesChanged" Disabled="@(!(CustomEnabled && InactiveMinutesEnabled))" Min="1" Max="1024000" Variant="Variant.Outlined" Adornment="Adornment.End" AdornmentText="minutes" />
|
||||
</MudItem>
|
||||
</MudGrid>
|
||||
</DialogContent>
|
||||
|
@@ -1,18 +1,30 @@
|
||||
@typeparam T
|
||||
@inherits SubmittableDialog
|
||||
|
||||
<MudDialog>
|
||||
<DialogContent>
|
||||
<MudGrid>
|
||||
<MudItem xs="12">
|
||||
<MudNumericField T="string" Label="@Label" Value="@GetDisplayValue()" ValueChanged="ValueChanged" Min="@(Min.ToString())" Max="@(Max.ToString())" Disabled="Disabled" Variant="Variant.Outlined" />
|
||||
<MudTextField T="string" Label="@Label" Value="@GetDisplayValue()" ValueChanged="ValueChanged" Disabled="Disabled" Variant="Variant.Outlined" Adornment="@Adornment" AdornmentText="@AdornmentText" />
|
||||
</MudItem>
|
||||
<MudItem xs="12">
|
||||
<MudSlider T="T" ValueLabel="true" Value="@Value" ValueChanged="ValueChanged" Min="@Min" Max="@Max" Disabled="Disabled" />
|
||||
<MudSlider T="T" ValueLabel="true" Value="@Value" ValueChanged="ValueChanged" Min="@Min" Max="@Max" Disabled="Disabled">
|
||||
<ValueLabelContent>
|
||||
@if (ValueDisplayFunc is not null)
|
||||
{
|
||||
@ValueDisplayFunc(context.Value)
|
||||
}
|
||||
else
|
||||
{
|
||||
@context.Value
|
||||
}
|
||||
</ValueLabelContent>
|
||||
</MudSlider>
|
||||
</MudItem>
|
||||
</MudGrid>
|
||||
</DialogContent>
|
||||
<DialogActions>
|
||||
<MudButton OnClick="Cancel">Cancel</MudButton>
|
||||
<MudButton Color="Color.Primary" OnClick="Submit">Save</MudButton>
|
||||
<MudButton Color="Color.Primary" ButtonType="ButtonType.Submit" OnClick="Submit">Save</MudButton>
|
||||
</DialogActions>
|
||||
</MudDialog>
|
@@ -1,7 +1,7 @@
|
||||
using Microsoft.AspNetCore.Components;
|
||||
using Lantean.QBTMudBlade.Models;
|
||||
using Microsoft.AspNetCore.Components;
|
||||
using Microsoft.AspNetCore.Components.Web;
|
||||
using MudBlazor;
|
||||
using System.ComponentModel;
|
||||
using System.Numerics;
|
||||
|
||||
namespace Lantean.QBTMudBlade.Components.Dialogs
|
||||
@@ -27,11 +27,17 @@ namespace Lantean.QBTMudBlade.Components.Dialogs
|
||||
public bool Disabled { get; set; }
|
||||
|
||||
[Parameter]
|
||||
public Func<T, string?>? ValueDisplayFunc { get; set; }
|
||||
public Func<T, string>? ValueDisplayFunc { get; set; }
|
||||
|
||||
[Parameter]
|
||||
public Func<string, T>? ValueGetFunc { get; set; }
|
||||
|
||||
[Parameter]
|
||||
public Adornment Adornment { get; set; }
|
||||
|
||||
[Parameter]
|
||||
public string? AdornmentText { get; set; }
|
||||
|
||||
private string? GetDisplayValue()
|
||||
{
|
||||
var value = ValueDisplayFunc?.Invoke(Value);
|
||||
@@ -47,7 +53,8 @@ namespace Lantean.QBTMudBlade.Components.Dialogs
|
||||
{
|
||||
if (ValueGetFunc is not null)
|
||||
{
|
||||
Value = ValueGetFunc.Invoke(value);
|
||||
T val = ValueGetFunc.Invoke(value);
|
||||
Value = val;
|
||||
|
||||
return;
|
||||
}
|
||||
@@ -62,14 +69,21 @@ namespace Lantean.QBTMudBlade.Components.Dialogs
|
||||
}
|
||||
}
|
||||
|
||||
protected void Cancel(MouseEventArgs args)
|
||||
protected void Cancel()
|
||||
{
|
||||
MudDialog.Cancel();
|
||||
}
|
||||
|
||||
protected void Submit(MouseEventArgs args)
|
||||
protected void Submit()
|
||||
{
|
||||
MudDialog.Close(DialogResult.Ok(Value));
|
||||
}
|
||||
|
||||
protected override Task Submit(KeyboardEvent keyboardEvent)
|
||||
{
|
||||
Submit();
|
||||
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
}
|
||||
}
|
@@ -1,4 +1,6 @@
|
||||
<MudDialog>
|
||||
@inherits SubmittableDialog
|
||||
|
||||
<MudDialog>
|
||||
<DialogContent>
|
||||
<MudGrid>
|
||||
<MudItem xs="12">
|
||||
|
@@ -1,5 +1,5 @@
|
||||
using Microsoft.AspNetCore.Components;
|
||||
using Microsoft.AspNetCore.Components.Web;
|
||||
using Lantean.QBTMudBlade.Models;
|
||||
using Microsoft.AspNetCore.Components;
|
||||
using MudBlazor;
|
||||
|
||||
namespace Lantean.QBTMudBlade.Components.Dialogs
|
||||
@@ -18,14 +18,21 @@ namespace Lantean.QBTMudBlade.Components.Dialogs
|
||||
[Parameter]
|
||||
public bool Disabled { get; set; }
|
||||
|
||||
protected void Cancel(MouseEventArgs args)
|
||||
protected void Cancel()
|
||||
{
|
||||
MudDialog.Cancel();
|
||||
}
|
||||
|
||||
protected void Submit(MouseEventArgs args)
|
||||
protected void Submit()
|
||||
{
|
||||
MudDialog.Close(DialogResult.Ok(Value));
|
||||
}
|
||||
|
||||
protected override Task Submit(KeyboardEvent keyboardEvent)
|
||||
{
|
||||
Submit();
|
||||
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
}
|
||||
}
|
44
Lantean.QBTMudBlade/Components/Dialogs/SubmittableDialog.cs
Normal file
44
Lantean.QBTMudBlade/Components/Dialogs/SubmittableDialog.cs
Normal file
@@ -0,0 +1,44 @@
|
||||
using Lantean.QBTMudBlade.Models;
|
||||
using Lantean.QBTMudBlade.Services;
|
||||
using Microsoft.AspNetCore.Components;
|
||||
|
||||
namespace Lantean.QBTMudBlade.Components.Dialogs
|
||||
{
|
||||
public abstract class SubmittableDialog : ComponentBase, IAsyncDisposable
|
||||
{
|
||||
private bool _disposedValue;
|
||||
|
||||
[Inject]
|
||||
protected IKeyboardService KeyboardService { get; set; } = default!;
|
||||
|
||||
protected override async Task OnAfterRenderAsync(bool firstRender)
|
||||
{
|
||||
if (firstRender)
|
||||
{
|
||||
await KeyboardService.RegisterKeypressEvent("Enter", k => Submit(k));
|
||||
}
|
||||
}
|
||||
|
||||
protected abstract Task Submit(KeyboardEvent keyboardEvent);
|
||||
|
||||
protected virtual async ValueTask DisposeAsync(bool disposing)
|
||||
{
|
||||
if (!_disposedValue)
|
||||
{
|
||||
if (disposing)
|
||||
{
|
||||
await KeyboardService.UnregisterKeypressEvent("Enter");
|
||||
}
|
||||
|
||||
_disposedValue = true;
|
||||
}
|
||||
}
|
||||
|
||||
public async ValueTask DisposeAsync()
|
||||
{
|
||||
// Do not change this code. Put cleanup code in 'Dispose(bool disposing)' method
|
||||
await DisposeAsync(disposing: true);
|
||||
GC.SuppressFinalize(this);
|
||||
}
|
||||
}
|
||||
}
|
@@ -270,13 +270,14 @@ namespace Lantean.QBTMudBlade.Helpers
|
||||
|
||||
var parameters = new DialogParameters
|
||||
{
|
||||
{ nameof(SliderFieldDialog<long>.Value), rate },
|
||||
{ nameof(SliderFieldDialog<long>.Min), -1L },
|
||||
{ nameof(SliderFieldDialog<long>.Max), 100L },
|
||||
{ nameof(SliderFieldDialog<long>.Value), rate },
|
||||
{ nameof(SliderFieldDialog<long>.Max), 1000L },
|
||||
{ nameof(SliderFieldDialog<long>.Value), rate / 1024 },
|
||||
{ nameof(SliderFieldDialog<long>.ValueDisplayFunc), valueDisplayFunc },
|
||||
{ nameof(SliderFieldDialog<long>.ValueGetFunc), valueGetFunc },
|
||||
{ nameof(SliderFieldDialog<long>.Label), "Download rate limit" }
|
||||
{ nameof(SliderFieldDialog<long>.Label), "Download rate limit" },
|
||||
{ nameof(SliderFieldDialog<long>.Adornment), Adornment.End },
|
||||
{ nameof(SliderFieldDialog<long>.AdornmentText), "KiB/s" },
|
||||
};
|
||||
var result = await dialogService.ShowAsync<SliderFieldDialog<long>>("Download Rate", parameters, FormDialogOptions);
|
||||
|
||||
@@ -285,8 +286,8 @@ namespace Lantean.QBTMudBlade.Helpers
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
await apiClient.SetTorrentDownloadLimit((long)dialogResult.Data, null, hashes.ToArray());
|
||||
var kibs = (long)dialogResult.Data;
|
||||
await apiClient.SetTorrentDownloadLimit(kibs * 1024, null, hashes.ToArray());
|
||||
}
|
||||
|
||||
public static async Task InvokeUploadRateDialog(this IDialogService dialogService, IApiClient apiClient, long rate, IEnumerable<string> hashes)
|
||||
@@ -296,13 +297,14 @@ namespace Lantean.QBTMudBlade.Helpers
|
||||
|
||||
var parameters = new DialogParameters
|
||||
{
|
||||
{ nameof(SliderFieldDialog<long>.Value), rate },
|
||||
{ nameof(SliderFieldDialog<long>.Min), -1L },
|
||||
{ nameof(SliderFieldDialog<long>.Max), 100L },
|
||||
{ nameof(SliderFieldDialog<long>.Value), rate },
|
||||
{ nameof(SliderFieldDialog<long>.Max), 1000L },
|
||||
{ nameof(SliderFieldDialog<long>.Value), rate / 1024 },
|
||||
{ nameof(SliderFieldDialog<long>.ValueDisplayFunc), valueDisplayFunc },
|
||||
{ nameof(SliderFieldDialog<long>.ValueGetFunc), valueGetFunc },
|
||||
{ nameof(SliderFieldDialog<long>.Label), "Upload rate limit" }
|
||||
{ nameof(SliderFieldDialog<long>.Label), "Upload rate limit" },
|
||||
{ nameof(SliderFieldDialog<long>.Adornment), Adornment.End },
|
||||
{ nameof(SliderFieldDialog<long>.AdornmentText), "KiB/s" },
|
||||
};
|
||||
var result = await dialogService.ShowAsync<SliderFieldDialog<long>>("Upload Rate", parameters, FormDialogOptions);
|
||||
|
||||
@@ -311,8 +313,8 @@ namespace Lantean.QBTMudBlade.Helpers
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
await apiClient.SetTorrentUploadLimit((long)dialogResult.Data, null, hashes.ToArray());
|
||||
var kibs = (long)dialogResult.Data;
|
||||
await apiClient.SetTorrentUploadLimit(kibs * 1024, null, hashes.ToArray());
|
||||
}
|
||||
|
||||
public static async Task InvokeShareRatioDialog(this IDialogService dialogService, IApiClient apiClient, IEnumerable<Torrent> torrents)
|
||||
|
Reference in New Issue
Block a user