Author SHA1 Message Date
ivanszabo 717becd1fc ServerSide Paging 2026-08-02 16:36:21 +02:00
ivanszabo 92acb42601 Na most jó a lapozás 2026-03-09 11:32:12 +01:00
ivanszabo 53dc9b326a Ez most szerver oldalon szűr és lapoz 2026-03-02 14:12:43 +01:00
9 changed files with 191 additions and 6 deletions
@@ -2,6 +2,7 @@
using Serilog;
using WorkFlowCheck.BL.Services;
using WorkFlowCheck.BL.Services.Interfaces;
using WorkFlowCheck.Common.DataTables;
using WorkFlowCheck.Common.DTO;
namespace WorkFlowCheck.API.Controllers
@@ -39,6 +40,28 @@ namespace WorkFlowCheck.API.Controllers
return retVal;
}
[HttpPost("GetFilteredCheckListHeader")]
public async Task<ApiResponseListDTO<List<CheckListHeaderDTO>>> GetFilteredCheckListHeader([FromBody] DataTablesRequest dataTablesRequest)
{
var retVal = new ApiResponseListDTO<List<CheckListHeaderDTO>>()
{
IsSuccess = true
};
try
{
var result = await _checkListService.GetFilteredCheckListHeaderAsync(dataTablesRequest);
retVal.Data = result.Data;
retVal.Total = result.Total;
retVal.Filtered = result.Filtered;
}
catch (Exception ex)
{
retVal.IsSuccess = false;
Log.Error(ex.Message);
}
return retVal;
}
[HttpGet("CreatePDF/{id}")]
public async Task<ApiResponseDTO<byte[]>> CreatePDF(int id)
{
@@ -15,6 +15,7 @@ using System.Text;
using System.Threading.Tasks;
using WorkFlowCheck.BL.DocumentGenerator;
using WorkFlowCheck.BL.Services.Interfaces;
using WorkFlowCheck.Common.DataTables;
using WorkFlowCheck.Common.DTO;
using WorkFlowCheck.Common.Enums;
using WorkFlowCheck.DL;
@@ -81,6 +82,69 @@ namespace WorkFlowCheck.BL.Services
return retVal;
}
public async Task<ApiResponseListDTO<List<CheckListHeaderDTO>>> GetFilteredCheckListHeaderAsync(DataTablesRequest req)
{
var retVal = new ApiResponseListDTO<List<CheckListHeaderDTO>>();
try
{
var baseQuery = _dbContext.CheckListHeaders
.AsNoTracking()
.Where(x => !x.IsDeleted);
// MODE szűrés (csak WHERE, ORDER BY nélkül)
IQueryable<CheckListHeader> modeQuery = req.Mode switch
{
0 => baseQuery.Where(w => w.CheckStatus == CheckStatus.InProgress || w.CheckStatus == CheckStatus.Open),
1 => baseQuery.Where(w => w.CheckStatus == CheckStatus.Sent),
2 => baseQuery.Where(w => w.CheckStatus == CheckStatus.Closed),
3 => baseQuery.Where(w => w.CheckStatus == CheckStatus.Signed),
_ => baseQuery
};
// Total = mode szűrés után, keresés előtt
retVal.Total = await modeQuery.CountAsync();
// Search
var search = req.Search?.Value?.Trim();
IQueryable<CheckListHeader> filteredQuery = modeQuery;
if (!string.IsNullOrWhiteSpace(search))
{
filteredQuery = filteredQuery.Where(x =>
x.DocumentNumber.Contains(search) ||
(x.ShortName != null && x.ShortName.Contains(search)) ||
(x.Description != null && x.Description.Contains(search)) ||
(x.CreatedBy != null && x.CreatedBy.Contains(search)) ||
(x.AcceptUser != null && x.AcceptUser.UserName.Contains(search))
);
}
retVal.Filtered = await filteredQuery.CountAsync();
// Ordering (itt már jöhet)
filteredQuery = filteredQuery.OrderByDescending(o => o.CreatedAt);
// Paging
var list = await filteredQuery
.Include(x => x.CheckListRows)
.Include(x => x.User)
.Include(x => x.AcceptUser)
.AsSplitQuery()
.Skip(req.Start)
.Take(req.Length)
.ToListAsync();
retVal.Data = _mapper.Map<List<CheckListHeaderDTO>>(list);
}
catch (Exception ex)
{
Log.Error(ex, "GetFilteredCheckListHeaderAsync failed");
}
return retVal;
}
public async Task<List<CheckListHeaderDTO>> GetAllCheckListHeaderAsync(int mode = 0)
{
var retVal = new List<CheckListHeaderDTO>();
@@ -1,4 +1,5 @@
using Microsoft.AspNetCore.Mvc.Rendering;
using WorkFlowCheck.Common.DataTables;
using WorkFlowCheck.Common.DTO;
namespace WorkFlowCheck.BL.Services.Interfaces
@@ -6,6 +7,7 @@ namespace WorkFlowCheck.BL.Services.Interfaces
public interface ICheckListService
{
Task<CheckListHeaderDTO> GetCheckListHeaderAsync(int Id);
Task<ApiResponseListDTO<List<CheckListHeaderDTO>>> GetFilteredCheckListHeaderAsync(DataTablesRequest dataTablesRequest);
Task<List<CheckListHeaderDTO>> GetAllCheckListHeaderAsync(int mode = 0);
Task<CheckListHeaderDTO> UpdateCheckListHeaderAsync(CheckListHeaderDTO checkListHeaderDTO);
Task<bool> AcceptCheckListHeaderAsync(int id, int userid);
@@ -35,9 +35,11 @@ namespace WorkFlowCheck.Common.DTO
{
public T Data { get; set; }
}
public class ApiResponseListDTO<T> : ApiResponseBaseDTO
{
public T[] Data { get; set; }
public T Data { get; set; }
public int Total { get; set; }
public int Filtered { get; set; }
}
}
@@ -0,0 +1,22 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace WorkFlowCheck.Common.DataTables
{
public class DataTablesRequest
{
public int Mode { get; set; }
public int Draw { get; set; }
public int Start { get; set; }
public int Length { get; set; }
public DataTablesSearch Search { get; set; } = new();
public List<DataTablesOrder> Order { get; set; } = new();
public List<DataTablesColumn> Columns { get; set; } = new();
}
public class DataTablesSearch { public string? Value { get; set; } }
public class DataTablesOrder { public int Column { get; set; } public string? Dir { get; set; } }
public class DataTablesColumn { public string? Data { get; set; } public bool Searchable { get; set; } public bool Orderable { get; set; } }
}
@@ -58,11 +58,12 @@
<script>
let currentMode = @Model.Mode;
const table = new DataTable('#tbCheckListHeadersPage', {
serverSide: true,
ordering: true,
order: [],
ajax: {
url: "@Url.Page("./CheckListHeaderPage", "LoadCheckListHeaders")",
type: "GET",
type: "POST",
data: function (d) {
d.mode = currentMode;
},
@@ -1,4 +1,4 @@
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.RazorPages;
using Microsoft.AspNetCore.Mvc.Rendering;
using System.ComponentModel.DataAnnotations;
@@ -9,6 +9,7 @@ using System.Security.Claims;
using WorkFlowCheck.Common.DTO;
namespace WorkFlowCheck.Web.Pages.CheckList.CheckListHeader
{
[IgnoreAntiforgeryToken]
public class CheckListHeaderPageModel : PageModel
{
private readonly ILogger<IndexModel> _logger;
@@ -28,10 +29,50 @@ namespace WorkFlowCheck.Web.Pages.CheckList.CheckListHeader
}
public async Task<JsonResult> OnGetLoadCheckListHeaders(int mode = 0)
public async Task<JsonResult> OnPostLoadCheckListHeadersAsync()
{
var results = await _checkListService.GetAllCheckListHeaderAsync(mode);
return new JsonResult(new { data = results });
var mode = int.Parse(Request.Form["mode"]);
var draw = int.Parse(Request.Form["draw"]);
var start = int.Parse(Request.Form["start"]);
var length = int.Parse(Request.Form["length"]);
var search = Request.Form["search[value]"].ToString();
var orderColIndexStr = Request.Query["order[0][column]"].ToString();
var orderDir = Request.Query["order[0][dir]"].ToString(); // "asc" / "desc"
int? orderColIndex = int.TryParse(orderColIndexStr, out var idx) ? idx : null;
// columns[x][data] alapján tudod, melyik mezőt rendezi
string? orderColData = null;
if (orderColIndex.HasValue)
orderColData = Request.Query[$"columns[{orderColIndex.Value}][data]"].ToString();
//var results = await _checkListService.GetAllCheckListHeaderAsync(mode);
var dataTablesRequest = new Common.DataTables.DataTablesRequest()
{
Mode = mode,
Length = length,
Start = start,
Draw = draw,
};
dataTablesRequest.Search.Value = search;
var results = await _checkListService.GetFilteredCheckListHeaderAsync(dataTablesRequest);
return new JsonResult(new
{
draw = draw,
recordsTotal = results.Total,
recordsFiltered = results.Filtered,
data = results.Data
});
//var results = await _checkListService.GetAllCheckListHeaderAsync(mode);
//return new JsonResult(new
//{
// draw = draw,
// data = results
//});
}
public async Task<IActionResult> OnGetCreatePDF(int id)
@@ -4,6 +4,7 @@ using Serilog;
using System.ComponentModel.DataAnnotations;
using System.Net.Http;
using System.Reflection;
using WorkFlowCheck.Common.DataTables;
using WorkFlowCheck.Common.DTO;
using WorkFlowCheck.Common.Enums;
using WorkFlowCheck.Web.Services.Interfaces;
@@ -15,7 +16,34 @@ namespace WorkFlowCheck.Web.Services
public CheckListService(HttpClient httpClient, IConfiguration configuration, IHttpContextAccessor httpContextAccessor) : base(httpClient, configuration, httpContextAccessor)
{
}
public async Task<ApiResponseListDTO<List<CheckListHeaderDTO>>> GetFilteredCheckListHeaderAsync(DataTablesRequest dataTablesRequest)
{
try
{
string endpoint = $"{_httpClient.BaseAddress}api/CheckList/GetFilteredCheckListHeader";
using (HttpResponseMessage httpResponseMessage = await _httpClient.PostAsJsonAsync(endpoint, dataTablesRequest))
{
httpResponseMessage.EnsureSuccessStatusCode();
var jsonString = await httpResponseMessage.Content.ReadAsStringAsync();
var response = JsonConvert.DeserializeObject<ApiResponseListDTO<List<CheckListHeaderDTO>>>(jsonString);
return response ?? new ApiResponseListDTO<List<CheckListHeaderDTO>>
{
IsSuccess = false,
};
}
}
catch (Exception ex)
{
// Hiba visszaadása
return new ApiResponseListDTO<List<CheckListHeaderDTO>>
{
IsSuccess = false
};
}
}
public async Task<List<CheckListHeaderDTO>> GetAllCheckListHeaderAsync(int mode = 0)
{
var endpoint = $"{_httpClient.BaseAddress}api/CheckList/GetAllCheckListHeaders/{mode}";
@@ -1,4 +1,5 @@
using Microsoft.AspNetCore.Mvc.Rendering;
using WorkFlowCheck.Common.DataTables;
using WorkFlowCheck.Common.DTO;
namespace WorkFlowCheck.Web.Services.Interfaces
@@ -6,6 +7,7 @@ namespace WorkFlowCheck.Web.Services.Interfaces
public interface ICheckListService
{
Task<CheckListHeaderDTO> GetCheckListHeader(int id);
Task<ApiResponseListDTO<List<CheckListHeaderDTO>>> GetFilteredCheckListHeaderAsync(DataTablesRequest dataTablesRequest);
Task<List<CheckListHeaderDTO>> GetAllCheckListHeaderAsync(int mode = 0);
Task<ApiResponseDTO<CheckListHeaderDTO>> UpdateCheckListHeader(CheckListHeaderDTO checkListHeaderDTO);
Task<ApiResponseDTO<byte[]>> CreatePDF(int id);