Files
mapo-mono/MP.MONO.UI/Components/AlarmsSetupRawList.razor.cs
Samuele Locatelli f96ba8388b Fix pagina allarmi:
- richiesta pwd priam di fare setup
- fix comportamento
- fix salvataggio setup con filtro display
2022-06-20 16:27:41 +02:00

111 lines
3.2 KiB
C#

using Microsoft.JSInterop;
using MP.MONO.Data.DbModels;
namespace MP.MONO.UI.Components
{
public partial class AlarmsSetupRawList
{
#region Protected Fields
protected List<AlarmListModel>? ListRecords = null;
protected List<AlarmListModel>? DisplayRecords = null;
#endregion Protected Fields
#region Protected Methods
protected string cssSilenced(bool isMuted)
{
string answ = isMuted ? "bg-secondary text-light" : "bg-primary text-light";
return answ;
}
protected override async Task OnInitializedAsync()
{
await ReloadData();
}
protected async Task ReloadData()
{
ListRecords = null;
await Task.Delay(1);
ListRecords = await MMDataService.getAlarmRawSetup();
await Task.Delay(1);
}
/// <summary>
/// Verifica se sia da mostrare (filtro SearchVal attivo e rispettato)
/// </summary>
/// <param name="fullVal"></param>
/// <returns></returns>
protected bool okShow(string fullVal)
{
bool answ = string.IsNullOrEmpty(SearchVal);
// se c'è filtro
if (!answ)
{
answ = fullVal.ToLower().Contains(SearchVal.ToLower());
}
return answ;
}
protected async Task resetAlarmSetup()
{
if (!await JSRuntime.InvokeAsync<bool>("confirm", "Reset Alarm Config: you are going to reset actual alarm configuration. Are you sure to proceed?"))
return;
await Task.Delay(1);
var baseConf = await MMDataService.getAlarmRLConfig();
await MMDataService.setAlarmSetupRawList(baseConf);
await ReloadData();
}
/// <summary>
/// Inverte valore muted dell'allarme
/// </summary>
/// <param name="currAlarm"></param>
/// <returns></returns>
protected async Task toggleMute(AlarmListModel currAlarm)
{
// calcolo inverso del valore richiesto
if (ListRecords != null && ListRecords.Count > 0)
{
// sostituisco in elenco
ListRecords.Remove(currAlarm);
currAlarm.Muted = !currAlarm.Muted;
ListRecords.Add(currAlarm);
ListRecords = ListRecords.OrderBy(x => x.FullValue).ToList();
// salvo su redis...
await MMDataService.setAlarmSetupRawList(ListRecords);
}
await Task.Delay(1);
await ReloadData();
await Task.Delay(1);
}
#endregion Protected Methods
#region Private Properties
private string _searchVal { get; set; } = "";
private string SearchVal
{
get
{
return _searchVal;
}
set
{
_searchVal = value;
var pUpd = Task.Run(async () =>
{
await ReloadData();
});
pUpd.Wait();
}
}
#endregion Private Properties
}
}