Frontend navbar retrieves modules from database
This commit is contained in:
parent
bbb1df772b
commit
6ad23b3e14
9
src/PanoptesFrontend/Data/Module.cs
Normal file
9
src/PanoptesFrontend/Data/Module.cs
Normal file
@ -0,0 +1,9 @@
|
||||
public class Module {
|
||||
public String Name {get; set;}
|
||||
public String Container {get; set;}
|
||||
|
||||
public Module(string name, string container){
|
||||
Name = name;
|
||||
Container = container;
|
||||
}
|
||||
}
|
||||
@ -1,4 +1,8 @@
|
||||
<div class="top-row ps-3 navbar navbar-dark">
|
||||
@using PanoptesFrontend.Data
|
||||
@using System.Text.Json;
|
||||
@inject IHttpService httpService
|
||||
|
||||
<div class="top-row ps-3 navbar navbar-dark">
|
||||
<div class="container-fluid">
|
||||
<a class="navbar-brand" href="">PanoptesFrontend</a>
|
||||
<button title="Navigation menu" class="navbar-toggler" @onclick="ToggleNavMenu">
|
||||
@ -9,27 +13,29 @@
|
||||
|
||||
<div class="@NavMenuCssClass" @onclick="ToggleNavMenu">
|
||||
<nav class="flex-column">
|
||||
<div class="nav-item px-3">
|
||||
<NavLink class="nav-link" href="" Match="NavLinkMatch.All">
|
||||
<span class="oi oi-home" aria-hidden="true"></span> Home
|
||||
</NavLink>
|
||||
</div>
|
||||
<div class="nav-item px-3">
|
||||
<NavLink class="nav-link" href="counter">
|
||||
<span class="oi oi-plus" aria-hidden="true"></span> Counter
|
||||
</NavLink>
|
||||
</div>
|
||||
<div class="nav-item px-3">
|
||||
<NavLink class="nav-link" href="fetchdata">
|
||||
<span class="oi oi-list-rich" aria-hidden="true"></span> Fetch data
|
||||
</NavLink>
|
||||
</div>
|
||||
@if (response != null)
|
||||
{
|
||||
@foreach (var module in response){
|
||||
<div class="nav-item px-3">
|
||||
<NavLink class="nav-link" href="" Match="NavLinkMatch.All">
|
||||
<span class="oi oi-home" aria-hidden="true"></span> @module.Name
|
||||
</NavLink>
|
||||
</div>
|
||||
}
|
||||
}
|
||||
</nav>
|
||||
</div>
|
||||
|
||||
@code {
|
||||
private bool collapseNavMenu = true;
|
||||
|
||||
public Module[] response;
|
||||
|
||||
protected override async Task OnInitializedAsync()
|
||||
{
|
||||
response = await httpService.GetAsync<Module[]>("http://localhost:10000/modules");
|
||||
}
|
||||
|
||||
private bool collapseNavMenu = true;
|
||||
private string? NavMenuCssClass => collapseNavMenu ? "collapse" : null;
|
||||
|
||||
private void ToggleNavMenu()
|
||||
|
||||
@ -32,7 +32,7 @@ type Module struct {
|
||||
}
|
||||
|
||||
var Containers []Container
|
||||
var Modules []Module
|
||||
|
||||
|
||||
func homePage(w http.ResponseWriter, r *http.Request) {
|
||||
fmt.Fprintf(w, "Welcome to the home page!")
|
||||
@ -92,6 +92,7 @@ func getStats(w http.ResponseWriter, r *http.Request){
|
||||
func getModules(db *sql.DB) http.HandlerFunc{
|
||||
return func(w http.ResponseWriter, r *http.Request){
|
||||
if r.Method == "GET" {
|
||||
var Modules []Module
|
||||
rows, err := db.Query("Select name, container_name FROM Module")
|
||||
if err != nil {
|
||||
panic(err)
|
||||
@ -127,6 +128,7 @@ func handleRequests(DB *sql.DB) {
|
||||
}
|
||||
|
||||
|
||||
|
||||
func main() {
|
||||
DB := db.ConnectDB()
|
||||
handleRequests(DB)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user