7099f02b60
MudDialogProvider aveva NoHeader="true" come valore predefinito di tutti i dialog. MudMessageBox rende il proprio titolo nella testata, quindi quel valore lo sopprimeva ovunque: davanti a "Elimina" si leggeva solo il testo delle conseguenze, senza la domanda. Le schermate a tutto schermo (form scheda, scelta punto vendita, scelta articoli) chiedono gia' NoHeader per conto loro nelle DialogOptions, quindi toglierlo dal provider non le tocca. I titoli ora dicono cosa sta per succedere invece del generico "Attenzione!": "Eliminare la scheda?", "Uscire dall'account?", "Inviare le schede del reparto?". Le scelte in fondo al dialog si dispongono a destra e, sotto i 380 punti, diventano una colonna a piena larghezza: con etichette lunghe come "Salva come bozza" i bersagli non si comprimono. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
264 lines
9.4 KiB
Plaintext
264 lines
9.4 KiB
Plaintext
@using SteUp.Shared.Components.SingleElements.MessageBox
|
|
@using SteUp.Shared.Core.Dto
|
|
@using SteUp.Shared.Core.Entities
|
|
@using SteUp.Shared.Core.Enum
|
|
@using SteUp.Shared.Core.Helpers
|
|
@using SteUp.Shared.Core.Interface.IntegryApi
|
|
@using SteUp.Shared.Core.Interface.LocalDb
|
|
@using SteUp.Shared.Core.Interface.System
|
|
@using Microsoft.Extensions.Logging
|
|
@inject IIspezioniService IspezioniService
|
|
@inject IIntegrySteupService IntegrySteupService
|
|
@inject IDialogService Dialog
|
|
@inject IFileManager FileManager
|
|
@inject ILogger<SchedaCard> Logger
|
|
|
|
<div class="list-card" aria-label="@SemanticLabel">
|
|
<div class="list-card__head">
|
|
<div class="list-card__ident">
|
|
<div class="t-ident">@Scheda.DescrizioneReparto</div>
|
|
<h3 class="list-card__title">@Titolo</h3>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="list-card__badges badge-row">
|
|
<Badge Spec="@SyncState.ToBadge()"/>
|
|
<Badge Spec="@ScadenzaBadge" />
|
|
</div>
|
|
|
|
@if (!Scheda.Note.IsNullOrEmpty())
|
|
{
|
|
<p class="list-card__meta t-prose">@Scheda.Note</p>
|
|
}
|
|
|
|
<div class="list-card__footer">
|
|
<i class="icon ri-qr-code-line" aria-hidden="true"></i>
|
|
<span>@ArticoliLabel</span>
|
|
<span aria-hidden="true">·</span>
|
|
<i class="icon ri-camera-line" aria-hidden="true"></i>
|
|
<span>@FotoLabel</span>
|
|
</div>
|
|
|
|
<div class="list-card__actions">
|
|
@if (ReadOnly)
|
|
{
|
|
<MudButton Variant="Variant.Outlined" FullWidth="true"
|
|
StartIcon="@Icons.Material.Rounded.Visibility" OnClick="@ViewScheda">
|
|
Apri
|
|
</MudButton>
|
|
|
|
@if (Scheda.ImageNames?.Count > 0)
|
|
{
|
|
<MudButton Variant="Variant.Filled" Color="Color.Primary" FullWidth="true"
|
|
StartIcon="@Icons.Material.Rounded.CloudUpload" OnClick="@ExportImg">
|
|
Invia foto
|
|
</MudButton>
|
|
}
|
|
}
|
|
else
|
|
{
|
|
<MudButton Variant="Variant.Outlined" FullWidth="true"
|
|
StartIcon="@Icons.Material.Rounded.Edit" OnClick="@UpdateScheda">
|
|
@(IsBozza ? "Completa" : "Modifica")
|
|
</MudButton>
|
|
|
|
@if (NetworkService.IsNetworkAvailable() && SyncState == Core.Helpers.SyncState.DaInviare)
|
|
{
|
|
<MudButton Variant="Variant.Filled" Color="Color.Primary" FullWidth="true"
|
|
StartIcon="@Icons.Material.Rounded.CloudUpload" OnClick="@ExportScheda">
|
|
Invia
|
|
</MudButton>
|
|
}
|
|
}
|
|
</div>
|
|
|
|
@if (!ReadOnly)
|
|
{
|
|
<MudButton Class="mt-2" Variant="Variant.Text" FullWidth="true"
|
|
StartIcon="@Icons.Material.Rounded.DeleteOutline"
|
|
Style="color: var(--danger-ink)" OnClick="@DeleteScheda">
|
|
Elimina scheda
|
|
</MudButton>
|
|
}
|
|
</div>
|
|
|
|
<ConfirmMessageBox @ref="_messageBox" Title="Eliminare la scheda?" NoText="Annulla"
|
|
YesText="Elimina" YesColor="Color.Error"
|
|
Message="La scheda verrà eliminata dal dispositivo e, se già inviata, anche dal server. L'operazione non è reversibile."/>
|
|
|
|
@code{
|
|
[Parameter] public Ispezione Ispezione { get; set; } = new();
|
|
[Parameter] public required Scheda Scheda { get; set; }
|
|
[Parameter] public EventCallback<Scheda> OnSchedaModified { get; set; }
|
|
[Parameter] public EventCallback<Scheda> OnSchedaDeleted { get; set; }
|
|
[Parameter] public EventCallback<bool> OnBusyChanged { get; set; }
|
|
|
|
private ConfirmMessageBox _messageBox = null!;
|
|
private bool _busy;
|
|
|
|
private bool ReadOnly => Ispezione.Stato == StatusEnum.Completata;
|
|
private SyncState SyncState => Scheda.GetSyncState();
|
|
private bool IsBozza => SyncState == Core.Helpers.SyncState.Bozza;
|
|
|
|
// Una bozza puo' non avere ancora il motivo: meglio dirlo che lasciare un vuoto.
|
|
private string Titolo => Scheda.ActivityTypeId.IsNullOrEmpty()
|
|
? "Motivo da indicare"
|
|
: Scheda.ActivityTypeId!;
|
|
|
|
private StatusBadgeHelper.BadgeSpec ScadenzaBadge => (ScadenzaEnum)Scheda.Scadenza switch
|
|
{
|
|
ScadenzaEnum.Altissima24Ore => new StatusBadgeHelper.BadgeSpec("danger", "ri-alarm-warning-line", "Entro 24 ore"),
|
|
ScadenzaEnum.Alta1Settimana => new StatusBadgeHelper.BadgeSpec("warning", "ri-time-line", "Entro 1 settimana"),
|
|
ScadenzaEnum.Media1Mese => new StatusBadgeHelper.BadgeSpec("info", "ri-calendar-line", "Entro 1 mese"),
|
|
_ => new StatusBadgeHelper.BadgeSpec("neutral", "ri-calendar-line", "Entro 2 mesi")
|
|
};
|
|
|
|
private string ArticoliLabel => Scheda.Articoli.Count == 1
|
|
? "1 articolo"
|
|
: $"{Scheda.Articoli.Count} articoli";
|
|
|
|
private string FotoLabel => Scheda.ImageNames?.Count switch
|
|
{
|
|
null or 0 => "nessuna foto",
|
|
1 => "1 foto",
|
|
var n => $"{n} foto"
|
|
};
|
|
|
|
private string SemanticLabel =>
|
|
$"Scheda {Titolo}, reparto {Scheda.DescrizioneReparto}, {SyncState.ToBadge().Label}, {ArticoliLabel}, {FotoLabel}";
|
|
|
|
private async Task SetBusy(bool value)
|
|
{
|
|
_busy = value;
|
|
await OnBusyChanged.InvokeAsync(value);
|
|
StateHasChanged();
|
|
}
|
|
|
|
private async Task UpdateScheda()
|
|
{
|
|
var modal = await Dialog.OpenFormScheda(Ispezione.CodMdep, Ispezione.Data, false, Scheda);
|
|
if (modal is { Canceled: false, Data: Scheda scheda }) await OnSchedaModified.InvokeAsync(scheda);
|
|
}
|
|
|
|
private void ViewScheda() =>
|
|
_ = Dialog.OpenFormScheda(Ispezione.CodMdep, Ispezione.Data, false, Scheda, true);
|
|
|
|
private async Task DeleteScheda()
|
|
{
|
|
var result = await _messageBox.ShowAsync();
|
|
if (result is not true) return;
|
|
|
|
await SetBusy(true);
|
|
|
|
try
|
|
{
|
|
if (Scheda.ActivityId != null)
|
|
await IntegrySteupService.DeleteScheda(Scheda.ActivityId);
|
|
|
|
if (Scheda.ImageNames != null)
|
|
{
|
|
foreach (var fileName in Scheda.ImageNames)
|
|
{
|
|
FileManager.RemoveInspectionFile(Ispezione, fileName);
|
|
}
|
|
}
|
|
|
|
var deleteScheda = await IspezioniService.DeleteSchedaAsync(Scheda.Id);
|
|
if (deleteScheda) await OnSchedaDeleted.InvokeAsync(Scheda);
|
|
}
|
|
finally
|
|
{
|
|
await SetBusy(false);
|
|
}
|
|
}
|
|
|
|
private async Task ExportScheda()
|
|
{
|
|
// Guardia anti doppio-tap: invio irreversibile al server.
|
|
if (_busy) return;
|
|
await SetBusy(true);
|
|
|
|
try
|
|
{
|
|
var apiResponse = await IntegrySteupService.SaveScheda(
|
|
new SaveRequestDto
|
|
{
|
|
LocalIdScheda = Scheda.Id,
|
|
ActivityTypeId = Scheda.ActivityTypeId,
|
|
CodJfas = Scheda.CodJfas,
|
|
CodMdep = Ispezione.CodMdep,
|
|
DataCreazione = Ispezione.Data,
|
|
Note = Scheda.Note,
|
|
PersonaRif = Scheda.Responsabile,
|
|
Barcodes = Scheda.Articoli.ConvertAll(x => x.Barcode),
|
|
Scandeza = (ScadenzaEnum)Scheda.Scadenza,
|
|
// Aggancia all'ispezione esistente sul server (evita di crearne una nuova a ogni invio).
|
|
ParentActivityId = SteupDataService.InspectionPageState.Ispezione.ActivityId
|
|
}
|
|
);
|
|
|
|
if (apiResponse == null)
|
|
{
|
|
Snackbar.Add("Invio non riuscito. La scheda resta sul dispositivo, riprova.", Severity.Error);
|
|
return;
|
|
}
|
|
|
|
Scheda.ActivityId = apiResponse.ActivityIdScheda;
|
|
SteupDataService.InspectionPageState.Ispezione.ActivityId = apiResponse.ActivityIdIspezione;
|
|
|
|
await IspezioniService.UpdateActivityIdIspezioneAsync(Ispezione.CodMdep, Ispezione.Data,
|
|
UserSession.User.Username, apiResponse.ActivityIdIspezione
|
|
);
|
|
await IspezioniService.UpdateActivityIdSchedaAsync(Scheda.Id, Scheda.ActivityId);
|
|
|
|
// Notifica il genitore così il contatore "da inviare" del reparto si aggiorna.
|
|
await OnSchedaModified.InvokeAsync(Scheda);
|
|
|
|
Snackbar.Add("Scheda inviata", Severity.Success);
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
Snackbar.Add("Invio non riuscito. La scheda resta sul dispositivo, riprova.", Severity.Error);
|
|
Logger.LogError(e, e.Message);
|
|
}
|
|
finally
|
|
{
|
|
await SetBusy(false);
|
|
}
|
|
}
|
|
|
|
private async Task ExportImg()
|
|
{
|
|
if (_busy || Scheda.ImageNames == null) return;
|
|
await SetBusy(true);
|
|
|
|
try
|
|
{
|
|
var fileList = (await FileManager.GetInspectionFiles(Ispezione, Scheda.ImageNames))?
|
|
.Where(x => x.ToUpload).ToList();
|
|
|
|
if (fileList == null || fileList.Count == 0)
|
|
{
|
|
Snackbar.Add("Nessuna nuova foto da inviare", Severity.Info);
|
|
return;
|
|
}
|
|
|
|
foreach (var file in fileList)
|
|
{
|
|
await IntegrySteupService.UploadFile(Scheda.ActivityId!, file.FileBytes!, file.Name!);
|
|
}
|
|
|
|
Snackbar.Add(fileList.Count == 1 ? "Foto inviata" : $"{fileList.Count} foto inviate", Severity.Success);
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
Snackbar.Add("Invio foto non riuscito, riprova.", Severity.Error);
|
|
Logger.LogError(e, e.Message);
|
|
}
|
|
finally
|
|
{
|
|
await SetBusy(false);
|
|
}
|
|
}
|
|
}
|