Gestita fotocamera per allegare immagini
This commit is contained in:
@@ -8,23 +8,54 @@
|
||||
<DialogContent>
|
||||
<HeaderLayout ShowProfile="false" SmallHeader="true" Cancel="true" OnCancel="() => MudDialog.Cancel()" Title="Aggiungi allegati"/>
|
||||
|
||||
<div style="margin-bottom: 1rem;" class="content attached">
|
||||
<MudFab Size="Size.Small" Color="Color.Primary"
|
||||
StartIcon="@Icons.Material.Rounded.Image"
|
||||
Label="Immagini" OnClick="OnImage"/>
|
||||
|
||||
<MudFab Size="Size.Small" Color="Color.Primary"
|
||||
StartIcon="@Icons.Material.Rounded.InsertDriveFile"
|
||||
Label="File" OnClick="OnFile"/>
|
||||
|
||||
@if (CanAddPosition)
|
||||
@if (RequireNewName)
|
||||
{
|
||||
<MudTextField @bind-Value="NewName" Class="px-3" Variant="Variant.Outlined"/>
|
||||
}
|
||||
else
|
||||
{
|
||||
@if (!SelectTypePicture)
|
||||
{
|
||||
<MudFab Size="Size.Small" Color="Color.Primary"
|
||||
StartIcon="@Icons.Material.Rounded.AddLocationAlt"
|
||||
Label="Posizione" OnClick="OnPosition"/>
|
||||
<div style="margin-bottom: 1rem;" class="content attached">
|
||||
<MudFab Size="Size.Small" Color="Color.Primary"
|
||||
StartIcon="@Icons.Material.Rounded.Image"
|
||||
Label="Immagini" OnClick="OnImage"/>
|
||||
|
||||
<MudFab Size="Size.Small" Color="Color.Primary"
|
||||
StartIcon="@Icons.Material.Rounded.InsertDriveFile"
|
||||
Label="File" OnClick="OnFile"/>
|
||||
|
||||
@if (CanAddPosition)
|
||||
{
|
||||
<MudFab Size="Size.Small" Color="Color.Primary"
|
||||
StartIcon="@Icons.Material.Rounded.AddLocationAlt"
|
||||
Label="Posizione" OnClick="OnPosition"/>
|
||||
}
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
else
|
||||
{
|
||||
<div style="margin-bottom: 1rem;" class="content attached">
|
||||
<MudFab Size="Size.Small" Color="Color.Primary"
|
||||
StartIcon="@Icons.Material.Rounded.CameraAlt"
|
||||
Label="Camera" OnClick="OnCamera"/>
|
||||
|
||||
<MudFab Size="Size.Small" Color="Color.Primary"
|
||||
StartIcon="@Icons.Material.Rounded.Image"
|
||||
Label="Galleria" OnClick="OnGallery"/>
|
||||
</div>
|
||||
}
|
||||
}
|
||||
</DialogContent>
|
||||
<DialogActions>
|
||||
@if (RequireNewName)
|
||||
{
|
||||
<MudButton Disabled="NewName.IsNullOrEmpty()" Class="my-3" Size="Size.Small" Variant="Variant.Filled" Color="Color.Primary"
|
||||
StartIcon="@Icons.Material.Rounded.Check" OnClick="OnNewName">
|
||||
Salva
|
||||
</MudButton>
|
||||
}
|
||||
</DialogActions>
|
||||
</MudDialog>
|
||||
|
||||
<SaveOverlay VisibleOverlay="VisibleOverlay" SuccessAnimation="SuccessAnimation"/>
|
||||
@@ -40,36 +71,47 @@
|
||||
|
||||
private AttachedDTO? Attached { get; set; }
|
||||
|
||||
private bool RequireNewName { get; set; }
|
||||
private bool SelectTypePicture { get; set; }
|
||||
|
||||
private string? _newName;
|
||||
private string? NewName
|
||||
{
|
||||
get => _newName;
|
||||
set
|
||||
{
|
||||
_newName = value;
|
||||
StateHasChanged();
|
||||
}
|
||||
}
|
||||
|
||||
protected override async Task OnInitializedAsync()
|
||||
{
|
||||
SelectTypePicture = false;
|
||||
RequireNewName = false;
|
||||
Snackbar.Configuration.PositionClass = Defaults.Classes.Position.TopCenter;
|
||||
|
||||
_ = LoadData();
|
||||
}
|
||||
|
||||
private async Task LoadData()
|
||||
{
|
||||
}
|
||||
|
||||
private async Task Save()
|
||||
{
|
||||
VisibleOverlay = true;
|
||||
StateHasChanged();
|
||||
|
||||
SuccessAnimation = true;
|
||||
StateHasChanged();
|
||||
|
||||
await Task.Delay(1250);
|
||||
|
||||
MudDialog.Close();
|
||||
}
|
||||
|
||||
private async Task OnImage()
|
||||
{
|
||||
Attached = await AttachedService.SelectImage();
|
||||
MudDialog.Close(Attached);
|
||||
SelectTypePicture = true;
|
||||
StateHasChanged();
|
||||
}
|
||||
|
||||
private async Task OnCamera()
|
||||
{
|
||||
Attached = await AttachedService.SelectImageFromCamera();
|
||||
|
||||
RequireNewName = true;
|
||||
StateHasChanged();
|
||||
}
|
||||
|
||||
private async Task OnGallery()
|
||||
{
|
||||
Attached = await AttachedService.SelectImageFromGallery();
|
||||
|
||||
RequireNewName = true;
|
||||
StateHasChanged();
|
||||
}
|
||||
|
||||
private async Task OnFile()
|
||||
@@ -81,6 +123,37 @@
|
||||
private async Task OnPosition()
|
||||
{
|
||||
Attached = await AttachedService.SelectPosition();
|
||||
|
||||
RequireNewName = true;
|
||||
StateHasChanged();
|
||||
}
|
||||
|
||||
private void OnNewName()
|
||||
{
|
||||
switch (Attached.Type)
|
||||
{
|
||||
case AttachedDTO.TypeAttached.Position:
|
||||
{
|
||||
CanAddPosition = false;
|
||||
|
||||
Attached.Description = NewName!;
|
||||
Attached.Name = NewName!;
|
||||
|
||||
break;
|
||||
}
|
||||
case AttachedDTO.TypeAttached.Image:
|
||||
{
|
||||
var extension = Path.GetExtension(Attached.Name);
|
||||
Attached.Name = NewName! + extension;
|
||||
|
||||
break;
|
||||
}
|
||||
case AttachedDTO.TypeAttached.Document:
|
||||
break;
|
||||
default:
|
||||
throw new ArgumentOutOfRangeException();
|
||||
}
|
||||
|
||||
MudDialog.Close(Attached);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user