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.Globalization
@using System.Text.RegularExpressions @using System.Text.RegularExpressions
@using CommunityToolkit.Mvvm.Messaging @using CommunityToolkit.Mvvm.Messaging
@using Java.Util.Jar
@using salesbook.Shared.Core.Dto @using salesbook.Shared.Core.Dto
@using salesbook.Shared.Components.Layout @using salesbook.Shared.Components.Layout
@using salesbook.Shared.Core.Entity @using salesbook.Shared.Core.Entity
@@ -123,9 +124,18 @@
{ {
foreach (var item in AttachedList!.Select((p, index) => new { p, index })) foreach (var item in AttachedList!.Select((p, index) => new { p, index }))
{ {
<MudChip T="string" Color="Color.Default" OnClose="() => OnRemoveAttached(item.index)"> @if (item.p.Type == AttachedDTO.TypeAttached.Position)
@item.p.Name {
</MudChip> <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,11 +193,23 @@
</MessageContent> </MessageContent>
<YesButton> <YesButton>
<MudButton Size="Size.Small" Variant="Variant.Filled" Color="Color.Error" <MudButton Size="Size.Small" Variant="Variant.Filled" Color="Color.Error"
StartIcon="@Icons.Material.Rounded.Check"> StartIcon="@Icons.Material.Rounded.DeleteForever">
Cancella Cancella
</MudButton> </MudButton>
</YesButton> </YesButton>
</MudMessageBox> </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"> <MudMessageBox @ref="ConfirmMemo" Class="c-messageBox" Title="Attenzione!" CancelText="Annulla">
<MessageContent> <MessageContent>
@@ -195,7 +217,7 @@
</MessageContent> </MessageContent>
<YesButton> <YesButton>
<MudButton Size="Size.Small" Variant="Variant.Filled" Color="Color.Primary" <MudButton Size="Size.Small" Variant="Variant.Filled" Color="Color.Primary"
StartIcon="@Icons.Material.Rounded.DeleteForever"> StartIcon="@Icons.Material.Rounded.Check">
Crea Crea
</MudButton> </MudButton>
</YesButton> </YesButton>
@@ -241,9 +263,12 @@
//MessageBox //MessageBox
private MudMessageBox ConfirmDelete { get; set; } private MudMessageBox ConfirmDelete { get; set; }
private MudMessageBox ConfirmMemo { get; set; } private MudMessageBox ConfirmMemo { get; set; }
private MudMessageBox AddNamePosition { get; set; }
//Attached //Attached
private List<AttachedDTO>? AttachedList { get; set; } private List<AttachedDTO>? AttachedList { get; set; }
private string? NamePosition { get; set; }
private bool CanAddPosition { get; set; } = true;
protected override async Task OnInitializedAsync() protected override async Task OnInitializedAsync()
{ {
@@ -479,12 +504,25 @@
private async Task OpenAddAttached() 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)) 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 ??= [];
AttachedList.Add((AttachedDTO)result.Data); AttachedList.Add(attached);
LabelSave = "Aggiorna"; LabelSave = "Aggiorna";
} }
@@ -495,6 +533,11 @@
if (AttachedList is null || index < 0 || index >= AttachedList.Count) if (AttachedList is null || index < 0 || index >= AttachedList.Count)
return; return;
var attached = AttachedList[index];
if (attached.Type == AttachedDTO.TypeAttached.Position)
CanAddPosition = true;
AttachedList.RemoveAt(index); AttachedList.RemoveAt(index);
StateHasChanged(); StateHasChanged();
} }

View File

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

View File

@@ -67,11 +67,14 @@ public class ModalHelpers
return await modal.Result; 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>( var modal = await dialog.ShowAsync<AddAttached>(
"Add attached", "Add attached",
new DialogParameters<AddAttached>(), new DialogParameters<AddAttached>
{
{ x => x.CanAddPosition, canAddPosition}
},
new DialogOptions new DialogOptions
{ {
FullScreen = false, FullScreen = false,