Refactoring; GeneralSettings-Klasse hinzugefügt

This commit is contained in:
BuildTools committed 2024-02-05 17:58:53 +01:00
1 parent 531c833e76
commit 6cd0f31ef9
21 files changed
+227 -71

No files matched your search

+37 -7
View File
@@ -1,16 +1,46 @@
@page "/cocktails/{CocktailId}"
@using CocktailWeb.Data
@using Microsoft.AspNetCore.Components.Sections
@using Microsoft.EntityFrameworkCore
@inject IDbContextFactory<DbDataContext> DataContextFactory;
@if(SelectedCocktail != null)
{
<h3>@SelectedCocktail.Name</h3>
} else
<SectionContent SectionId="TopRow.Title">
<a class="btn btn-primary" href="/cocktails">
<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-arrow-left-circle" viewBox="0 0 16 16">
<path fill-rule="evenodd" d="M1 8a7 7 0 1 0 14 0A7 7 0 0 0 1 8m15 0A8 8 0 1 1 0 8a8 8 0 0 1 16 0m-4.5-.5a.5.5 0 0 1 0 1H5.707l2.147 2.146a.5.5 0 0 1-.708.708l-3-3a.5.5 0 0 1 0-.708l3-3a.5.5 0 1 1 .708.708L5.707 7.5z" />
</svg>
Zurück
</a>
</SectionContent>
@if (SelectedCocktail == null)
{
<h3>Cocktail konnte nicht gefunden werden</h3>
<h3>Cocktail konnte nicht gefunden werden</h3>
}
else
{
<div class="card mb-3" style="max-width: 540px;">
<div class="row g-0">
<div class="col-md-4">
<img src="@SelectedCocktail.ImageURL" class="img-fluid rounded-start" alt="...">
</div>
<div class="col-md-8">
<div class="card-body">
<h5 class="card-title">@SelectedCocktail.Name</h5>
<p class="card-text">
<h6>Zutaten:</h6>
<ul>
@foreach (var Zutat in SelectedCocktail.Cocktailflaschen)
{
<li>@Zutat.Flasche?.Name (@Zutat.Menge ml)</li>
}
</ul>
</p>
</div>
</div>
</div>
</div>
}
@@ -28,7 +58,7 @@
_DataContext ??= await DataContextFactory.CreateDbContextAsync();
if (_DataContext != null)
{
SelectedCocktail = _DataContext.Cocktails.FirstOrDefault(c => c.Id == id);
SelectedCocktail = _DataContext.Cocktails.Include(c => c.Cocktailflaschen).ThenInclude(cf => cf.Flasche).Single(c => c.Id == id);
}
}
}
+12 -19
View File
@@ -1,23 +1,14 @@
@page "/cocktails"
@page "/"
@using CocktailWeb.Data
@using Microsoft.AspNetCore.Components.Sections
@using Microsoft.EntityFrameworkCore
@inject IDbContextFactory<DbDataContext> DataContextFactory;
@inject IWebHostEnvironment env;
<!--layout SideScrollLayout-->
<!--<h3>Cocktails</h3>-->
<PageTitle>Cocktails</PageTitle>
<SectionContent SectionId="TopRow.Title">
<label>Cocktails</label>
</SectionContent>
<!--
<p>
<a href="/cocktails/add">Cocktail hinzufügen</a>
</p>
-->
<!-- Flex Container für Horizontalen Scroll - klappt aber nicht so richtig->
<!--<div class="container py-2 border border-5 overflow-auto d-inline-block">
<div class="row flex-nowrap">-->
<div class="card-group gap-3 flex-nowrap">
@foreach (Cocktail c in CocktailListe)
@@ -25,14 +16,14 @@
<div class="col">
<a class="text-decoration-none text-black;" href="/cocktails/@c.Id">
<div class="card" style="width: 20vw; min-width:15rem; max-height:350px; ">
@if (c.ImageURL != null && File.Exists(Path.Join(env.WebRootPath, c.ImageURL)))
{
@if (c.ImageURL != null && File.Exists(Path.Join(env.WebRootPath, c.ImageURL)))
{
<img class="card-img-top" style="width:100%; min-height:70vh; object-fit:cover;" src="@($"/{c.ImageURL}")" alt="@c.Name">
}
else
{
}
else
{
<img class="card-img-top" style="width:100%; min-height:70vh; object-fit:cover;" src="@($"/img/cocktail-default.jpg")" alt="@c.Name">
}
<div class="card-footer">
@@ -46,4 +37,6 @@
</div>
}
</div>
</div>
+3 -1
View File
@@ -1,4 +1,4 @@
@page "/"
@page "/index"
<PageTitle>Index</PageTitle>
@@ -6,6 +6,8 @@
Welcome to your new app.
<a href="/cocktails">
Cocktails</a>
@code {
+5 -7
View File
@@ -1,10 +1,10 @@
@page "/serialtest"
@using System.IO.Ports
@using Microsoft.Extensions.Options
@inject IOptions<GeneralSettings> Config;
<PageTitle>Serial Test</PageTitle>
<label for="portname">Port:</label>
<InputText id="portname" @bind-Value="portname"></InputText>
<label for="inputdata">Data:</label>
<InputText id="inputdata" @bind-Value="inputdata"></InputText>
<button @onclick="SendData">Send</button>
@@ -16,7 +16,6 @@
@code {
SerialPort? port;
string? portname = "COM5";
string? receivedText;
string? inputdata ="LED";
@@ -24,15 +23,14 @@
bool Sending = false;
bool Receiving = false;
public async Task SendData()
{
if (Sending) return; // nichts senden, wenn bereits am Senden
Sending = true;
if (port == null && portname != null)
if (port == null && Config.Value.SerialPort != null)
{
port = new SerialPort(portname);
port.BaudRate = 115200; //9600
port = new SerialPort(Config.Value.SerialPort);
port.BaudRate = Config.Value.Baudrate; //9600
port.DataReceived += port_DataReceived;
//port.DataBits = 8;
//port.StopBits = StopBits.One;
@@ -1,10 +1,17 @@
@using Microsoft.EntityFrameworkCore
@using Microsoft.AspNetCore.Components.Sections
@using Microsoft.EntityFrameworkCore
@using CocktailWeb.Data
@page "/cocktails/add"
@using Microsoft.Extensions.Options
@page "/settings/cocktails/edit"
@page "/settings/cocktails/edit/{id}"
@inject IDbContextFactory<DbDataContext> DataContextFactory;
@inject NavigationManager nav;
@inject IWebHostEnvironment env;
<h3>Cocktail hinzufügen</h3>
@inject IOptions<GeneralSettings> Config;
<SectionContent SectionId="TopRow.Title">
<label>Cocktail hinzufügen</label>
</SectionContent>
<div class="d-flex gap-3">
@@ -69,7 +76,7 @@
</tbody>
</table>
<button @onclick="OnSubmit" class="btn btn-primary">Speichern</button>
<button @onclick="@(() => nav.NavigateTo("/cocktails"))" class="btn btn-secondary">Abbrechen</button>
<button @onclick="@(() => nav.NavigateTo("/settings/cocktails"))" class="btn btn-secondary">Abbrechen</button>
</div>
<div class="border border-2 rounded p-3 w-100">
@@ -1,28 +1,40 @@
using CocktailWeb;
using CocktailWeb.Data;
using CocktailWeb.Data;
using Microsoft.AspNetCore.Components;
using Microsoft.AspNetCore.Components.Forms;
using Microsoft.AspNetCore.Components.Web;
using Microsoft.EntityFrameworkCore;
namespace CocktailWeb.Pages
namespace CocktailWeb.Pages.Settings
{
public partial class CocktailHinzufuegen
{
[Parameter]
public string? id { get; set; }
public List<Flasche> FlaschenListe { get; set; } = new();
public Cocktail EditCocktail = new();
public Cocktail? EditCocktail;
private IBrowserFile? CocktaiLBildDatei;
private DbDataContext? _DataContext;
private int MaxAllowedUploadSizeInMB = 10;
private string ImageUploadDir = "cocktails";
protected override async Task OnInitializedAsync()
{
if (id != null)
{
_DataContext ??= await DataContextFactory.CreateDbContextAsync();
if (_DataContext != null)
{
EditCocktail = _DataContext.Cocktails.Include(c => c.Cocktailflaschen).ThenInclude(cf => cf.Flasche).Single(c => c.Id == Convert.ToInt32(id));
}
}
// Falls keine ID angegeben wurde oder der Cocktail in der Datenbank nicht gefunden wurde, gehen wir davon aus dass ein neuer Cocktail erstellt wird.
if (EditCocktail == null)
{
EditCocktail = new();
}
await FillFlaschenListe();
await InvokeAsync(StateHasChanged);
}
public async Task FillFlaschenListe()
@@ -36,13 +48,13 @@ namespace CocktailWeb.Pages
public void FlascheHinzufuegen(MouseEventArgs e, Flasche f)
{
EditCocktail.Cocktailflaschen.Add(new CocktailFlasche() { Flasche = f, Reihenfolge = EditCocktail.Cocktailflaschen.Count + 1 });
EditCocktail?.Cocktailflaschen.Add(new CocktailFlasche() { Flasche = f, Reihenfolge = EditCocktail.Cocktailflaschen.Count + 1 });
CocktailFlaschenSortieren();
}
public void FlascheEntfernen(MouseEventArgs e, CocktailFlasche cf)
{
EditCocktail.Cocktailflaschen.Remove(cf);
EditCocktail?.Cocktailflaschen.Remove(cf);
CocktailFlaschenSortieren();
}
@@ -85,12 +97,12 @@ namespace CocktailWeb.Pages
try
{
// Bild hochladen
var relativeuploadpath = Path.Join(ImageUploadDir, $"{EditCocktail.Id}{Path.GetExtension(CocktaiLBildDatei.Name)}");
var relativeuploadpath = Path.Join(Config.Value.ImageUploadDir, $"{EditCocktail.Id}{Path.GetExtension(CocktaiLBildDatei.Name)}");
var fullpath = Path.Join(env.WebRootPath, relativeuploadpath);
string? folder = Path.GetDirectoryName(fullpath);
if (folder != null && !Path.Exists(folder)) Directory.CreateDirectory(folder);
Stream stream = CocktaiLBildDatei.OpenReadStream(maxAllowedSize: MaxAllowedUploadSizeInMB * 1024 * 1024);
Stream stream = CocktaiLBildDatei.OpenReadStream(maxAllowedSize: Config.Value.MaxAllowedUploadSizeInMB * 1024 * 1024);
FileStream fs = File.Create(fullpath);
await stream.CopyToAsync(fs);
stream.Close();
@@ -0,0 +1,30 @@
@page "/settings/cocktails"
@using CocktailWeb.Data
@using Microsoft.AspNetCore.Components.Sections
@using Microsoft.EntityFrameworkCore
@inject IDbContextFactory<DbDataContext> DataContextFactory;
@inject IWebHostEnvironment env;
<!--layout SideScrollLayout-->
<!--<h3>Cocktails</h3>-->
<SectionContent SectionId="TopRow.Title">
<label>Einstellungen - Cocktails</label>
</SectionContent>
<a class="btn btn-primary mb-3" href="/settings/cocktails/edit">Cocktail hinzufügen</a>
<div class="table-responsive">
<table class="table table-striped table-hover table-bordered table-light border-dark">
<tbody>
@foreach (Cocktail c in CocktailListe)
{
<tr>
<td class="p-0"><img src="@c.ImageURL" style="max-height:40px;" /></td>
<td>@c.Name</td>
<td> <a class="btn btn-primary" href="/settings/cocktails/edit/@c.Id">Bearbeiten</a></td>
</tr>
}
</tbody>
</table>
</div>
@@ -0,0 +1,30 @@
using CocktailWeb;
using CocktailWeb.Data;
using Microsoft.AspNetCore.Components;
using Microsoft.AspNetCore.Components.Forms;
using Microsoft.AspNetCore.Components.Web;
using Microsoft.EntityFrameworkCore;
namespace CocktailWeb.Pages.Settings
{
public partial class Cocktails
{
private DbDataContext? _DataContext;
private List<Cocktail> CocktailListe { get; set; } = new();
protected override async Task OnInitializedAsync()
{
await ShowCocktails();
}
private async Task ShowCocktails()
{
_DataContext ??= await DataContextFactory.CreateDbContextAsync();
if (_DataContext != null)
{
CocktailListe = await _DataContext.Cocktails.OrderBy(f => f.Name).ToListAsync();
}
}
}
}
@@ -1,10 +1,16 @@
@using Microsoft.EntityFrameworkCore
@using Microsoft.AspNetCore.Components.Sections
@using Microsoft.EntityFrameworkCore
@using CocktailWeb.Data
@page "/flaschen"
@page "/settings/flaschen"
@inject IDbContextFactory<DbDataContext> FlascheDataContextFactory;
<PageTitle>Flaschen</PageTitle>
<SectionContent SectionId="TopRow.Title">
<label>Einstellungen - Zutaten</label>
</SectionContent>
@if (CreateFormVisible && FlascheToCreate != null)
{
<h3>Flasche hinzufügen</h3>
@@ -16,7 +22,7 @@
</div>
<div class="form-group row">
<div class="offset-4 col-8">
<button name="submit" type="submit" class="btn btn-primary" @onclick="CreateNewFlasche">Submit</button>
<button name="submit" type="submit" class="btn btn-primary" @onclick="CreateNewFlasche">Hinzufügen</button>
</div>
</div>
}
@@ -29,15 +35,13 @@ else
</div>
}
<h3>Flaschen</h3>
@if (FlaschenListe != null && FlaschenListe.Count > 0)
{
<div class="table-responsive">
<table class="table table-striped table-hover table-bordered table-light border-dark">
<thead>
<tr>
<th scope="col">ID</th>
<!--<th scope="col">ID</th>-->
<th scope="col">Name</th>
<th scope="col">Action</th>
</tr>
@@ -48,20 +52,20 @@ else
@if (EditFormVisible && FlascheToUpdate != null && FlascheToUpdate.Id == flasche.Id)
{
<tr>
<th scope="row">@FlascheToUpdate.Id</th>
<!-- <th scope="row">@FlascheToUpdate.Id</th>-->
<td> <input id="Name" name="Name" type="text" class="form-control" @bind="@FlascheToUpdate.Name" /></td>
<td><button name="submit" type="submit" class="btn btn-primary" @onclick="() => UpdateEmployee(FlascheToUpdate)">Save</button></td>
<td><button name="submit" type="submit" class="btn btn-primary" @onclick="() => UpdateEmployee(FlascheToUpdate)">Speichern</button></td>
</tr>
}
else
{
<tr>
<th scope="row">@flasche.Id</th>
<!-- <th scope="row">@flasche.Id</th> -->
<td>@flasche.Name</td>
<td>
<button name="submit" type="submit" class="btn btn-primary" @onclick="() => ShowEditForm(flasche)">Edit</button>
<button name="submit" type="submit" class="btn btn-primary" @onclick="() => DeleteFlasche(flasche)">Delete</button>
</td>
<button name="submit" type="submit" class="btn btn-primary" @onclick="() => ShowEditForm(flasche)">Bearbeiten</button>
<button name="submit" type="submit" class="btn btn-primary" @onclick="() => DeleteFlasche(flasche)">Löschen</button>
</td>
</tr>
}
}
@@ -2,7 +2,7 @@
using Microsoft.EntityFrameworkCore;
using CocktailWeb.Data;
namespace CocktailWeb.Pages
namespace CocktailWeb.Pages.Settings
{
public partial class Flaschen
{
+13
View File
@@ -0,0 +1,13 @@
@page "/settings/maschine";
@using Microsoft.EntityFrameworkCore
@using CocktailWeb.Data
@using Microsoft.AspNetCore.Components.Sections
@inject IDbContextFactory<DbDataContext> FlascheDataContextFactory;
<PageTitle>Maschine</PageTitle>
<SectionContent SectionId="TopRow.Title">
<label>Einstellungen - Maschine</label>
</SectionContent>
@@ -0,0 +1,6 @@
namespace CocktailWeb.Pages.Settings
{
partial class Maschine
{
}
}