228 lines
7.5 KiB
Plaintext
228 lines
7.5 KiB
Plaintext
@inject NavigationManager Navigation
|
|
@layout ConfiguracionLayout
|
|
@rendermode InteractiveServer
|
|
|
|
@using BlazorBootstrap
|
|
@using System.Globalization
|
|
@using Microsoft.EntityFrameworkCore
|
|
@using bdHerramientaCACOA.db
|
|
|
|
<Toasts class="p-3 font-weight-bold" Style="color:white;" AutoHide="true" Delay="4000" Messages="mensajes" Placement="ToastsPlacement.BottomCenter" />
|
|
|
|
<EditForm EditContext="@editContext" OnValidSubmit="guardarFormulario" OnInvalidSubmit="@MostrarErrores" FormName="PuntoInfoForm">
|
|
<DataAnnotationsValidator></DataAnnotationsValidator>
|
|
<Modal @ref="popupGestionDatos" title="@tituloPopup" IsVerticallyCentered="true" UseStaticBackdrop="true" CloseOnEscape="false">
|
|
<BodyTemplate>
|
|
<div class="row">
|
|
<div class="col-12 formatoCampos pt-2">
|
|
<label class="tituloLbl">Título:</label>
|
|
<InputText MaxLength="60" @bind-Value="TituloPunto" @oninput="e => ValidarYActualizar(e, nameof(TituloPunto))" class="inputForm"></InputText>
|
|
</div>
|
|
<div class="validation-message">@GetExternalValidationMessage(nameof(TituloPunto))</div>
|
|
</div>
|
|
|
|
<div class="row">
|
|
<div class="col-12 formatoCampos pt-2">
|
|
<label class="tituloLbl">Descripción:</label>
|
|
<TextAreaInput Style="height:220px; max-height:220px" MaxLength="400" @bind-Value="@DescripcionPunto" Rows="3" TextAlignment="Alignment.Start" />
|
|
</div>
|
|
</div>
|
|
</BodyTemplate>
|
|
<FooterTemplate>
|
|
<Button Color="ButtonColor.Secondary" @onclick="cerrarPopupGestionDatos">Cerrar</Button>
|
|
<Button Type="ButtonType.Submit" Color="ButtonColor.Primary">@("Modificar")</Button>
|
|
</FooterTemplate>
|
|
</Modal>
|
|
</EditForm>
|
|
|
|
<div>
|
|
<Grid TItem="puntosinformacion"
|
|
Class="tablaCACOA table"
|
|
Data="listadoPuntosInfo"
|
|
AllowFiltering="false"
|
|
PageSize="10"
|
|
FixedHeader="true"
|
|
Height="750"
|
|
Unit="Unit.Px"
|
|
EmptyText="No hay registros."
|
|
PageSizeSelectorVisible="false"
|
|
Responsive="true">
|
|
<GridColumns>
|
|
<GridColumn TItem="puntosinformacion" HeaderTextAlignment="Alignment.Center" Class="columna20Ancho" HeaderText="Título">
|
|
<span>@context.Titulo</span>
|
|
</GridColumn>
|
|
|
|
<GridColumn TItem="puntosinformacion" HeaderTextAlignment="Alignment.Center" HeaderText="Descripción">
|
|
<span>@context.Descripcion</span>
|
|
</GridColumn>
|
|
|
|
<GridColumn TItem="puntosinformacion" Class="botonesTabla columna3Ancho" HeaderText="">
|
|
<div class="btnTablasEspaciado">
|
|
<span @onclick="@(() => abrirPopupGestionDatos(@context, false))" class="btnBorrarGuardar">
|
|
<Icon CustomIconName="fas fa-edit"></Icon>
|
|
</span>
|
|
</div>
|
|
</GridColumn>
|
|
</GridColumns>
|
|
</Grid>
|
|
</div>
|
|
|
|
@code {
|
|
|
|
public List<puntosinformacion> listadoPuntosInfo { get; set; } = new List<puntosinformacion>();
|
|
|
|
[SupplyParameterFromForm]
|
|
private puntosinformacion itemSeleccionado { get; set; } = new puntosinformacion();
|
|
|
|
private string tituloPopup = "";
|
|
public string Filter { get; set; } = "";
|
|
private Modal popupGestionDatos = default!;
|
|
|
|
private string TituloPunto = "";
|
|
private string DescripcionPunto = "";
|
|
|
|
List<ToastMessage> mensajes = new List<ToastMessage>();
|
|
|
|
private EditContext? editContext;
|
|
private ValidationMessageStore? messageStore;
|
|
public tsHerramientasCACOA bd;
|
|
|
|
private int idHerramienta = 34;
|
|
|
|
protected override async Task OnInitializedAsync()
|
|
{
|
|
bd = tsHerramientasCACOA.NuevoContexto(SoloLectura: false);
|
|
|
|
editContext = new EditContext(itemSeleccionado);
|
|
messageStore = new ValidationMessageStore(editContext);
|
|
|
|
listadoPuntosInfo = bd.puntosinformacion.Where(x => x.idTipoHerramienta == idHerramienta).ToList();
|
|
}
|
|
|
|
private async Task abrirPopupGestionDatos(puntosinformacion objeto, bool esNuevo)
|
|
{
|
|
itemSeleccionado = objeto;
|
|
|
|
TituloPunto = objeto.Titulo;
|
|
DescripcionPunto = objeto.Descripcion;
|
|
|
|
tituloPopup = "Modificar punto información";
|
|
|
|
|
|
await popupGestionDatos.ShowAsync();
|
|
}
|
|
private async Task cerrarPopupGestionDatos()
|
|
{
|
|
await popupGestionDatos.HideAsync();
|
|
}
|
|
|
|
private void ValidarYActualizar(ChangeEventArgs e, string fieldName)
|
|
{
|
|
var value = e.Value?.ToString();
|
|
var field = new FieldIdentifier(itemSeleccionado, fieldName);
|
|
|
|
switch (fieldName)
|
|
{
|
|
case nameof(TituloPunto):
|
|
if (!string.IsNullOrEmpty(value))
|
|
{
|
|
|
|
TituloPunto = value;
|
|
}
|
|
else
|
|
{
|
|
TituloPunto = "";
|
|
}
|
|
break;
|
|
}
|
|
|
|
messageStore?.Clear(field);
|
|
if (fieldName == nameof(TituloPunto) && TituloPunto == "")
|
|
{
|
|
messageStore?.Add(field, "El título no puede estar vacío.");
|
|
}
|
|
editContext?.NotifyValidationStateChanged();
|
|
}
|
|
|
|
private void ValidarTodo()
|
|
{
|
|
ValidarYActualizar(new ChangeEventArgs { Value = TituloPunto }, nameof(TituloPunto));
|
|
}
|
|
|
|
private string GetExternalValidationMessage(string fieldName)
|
|
{
|
|
var field = new FieldIdentifier(itemSeleccionado, fieldName);
|
|
return messageStore?[field].FirstOrDefault() ?? string.Empty;
|
|
}
|
|
|
|
private async Task GestionarDatos(string accion)
|
|
{
|
|
switch (accion)
|
|
{
|
|
case "update":
|
|
var puntoObtenido = bd.puntosinformacion.Where(x => x.idPuntosInformacion == itemSeleccionado.idPuntosInformacion).FirstOrDefault();
|
|
|
|
|
|
itemSeleccionado.Descripcion = DescripcionPunto;
|
|
itemSeleccionado.Titulo = TituloPunto;
|
|
|
|
UtilidadesCASA.actualizarPuntoInformacion(bd, puntoObtenido, itemSeleccionado);
|
|
|
|
await cerrarPopupGestionDatos();
|
|
|
|
mensajes.Add(new ToastMessage
|
|
{
|
|
Type = ToastType.Primary,
|
|
Message = $"Actualizado correctamente.",
|
|
});
|
|
|
|
break;
|
|
}
|
|
bd.SaveChanges();
|
|
listadoPuntosInfo = bd.puntosinformacion.Where(x => x.idTipoHerramienta == idHerramienta).ToList();
|
|
await InvokeAsync(StateHasChanged);
|
|
}
|
|
|
|
// GUARDAR
|
|
private async Task guardarFormulario()
|
|
{
|
|
try
|
|
{
|
|
ValidarTodo();
|
|
|
|
if (!editContext!.GetValidationMessages().Any())
|
|
{
|
|
string accion = "update";
|
|
await GestionarDatos(accion);
|
|
}
|
|
else
|
|
{
|
|
mensajes.Add(new ToastMessage
|
|
{
|
|
Type = ToastType.Warning,
|
|
Message = $"Debe rellenar los campos obligatorios.",
|
|
});
|
|
}
|
|
|
|
}
|
|
catch (Exception)
|
|
{
|
|
mensajes.Add(new ToastMessage
|
|
{
|
|
Type = ToastType.Danger,
|
|
Message = $"Error al guardar.",
|
|
});
|
|
}
|
|
|
|
}
|
|
|
|
private void MostrarErrores()
|
|
{
|
|
messageStore?.Clear();
|
|
foreach (var field in new[] { nameof(TituloPunto) })
|
|
{
|
|
ValidarYActualizar(new ChangeEventArgs { Value = typeof(puntosinformacion).GetProperty(field)?.GetValue(itemSeleccionado) }, field);
|
|
}
|
|
}
|
|
|
|
} |