-
Notifications
You must be signed in to change notification settings - Fork 0
/
ChartBuilder.razor.cs
90 lines (77 loc) · 2.5 KB
/
ChartBuilder.razor.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
using System.Diagnostics.CodeAnalysis;
using System.Text.Json;
using Cascading_Dropdowns.Models;
using Microsoft.AspNetCore.Components;
using Microsoft.AspNetCore.Components.Forms;
namespace Cascading_Dropdowns.Components.Pages;
public partial class ChartBuilder
{
private List<AggregationsResult>? results { get; set; }
private bool results_loading { get; set; }
[Parameter, SupplyParameterFromForm(FormName = "charts")]
public FilterSetupContext? ctx { get; set; }
protected override async Task OnInitializedAsync()
{
await CleanupCtx();
}
[MemberNotNull(nameof(ctx))]
private async Task CleanupCtx()
{
if (ctx == null)
{
ctx = new()
{
CurrentRequest = new()
{
filterId = string.Empty,
startTime = DateTime.UtcNow.AddDays(-14), endTime = DateTime.UtcNow
}
};
}
if (ctx.Filters == null)
{
ctx.Filters = new List<FilterDefinition>();
await foreach (var f in _svc.GetFilters())
{
if (f != null)
{
ctx.Filters.Add(f);
}
}
}
if (ctx.SelectedFilter != null && ctx.SelectedAggregation == null)
{
ctx.CurrentRequest.aggregationId = ctx.SelectedFilter.aggregations.First().id;
}
if (ctx.SelectedAggregation != null)
{
if (!ctx.SelectedAggregation.calculations.Contains(ctx.CurrentRequest.calculation))
{
ctx.CurrentRequest.calculation = ctx.SelectedAggregation.calculations.First();
}
if (ctx.CurrentRequest.calculation == CalculationType.PERCENTILES)
{
if (double.TryParse(ctx.PercentileStr ?? String.Empty, out double _d))
{
ctx.CurrentRequest.percentile = _d;
}
}
}
}
private async Task FormSubmitted(EditContext obj)
{
await CleanupCtx();
if (ctx.Type == FilterSetupContext.SubmitType.GoBtn && ctx.Submittable)
{
results_loading = true;
await Task.Delay(5);
results = new List<AggregationsResult>();
var res = _svc.GetResults(ctx.CurrentRequest);
await foreach (var r in res)
{
results.Add(r);
}
results_loading = false;
}
}
}