All checks were successful
CI/CD Pipeline / Build and Deploy with Docker Compose (push) Successful in 5m31s
211 lines
7.8 KiB
Plaintext
211 lines
7.8 KiB
Plaintext
@page "/sales/professionals"
|
|
@using phronCare.UIBlazor.Services.Sales
|
|
@using phronCare.UIBlazor.Data
|
|
@using Domain.Entities
|
|
@using Domain.Generics
|
|
@inject IToastService toastService
|
|
@inject NavigationManager Navigation
|
|
@inject ProfessionalService professionalService
|
|
|
|
<div class="card">
|
|
<div class="card-header d-flex justify-content-center align-items-center" style="zoom:80%;">
|
|
<h3 class="card-title m-0">Búsqueda de profesionales</h3>
|
|
</div>
|
|
<div class="card-body" style="zoom:80%;">
|
|
<div class="mb-4 space-y-2">
|
|
<input @bind="SearchParams.Fullname" placeholder="Nombre y apellido" class="border rounded p-1 w-full" />
|
|
<input @bind="SearchParams.Document" placeholder="Documento o Matricula" class="border rounded p-1 w-full" />
|
|
<input @bind="SearchParams.Type" placeholder="Tipo de profesional" class="border rounded p-1 w-full" />
|
|
<button class="btn btn-primary rounded-pill" @onclick="BuscarProfesionales">
|
|
<i class="fas fa-binoculars me-1"></i> Buscar
|
|
</button>
|
|
<button class="btn btn-success rounded-pill" @onclick="NuevoProfesional">
|
|
<i class="fas fa-plus me-1"></i> Nuevo
|
|
</button>
|
|
<button class="btn btn-success rounded-pill" @onclick="ExportarExcel">
|
|
<i class="fas fa-file-excel me-1"></i> Excel
|
|
</button>
|
|
<button class="btn btn-secondary rounded-pill" @onclick="Cancel">
|
|
<i class="fas fa-arrow-left me-1"></i> Volver
|
|
</button>
|
|
</div>
|
|
<hr />
|
|
<div>
|
|
@if (TablaProfesionales != null && TablaProfesionales.Any())
|
|
{
|
|
<PhTable Columns="TableColumns"
|
|
Data="TablaProfesionales"
|
|
SelectionField="Id"
|
|
RowsPerPage=SearchParams.PageSize
|
|
RenderButtons="true" Buttons="botones"
|
|
ShowPageButtons="false"
|
|
ShowQuickSearch="false"
|
|
RenderSelect="false" />
|
|
}
|
|
else
|
|
{
|
|
<p>No hay resultados.</p>
|
|
}
|
|
</div>
|
|
</div>
|
|
<div class="card-footer d-flex justify-content-center align-items-center" style="zoom:80%;">
|
|
<div class="d-flex align-items-center gap-3">
|
|
<button class="btn btn-secondary rounded-pill" @onclick="PrimeraPagina" disabled="@(SearchParams.Page == 1)">
|
|
<i class="fas fa-angle-double-left me-1"></i> Primera
|
|
</button>
|
|
<button class="btn btn-secondary rounded-pill" @onclick="AnteriorPagina" disabled="@(!PuedeRetroceder)">
|
|
<i class="fas fa-chevron-left me-1"></i> Anterior
|
|
</button>
|
|
<span class="mx-2">
|
|
Página <strong>@SearchParams.Page</strong> de <strong>@TotalPaginas</strong>
|
|
</span>
|
|
<button class="btn btn-secondary rounded-pill" @onclick="SiguientePagina" disabled="@(!PuedeAvanzar)">
|
|
Siguiente <i class="fas fa-chevron-right ms-1"></i>
|
|
</button>
|
|
<button class="btn btn-secondary rounded-pill" @onclick="UltimaPagina" disabled="@(SearchParams.Page == TotalPaginas)">
|
|
Última <i class="fas fa-angle-double-right ms-1"></i>
|
|
</button>
|
|
<div class="d-flex align-items-center ms-3">
|
|
<input type="number" class="form-control form-control-sm rounded" style="width: 80px;" min="1" max="@TotalPaginas" @bind="PaginaDeseada" />
|
|
<button class="btn btn-outline-primary btn-sm ms-2 rounded-pill" @onclick="IrAPagina">
|
|
<i class="fas fa-arrow-right-to-bracket me-1"></i> Ir
|
|
</button>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
@code {
|
|
private ProfessionalSearchParams SearchParams = new();
|
|
private PagedResult<EProfessional>? PagedResult;
|
|
private List<Dictionary<string, object>> TablaProfesionales = new();
|
|
private List<string> TableColumns = new()
|
|
{
|
|
"Id", "Nombre", "Tipo Documento", "N° Documento", "Tipo", "Especialidad",
|
|
"Email", "Teléfono 1", "Teléfono 2", "Matrícula", "Activo"
|
|
};
|
|
private int PaginaDeseada = 1;
|
|
private List<PhTable.ButtonOptions> botones = new();
|
|
|
|
protected override void OnInitialized()
|
|
{
|
|
botones = new List<PhTable.ButtonOptions>
|
|
{
|
|
new PhTable.ButtonOptions
|
|
{
|
|
Caption = "Editar",
|
|
ElementClass = "btn btn-primary btn-sm",
|
|
UrlAction = "/sales/professionals/edit/",
|
|
OnClickAction = async (id) =>
|
|
{
|
|
if (int.TryParse(id, out var profId))
|
|
{
|
|
Navigation.NavigateTo($"/sales/professionalform/{profId}");
|
|
}
|
|
}
|
|
}
|
|
};
|
|
}
|
|
|
|
private async Task BuscarProfesionales()
|
|
{
|
|
await CargarProfesionales();
|
|
}
|
|
|
|
private async Task CargarProfesionales()
|
|
{
|
|
PagedResult = await professionalService.SearchAsync(SearchParams);
|
|
if (PagedResult?.Items is not null)
|
|
{
|
|
TablaProfesionales = PagedResult.Items.Select(p => new Dictionary<string, object>
|
|
{
|
|
{ "Id", p.Id },
|
|
{ "Nombre", p.Fullname ?? string.Empty },
|
|
{ "Tipo Documento", p.DocumenttypeName ?? string.Empty },
|
|
{ "N° Documento", p.DocumentNumber ?? string.Empty },
|
|
{ "Tipo", p.Type ?? string.Empty },
|
|
{ "Especialidad", p.Specialty?.Name ?? string.Empty },
|
|
{ "Email", p.Email ?? string.Empty },
|
|
{ "Teléfono 1", p.Phone1 ?? string.Empty },
|
|
{ "Teléfono 2", p.Phone2 ?? string.Empty },
|
|
{ "Matrícula", p.License ?? string.Empty },
|
|
{ "Activo", p.Active ? "Sí" : "No" },
|
|
}).ToList();
|
|
}
|
|
}
|
|
|
|
private async Task ExportarExcel()
|
|
{
|
|
var searchParams = new ProfessionalSearchParams
|
|
{
|
|
Fullname = SearchParams.Fullname,
|
|
Document = SearchParams.Document,
|
|
Type = SearchParams.Type,
|
|
Page = 1,
|
|
PageSize = int.MaxValue
|
|
};
|
|
try
|
|
{
|
|
await professionalService.ExportFilteredAsync(searchParams);
|
|
toastService.ShowSuccess("Exportación completada exitosamente.");
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
toastService.ShowError($"{ex.Message}");
|
|
}
|
|
}
|
|
|
|
private async Task PrimeraPagina()
|
|
{
|
|
SearchParams.Page = 1;
|
|
await BuscarProfesionales();
|
|
}
|
|
|
|
private async Task UltimaPagina()
|
|
{
|
|
SearchParams.Page = TotalPaginas;
|
|
await BuscarProfesionales();
|
|
}
|
|
|
|
private async Task IrAPagina()
|
|
{
|
|
if (PaginaDeseada >= 1 && PaginaDeseada <= TotalPaginas)
|
|
{
|
|
SearchParams.Page = PaginaDeseada;
|
|
await BuscarProfesionales();
|
|
}
|
|
else
|
|
{
|
|
toastService.ShowWarning("Número de página fuera de rango.");
|
|
}
|
|
}
|
|
|
|
private async Task SiguientePagina() => await CambiarPagina(1);
|
|
private async Task AnteriorPagina() => await CambiarPagina(-1);
|
|
private async Task CambiarPagina(int delta)
|
|
{
|
|
var nuevaPagina = SearchParams.Page + delta;
|
|
if (nuevaPagina >= 1 && nuevaPagina <= TotalPaginas)
|
|
{
|
|
SearchParams.Page = nuevaPagina;
|
|
await BuscarProfesionales();
|
|
}
|
|
}
|
|
|
|
private int TotalPaginas => PagedResult is null ? 1 :
|
|
(int)Math.Ceiling((double)(PagedResult.TotalItems) / SearchParams.PageSize);
|
|
|
|
private bool PuedeRetroceder => PagedResult != null && SearchParams.Page > 1;
|
|
private bool PuedeAvanzar => PagedResult != null && SearchParams.Page < TotalPaginas;
|
|
|
|
private void NuevoProfesional()
|
|
{
|
|
Navigation.NavigateTo("/sales/professionalform/");
|
|
}
|
|
|
|
public void Cancel()
|
|
{
|
|
Navigation.NavigateTo("/DashboardPanel");
|
|
}
|
|
}
|