Files
mapo-mono/MP.MONO.UI/Components/ProdOverview.razor.cs
T

65 lines
1.9 KiB
C#

using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Components;
using System.Net.Http;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Components.Authorization;
using Microsoft.AspNetCore.Components.Forms;
using Microsoft.AspNetCore.Components.Routing;
using Microsoft.AspNetCore.Components.Web;
using Microsoft.AspNetCore.Components.Web.Virtualization;
using Microsoft.JSInterop;
using MP.MONO.UI;
using MP.MONO.UI.Shared;
using MP.MONO.UI.Components;
using MP.MONO.Core.DTO;
using MP.MONO.UI.Data;
using MP.MONO.Data;
using Newtonsoft.Json;
namespace MP.MONO.UI.Components
{
public partial class ProdOverview
{
private ProductionDTO? currProd { get; set; } = null;
protected override async Task OnInitializedAsync()
{
await ReloadData();
MMDataService.productionPipe.EA_NewMessage += ProductionPipe_EA_NewMessage;
}
private void ProductionPipe_EA_NewMessage(object? sender, EventArgs e)
{
PubSubEventArgs currArgs = (PubSubEventArgs)e;
if (!string.IsNullOrEmpty(currArgs.newMessage))
{
try
{
currProd = JsonConvert.DeserializeObject<ProductionDTO>(currArgs.newMessage);
}
catch
{ }
}
InvokeAsync(() =>
{
StateHasChanged();
});
}
protected string percProgress(int num, int den)
{
string answ = "width: 0%;";
den = den != 0 ? den : 1;
double ratio = ((double)num) / den;
answ = $"width: {ratio:P0};";
return answ;
}
protected async Task ReloadData()
{
currProd = await MMDataService.getProd();
}
}
}