Neue Version

This commit is contained in:
MarcWieland 2025-11-19 00:47:06 +01:00
parent 92e92142ce
commit b1604775fc
3 changed files with 64 additions and 4 deletions

View File

@ -12,6 +12,17 @@
<i class="bi bi-geo-alt me-2"></i> Stationen der Fabrik
</h4>
@if (isPreloadingFilters)
{
<div class="alert alert-info d-flex align-items-center mt-3">
<div class="spinner-border spinner-border-sm me-3" role="status"></div>
<div>
<strong>Offline-Modus wird vorbereitet…</strong><br>
<small>Lade alle Filter dieses Kunden (@preloadedCount von @totalStations Stationen)</small>
</div>
</div>
}
<!-- QR Scanner -->
<div class="text-center mb-4">
<video id="video" autoplay playsinline class="border rounded shadow-sm"
@ -77,9 +88,13 @@
private string? scanResult;
private bool isLoading = true;
private bool isPreloadingFilters = false;
private int preloadedCount = 0;
private int totalStations = 0;
protected override async Task OnInitializedAsync()
{
await LoadStations();
await LoadStationsAndPreloadAllFilters();
}
protected override async Task OnAfterRenderAsync(bool firstRender)
@ -90,23 +105,64 @@
}
}
private async Task LoadStations()
private async Task LoadStationsAndPreloadAllFilters()
{
isLoading = true;
StateHasChanged();
try
{
isLoading = true;
// 1. Stationen laden
stations = await StationService.GetStationsByCustomerAsync(customerId);
totalStations = stations.Count;
if (stations.Count == 0)
{
isLoading = false;
StateHasChanged();
return;
}
// 2. Sofort alle Filter aller Stationen vorladen (parallel!)
isPreloadingFilters = true;
preloadedCount = 0;
StateHasChanged();
var preloadTasks = stations.Select(async station =>
{
try
{
// Lädt Filter + speichert automatisch im IndexedDB (durch deinen Cache-Mechanismus)
await FilterService.GetFiltersByStationAsync(station.Id);
preloadedCount++;
StateHasChanged(); // Live-Update des Fortschritts
}
catch (Exception ex)
{
Console.WriteLine($"Preload Fehler für Station {station.Id}: {ex.Message}");
}
});
await Task.WhenAll(preloadTasks);
await JS.InvokeVoidAsync("showToast",
$"✅ {preloadedCount} Stationen + alle Filter offline verfügbar!",
"success");
}
catch (Exception ex)
{
Console.WriteLine($"❌ Fehler beim Laden der Stationen: {ex.Message}");
await JS.InvokeVoidAsync("showToast", "Teilweise offline verfügbar", "warning");
Console.WriteLine(ex);
}
finally
{
isLoading = false;
isPreloadingFilters = false;
StateHasChanged();
}
}
private void SelectStation(StationModel s)
{
Nav.NavigateTo($"/stations/{customerId}/filters/{s.Id}");

Binary file not shown.

View File

@ -6,4 +6,8 @@
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Newtonsoft.Json" Version="13.0.4" />
</ItemGroup>
</Project>