Maschinenzuordnung funktionsfähig gemacht

This commit is contained in:
BuildTools 2024-02-07 19:53:05 +01:00
parent c86262ab02
commit 7fcd0c3247
2 changed files with 88 additions and 57 deletions

View File

@ -2,6 +2,8 @@
@using Microsoft.EntityFrameworkCore
@using CocktailWeb.Data
@using Microsoft.AspNetCore.Components.Sections
@using CocktailWeb.Shared
@inject IDbContextFactory<DbDataContext> DataContextFactory;
<PageTitle>Maschineneinstellungen</PageTitle>
@ -14,7 +16,7 @@
<div class="row pb-2 gap-2" style="height:45vh">
@foreach (Filler f in Fillers.Where(f => f.Type == Filler.FillerType.Pourer))
{
<a class="col border border-1 rounded-2 text-decoration-none text-light" href="#" data-bs-toggle="modal" data-bs-target="#examplemodal">
<a class="col border border-1 rounded-2 text-decoration-none text-light" @onclick="args => OpenSelectionDialog(args,f)">
@f.Pos - @f.Flasche?.Name
</a>
}
@ -24,64 +26,30 @@
<div class="row gap-2" style="height:25vh">
@foreach (Filler f in Fillers.Where(f => f.Type == Filler.FillerType.Pump))
{
<a class="col border border-1 rounded-2 text-decoration-none text-light" href="#" data-bs-toggle="modal" data-bs-target="#examplemodal">
<a class="col border border-1 rounded-2 text-decoration-none text-light" @onclick="args => OpenSelectionDialog(args,f)">
@f.Pos - @f.Flasche?.Name
</a>
}
</div>
</div>
<div class="modal fade" id="examplemodal" tabindex="-1" aria-hidden="true">
<div class="modal-dialog modal-dialog-centered modal-dialog-scrollable">
<div class="modal-content">
<div class="modal-header">
Testdialog
</div>
<div class="modal-body">
<ul class="list-group">
@if (Flaschen.Count == 0)
{
<li class="list-group-item list-group-item-action align-middle">
Es wurden noch keine Zutaten angelegt
</li>
}
else
{
@foreach (Flasche fl in Flaschen)
{
<li class="list-group-item list-group-item-action align-middle">
<label class="form-check-label stretched-link">@fl.Name</label>
</li>
}
}
</ul>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Abbrechen</button>
<button type="button" class="btn btn-primary">Speichern</button>
</div>
</div>
</div>
</div>
@code {
private DbDataContext? _DataContext;
private List<Filler> Fillers { get; set; } = new();
private List<Flasche> Flaschen { get; set; } = new();
protected override async Task OnInitializedAsync()
{
await ShowFillers();
}
private async Task ShowFillers()
{
_DataContext ??= await DataContextFactory.CreateDbContextAsync();
if (_DataContext != null)
{
Fillers = await _DataContext.Fillers.Include(f => f.Flasche).OrderBy(f => f.Pos).ToListAsync();
Flaschen = await _DataContext.Flaschen.OrderBy(fl => fl.Name).ToListAsync();
}
}
}
<ModalComponent @ref="modal">
<Title>Flasche auswählen</Title>
<Body>
<ul class="list-group">
<li class="list-group-item list-group-item-action align-middle @(SelectedFlasche == null ? "text-bg-success" : "")" @onclick="args => SelectFlasche(args,null)">
<label class="form-check-label stretched-link">(Leer)</label>
</li>
@foreach (Flasche fl in Flaschen)
{
<li class="list-group-item list-group-item-action align-middle @(SelectedFlasche == fl ? "text-bg-success" : "")" @onclick="args => SelectFlasche(args,fl)">
<label class="form-check-label stretched-link">@fl.Name</label>
</li>
}
</ul>
</Body>
<Footer>
<button type="button" class="btn btn-secondary" @onclick="CloseDialog">Abbrechen</button>
<button type="button" class="btn btn-primary" @onclick="SaveSelection">Speichern</button>
</Footer>
</ModalComponent>

View File

@ -1,6 +1,69 @@
namespace CocktailWeb.Pages.Settings
using CocktailWeb.Data;
using Microsoft.AspNetCore.Components.Web;
using Microsoft.EntityFrameworkCore;
namespace CocktailWeb.Pages.Settings
{
partial class Maschine
{
private DbDataContext? _DataContext;
private List<Filler> Fillers { get; set; } = new();
private List<Flasche> Flaschen { get; set; } = new();
private Filler? SelectedFiller { get; set; }
private Flasche? SelectedFlasche { get; set; }
private ModalComponent modal = null!;
protected override async Task OnInitializedAsync()
{
await ShowFillers();
}
private async Task ShowFillers()
{
_DataContext ??= await DataContextFactory.CreateDbContextAsync();
if (_DataContext != null)
{
Fillers = await _DataContext.Fillers.Include(f => f.Flasche).OrderBy(f => f.Pos).ToListAsync();
Flaschen = await _DataContext.Flaschen.OrderBy(fl => fl.Name).ToListAsync();
}
}
public async Task OpenSelectionDialog(MouseEventArgs e, Filler f)
{
SelectedFiller = f;
SelectedFlasche = f.Flasche;
await modal.OpenModal();
}
public void SelectFlasche(MouseEventArgs e, Flasche? fl)
{
SelectedFlasche = fl;
}
private async Task SaveSelection(MouseEventArgs e)
{
if (SelectedFiller != null)
{
SelectedFiller.Flasche = SelectedFlasche;
_DataContext ??= await DataContextFactory.CreateDbContextAsync();
if (_DataContext != null)
{
_DataContext.Fillers.Update(SelectedFiller);
await _DataContext.SaveChangesAsync();
}
}
await CloseDialog();
}
private async Task CloseDialog()
{
SelectedFiller = null;
SelectedFlasche = null;
await modal.Close();
}
}
}