Le foto venivano zippate tutte in un unico allegato: oltre i 100 MB i servizi rifiutavano l'invio (MaxUploadSizeExceededException) e, costruendo tutto in RAM sul thread della UI, il dispositivo si bloccava. - Invio diviso in più email da massimo ~40 MB ciascuna - Zip scritti su disco una parte alla volta e caricati in streaming - Preparazione in background, avanzamento "parte X di N" - Richiesta se includere le foto, con il loro peso (default: solo i log) - Database inviato insieme al file -wal - Avviso subito se si è offline Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
267 lines
10 KiB
Plaintext
267 lines
10 KiB
Plaintext
@page "/user"
|
|
@attribute [Authorize]
|
|
@using Microsoft.Extensions.Logging
|
|
@using SteUp.Shared.Components.Layout
|
|
@using SteUp.Shared.Components.Layout.Overlay
|
|
@using SteUp.Shared.Components.SingleElements
|
|
@using SteUp.Shared.Components.SingleElements.MessageBox
|
|
@using SteUp.Shared.Core.Authorization.Enum
|
|
@using SteUp.Shared.Core.Dto
|
|
@using SteUp.Shared.Core.Interface.IntegryApi
|
|
@using SteUp.Shared.Core.Interface.System
|
|
@using SteUp.Shared.Core.Services
|
|
@using SteUp.Shared.Core.Utility
|
|
@inject AppAuthenticationStateProvider AuthenticationStateProvider
|
|
@inject IGenericSystemService GenericSystemService
|
|
@inject IFileManager FileManager
|
|
@inject IIntegryApiService IntegryApiService
|
|
@inject ILogger<UserPage> Logger
|
|
|
|
<HeaderLayout Title="Profilo"/>
|
|
|
|
<div class="app-scroll">
|
|
<div class="page-width page-body stack stack-md">
|
|
|
|
@if (IsLoggedIn)
|
|
{
|
|
@* §6.16 Intestazione profilo *@
|
|
<section class="panel panel--lg">
|
|
<div class="profile-head">
|
|
<div class="profile-avatar" aria-hidden="true">
|
|
@UtilityString.ExtractInitials(UserSession.User.Fullname)
|
|
</div>
|
|
<div class="section-header__text">
|
|
<h2 class="summary__title">@UserSession.User.Fullname</h2>
|
|
@if (UserSession.User.KeyGroup is not null)
|
|
{
|
|
<p class="summary__subtitle">
|
|
@(((KeyGroupEnum)UserSession.User.KeyGroup).ConvertToHumanReadable())
|
|
</p>
|
|
}
|
|
</div>
|
|
</div>
|
|
</section>
|
|
|
|
<section class="panel">
|
|
<div class="nav-list__item" style="pointer-events: none;">
|
|
<i class="nav-list__icon ri-building-line" aria-hidden="true"></i>
|
|
<span class="nav-list__label">Profilo azienda</span>
|
|
<span class="t-meta">@CodHash</span>
|
|
</div>
|
|
|
|
<div class="nav-list__item" style="pointer-events: none;">
|
|
<i class="nav-list__icon ri-cloud-line" aria-hidden="true"></i>
|
|
<span class="nav-list__label">Connessione</span>
|
|
<Badge Spec="@ConnessioneBadge"/>
|
|
</div>
|
|
|
|
<div class="nav-list__item" style="pointer-events: none;">
|
|
<i class="nav-list__icon ri-information-line" aria-hidden="true"></i>
|
|
<span class="nav-list__label">Versione</span>
|
|
<span class="t-meta">@GenericSystemService.GetCurrentAppVersion()</span>
|
|
</div>
|
|
</section>
|
|
|
|
<section class="panel">
|
|
<button type="button" class="nav-list__item" @onclick="UpdateDb">
|
|
<i class="nav-list__icon ri-refresh-line" aria-hidden="true"></i>
|
|
<span class="nav-list__label">Sincronizza ispezioni esportate</span>
|
|
<i class="nav-list__chevron ri-arrow-right-s-line" aria-hidden="true"></i>
|
|
</button>
|
|
|
|
<button type="button" class="nav-list__item" @onclick="ExportLog">
|
|
<i class="nav-list__icon ri-file-upload-line" aria-hidden="true"></i>
|
|
<span class="nav-list__label">Invia i log allo sviluppo</span>
|
|
<i class="nav-list__chevron ri-arrow-right-s-line" aria-hidden="true"></i>
|
|
</button>
|
|
|
|
@* Le voci distruttive portano l'icona nel tono danger e non hanno chevron. *@
|
|
<button type="button" class="nav-list__item nav-list__item--danger" @onclick="ConfirmLogout">
|
|
<i class="nav-list__icon ri-logout-box-r-line" aria-hidden="true"></i>
|
|
<span class="nav-list__label">Esci</span>
|
|
</button>
|
|
</section>
|
|
}
|
|
</div>
|
|
</div>
|
|
|
|
<SpinnerOverlay VisibleOverlay="VisibleOverlay" Message="@_progressMessage"/>
|
|
<ConfirmMessageBox @ref="_logoutBox" Title="Uscire dall'account?" NoText="Annulla"
|
|
YesText="Esci" YesColor="Color.Error"
|
|
Message="Uscendo servirà di nuovo la connessione per rientrare. Le ispezioni salvate sul dispositivo restano al loro posto."/>
|
|
<ConfirmMessageBox @ref="_imagesBox" Title="Inviare anche le foto?" NoText="Annulla"
|
|
YesText="Solo i log" AltText="Includi le foto"
|
|
Message="@_imagesBoxMessage"/>
|
|
|
|
@code {
|
|
private bool IsLoggedIn { get; set; }
|
|
private bool VisibleOverlay { get; set; }
|
|
private string? _progressMessage;
|
|
private string? CodHash { get; set; } = "";
|
|
|
|
private ConfirmMessageBox _logoutBox = null!;
|
|
private ConfirmMessageBox _imagesBox = null!;
|
|
private string _imagesBoxMessage = string.Empty;
|
|
|
|
private Core.Helpers.StatusBadgeHelper.BadgeSpec ConnessioneBadge => NetworkService.ConnectionAvailable
|
|
? new Core.Helpers.StatusBadgeHelper.BadgeSpec("success", "ri-cloud-line", "Online")
|
|
: new Core.Helpers.StatusBadgeHelper.BadgeSpec("danger", "ri-wifi-off-line", "Offline");
|
|
|
|
protected override async Task OnInitializedAsync()
|
|
{
|
|
IsLoggedIn = await UserSession.IsLoggedIn();
|
|
CodHash = LocalStorage.GetString("codHash");
|
|
StateHasChanged();
|
|
}
|
|
|
|
private async Task ExportLog()
|
|
{
|
|
if (VisibleOverlay) return;
|
|
|
|
if (!NetworkService.ConnectionAvailable)
|
|
{
|
|
Snackbar.Add("Sei offline: per inviare i log serve la connessione.", Severity.Warning);
|
|
return;
|
|
}
|
|
|
|
var includeImages = await AskIncludeImages();
|
|
if (includeImages is null) return;
|
|
|
|
_progressMessage = "Preparazione dei log…";
|
|
VisibleOverlay = true;
|
|
StateHasChanged();
|
|
|
|
var partCount = 0;
|
|
var sentParts = 0;
|
|
|
|
try
|
|
{
|
|
// Un'email per parte: ogni parte resta sotto i limiti di upload dei servizi.
|
|
await using var export = await FileManager.PrepareLogExportAsync(includeImages.Value);
|
|
partCount = export.PartCount;
|
|
|
|
var profiloAzienda = LocalStorage.GetString("codHash");
|
|
var subject = $"SteUP - Log del {DateTime.Today:d} di {UserSession.User.Username}";
|
|
var body = $"Username: <b>{UserSession.User.Username}</b><br/>" +
|
|
$"Profilo azienda: <b>{profiloAzienda}</b><br/>" +
|
|
$"ProfileDb: <b>{UserSession.ProfileDb}</b><br/>" +
|
|
$"Versione app: <b>{GenericSystemService.GetCurrentAppVersion()}</b>";
|
|
|
|
for (var i = 0; i < partCount; i++)
|
|
{
|
|
var multiPart = partCount > 1;
|
|
|
|
_progressMessage = multiPart ? $"Invio dei log… parte {i + 1} di {partCount}" : "Invio dei log…";
|
|
StateHasChanged();
|
|
|
|
var attachments = await export.BuildPartAsync(i);
|
|
|
|
await IntegryApiService.SendEmail(new SendEmailDto
|
|
{
|
|
FromName = "Integry Log",
|
|
To = "developer@integry.it",
|
|
Subject = multiPart ? $"{subject} (parte {i + 1}/{partCount})" : subject,
|
|
IsHtml = true,
|
|
MsgText = multiPart ? $"{body}<br/>Parte: <b>{i + 1} di {partCount}</b>" : body,
|
|
Attachments = attachments
|
|
});
|
|
|
|
sentParts++;
|
|
}
|
|
|
|
Snackbar.Add(partCount > 1 ? $"Log inviati allo sviluppo in {partCount} parti" : "Log inviati allo sviluppo",
|
|
Severity.Success);
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
Logger.LogError(e, "Invio dei log interrotto dopo {Sent} parti su {Total}", sentParts, partCount);
|
|
Snackbar.Add(sentParts > 0
|
|
? $"Invio interrotto: inviate {sentParts} parti su {partCount}. Controlla la connessione e riprova."
|
|
: "Invio dei log non riuscito. Controlla la connessione e riprova.",
|
|
Severity.Error);
|
|
}
|
|
finally
|
|
{
|
|
VisibleOverlay = false;
|
|
_progressMessage = null;
|
|
StateHasChanged();
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Chiede se allegare le foto, indicando quanto pesano. Null = invio annullato.
|
|
/// Se sul dispositivo non ci sono foto non chiede niente.
|
|
/// </summary>
|
|
private async Task<bool?> AskIncludeImages()
|
|
{
|
|
long imagesSize;
|
|
|
|
_progressMessage = "Controllo delle foto…";
|
|
VisibleOverlay = true;
|
|
StateHasChanged();
|
|
|
|
try
|
|
{
|
|
imagesSize = await FileManager.GetLogExportImagesSizeAsync();
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
// Senza sapere quanto pesano, meglio un invio leggero che uno che rischia di fallire.
|
|
Logger.LogWarning(e, "Impossibile calcolare la dimensione delle foto da inviare");
|
|
imagesSize = 0;
|
|
}
|
|
finally
|
|
{
|
|
VisibleOverlay = false;
|
|
_progressMessage = null;
|
|
StateHasChanged();
|
|
}
|
|
|
|
if (imagesSize == 0) return false;
|
|
|
|
var sizeText = imagesSize < 1024 * 1024
|
|
? "meno di 1 MB"
|
|
: $"circa {imagesSize / (1024d * 1024):N0} MB";
|
|
_imagesBoxMessage = $"Le foto delle ispezioni occupano {sizeText}. Servono solo se il problema " +
|
|
"riguarda le foto: senza, l'invio è molto più veloce.";
|
|
StateHasChanged();
|
|
|
|
// "Solo i log" è la scelta consigliata (pulsante pieno, true); "Includi le foto" -> false.
|
|
var result = await _imagesBox.ShowAsync();
|
|
return result is null ? null : result == false;
|
|
}
|
|
|
|
private async Task UpdateDb()
|
|
{
|
|
_progressMessage = "Sincronizzazione…";
|
|
VisibleOverlay = true;
|
|
StateHasChanged();
|
|
|
|
try
|
|
{
|
|
await SteupDataService.CheckAndUpdateStatus();
|
|
Snackbar.Add("Ispezioni aggiornate", Severity.Success);
|
|
}
|
|
catch
|
|
{
|
|
Snackbar.Add("Sincronizzazione non riuscita. Controlla la connessione e riprova.", Severity.Error);
|
|
}
|
|
finally
|
|
{
|
|
VisibleOverlay = false;
|
|
_progressMessage = null;
|
|
StateHasChanged();
|
|
}
|
|
}
|
|
|
|
private async Task ConfirmLogout()
|
|
{
|
|
var result = await _logoutBox.ShowAsync();
|
|
if (result is not true) return;
|
|
|
|
await AuthenticationStateProvider.SignOut();
|
|
IsLoggedIn = await UserSession.IsLoggedIn();
|
|
StateHasChanged();
|
|
}
|
|
}
|