diff --git a/src/PanoptesFrontend/Data/Component.cs b/src/PanoptesFrontend/Data/Component.cs index 2fc7f06..f351ade 100644 --- a/src/PanoptesFrontend/Data/Component.cs +++ b/src/PanoptesFrontend/Data/Component.cs @@ -1,13 +1,25 @@ -public class Component { - public int Type {get; set;} - public string Text {get; set;} - public Stats[] Stats {get; set;} +using System.Collections.Generic; +public class TableComponent { + public int Id {get; set;} + public List> Data { get; set; } + public TableComponent(int id, List> data){ + Id = id; + Data = data; + } +} - public Component(int type, string text, Stats[] stats){ - Type = type; - Text = text; - Stats = stats; +public class GraphComponent { + public int Id {get; set;} + public string Graph {get; set;} + public string Title {get; set;} + public List Stats { get; set; } + + public GraphComponent(int id, string graph, string title, List stats){ + Id = id; + Graph = graph; + Title = title; + Stats = stats; } } \ No newline at end of file diff --git a/src/PanoptesFrontend/Data/Schema.cs b/src/PanoptesFrontend/Data/Schema.cs index dfee85c..fc5104d 100644 --- a/src/PanoptesFrontend/Data/Schema.cs +++ b/src/PanoptesFrontend/Data/Schema.cs @@ -1,3 +1,4 @@ public class Schema { - public Component[] components {get; set;} + public TableComponent[] tables {get; set;} + public GraphComponent[] graphs {get; set;} } \ No newline at end of file diff --git a/src/PanoptesFrontend/Pages/DynamicChart.razor b/src/PanoptesFrontend/Pages/DynamicChart.razor new file mode 100644 index 0000000..fcc2096 --- /dev/null +++ b/src/PanoptesFrontend/Pages/DynamicChart.razor @@ -0,0 +1,68 @@ +@using ApexCharts +@using System.Collections.Generic +@using PanoptesFrontend.Data; +@using System.Timers +@implements IDisposable +@inject IHttpService httpService +@using PanoptesFrontend.Services + + + + + + + +@code { + private ApexChart chart; + private bool timerInitialized; + private Timer timer; + private Dictionary SeriesTypes = new Dictionary + { + {"line", SeriesType.Line}, + {"area", SeriesType.Area}, + {"bar", SeriesType.Bar}, + {"pie", SeriesType.Pie}, + {"donut", SeriesType.Donut}, + {"radial-bar", SeriesType.RadialBar}, + }; + [Parameter] + public string ChartTitle {get; set;} + [Parameter] + public List StatsList { get; set; } + [Parameter] + public string SelectedChartType {get; set;} + [Parameter] + public int ChartId {get; set;} + + protected override void OnAfterRender(bool firstRender) + { + if (firstRender && !timerInitialized) + { + timerInitialized = true; + timer = new Timer(5000); + timer.Elapsed += async delegate { await UpdateChartSeries(); }; + timer.Enabled = true; + } + } + + private async Task UpdateChartSeries() + { + string module = "localhost:8080"; + var response = await httpService.GetAsync($"http://localhost:10000/{module}/{ChartId}"); + StatsList = response.Stats; + await chart.UpdateSeriesAsync(true); + await InvokeAsync(() => StateHasChanged()); + } + + public void Dispose() + { + timer?.Stop(); + timer = null; + } +} diff --git a/src/PanoptesFrontend/Pages/DynamicTable.razor b/src/PanoptesFrontend/Pages/DynamicTable.razor new file mode 100644 index 0000000..f06cffc --- /dev/null +++ b/src/PanoptesFrontend/Pages/DynamicTable.razor @@ -0,0 +1,77 @@ +@using System.Linq.Dynamic.Core +@inject IHttpService httpService +@using PanoptesFrontend.Services + + + + @foreach(var column in columns) + { + + + + } + + + + +@code { + IList> selectedItems; + + [Parameter] + public List> data { get; set; } + [Parameter] + public int TableId {get; set;} + + public IDictionary columns { get; set; } + public string GetColumnPropertyExpression(string name, Type type) + { + var expression = $@"it[""{name}""].ToString()"; + + if (type == typeof(int)) + { + return $"int.Parse({expression})"; + } + else if (type == typeof(DateTime)) + { + return $"DateTime.Parse({expression})"; + } + + return expression; + } + + protected override async Task OnInitializedAsync() + { + // Generate the columns dynamically based on the properties of the first object in the list + var firstItem = data.FirstOrDefault(); + if (firstItem != null) + { + columns = firstItem.ToDictionary(p => p.Key, p => p.Value.GetType()); + + foreach (var column in columns.ToList()) + { + if (column.Value != typeof(int) && column.Value != typeof(DateTime)) + { + columns[column.Key] = typeof(string); + } + } + } + } + + private async Task Update() + { + string module = "localhost:8080"; + + var response = await httpService.GetAsync($"http://localhost:10000/{module}/{TableId}"); + + if (response.Data != null) + { + data.Clear(); + data.AddRange(response.Data); + } + await InvokeAsync(() => StateHasChanged()); + } +} \ No newline at end of file diff --git a/src/PanoptesFrontend/Pages/Logout.razor b/src/PanoptesFrontend/Pages/Logout.razor new file mode 100644 index 0000000..f82ab67 --- /dev/null +++ b/src/PanoptesFrontend/Pages/Logout.razor @@ -0,0 +1,16 @@ +@using PanoptesFrontend.Data.Account; +@using PanoptesFrontend.Services; +@inject IAccountService AccountService + + + + + +@code { + private string token; + private async Task LogoutButtonClick() + { + token = await AccountService.GetTokenFromLocalStorage(); + await AccountService.Logout(token); + } +} diff --git a/src/PanoptesFrontend/Pages/ModDisplay.razor b/src/PanoptesFrontend/Pages/ModDisplay.razor new file mode 100644 index 0000000..a5e6d0d --- /dev/null +++ b/src/PanoptesFrontend/Pages/ModDisplay.razor @@ -0,0 +1,58 @@ +@page "/test" + +@using System.Net; +@using PanoptesFrontend.Data +@using PanoptesFrontend.Services +@using System.Text.Json; +@using Microsoft.AspNetCore.Components.Web +@inject IHttpService httpService +@inject IJSRuntime JSRuntime + +@if (tables != null | graphs != null) +{ +
+
+
+ @foreach (var component in tables) + { +
+
+ +
+
+ } +
+
+ @foreach (var component in graphs) + { +
+
+ +
+
+ } +
+
+
+ +} + + +@code { + private TableComponent[] tables; + private GraphComponent[] graphs; + + private string module = "localhost:8080"; + + protected async override Task OnInitializedAsync() + { + var schema = await httpService.GetAsync($"http://localhost:10000/{module}/schema"); + tables = schema.tables; + graphs = schema.graphs; + } + +} + diff --git a/src/PanoptesFrontend/Pages/QueryInput.razor b/src/PanoptesFrontend/Pages/QueryInput.razor new file mode 100644 index 0000000..74bee37 --- /dev/null +++ b/src/PanoptesFrontend/Pages/QueryInput.razor @@ -0,0 +1,16 @@ +@inject IHttpService httpService +@using PanoptesFrontend.Services + + + + +@code { + string sqlQuery; + + private async Task ExecuteSqlQuery() + { + // Send the SQL query to your backend and handle the response + var response = await httpService.PostAsync($"http://localhost:10000/sqlquery", sqlQuery); + + } +} \ No newline at end of file diff --git a/src/PanoptesFrontend/Pages/TestCard.razor b/src/PanoptesFrontend/Pages/TestCard.razor deleted file mode 100644 index 13fccaf..0000000 --- a/src/PanoptesFrontend/Pages/TestCard.razor +++ /dev/null @@ -1,10 +0,0 @@ -
-
-

@Data.Text

-
-
- -@code { - [Parameter] - public Component Data { get; set; } -} diff --git a/src/PanoptesFrontend/Pages/TestRequest.razor b/src/PanoptesFrontend/Pages/TestRequest.razor deleted file mode 100644 index fb3d290..0000000 --- a/src/PanoptesFrontend/Pages/TestRequest.razor +++ /dev/null @@ -1,47 +0,0 @@ -@page "/test" - -@using System.Net; -@using PanoptesFrontend.Data -@using PanoptesFrontend.Services -@using System.Text.Json; -@inject IHttpService httpService - -@if (data != null) -{ - @foreach (var component in data) { - switch (component.Type) { - case 0: - - break; - case 1: - - - - - break; - } - - } -} - - -@code { - private Component[] data; - - - - protected override async Task OnInitializedAsync() - { - var response = await httpService.GetAsync("http://localhost:10000/localhost:8080/schema"); - data = response.components; - } - -} - diff --git a/src/PanoptesFrontend/Pages/_Host.cshtml b/src/PanoptesFrontend/Pages/_Host.cshtml index 3d1ede5..110f53c 100644 --- a/src/PanoptesFrontend/Pages/_Host.cshtml +++ b/src/PanoptesFrontend/Pages/_Host.cshtml @@ -7,5 +7,7 @@ + + diff --git a/src/PanoptesFrontend/PanoptesFrontend.csproj b/src/PanoptesFrontend/PanoptesFrontend.csproj index 839378d..828d37e 100644 --- a/src/PanoptesFrontend/PanoptesFrontend.csproj +++ b/src/PanoptesFrontend/PanoptesFrontend.csproj @@ -12,6 +12,7 @@ + diff --git a/src/PanoptesFrontend/Program.cs b/src/PanoptesFrontend/Program.cs index 66258be..adfeda8 100644 --- a/src/PanoptesFrontend/Program.cs +++ b/src/PanoptesFrontend/Program.cs @@ -9,6 +9,7 @@ var builder = WebApplication.CreateBuilder(args); builder.Services.AddRazorPages(); builder.Services.AddServerSideBlazor(); builder.Services.AddHttpClient(); +builder.Services.AddScoped(); builder.Services.AddScoped(); builder.Services.AddScoped(); builder.Services.AddBlazoredLocalStorage(); diff --git a/src/PanoptesFrontend/Services/AccountService.cs b/src/PanoptesFrontend/Services/AccountService.cs index 21a3915..d2658cd 100644 --- a/src/PanoptesFrontend/Services/AccountService.cs +++ b/src/PanoptesFrontend/Services/AccountService.cs @@ -9,7 +9,8 @@ public interface IAccountService { Task Register(AddUser model); Task Login(LoginUser model); - Task Logout(User model); + Task Logout(string token); + Task GetTokenFromLocalStorage(); } @@ -38,8 +39,16 @@ public class AccountService : IAccountService await localStorage.SetItemAsync("authToken", token); } - public async Task Logout(User model){ - await httpService.PostAsync("http://localhost:10000/user/logout", model); + public async Task Logout(string token){ + + var authtoken = await localStorage.GetItemAsStringAsync("authToken"); + + await httpService.PostAsync("http://localhost:10000/user/logout", authtoken); await localStorage.RemoveItemAsync("authToken"); } + + public async Task GetTokenFromLocalStorage() + { + return await localStorage.GetItemAsStringAsync("authToken"); + } } \ No newline at end of file diff --git a/src/PanoptesFrontend/Services/HttpService.cs b/src/PanoptesFrontend/Services/HttpService.cs index 30171a8..98d863d 100644 --- a/src/PanoptesFrontend/Services/HttpService.cs +++ b/src/PanoptesFrontend/Services/HttpService.cs @@ -15,8 +15,9 @@ public class HttpService : IHttpService { private readonly HttpClient httpClient; - public HttpService(HttpClient httpClient){ - this.httpClient = httpClient; + public HttpService(IHttpClientFactory httpClientFactory) + { + this.httpClient = httpClientFactory.CreateClient(); } public async Task GetAsync(string endpoint){ diff --git a/src/PanoptesFrontend/Shared/MainLayout.razor b/src/PanoptesFrontend/Shared/MainLayout.razor index b599e70..df8e5b5 100644 --- a/src/PanoptesFrontend/Shared/MainLayout.razor +++ b/src/PanoptesFrontend/Shared/MainLayout.razor @@ -1,4 +1,5 @@ @inherits LayoutComponentBase +@using PanoptesFrontend.Pages PanoptesFrontend @@ -9,11 +10,12 @@
- About + Login +
@Body
- + \ No newline at end of file diff --git a/src/PanoptesFrontend/Shared/NavMenu.razor b/src/PanoptesFrontend/Shared/NavMenu.razor index 50bf19d..2a47b6b 100644 --- a/src/PanoptesFrontend/Shared/NavMenu.razor +++ b/src/PanoptesFrontend/Shared/NavMenu.razor @@ -5,7 +5,7 @@