NEW: Zusagen / Absagen Chart (PoC)
This commit is contained in:
@ -11,5 +11,20 @@ namespace SZUAbsolventenverein.Module.EventRegistration
|
||||
{
|
||||
_jsRuntime = jsRuntime;
|
||||
}
|
||||
|
||||
public async Task CreateChart(string divid, string type, string[] labels, object[] datasets, object options)
|
||||
{
|
||||
try
|
||||
{
|
||||
await _jsRuntime.InvokeVoidAsync(
|
||||
"SZUAbsolventenverein.EventRegistration.createChart",
|
||||
divid, type, (object) labels, (object) datasets, options);
|
||||
}
|
||||
catch
|
||||
{
|
||||
// handle exception
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@ -42,6 +42,7 @@
|
||||
{
|
||||
<AuditInfo CreatedBy="@_createdby" CreatedOn="@_createdon" ModifiedBy="@_modifiedby" ModifiedOn="@_modifiedon"></AuditInfo>
|
||||
}
|
||||
<div id="chart"></div>
|
||||
</form>
|
||||
|
||||
@code {
|
||||
@ -53,7 +54,9 @@
|
||||
|
||||
public override List<Resource> Resources => new List<Resource>()
|
||||
{
|
||||
new Resource { ResourceType = ResourceType.Stylesheet, Url = ModulePath() + "Module.css" }
|
||||
new Resource { ResourceType = ResourceType.Stylesheet, Url = ModulePath() + "Module.css" },
|
||||
new Resource { ResourceType = ResourceType.Script, Bundle = "ChartJS", Url = "https://cdn.jsdelivr.net/npm/chart.js" },
|
||||
new Resource { ResourceType = ResourceType.Script, Bundle = "ChartJS", Url = ModulePath() + "Module.js"}
|
||||
};
|
||||
|
||||
|
||||
@ -71,6 +74,9 @@
|
||||
private DateTime _createdon;
|
||||
private string _modifiedby;
|
||||
private DateTime _modifiedon;
|
||||
|
||||
bool _refresh = false;
|
||||
private List<Response> _responses;
|
||||
|
||||
protected override async Task OnInitializedAsync()
|
||||
{
|
||||
@ -92,6 +98,10 @@
|
||||
_modifiedby = EventRegistration.ModifiedBy;
|
||||
_modifiedon = EventRegistration.ModifiedOn;
|
||||
}
|
||||
|
||||
_responses = await EventRegistrationService.GetEventResponses(_id, ModuleState.ModuleId);
|
||||
Console.WriteLine("Responses count: " + (_responses != null ? _responses.Count.ToString() : "null"));
|
||||
_refresh = true;
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
@ -101,6 +111,37 @@
|
||||
}
|
||||
}
|
||||
|
||||
protected override async Task OnAfterRenderAsync(bool firstRender)
|
||||
{
|
||||
try
|
||||
{
|
||||
await base.OnAfterRenderAsync(firstRender);
|
||||
|
||||
Console.WriteLine("Responses count: " + (_responses != null ? _responses.Count.ToString() : "null"));
|
||||
|
||||
if (_refresh && _responses != null)
|
||||
{
|
||||
List<string> labels = new List<string>();
|
||||
List<object> datasets = new List<object>();
|
||||
string[] colors = new string[] { "#FF0000", "#FF8000", "#FFFF00", "#00FF00", "#00FFFF", "#0080FF", "#0000FF", "#8000FF", "#FF00FF", "#CCCCCC" };
|
||||
|
||||
labels.AddRange("Zusage", "Absage");
|
||||
datasets.Add(new { label = "DS1", data = new int[] { _responses.Count(r => r.ResponseType == true), _responses.Count(r => r.ResponseType == false) }, fill = false, backgroundColor = colors });
|
||||
object options = new { maintainAspectRatio = false, legend = new { display = true, position = "bottom", labels = new { fontColor = "white", fontSize = 16 } } };
|
||||
|
||||
var interop = new Interop(JSRuntime);
|
||||
await interop.CreateChart("chart", "pie", labels.ToArray(), datasets.ToArray(), options);
|
||||
|
||||
_refresh = false;
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
await logger.LogError(ex, "Error Rendering Chart {Error}", ex.Message);
|
||||
AddModuleMessage("Error Rendering Chart", MessageType.Error);
|
||||
}
|
||||
}
|
||||
|
||||
private async Task Save()
|
||||
{
|
||||
try
|
||||
|
||||
@ -14,28 +14,7 @@ namespace SZUAbsolventenverein.Module.EventRegistration.Services
|
||||
public EventRegistrationService(HttpClient http, SiteState siteState) : base(http, siteState) { }
|
||||
|
||||
private string Apiurl => CreateApiUrl("EventRegistration");
|
||||
|
||||
/*public async Task<List<Models.Event>> GetEventRegistrationsAsync(int ModuleId)
|
||||
{
|
||||
List<Models.Event> EventRegistrations = await GetJsonAsync<List<Models.Event>>(CreateAuthorizationPolicyUrl($"{Apiurl}?moduleid={ModuleId}", EntityNames.Module, ModuleId), Enumerable.Empty<Models.Event>().ToList());
|
||||
return EventRegistrations.OrderBy(item => item.Name).ToList();
|
||||
}
|
||||
|
||||
public async Task<Models.Event> GetEventRegistrationAsync(int EventRegistrationId, int ModuleId)
|
||||
{
|
||||
return await GetJsonAsync<Models.Event>(CreateAuthorizationPolicyUrl($"{Apiurl}/{EventRegistrationId}/{ModuleId}", EntityNames.Module, ModuleId));
|
||||
}
|
||||
|
||||
public async Task<Models.Event> AddEventRegistrationAsync(Models.Event EventRegistration)
|
||||
{
|
||||
return await PostJsonAsync<Models.Event>(CreateAuthorizationPolicyUrl($"{Apiurl}", EntityNames.Module, EventRegistration.ModuleId), EventRegistration);
|
||||
}
|
||||
|
||||
public async Task<Models.Event> UpdateEventRegistrationAsync(Models.Event EventRegistration)
|
||||
{
|
||||
return await PutJsonAsync<Models.Event>(CreateAuthorizationPolicyUrl($"{Apiurl}/{EventRegistration.EventRegistrationId}", EntityNames.Module, EventRegistration.ModuleId), EventRegistration);
|
||||
}*/
|
||||
|
||||
|
||||
public async Task<List<Event>> GetEventsAsync(int ModuleId)
|
||||
{
|
||||
List<Event> EventRegistrations = await GetJsonAsync(CreateAuthorizationPolicyUrl($"{Apiurl}?moduleid={ModuleId}", EntityNames.Module, ModuleId), Enumerable.Empty<Event>().ToList());
|
||||
@ -51,9 +30,9 @@ namespace SZUAbsolventenverein.Module.EventRegistration.Services
|
||||
return await PostJsonAsync(CreateAuthorizationPolicyUrl($"{Apiurl}", EntityNames.Module, NewEvent.ModuleId), NewEvent);
|
||||
}
|
||||
|
||||
public async Task<Event> UpdateEventAsync(Event NewEvent)
|
||||
public async Task<Event> UpdateEventAsync(Event UpdatedEvent)
|
||||
{
|
||||
return await PutJsonAsync<Event>(CreateAuthorizationPolicyUrl($"{Apiurl}/{NewEvent.EventId}", EntityNames.Module, NewEvent.ModuleId), NewEvent);
|
||||
return await PutJsonAsync<Event>(CreateAuthorizationPolicyUrl($"{Apiurl}/{UpdatedEvent.EventId}", EntityNames.Module, UpdatedEvent.ModuleId), UpdatedEvent);
|
||||
}
|
||||
|
||||
public async Task DeleteEventAsync(int EventId, int ModuleId)
|
||||
@ -76,7 +55,12 @@ namespace SZUAbsolventenverein.Module.EventRegistration.Services
|
||||
return await GetJsonAsync<(Event, Response)>(CreateAuthorizationPolicyUrl($"{Apiurl}/details/{EventId}/{ModuleId}", EntityNames.Module, ModuleId));
|
||||
}
|
||||
|
||||
public Task<List<Response>> GetEventResponses(int EventId, int ModuleId)
|
||||
public async Task<List<Response>> GetEventResponses(int EventId, int ModuleId)
|
||||
{
|
||||
return await GetJsonAsync<List<Response>>(CreateAuthorizationPolicyUrl($"{Apiurl}/all-responses/{EventId}/{ModuleId}", EntityNames.Module, ModuleId));
|
||||
}
|
||||
|
||||
public Task<List<Response>> GetRecommendedEventResponses(int EventId, int MouleId)
|
||||
{
|
||||
throw new System.NotImplementedException();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user