Projektdateien hinzufügen.

This commit is contained in:
BuildTools committed 2024-09-01 21:12:09 +02:00
1 parent 0682df4d16
commit 749bdb5179
142 files changed
+63622

No files matched your search

+21
View File
@@ -0,0 +1,21 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<base href="/" />
<link rel="stylesheet" href="bootstrap/css/bootstrap.css" />
<link rel="stylesheet" href="app.css" />
<link rel="stylesheet" href="FWLAZ_Web.styles.css" />
<link rel="icon" type="image/png" href="favicon.png" />
<HeadOutlet @rendermode="InteractiveServer" />
</head>
<body>
<Routes @rendermode="InteractiveServer" />
<script src="_framework/blazor.web.js"></script>
<script src="bootstrap/js/bootstrap.js"></script>
</body>
</html>
@@ -0,0 +1,23 @@
@inherits LayoutComponentBase
<div class="page">
<div class="sidebar">
<NavMenu />
</div>
<main>
<div class="top-row px-4">
<a href="https://learn.microsoft.com/aspnet/core/" target="_blank">About</a>
</div>
<article class="content px-4">
@Body
</article>
</main>
</div>
<div id="blazor-error-ui">
An unhandled error has occurred.
<a href="" class="reload">Reload</a>
<a class="dismiss">🗙</a>
</div>
@@ -0,0 +1,96 @@
.page {
position: relative;
display: flex;
flex-direction: column;
}
main {
flex: 1;
}
.sidebar {
background-image: linear-gradient(180deg, rgb(5, 39, 103) 0%, #3a0647 70%);
}
.top-row {
background-color: #f7f7f7;
border-bottom: 1px solid #d6d5d5;
justify-content: flex-end;
height: 3.5rem;
display: flex;
align-items: center;
}
.top-row ::deep a, .top-row ::deep .btn-link {
white-space: nowrap;
margin-left: 1.5rem;
text-decoration: none;
}
.top-row ::deep a:hover, .top-row ::deep .btn-link:hover {
text-decoration: underline;
}
.top-row ::deep a:first-child {
overflow: hidden;
text-overflow: ellipsis;
}
@media (max-width: 640.98px) {
.top-row {
justify-content: space-between;
}
.top-row ::deep a, .top-row ::deep .btn-link {
margin-left: 0;
}
}
@media (min-width: 641px) {
.page {
flex-direction: row;
}
.sidebar {
width: 250px;
height: 100vh;
position: sticky;
top: 0;
}
.top-row {
position: sticky;
top: 0;
z-index: 1;
}
.top-row.auth ::deep a:first-child {
flex: 1;
text-align: right;
width: 0;
}
.top-row, article {
padding-left: 2rem !important;
padding-right: 1.5rem !important;
}
}
#blazor-error-ui {
background: lightyellow;
bottom: 0;
box-shadow: 0 -1px 2px rgba(0, 0, 0, 0.2);
display: none;
left: 0;
padding: 0.6rem 1.25rem 0.7rem 1.25rem;
position: fixed;
width: 100%;
z-index: 1000;
}
#blazor-error-ui .dismiss {
cursor: pointer;
position: absolute;
right: 0.75rem;
top: 0.5rem;
}
+35
View File
@@ -0,0 +1,35 @@
<div class="top-row ps-3 navbar navbar-dark">
<div class="container-fluid">
<a class="navbar-brand" href="">FWLAZ_Web</a>
</div>
</div>
<input type="checkbox" title="Navigation menu" class="navbar-toggler" />
<div class="nav-scrollable" onclick="document.querySelector('.navbar-toggler').click()">
<nav class="flex-column">
<div class="nav-item px-3">
<NavLink class="nav-link" href="" Match="NavLinkMatch.All">
<span class="bi bi-house-door-fill-nav-menu" aria-hidden="true"></span> Home
</NavLink>
</div>
<div class="nav-item px-3">
<NavLink class="nav-link" href="counter">
<span class="bi bi-plus-square-fill-nav-menu" aria-hidden="true"></span> Counter
</NavLink>
</div>
<div class="nav-item px-3">
<NavLink class="nav-link" href="weather">
<span class="bi bi-list-nested-nav-menu" aria-hidden="true"></span> Weather
</NavLink>
</div>
<div class="nav-item px-3">
<NavLink class="nav-link" href="settings/quizzes">
<span class="bi bi-list-nested-nav-menu" aria-hidden="true"></span> Quizzes
</NavLink>
</div>
</nav>
</div>
@@ -0,0 +1,105 @@
.navbar-toggler {
appearance: none;
cursor: pointer;
width: 3.5rem;
height: 2.5rem;
color: white;
position: absolute;
top: 0.5rem;
right: 1rem;
border: 1px solid rgba(255, 255, 255, 0.1);
background: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 30 30'%3e%3cpath stroke='rgba%28255, 255, 255, 0.55%29' stroke-linecap='round' stroke-miterlimit='10' stroke-width='2' d='M4 7h22M4 15h22M4 23h22'/%3e%3c/svg%3e") no-repeat center/1.75rem rgba(255, 255, 255, 0.1);
}
.navbar-toggler:checked {
background-color: rgba(255, 255, 255, 0.5);
}
.top-row {
height: 3.5rem;
background-color: rgba(0,0,0,0.4);
}
.navbar-brand {
font-size: 1.1rem;
}
.bi {
display: inline-block;
position: relative;
width: 1.25rem;
height: 1.25rem;
margin-right: 0.75rem;
top: -1px;
background-size: cover;
}
.bi-house-door-fill-nav-menu {
background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' fill='white' class='bi bi-house-door-fill' viewBox='0 0 16 16'%3E%3Cpath d='M6.5 14.5v-3.505c0-.245.25-.495.5-.495h2c.25 0 .5.25.5.5v3.5a.5.5 0 0 0 .5.5h4a.5.5 0 0 0 .5-.5v-7a.5.5 0 0 0-.146-.354L13 5.793V2.5a.5.5 0 0 0-.5-.5h-1a.5.5 0 0 0-.5.5v1.293L8.354 1.146a.5.5 0 0 0-.708 0l-6 6A.5.5 0 0 0 1.5 7.5v7a.5.5 0 0 0 .5.5h4a.5.5 0 0 0 .5-.5Z'/%3E%3C/svg%3E");
}
.bi-plus-square-fill-nav-menu {
background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' fill='white' class='bi bi-plus-square-fill' viewBox='0 0 16 16'%3E%3Cpath d='M2 0a2 2 0 0 0-2 2v12a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V2a2 2 0 0 0-2-2H2zm6.5 4.5v3h3a.5.5 0 0 1 0 1h-3v3a.5.5 0 0 1-1 0v-3h-3a.5.5 0 0 1 0-1h3v-3a.5.5 0 0 1 1 0z'/%3E%3C/svg%3E");
}
.bi-list-nested-nav-menu {
background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' fill='white' class='bi bi-list-nested' viewBox='0 0 16 16'%3E%3Cpath fill-rule='evenodd' d='M4.5 11.5A.5.5 0 0 1 5 11h10a.5.5 0 0 1 0 1H5a.5.5 0 0 1-.5-.5zm-2-4A.5.5 0 0 1 3 7h10a.5.5 0 0 1 0 1H3a.5.5 0 0 1-.5-.5zm-2-4A.5.5 0 0 1 1 3h10a.5.5 0 0 1 0 1H1a.5.5 0 0 1-.5-.5z'/%3E%3C/svg%3E");
}
.nav-item {
font-size: 0.9rem;
padding-bottom: 0.5rem;
}
.nav-item:first-of-type {
padding-top: 1rem;
}
.nav-item:last-of-type {
padding-bottom: 1rem;
}
.nav-item ::deep .nav-link {
color: #d7d7d7;
background: none;
border: none;
border-radius: 4px;
height: 3rem;
display: flex;
align-items: center;
line-height: 3rem;
width: 100%;
}
.nav-item ::deep a.active {
background-color: rgba(255,255,255,0.37);
color: white;
}
.nav-item ::deep .nav-link:hover {
background-color: rgba(255,255,255,0.1);
color: white;
}
.nav-scrollable {
display: none;
}
.navbar-toggler:checked ~ .nav-scrollable {
display: block;
}
@media (min-width: 641px) {
.navbar-toggler {
display: none;
}
.nav-scrollable {
/* Never collapse the sidebar for wide screens */
display: block;
/* Allow sidebar to scroll for tall menus */
height: calc(100vh - 3.5rem);
overflow-y: auto;
}
}
+18
View File
@@ -0,0 +1,18 @@
@page "/counter"
<PageTitle>Counter</PageTitle>
<h1>Counter</h1>
<p role="status">Current count: @currentCount</p>
<button class="btn btn-primary" @onclick="IncrementCount">Click me</button>
@code {
private int currentCount = 0;
private void IncrementCount()
{
currentCount++;
}
}
+36
View File
@@ -0,0 +1,36 @@
@page "/Error"
@using System.Diagnostics
<PageTitle>Error</PageTitle>
<h1 class="text-danger">Error.</h1>
<h2 class="text-danger">An error occurred while processing your request.</h2>
@if (ShowRequestId)
{
<p>
<strong>Request ID:</strong> <code>@RequestId</code>
</p>
}
<h3>Development Mode</h3>
<p>
Swapping to <strong>Development</strong> environment will display more detailed information about the error that occurred.
</p>
<p>
<strong>The Development environment shouldn't be enabled for deployed applications.</strong>
It can result in displaying sensitive information from exceptions to end users.
For local debugging, enable the <strong>Development</strong> environment by setting the <strong>ASPNETCORE_ENVIRONMENT</strong> environment variable to <strong>Development</strong>
and restarting the app.
</p>
@code{
[CascadingParameter]
private HttpContext? HttpContext { get; set; }
private string? RequestId { get; set; }
private bool ShowRequestId => !string.IsNullOrEmpty(RequestId);
protected override void OnInitialized() =>
RequestId = Activity.Current?.Id ?? HttpContext?.TraceIdentifier;
}
+7
View File
@@ -0,0 +1,7 @@
@page "/"
<PageTitle>Home</PageTitle>
<h1>Hello, world!</h1>
Welcome to your new app.
@@ -0,0 +1,51 @@
<div class="modal @modalClass" tabindex="-1" role="dialog" style="display:@modalDisplay; overflow-y: auto;">
<div class="modal-dialog modal-dialog-centered modal-dialog-scrollable">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title">@Title</h5>
</div>
<div class="modal-body">
@Body
</div>
<div class="modal-footer">
@Footer
</div>
</div>
</div>
</div>
@if (showBackdrop)
{
<div class="modal-backdrop fade show"></div>
}
@code {
[Parameter]
public RenderFragment? Title { get; set; }
[Parameter]
public RenderFragment? Body { get; set; }
[Parameter]
public RenderFragment? Footer { get; set; }
private string modalDisplay = "none;";
private string modalClass = "";
private bool showBackdrop = false;
public async Task ShowAsync()
{
modalDisplay = "block;";
await Task.Delay(100);//Delay allows bootstrap to perform nice fade animation
modalClass = "show";
showBackdrop = true;
}
public async Task CloseAsync()
{
modalDisplay = "none";
await Task.Delay(250);//Delay allows bootstrap to perform nice fade animation
modalClass = "";
showBackdrop = false;
}
}
@@ -0,0 +1,90 @@
@page "/settings/quizzes/edit"
@page "/settings/quizzes/edit/{id}"
@using FWLAZ_Web.Data
@using Microsoft.EntityFrameworkCore
@inject IDbContextFactory<LocalDbContext> DbFactory;
@inject NavigationManager nav;
<h3>QuizEdit</h3>
<div class="d-flex gap-3">
<div class="border border-2 rounded p-3 w-100">
<div class="mb-3">
<label class="form-label" for="name">Name</label>
<input id="name" name="name" type="text" class="form-control" @bind="@SelectedItem.Name" />
</div>
<h3>Question Groups</h3>
<div class="input-group m-3">
<input id="qgnew" name="qgnew" type="text" class="form-control" @bind="@NewQuestionGroup" />
<button @onclick="AddQuestionGroup" class="btn btn-primary">Add</button>
</div>
<div class="m-3">
@foreach (QuestionGroup qg in SelectedItem.Questiongroups)
{
<div class="row">
<div class="col-sm-1">
<input class="form-control col-sm" type="number" @bind="qg.Order" />
</div>
<div class="col-sm">
<input class="form-control" type="text" @bind="qg.Name" />
</div>
</div>
}
</div>
<button @onclick="OnSubmit" class="btn btn-primary">Save</button>
<button @onclick="@(() => nav.NavigateTo(PrevURL))" class="btn btn-secondary">Cancel</button>
</div>
</div>
@code {
[Parameter]
public string? id { get; set; }
private LocalDbContext? DbContext;
public Quiz SelectedItem = null!;
private string? NewQuestionGroup;
private string PrevURL = "/settings/quizzes";
protected override async Task OnInitializedAsync()
{
if (id != null)
{
DbContext ??= await DbFactory.CreateDbContextAsync();
if (DbContext != null) SelectedItem = DbContext.Quiz.Include(qu => qu.Questiongroups).Single(qu => qu.Id == Convert.ToInt32(id));
}
SelectedItem ??= new();
//await InvokeAsync(StateHasChanged);
}
private async Task OnSubmit(EventArgs e)
{
DbContext ??= await DbFactory.CreateDbContextAsync();
if (SelectedItem == null || DbContext == null)
{
// nav.NavigateTo(PrevURL);
return;
}
if (id != null)
{
DbContext.Quiz.Update(SelectedItem);
}
else
{
DbContext.Quiz.Add(SelectedItem);
}
await DbContext.SaveChangesAsync();
nav.NavigateTo(PrevURL);
}
private void AddQuestionGroup(MouseEventArgs e)
{
if (NewQuestionGroup != null && NewQuestionGroup.Trim().Length > 0)
{
SelectedItem.Questiongroups.Add(new QuestionGroup(NewQuestionGroup));
NewQuestionGroup = null;
}
}
}
@@ -0,0 +1,271 @@
@page "/settings/quizzes/questions/{id}"
@using FWLAZ_Web.Data
@using Microsoft.EntityFrameworkCore;
@inject IDbContextFactory<LocalDbContext> DbFactory;
@inject NavigationManager nav;
<h1>Questions for '@SelectedItem.Name'</h1>
<button type="button" @onclick="SaveQuiz" class="btn btn-primary">Save</button>
<div class="border border-2 rounded p-3 w-100 m-3">
<h3>New Question</h3>
<h3>Questiongroups</h3>
@foreach (QuestionGroupSelect qg in questionGroups)
{
<div class="form-check form-check-inline">
<input class="form-check-input" type="checkbox" @bind="qg.Checked" />
<label class="form-check-label">@qg.questionGroup.Name</label>
</div>
}
<div class="row">
<div class="col-sm-1">
<input class="form-control col-sm" type="number" @bind="NewQuestion.Number" />
</div>
<div class="col-sm">
<input class="form-control" type="text" @ref="txtNewQuestionText" @bind="NewQuestion.Text" />
</div>
</div>
<h3>Answers</h3>
@foreach (Answer aw in NewQuestion.Answers)
{
<div class="input-group mb-3">
<div class="input-group-text">
<input class="form-check-input mt-0" type="checkbox" @bind="aw.IsCorrect" @onkeyup="AddQuestion_Enter" />
</div>
<input class="form-control col-sm" style="max-width:70px;" type="text" @bind="aw.Position" @onkeyup="AddQuestion_Enter" />
<input class="form-control" type="text" @bind="aw.Text" @onkeyup="AddQuestion_Enter" />
<button class="btn btn-outline-secondary" type="button" @onclick="() => RemoveAnswer(NewQuestion, aw)">Remove</button>
</div>
}
<button type="button" @onclick="AddQuestion" class="btn btn-primary">Add Question</button>
<button type="button" @onclick="() => AddAnswerBox(NewQuestion)" class="btn btn-secondary">More Answers</button>
</div>
<div class="border border-2 rounded p-3 w-100 m-3">
<h3>Existing Questions</h3>
<div class="accordion" id="accordion_questions">
@{
int tabcount = 1;
}
@foreach (Question question in SelectedItem.Questions)
{
<div class="accordion-item">
<h2 class="accordion-header">
<button class="accordion-button collapsed" type="button" data-bs-toggle="collapse" data-bs-target="#collapse_@tabcount" aria-expanded="false" aria-controls="collapse_@tabcount">
@question.Number. @question.Text
</button>
</h2>
<div id="collapse_@tabcount" class="accordion-collapse collapse" data-bs-parent="#accordion_questions">
<div class="accordion-body">
<div class="row">
<div class="col-sm-1">
<input class="form-control col-sm" type="number" @bind="question.Number" />
</div>
<div class="col-sm">
<input class="form-control" type="text" @bind="question.Text" />
</div>
</div>
<h3>Question groups</h3>
<div class="d-flex gap-3">
<div class="border border-2 rounded p-3 w-100">
<h4>Added</h4>
<ul class="list-group">
@foreach (QuestionGroupSelect qgs in questionGroups.Where(qgs => question.QuestionGroups.Any(qg => qg.Id == qgs.questionGroup.Id)))
{
<li class="list-group-item list-group-item-action align-middle z-0" @onclick="args => RemoveQuestionGroup(question, qgs.questionGroup)">
<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-dash-circle text-danger" viewBox="0 0 16 16">
<path d="M8 15A7 7 0 1 1 8 1a7 7 0 0 1 0 14m0 1A8 8 0 1 0 8 0a8 8 0 0 0 0 16" />
<path d="M4 8a.5.5 0 0 1 .5-.5h7a.5.5 0 0 1 0 1h-7A.5.5 0 0 1 4 8" />
</svg>
<label class="form-check-label stretched-link">@qgs.questionGroup.Name</label>
</li>
}
</ul>
</div>
<div class="border border-2 rounded p-3 w-100">
<h4>Remaining</h4>
<ul class="list-group">
@foreach (QuestionGroupSelect qgs in questionGroups.Where(qgs => question.QuestionGroups.Any(qg => qg.Id == qgs.questionGroup.Id) == false))
{
<li class="list-group-item list-group-item-action align-middle z-0" @onclick="args => AddQuestionGroup(question, qgs.questionGroup)">
<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-plus-circle text-success" viewBox="0 0 16 16">
<path d="M8 15A7 7 0 1 1 8 1a7 7 0 0 1 0 14m0 1A8 8 0 1 0 8 0a8 8 0 0 0 0 16" />
<path d="M8 4a.5.5 0 0 1 .5.5v3h3a.5.5 0 0 1 0 1h-3v3a.5.5 0 0 1-1 0v-3h-3a.5.5 0 0 1 0-1h3v-3A.5.5 0 0 1 8 4" />
</svg>
<label class="form-check-label stretched-link">@qgs.questionGroup.Name</label>
</li>
}
</ul>
</div>
</div>
<h3>Answers</h3>
@foreach (Answer aw in question.Answers)
{
<div class="input-group mb-3">
<div class="input-group-text">
<input class="form-check-input mt-0" type="checkbox" @bind="aw.IsCorrect" />
</div>
<input class="form-control col-sm" style="max-width:70px;" type="text" @bind="aw.Position" />
<input class="form-control" type="text" @bind="aw.Text" />
<button class="btn btn-outline-secondary" type="button" @onclick="() => RemoveAnswer(question, aw)">Remove</button>
</div>
}
<button @onclick="() => AddAnswerBox(question)" class="btn btn-primary">More Answers</button>
<button @onclick="() => RemoveQuestion(question)" class="btn btn-danger">Delete question</button>
</div>
</div>
</div>
tabcount++;
}
</div>
</div>
@code {
[Parameter]
public string Id { get; set; } = null!;
ElementReference txtNewQuestionText;
public Quiz SelectedItem { get; set; } = null!;
private Question NewQuestion = null!;
private int DefaultAnswerCount = 3;
private List<QuestionGroupSelect> questionGroups = new();
private string PrevURL = "/settings/quizzes";
private LocalDbContext? DbContext;
protected override async Task OnInitializedAsync()
{
DbContext ??= await DbFactory.CreateDbContextAsync();
if (DbContext == null) return;
SelectedItem = DbContext.Quiz.Include(q => q.Questiongroups).ThenInclude(qg => qg.Questions).ThenInclude(qu => qu.Answers).Single(q => q.Id == Convert.ToInt32(Id));
foreach (QuestionGroup qg in SelectedItem.Questiongroups)
{
questionGroups.Add(new(qg));
}
PrepareNewQuestion();
}
private void PrepareNewQuestion()
{
NewQuestion = new();
if (SelectedItem.Questions.Count > 0) {
NewQuestion.Number = SelectedItem.Questions.Max(q => q.Number) + 1;
} else
{
NewQuestion.Number = 1;
}
NewQuestion.Quiz = SelectedItem;
for (int i = 0; i < DefaultAnswerCount; i++)
{
AddAnswerBox(NewQuestion);
}
}
private async Task AddQuestion_Enter(KeyboardEventArgs e)
{
if (e.Code == "Enter" || e.Code == "NumpadEnter") await AddQuestion(new MouseEventArgs());
}
private async Task AddQuestion(MouseEventArgs e)
{
NewQuestion.Answers.RemoveAll(aw => aw.Text == null || aw.Text.Trim().Length == 0);
if (NewQuestion.Answers.Count == 0 ||
NewQuestion.Text == null ||
NewQuestion.Text.Trim().Length == 0 ||
NewQuestion.Answers.Count(aw => aw.IsCorrect) == 0 ||
questionGroups.Count(qg => qg.Checked == true) == 0
) return;
foreach (QuestionGroupSelect qgs in questionGroups.Where(qg => qg.Checked))
{
NewQuestion.QuestionGroups.Add(qgs.questionGroup);
}
DefaultAnswerCount = NewQuestion.Answers.Count;
SelectedItem.Questions.Add(NewQuestion);
PrepareNewQuestion();
await txtNewQuestionText.FocusAsync();
}
private void RemoveAnswer(Question question, Answer answer)
{
question.Answers.Remove(answer);
}
private void AddAnswerBox(Question question)
{
char CurLetter = 'a';
for (int i = 0; i < question.Answers.Count; i++)
{
CurLetter = NextChar(CurLetter);
}
question.Answers.Add(new() { Position = CurLetter.ToString() });
}
private void RemoveQuestion(Question question)
{
SelectedItem.Questions.Remove(question);
}
private void RemoveQuestionGroup(Question question, QuestionGroup questionGroup)
{
question.QuestionGroups.Remove(questionGroup);
}
private void AddQuestionGroup(Question question, QuestionGroup questionGroup)
{
if (question.QuestionGroups.Any(qg => qg.Id == questionGroup.Id)) return;
question.QuestionGroups.Add(questionGroup);
}
private char NextChar(char StartLetter)
{
if (StartLetter == 'z')
{
return 'a';
}
else if (StartLetter == 'Z')
{
return 'A';
}
else
{
return (char)(((int)StartLetter) + 1);
}
}
public class QuestionGroupSelect
{
public bool Checked { get; set; }
public QuestionGroup questionGroup { get; }
public QuestionGroupSelect(QuestionGroup questionGroup)
{
this.questionGroup = questionGroup;
}
}
private async Task SaveQuiz(MouseEventArgs e)
{
foreach (Question question in SelectedItem.Questions)
{
question.Answers.RemoveAll(aw => aw.Text == null || aw.Text.Trim().Length == 0);
}
DbContext ??= await DbFactory.CreateDbContextAsync();
if (DbContext == null) return;
DbContext.Quiz.Update(SelectedItem);
await DbContext.SaveChangesAsync();
nav.NavigateTo(PrevURL);
}
}
@@ -0,0 +1,87 @@
@page "/settings/quizzes"
@using FWLAZ_Web.Data
@using Microsoft.EntityFrameworkCore
@inject IDbContextFactory<LocalDbContext> DbFactory ;
<h3>Quizzes</h3>
<a class="btn btn-primary mb-3" href="/settings/quizzes/edit">Neues Quiz</a>
<div class="table-responsive">
<table class="table table-striped table-hover table-bordered table-dark border-dark">
<tbody>
@foreach (Quiz q in QuizList)
{
<tr>
<td style="vertical-align:middle;">@q.Name</td>
<td style="text-align:right; vertical-align:middle;">
<a class="btn btn-primary" href="/settings/quizzes/questions/@q.Id">Fragen</a>
<a class="btn btn-primary" href="/settings/quizzes/edit/@q.Id">Bearbeiten</a>
<button name="submit" type="submit" class="btn btn-outline-danger" @onclick="() => ConfirmDelete(q)">Löschen</button>
</td>
</tr>
}
</tbody>
</table>
</div>
<ModalComponent @ref="modal">
<Title>Löschen bestätigen</Title>
<Body>
Willst du das Quiz wirklich löschen?
</Body>
<Footer>
<button class="btn btn-danger" @onclick="DeleteItem">Ja</button>
<button class="btn btn-primary" @onclick="CloseDialog">Nein</button>
</Footer>
</ModalComponent>
@code {
private LocalDbContext? DataContext;
private ModalComponent modal = null!;
private Quiz? SelectedItem;
private List<Quiz> QuizList { get; set; } = new();
protected override async Task OnInitializedAsync()
{
await ShowList();
}
private async Task ShowList()
{
DataContext ??= await DbFactory.CreateDbContextAsync();
if (DataContext != null)
{
QuizList = await DataContext.Quiz.OrderBy(q => q.Name).ToListAsync();
}
}
private async Task ConfirmDelete(Quiz itm)
{
SelectedItem = itm;
await modal.ShowAsync();
}
private async Task CloseDialog()
{
SelectedItem = null;
await modal.CloseAsync();
}
private async Task DeleteItem(MouseEventArgs e)
{
if (SelectedItem != null)
{
DataContext ??= await DbFactory.CreateDbContextAsync();
if (DataContext != null)
{
DataContext.Quiz.Remove(SelectedItem);
await DataContext.SaveChangesAsync();
await ShowList();
}
}
await CloseDialog();
}
}
+63
View File
@@ -0,0 +1,63 @@
@page "/weather"
<PageTitle>Weather</PageTitle>
<h1>Weather</h1>
<p>This component demonstrates showing data.</p>
@if (forecasts == null)
{
<p><em>Loading...</em></p>
}
else
{
<table class="table">
<thead>
<tr>
<th>Date</th>
<th>Temp. (C)</th>
<th>Temp. (F)</th>
<th>Summary</th>
</tr>
</thead>
<tbody>
@foreach (var forecast in forecasts)
{
<tr>
<td>@forecast.Date.ToShortDateString()</td>
<td>@forecast.TemperatureC</td>
<td>@forecast.TemperatureF</td>
<td>@forecast.Summary</td>
</tr>
}
</tbody>
</table>
}
@code {
private WeatherForecast[]? forecasts;
protected override async Task OnInitializedAsync()
{
// Simulate asynchronous loading to demonstrate a loading indicator
await Task.Delay(500);
var startDate = DateOnly.FromDateTime(DateTime.Now);
var summaries = new[] { "Freezing", "Bracing", "Chilly", "Cool", "Mild", "Warm", "Balmy", "Hot", "Sweltering", "Scorching" };
forecasts = Enumerable.Range(1, 5).Select(index => new WeatherForecast
{
Date = startDate.AddDays(index),
TemperatureC = Random.Shared.Next(-20, 55),
Summary = summaries[Random.Shared.Next(summaries.Length)]
}).ToArray();
}
private class WeatherForecast
{
public DateOnly Date { get; set; }
public int TemperatureC { get; set; }
public string? Summary { get; set; }
public int TemperatureF => 32 + (int)(TemperatureC / 0.5556);
}
}
+6
View File
@@ -0,0 +1,6 @@
<Router AppAssembly="typeof(Program).Assembly">
<Found Context="routeData">
<RouteView RouteData="routeData" DefaultLayout="typeof(Layout.MainLayout)" />
<FocusOnNavigate RouteData="routeData" Selector="h1" />
</Found>
</Router>
+10
View File
@@ -0,0 +1,10 @@
@using System.Net.Http
@using System.Net.Http.Json
@using Microsoft.AspNetCore.Components.Forms
@using Microsoft.AspNetCore.Components.Routing
@using Microsoft.AspNetCore.Components.Web
@using static Microsoft.AspNetCore.Components.Web.RenderMode
@using Microsoft.AspNetCore.Components.Web.Virtualization
@using Microsoft.JSInterop
@using FWLAZ_Web
@using FWLAZ_Web.Components