91 lines
2.2 KiB
Plaintext
91 lines
2.2 KiB
Plaintext
@using KoogleApp.Model.EventMessages
|
|
@using KoogleApp.Services
|
|
|
|
@implements IDisposable
|
|
@implements IMyHandle<PinValueChangedMessage>
|
|
|
|
@inject IMyEventAggregator EventAggregator
|
|
|
|
@if (Disabled)
|
|
{
|
|
<MudIcon Class="ma-2" Icon="@Icons.Material.Filled.CheckCircle" Color="Color.Dark"
|
|
Style="font-size: 3rem;"/>
|
|
@if (ShowSwitch)
|
|
{
|
|
<MudSwitch T="bool" Label="" Size="Size.Medium" Disabled="true"
|
|
ThumbIcon="Icons.Material.Filled.Done" ThumbIconColor="Color.Dark"
|
|
Value="true"/>
|
|
}
|
|
}
|
|
else
|
|
{
|
|
<MudButton OnClick="ToggleClick" Disabled="Disabled">
|
|
<MudIcon Class="ma-2"
|
|
Icon="@(Value ? Icons.Material.Filled.CheckCircleOutline: Icons.Material.Filled.ModeStandby)"
|
|
Color="@(Value ? Color.Warning: Color.Primary)"
|
|
Style="font-size: 3rem;" />
|
|
</MudButton>
|
|
|
|
@if (ShowSwitch)
|
|
{
|
|
<MudSwitch T="bool" Label="" Size="Size.Medium" Disabled="Disabled"
|
|
ThumbIcon="@(Value ? Icons.Material.Filled.Done : Icons.Material.Filled.Close)" ThumbIconColor="@(Value ? Color.Success : Color.Error)"
|
|
@bind-Value="Value"/>
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
@code {
|
|
private bool _value;
|
|
|
|
[Parameter]
|
|
public bool Value
|
|
{
|
|
get => _value;
|
|
set
|
|
{
|
|
_value = value;
|
|
InvokeAsync(StateHasChanged);
|
|
}
|
|
}
|
|
|
|
[Parameter]
|
|
public int PinNumber { get; set; }
|
|
|
|
[Parameter]
|
|
public bool Disabled { get; set; }
|
|
|
|
[Parameter]
|
|
public bool ShowSwitch { get; set; }
|
|
|
|
private const string PinIconStr =
|
|
"<image width=\"24\" height=\"24\" xlink:href=\"icons/pin_64.png\" />";
|
|
|
|
private async Task ToggleClick(MouseEventArgs obj)
|
|
{
|
|
Value = !Value;
|
|
await EventAggregator.PublishAsync(new PinValueChangedMessage(pinNumber: PinNumber, Value));
|
|
}
|
|
|
|
protected override void OnInitialized()
|
|
{
|
|
EventAggregator.Subscribe(this);
|
|
}
|
|
|
|
public void Dispose()
|
|
{
|
|
EventAggregator.Unsubscribe(this);
|
|
}
|
|
|
|
public async Task HandleAsync(PinValueChangedMessage message)
|
|
{
|
|
if (message.PinNumber == PinNumber)
|
|
{
|
|
Value = message.Value;
|
|
}
|
|
}
|
|
|
|
}
|