Fix posizione

This commit is contained in:
2025-08-07 09:27:07 +02:00
parent b561405ddc
commit de9d415f04
3 changed files with 64 additions and 13 deletions

View File

@@ -1,6 +1,7 @@
@using System.Globalization
@using System.Text.RegularExpressions
@using CommunityToolkit.Mvvm.Messaging
@using Java.Util.Jar
@using salesbook.Shared.Core.Dto
@using salesbook.Shared.Components.Layout
@using salesbook.Shared.Core.Entity
@@ -123,9 +124,18 @@
{
foreach (var item in AttachedList!.Select((p, index) => new { p, index }))
{
<MudChip T="string" Color="Color.Default" OnClose="() => OnRemoveAttached(item.index)">
@item.p.Name
</MudChip>
@if (item.p.Type == AttachedDTO.TypeAttached.Position)
{
<MudChip T="string" Icon="@Icons.Material.Rounded.LocationOn" Color="Color.Success" OnClose="() => OnRemoveAttached(item.index)">
@item.p.Description
</MudChip>
}
else
{
<MudChip T="string" Color="Color.Default" OnClose="() => OnRemoveAttached(item.index)">
@item.p.Name
</MudChip>
}
}
}
@@ -183,19 +193,31 @@
</MessageContent>
<YesButton>
<MudButton Size="Size.Small" Variant="Variant.Filled" Color="Color.Error"
StartIcon="@Icons.Material.Rounded.Check">
StartIcon="@Icons.Material.Rounded.DeleteForever">
Cancella
</MudButton>
</YesButton>
</MudMessageBox>
<MudMessageBox @ref="AddNamePosition" Class="c-messageBox" Title="Nome della posizione" CancelText="Annulla">
<MessageContent>
<MudTextField @bind-Value="NamePosition" Variant="Variant.Outlined" />
</MessageContent>
<YesButton>
<MudButton Size="Size.Small" Variant="Variant.Filled" Color="Color.Primary"
StartIcon="@Icons.Material.Rounded.Check">
Salva
</MudButton>
</YesButton>
</MudMessageBox>
<MudMessageBox @ref="ConfirmMemo" Class="c-messageBox" Title="Attenzione!" CancelText="Annulla">
<MessageContent>
Vuoi creare un promemoria?
</MessageContent>
<YesButton>
<MudButton Size="Size.Small" Variant="Variant.Filled" Color="Color.Primary"
StartIcon="@Icons.Material.Rounded.DeleteForever">
StartIcon="@Icons.Material.Rounded.Check">
Crea
</MudButton>
</YesButton>
@@ -241,9 +263,12 @@
//MessageBox
private MudMessageBox ConfirmDelete { get; set; }
private MudMessageBox ConfirmMemo { get; set; }
private MudMessageBox AddNamePosition { get; set; }
//Attached
private List<AttachedDTO>? AttachedList { get; set; }
private string? NamePosition { get; set; }
private bool CanAddPosition { get; set; } = true;
protected override async Task OnInitializedAsync()
{
@@ -479,12 +504,25 @@
private async Task OpenAddAttached()
{
var result = await ModalHelpers.OpenAddAttached(Dialog);
var result = await ModalHelpers.OpenAddAttached(Dialog, CanAddPosition);
if (result is { Canceled: false, Data: not null } && result.Data.GetType() == typeof(AttachedDTO))
{
var attached = (AttachedDTO)result.Data;
if (attached.Type == AttachedDTO.TypeAttached.Position)
{
CanAddPosition = false;
var resultNamePosition = await AddNamePosition.ShowAsync();
if (resultNamePosition is true)
attached.Description = NamePosition;
attached.Name = NamePosition!;
}
AttachedList ??= [];
AttachedList.Add((AttachedDTO)result.Data);
AttachedList.Add(attached);
LabelSave = "Aggiorna";
}
@@ -495,6 +533,11 @@
if (AttachedList is null || index < 0 || index >= AttachedList.Count)
return;
var attached = AttachedList[index];
if (attached.Type == AttachedDTO.TypeAttached.Position)
CanAddPosition = true;
AttachedList.RemoveAt(index);
StateHasChanged();
}

View File

@@ -17,9 +17,12 @@
StartIcon="@Icons.Material.Rounded.InsertDriveFile"
Label="File" OnClick="OnFile"/>
<MudFab Size="Size.Small" Color="Color.Primary"
StartIcon="@Icons.Material.Rounded.AddLocationAlt"
Label="Posizione" OnClick="OnPosition"/>
@if (CanAddPosition)
{
<MudFab Size="Size.Small" Color="Color.Primary"
StartIcon="@Icons.Material.Rounded.AddLocationAlt"
Label="Posizione" OnClick="OnPosition"/>
}
</div>
</DialogContent>
</MudDialog>
@@ -29,6 +32,8 @@
@code {
[CascadingParameter] private IMudDialogInstance MudDialog { get; set; }
[Parameter] public bool CanAddPosition { get; set; }
//Overlay for save
private bool VisibleOverlay { get; set; }
private bool SuccessAnimation { get; set; }

View File

@@ -67,11 +67,14 @@ public class ModalHelpers
return await modal.Result;
}
public static async Task<DialogResult?> OpenAddAttached(IDialogService dialog)
public static async Task<DialogResult?> OpenAddAttached(IDialogService dialog, bool canAddPosition)
{
var modal = await dialog.ShowAsync<AddAttached>(
"Add attached",
new DialogParameters<AddAttached>(),
new DialogParameters<AddAttached>
{
{ x => x.CanAddPosition, canAddPosition}
},
new DialogOptions
{
FullScreen = false,