Ez most szerver oldalon szűr és lapoz
This commit is contained in:
@@ -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,61 @@ namespace WorkFlowCheck.BL.Services
|
||||
|
||||
return retVal;
|
||||
}
|
||||
public async Task<ApiResponseListDTO<List<CheckListHeaderDTO>>> GetFilteredCheckListHeaderAsync(DataTablesRequest dataTablesRequest)
|
||||
{
|
||||
var retVal = new ApiResponseListDTO<List<CheckListHeaderDTO>>();
|
||||
try
|
||||
{
|
||||
IQueryable<CheckListHeader> query = _dbContext.CheckListHeaders
|
||||
.Include(i => i.CheckListRows)
|
||||
.Include(i => i.User)
|
||||
.Include(i => i.AcceptUser)
|
||||
.AsNoTracking();
|
||||
switch (dataTablesRequest.Mode)
|
||||
{
|
||||
case 0:
|
||||
query = query.Where(w => w.CheckStatus == CheckStatus.InProgress || w.CheckStatus == CheckStatus.Open).OrderByDescending(o => o.CreatedAt);
|
||||
break;
|
||||
|
||||
case 1:
|
||||
query = query.Where(w => w.CheckStatus == CheckStatus.Sent).OrderByDescending(o => o.CreatedAt);
|
||||
break;
|
||||
|
||||
case 2:
|
||||
query = query.Where(w => w.CheckStatus == CheckStatus.Closed).OrderByDescending(o => o.CreatedAt);
|
||||
break;
|
||||
case 3:
|
||||
query = query.Where(w => w.CheckStatus == CheckStatus.Signed).OrderByDescending(o => o.CreatedAt);
|
||||
break;
|
||||
|
||||
default:
|
||||
query = query.OrderByDescending(o => o.CreatedAt);
|
||||
break;
|
||||
}
|
||||
retVal.Total = await query.CountAsync();
|
||||
|
||||
if (!string.IsNullOrWhiteSpace(dataTablesRequest.Search.Value))
|
||||
{
|
||||
query = query.Where(x =>
|
||||
x.DocumentNumber.Contains(dataTablesRequest.Search.Value) ||
|
||||
x.ShortName.Contains(dataTablesRequest.Search.Value) ||
|
||||
x.Description.Contains(dataTablesRequest.Search.Value) ||
|
||||
x.CreatedBy.Contains(dataTablesRequest.Search.Value) ||
|
||||
(x.AcceptUser != null && x.AcceptUser.UserName.Contains(dataTablesRequest.Search.Value))
|
||||
);
|
||||
}
|
||||
retVal.Filtered = await query.CountAsync();
|
||||
|
||||
var list = await query.Skip(dataTablesRequest.Start).Take(dataTablesRequest.Length).ToListAsync();
|
||||
|
||||
retVal.Data = _mapper.Map<List<CheckListHeaderDTO>>(list);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Log.Error(ex.Message);
|
||||
}
|
||||
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,6 +58,7 @@
|
||||
<script>
|
||||
let currentMode = @Model.Mode;
|
||||
const table = new DataTable('#tbCheckListHeadersPage', {
|
||||
serverSide: true,
|
||||
ordering: true,
|
||||
order: [],
|
||||
ajax: {
|
||||
|
||||
+34
-3
@@ -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;
|
||||
@@ -30,8 +30,39 @@ namespace WorkFlowCheck.Web.Pages.CheckList.CheckListHeader
|
||||
|
||||
public async Task<JsonResult> OnGetLoadCheckListHeaders(int mode = 0)
|
||||
{
|
||||
var results = await _checkListService.GetAllCheckListHeaderAsync(mode);
|
||||
return new JsonResult(new { data = results });
|
||||
var draw = int.Parse(Request.Query["draw"]);
|
||||
var start = int.Parse(Request.Query["start"]);
|
||||
var length = int.Parse(Request.Query["length"]);
|
||||
var search = Request.Query["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
|
||||
});
|
||||
}
|
||||
|
||||
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);
|
||||
|
||||
Reference in New Issue
Block a user