This commit is contained in:
Markus 2024-09-21 16:19:49 +02:00
commit 7b9d778eb3
29 changed files with 4876 additions and 0 deletions

26
Pages/Counter.razor Normal file
View file

@ -0,0 +1,26 @@
@page "/counter"
<PageTitle>Counter</PageTitle>
<h2>Counter</h2>
<p role="status">Current count: @_currentCount</p>
<button class="btn btn-primary" @onclick="IncrementCount">Click me (+@_increment)</button>
@code {
private const int MinIncrement = 1;
private const int MaxIncrement = 10;
private int _increment = MinIncrement;
private int _currentCount;
private void IncrementCount()
{
_currentCount += _increment++;
if(_increment >= MaxIncrement)
{
_increment = MinIncrement;
}
}
}

61
Pages/Departments.razor Normal file
View file

@ -0,0 +1,61 @@
@page "/departments"
@inject HttpClient Http
<PageTitle>Departments</PageTitle>
<h2>Departments</h2>
<div class="dept-container">
@if (_initialized)
{
if (_departments is not null)
{
<table class="table table-striped table-hover">
<thead>
<tr>
<th>ID</th>
<th>Name</th>
<th>Programs</th>
</tr>
</thead>
<tbody>
@foreach (var department in _departments)
{
<tr>
<td>@department.Id</td>
<td>@department.Name</td>
<td>
@if (department.Programs.Length == 0)
{
<span>-</span>
}
else
{
<ul>
@foreach (var program in department.Programs)
{
<li>@program</li>
}
</ul>
}
</td>
</tr>
}
</tbody>
</table>
}
else
{
<span class="warning-text">Data could not be loaded!</span>
}
}
else
{
<div class="progress">
<div class="progress-bar progress-bar-striped progress-bar-animated" role="progressbar" style="width: 100%" aria-valuenow="100" aria-valuemin="0" aria-valuemax="100"></div>
</div>
}
</div>
@code {
}

View file

@ -0,0 +1,37 @@
using System.Net.Http.Json;
namespace HerbalGarden.Pages;
public sealed partial class Departments
{
private bool _initialized;
private Department[]? _departments;
protected override async Task OnInitializedAsync()
{
_initialized = false;
await base.OnInitializedAsync();
await LoadData();
_initialized = true;
}
private async Task LoadData()
{
try
{
// fake some delay to simulate network latency
await Task.Delay(1000);
_departments = await Http.GetFromJsonAsync<Department[]>("data/departments.json");
}
catch (HttpRequestException e)
{
Console.WriteLine($"Failed to load data via HTTP: {e.StatusCode}");
}
}
private sealed record Department(int Id, string Name, string[] Programs);
}

View file

@ -0,0 +1,7 @@
.dept-container {
max-width: 50rem;
}
.warning-text {
color: red;
}

7
Pages/Home.razor Normal file
View file

@ -0,0 +1,7 @@
@page "/"
<PageTitle>Home</PageTitle>
<h2>Hello, next level student!</h2>
Welcome to your new pages application.