Dasboard und Workspace-Anlage

This commit is contained in:
2026-05-29 12:35:16 +02:00
parent 2d05a18a0d
commit 818377c0a8
9 changed files with 421 additions and 25 deletions
+118 -25
View File
@@ -1,40 +1,133 @@
@page "/"
@using ZahlenAnalyse.Web.Models
@using ZahlenAnalyse.Web.Services
@using Microsoft.AspNetCore.Components.Authorization
@inject WorkspaceService DbService
@inject AuthenticationStateProvider AuthStateProvider
<MudText Typo="Typo.h3" Class="mb-4">Zahlen-Analyse</MudText>
<AuthorizeView>
<Authorized>
<MudText Typo="Typo.body1">Willkommen zurück, @context.User.Identity?.Name!</MudText>
<MudText Typo="Typo.body2" Color="Color.Secondary">Deine Pocket-ID (Sub): @_userId</MudText>
<MudContainer MaxWidth="MaxWidth.Large" Class="mt-8">
<MudStack Row="true" AlignItems="AlignItems.Center" Justify="Justify.SpaceBetween" Class="mb-8">
<MudText Typo="Typo.h3">Meine Workspaces</MudText>
<MudButton Href="/logout" Variant="Variant.Filled" Color="Color.Error" Class="mt-2">
Abmelden
</MudButton>
</Authorized>
<NotAuthorized>
<MudText Typo="Typo.body1" Class="mb-2">Bitte melde dich an, um deine Workspaces zu verwalten.</MudText>
<MudButton Href="/login" Variant="Variant.Filled" Color="Color.Primary">
Mit Pocket-ID anmelden
</MudButton>
</NotAuthorized>
</AuthorizeView>
<AuthorizeView>
<Authorized>
<MudButton Href="/workspaces/create"
Variant="Variant.Filled"
Color="Color.Primary"
StartIcon="@Icons.Material.Filled.Add">
Neuer Workspace
</MudButton>
</Authorized>
</AuthorizeView>
</MudStack>
<AuthorizeView>
<Authorized>
@if (_isLoading)
{
<MudProgressCircular Color="Color.Primary" Indeterminate="true" />
}
else if (!_workspaces.Any())
{
<MudPaper Class="pa-8 text-center" Elevation="1">
<MudIcon Icon="@Icons.Material.Filled.FolderOpen" Size="Size.Large" Color="Color.Default" Class="mb-4" />
<MudText Typo="Typo.h5" Class="mb-2">Noch keine Workspaces vorhanden</MudText>
<MudText Typo="Typo.body1" Color="Color.Secondary" Class="mb-6">
Erstelle deinen ersten Workspace (z.B. Urlaubsabrechnung), um mit der Datenanalyse zu beginnen.
</MudText>
<MudButton Href="/workspaces/create" Variant="Variant.Outlined" Color="Color.Primary">
Jetzt erstellen
</MudButton>
</MudPaper>
}
else
{
<MudGrid>
@foreach (var ws in _workspaces)
{
<MudItem xs="12" sm="6" md="4">
<MudCard Elevation="2" Class="h-100">
<MudCardHeader>
<CardHeaderContent>
<MudText Typo="Typo.h6">@ws.Name</MudText>
<MudText Typo="Typo.caption" Color="Color.Secondary">
Erstellt am @ws.CreatedAt.ToLocalTime().ToString("dd.MM.yyyy")
</MudText>
</CardHeaderContent>
<CardHeaderActions>
<MudIconButton Icon="@Icons.Material.Filled.Settings" Color="Color.Default" />
</CardHeaderActions>
</MudCardHeader>
<MudCardContent>
<MudText Typo="Typo.body2">
@ws.Dimensions.Count Dimensionen konfiguriert
</MudText>
<MudStack Row="true" Spacing="1" Class="mt-2 flex-wrap">
@foreach (var dim in ws.Dimensions.Take(3))
{
<MudChip T="string" Size="Size.Small" Variant="Variant.Outlined">@dim.Name</MudChip>
}
@if (ws.Dimensions.Count > 3)
{
<MudChip T="string" Size="Size.Small" Variant="Variant.Text">+@(ws.Dimensions.Count - 3)</MudChip>
}
</MudStack>
</MudCardContent>
<MudCardActions>
<MudButton Variant="Variant.Text" Color="Color.Primary">
Daten erfassen
</MudButton>
<MudButton Variant="Variant.Text" Color="Color.Secondary">
Auswertung
</MudButton>
</MudCardActions>
</MudCard>
</MudItem>
}
</MudGrid>
}
</Authorized>
<NotAuthorized>
<MudPaper Class="pa-8 text-center" Elevation="1">
<MudText Typo="Typo.h5" Class="mb-4">Willkommen beim Zahlen-Analyse Tool</MudText>
<MudText Typo="Typo.body1" Class="mb-6">Bitte melde dich an, um deine Daten zu verwalten.</MudText>
<MudButton Href="/login" Variant="Variant.Filled" Color="Color.Primary">
Mit Pocket-ID anmelden
</MudButton>
</MudPaper>
</NotAuthorized>
</AuthorizeView>
</MudContainer>
@code {
private string _userId = string.Empty;
private List<Workspace> _workspaces = new();
private bool _isLoading = true;
protected override async Task OnInitializedAsync()
{
var authState = await AuthStateProvider.GetAuthenticationStateAsync();
var user = authState.User;
if (user.Identity?.IsAuthenticated == true)
if (authState.User.Identity?.IsAuthenticated == true)
{
// Das ist der "sub"-Claim (Subject), den wir als OwnerId in RavenDB nutzen
_userId = user.FindFirst(c => c.Type == "http://schemas.xmlsoap.org/ws/2005/05/identity/claims/nameidentifier")?.Value
?? user.FindFirst("sub")?.Value
?? string.Empty;
await LoadWorkspaces();
}
else
{
_isLoading = false;
}
}
private async Task LoadWorkspaces()
{
_isLoading = true;
try
{
// Dank unseres Services reicht hier ein simpler Aufruf!
_workspaces = await DbService.GetWorkspacesForUserAsync();
}
finally
{
_isLoading = false;
}
}
}