CheckListServices továbbfejlesztése

This commit is contained in:
2025-03-19 18:16:34 +01:00
parent 63b9beef35
commit 2e335e7b8a
14 changed files with 366 additions and 64 deletions
@@ -171,5 +171,30 @@ namespace WorkFlowCheck.API.Controllers
}
return retVal;
}
[HttpGet("GetCheckListTemplateRow/{id}")]
public async Task<ApiResponseDTO<CheckListTemplateRowDTO>> GetCheckListTemplateRow(int id)
{
var retVal = new ApiResponseDTO<CheckListTemplateRowDTO>()
{
IsSuccess = true,
};
var checkListTemplateRowDTO = await _checkListService.GetCheckListTemplateRowAsync(id);
if (checkListTemplateRowDTO != null)
{
retVal.IsSuccess = true;
retVal.Data = checkListTemplateRowDTO;
}
else
{
retVal.IsSuccess = false;
retVal.Errors.Add("No data!");
}
return retVal;
}
}
}
+11 -1
View File
@@ -15,20 +15,30 @@ namespace WorkFlowCheck.BL.Mappings
public MapperProfile()
{
CreateMap<User, UserDTO>().ForMember(dest => dest.RoleDTO, opt => opt.MapFrom(src => src.UserRoles.Select(ur => ur.Role)));
CreateMap<Role, RoleDTO>();
CreateMap<UserRole, UserRoleDTO>()
.ForMember(dest => dest.RoleDTO, opt => opt.MapFrom(src => src.Role))
.ForMember(dest => dest.UserDTO, opt => opt.MapFrom(src => src.User));
CreateMap<UserDTO, User>()
.ForMember(dest => dest.PasswordHash, opt => opt.MapFrom<PasswordHashResolver>());
CreateMap<CheckListTemplateHeader, CheckListTemplateHeaderDTO>()
.ForMember(dest => dest.CheckListTemplateRowDTO, opt => opt.MapFrom(src => src.CheckListTemplateRows));
CreateMap<CheckListTemplateRow, CheckListTemplateRowDTO>();
CreateMap<CheckListTemplateRow, CheckListTemplateRowDTO>()
.ForMember(dest => dest.EquipmentDTO, opt => opt.MapFrom(src => src.Equipment))
.ForMember(dest => dest.CheckPointDTO, opt => opt.MapFrom(src => src.CheckPoint));
CreateMap<CheckPoint, CheckPointDTO>().ForMember(dest => dest.CheckListTemplateRowDTO, opt => opt.MapFrom(src => src.CheckListTemplateRows));
CreateMap<CheckPointDTO, CheckPoint>();
CreateMap<Location, LocationDTO>();
CreateMap<Equipment, EquipmentDTO>();
CreateMap<CheckListHeader, CheckListHeaderDTO>()
@@ -237,5 +237,32 @@ namespace WorkFlowCheck.BL.Services
return retVal;
}
public async Task<CheckListTemplateRowDTO> GetCheckListTemplateRowAsync(int id)
{
var retVal = new CheckListTemplateRowDTO();
try
{
var res = await _dbContext.CheckListTemplateRows
.Include(i=> i.Equipment)
.Include(i=> i.CheckPoint)
.Where(w => w.Id == id)
.AsNoTracking()
.FirstOrDefaultAsync();
if (res != null)
{
retVal = _mapper.Map<CheckListTemplateRowDTO>(res);
}
}
catch (Exception ex)
{
Log.Error(ex.Message);
}
return retVal;
}
public Task<CheckListTemplateRowDTO> UpdateCheckListTemplateRowAsync(CheckListTemplateRowDTO checkListTemplateRowDTO) => throw new NotImplementedException();
}
}
@@ -19,5 +19,9 @@ namespace WorkFlowCheck.BL.Services.Interfaces
Task<CheckListTemplateHeaderDTO> GetCheckListTemplateHeaderAsync(int Id);
Task<List<CheckListTemplateHeaderDTO>> GetAllCheckListTemplateHeaderAsync();
Task<CheckListTemplateHeaderDTO> UpdateCheckListTemplateHeaderAsync(CheckListTemplateHeaderDTO checkListTemplateHeaderDTO);
Task<CheckListTemplateRowDTO> GetCheckListTemplateRowAsync(int id);
Task<CheckListTemplateRowDTO> UpdateCheckListTemplateRowAsync(CheckListTemplateRowDTO checkListTemplateRowDTO);
}
}
@@ -9,8 +9,10 @@ namespace WorkFlowCheck.Common.DTO
public int CheckListTemplateHeaderId { get; set; }
public int EquipmentId { get; set; }
public EquipmentDTO EquipmentDTO { get; set; }
public int CheckPointId { get; set; }
public CheckPointDTO CheckPointDTO { get; set; }
public string OperationDescription { get; set; } = null!;
@@ -29,6 +29,7 @@
</div>
<div class="mb-3">
<button type="button" id="saveCheckPoint" class="btn btn-primary">Mentés</button>
<button type="button" class="btn btn-secondary" onclick="history.back()">Mégsem</button>
</div>
</form>
</div>
@@ -98,7 +99,7 @@
$('#tbCheckPointsEditPage').on('click', '.edit-btn', function ()
{
const row = table.row($(this).closest('tr')).data();
window.location.href = `@Url.Page("./CheckListTemplateRowEditPage")?id=${row.id}`;
window.location.href = `@Url.Page("/CheckListTemplate/CheckListTemplateRows/CheckListTemplateRowEditPage")?id=${row.id}`;
});
$('#tbCheckPointsEditPage').on('click', '.delete-btn', function ()
@@ -1,4 +1,165 @@
@page
@model WorkFlowCheck.Web.Pages.CheckListTemplate.CheckListTemplateHeader.CheckListTemplateHeaderEditPageModel
@using Microsoft.AspNetCore.Antiforgery
@inject IAntiforgery Antiforgery
@{
ViewData["Title"] = "Ellenőrzés sablon";
var CheckListTemplateHeaderId = Model.CheckListTemplateHeaderDTO.Id;
var url = Url.Page("./CheckListTemplateHeaderEditPage", "LoadCheckListTemplateRows", new { id = CheckListTemplateHeaderId });
var urlPost = Url.Page("./CheckListTemplateHeaderEditPage", "Save");
}
<h1>@ViewData["Title"]</h1>
<input type="hidden" id="CheckListTemplateHeaderEditUrl" value="@url" />
<input type="hidden" id="CheckListTemplateHeaderEditPostUrl" value="@urlPost" />
<div class="card shadow p-4">
<form method="post" id="CheckListTemplateHeaderForm">
<meta name="csrf-token" content="@Antiforgery.GetAndStoreTokens(HttpContext).RequestToken" />
<input type="hidden" asp-for="CheckListTemplateHeaderDTO.Id" />
<div class="mb-3">
<label asp-for="CheckListTemplateHeaderDTO.ShortName"></label>
<input asp-for="CheckListTemplateHeaderDTO.ShortName" class="form-control" />
<span asp-validation-for="CheckListTemplateHeaderDTO.ShortName" class="text-danger"></span>
</div>
<div class="mb-3 d-flex justify-content-between">
<button type="button" id="saveCheckListTemplateHeader" class="btn btn-primary">Mentés</button>
<button type="button" class="btn btn-secondary" onclick="history.back()">Mégsem</button>
</div>
</form>
</div>
<br></br>
<div class="card shadow p-4">
<table id="tbCheckListTemplateHeaderPage" class="table table-bordered table-hover table-sm" style="width:100%">
<thead class="table-primary">
<tr>
<th>ID</th>
<th>Short Name</th>
<th>OperationDescription</th>
<th>AnswerType</th>
<th class="text-center">Action</th>
</tr>
</thead>
<tfoot class="table-light">
<tr>
<th>ID</th>
<th>Short Name</th>
<th>OperationDescription</th>
<th>AnswerType</th>
<th class="text-center">Action</th>
</tr>
</tfoot>
</table>
</div>
@section Scripts {
<script>
const table = new DataTable('#tbCheckListTemplateHeaderPage', {
ajax: {
url: $('#CheckListTemplateHeaderEditUrl').val(),
type: "GET",
dataSrc : "data"
},
columns: [
{ data: "id" },
{ data: "rowIndex" },
{ data: "operationDescription" },
{ data: "answerType" },
{ data: null, render: function (data, type, row) {
return renderActionButtons(row.id);
}}
],
columnDefs: [
{
"targets": 0,
"visible": false
},
{
"targets": 4,
"className": "text-center",
"width": "10%"
}
],
processing:true,
language: { url: '//cdn.datatables.net/plug-ins/2.2.2/i18n/hu.json',}
});
$('#tbCheckListTemplateHeaderPage').on('click', '.edit-btn', function ()
{
const row = table.row($(this).closest('tr')).data();
window.location.href = `@Url.Page("/CheckListTemplate/CheckListTemplateRows/CheckListTemplateRowEditPage")?id=${row.id}`;
});
$('#tbCheckListTemplateHeaderPage').on('click', '.delete-btn', function ()
{
const row = table.row($(this).closest('tr')).data();
showConfirmModal({
title: 'Törlés megerősítése',
message: 'Biztosan törölni szeretnéd ezt az elemet?',
okText: 'Törlés',
cancelText: 'Mégsem'
}).then(function(result) {
if(result === 'ok') {
console.log('Törlés végrehajtva');
}
});
});
$("#saveCheckListTemplateHeader").click(function () {
const csrfToken = document.querySelector('meta[name="csrf-token"]').getAttribute('content');
var formData = getFormAsNestedObject('#CheckListTemplateHeaderForm');
const $form = $('#CheckListTemplateHeaderForm');
formData.CheckListTemplateHeader.RoleDTO=[];
if ($form.valid())
{
$.ajax({
url: $('#CheckListTemplateHeaderEditPostUrl').val(),
type: 'POST',
headers: {
'X-CSRF-TOKEN': csrfToken,
'Content-Type': 'application/json'
},
data: JSON.stringify(formData.CheckListTemplateHeader),
success: function (response) {
showMessageModal({
title: 'Figyelmem!',
message: 'Sikeres mentés.',
okText: 'Értettem'
});
},
error: function (xhr, status, error) {
// Hiba esetén
console.error("Hiba: ", error);
showMessageModal({
title: 'Hiba!',
message: 'A mentés NEM sikerült!',
okText: 'Értettem'
});
}
});
} else
{
$form[0].reportValidity();
}
});
$(document).ready(function () {
const $form = $("#CheckListTemplateHeaderForm");
$form.validate({
errorClass: "text-danger small",
errorPlacement: function (error, element) {
error.appendTo(element.parent());
}
});
// $form.on("submit", function (e) {
// if (!$form.valid()) {
// e.preventDefault(); // Ne küldje be, ha van hiba
// }
// });
});
</script>
}
@@ -1,12 +1,32 @@
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.RazorPages;
using WorkFlowCheck.Common.DTO;
using WorkFlowCheck.Web.Services.Interfaces;
namespace WorkFlowCheck.Web.Pages.CheckListTemplate.CheckListTemplateHeader
{
public class CheckListTemplateHeaderEditPageModel : PageModel
{
public void OnGet()
private readonly ILogger<IndexModel> _logger;
private readonly ICheckListService _checkListService;
[BindProperty]
public CheckListTemplateHeaderDTO CheckListTemplateHeaderDTO { get; set; }
public CheckListTemplateHeaderEditPageModel(ILogger<IndexModel> logger, ICheckListService checkListService)
{
_logger = logger;
_checkListService = checkListService;
}
public async Task OnGet(int id)
{
CheckListTemplateHeaderDTO = await _checkListService.GetCheckListTemplateHeader(id);
}
public async Task<JsonResult> OnGetLoadCheckListTemplateRows(int id)
{
CheckListTemplateHeaderDTO = await _checkListService.GetCheckListTemplateHeader(id);
return new JsonResult(new { data = CheckListTemplateHeaderDTO.CheckListTemplateRowDTO });
}
}
}
@@ -18,7 +18,7 @@ namespace WorkFlowCheck.Web.Pages.CheckListTemplate.CheckListTemplateHeader
}
public async Task<JsonResult> OnGetLoadCheckListTemplateHeaders()
{
var results = await _checkListService.GetAllCheckListHeaderAsync();
var results = await _checkListService.GetAllCheckListTemplateHeaderAsync();
return new JsonResult(new { data = results });
}
}
@@ -1,4 +1,4 @@
@page
@page
@model WorkFlowCheck.Web.Pages.CheckListTemplate.CheckListTemplateRows.CheckListTemplateRowEditPageModel
@using Microsoft.AspNetCore.Antiforgery
@inject IAntiforgery Antiforgery
@@ -20,7 +20,7 @@
<input type="hidden" asp-for="CheckListTemplateRow.CheckListTemplateHeaderId" />
<div class="mb-3">
<label asp-for="CheckListTemplateRow.OperationDescription"></label>
<input asp-for="CheckListTemplateRow.OperationDescription" class="form-control" />
<textarea asp-for="CheckListTemplateRow.OperationDescription" class="form-control" rows="4"></textarea>
<span asp-validation-for="CheckListTemplateRow.OperationDescription" class="text-danger"></span>
</div>
<div class="mb-3">
@@ -31,6 +31,7 @@
<div class="mb-3">
<button type="button" id="saveCheckListTemplateRow" class="btn btn-primary">Mentés</button>
<button type="button" class="btn btn-secondary" onclick="history.back()">Mégsem</button>
</div>
</form>
</div>
@@ -144,7 +144,7 @@ namespace WorkFlowCheck.Web.Services
public async Task<CheckListTemplateRowDTO> GetCheckListTemplateRow(int id)
{
string endpoint = $"{_httpClient.BaseAddress}api/Sync/GetCheckListTemplateRow/{id}";
string endpoint = $"{_httpClient.BaseAddress}api/CheckList/GetCheckListTemplateRow/{id}";
var retVal = new CheckListTemplateRowDTO();
try
{
@@ -0,0 +1,103 @@
using Serilog;
using System.Net.Http;
using WorkFlowCheck.Common.DTO;
using WorkFlowCheck.Web.Services.Interfaces;
namespace WorkFlowCheck.Web.Services
{
public class CheckListService : BaseService, ICheckListService
{
public CheckListService(HttpClient httpClient, IConfiguration configuration, IHttpContextAccessor httpContextAccessor) : base(httpClient, configuration, httpContextAccessor)
{
}
public async Task<List<CheckListHeaderDTO>> GetAllCheckListHeaderAsync()
{
var endpoint = $"{_httpClient.BaseAddress}api/CheckList/GetAllCheckListHeaders";
var retVal = new List<CheckListHeaderDTO>();
try
{
var response = await _httpClient.GetFromJsonAsync<ApiResponseDTO<List<CheckListHeaderDTO>>>(endpoint);
if (response != null)
{
if (response.IsSuccess)
{
return response.Data;
}
}
}
catch (Exception ex)
{
Log.Error(ex.Message);
}
return retVal;
}
public async Task<CheckListHeaderDTO> GetCheckListHeader(int id)
{
var endpoint = $"{_httpClient.BaseAddress}api/CheckList/GetCheckListHeader/{id}";
var retVal = new CheckListHeaderDTO() { CheckListRowDTO = new List<CheckListRowDTO>() };
try
{
var response = await _httpClient.GetFromJsonAsync<ApiResponseDTO<CheckListHeaderDTO>>(endpoint);
if (response != null)
{
if (response.IsSuccess)
{
return response.Data;
}
}
}
catch (Exception ex)
{
Log.Error(ex.Message);
}
return retVal;
}
public async Task<ApiResponseDTO<CheckListHeaderDTO>> UpdateCheckListHeader(CheckListHeaderDTO checkListHeaderDTO) => throw new NotImplementedException();
public async Task<List<CheckListTemplateHeaderDTO>> GetAllCheckListTemplateHeaderAsync()
{
var endpoint = $"{_httpClient.BaseAddress}api/CheckList/GetAllCheckListTemplateHeaders";
var retVal = new List<CheckListTemplateHeaderDTO>();
try
{
var response = await _httpClient.GetFromJsonAsync<ApiResponseDTO<List<CheckListTemplateHeaderDTO>>>(endpoint);
if (response != null)
{
if (response.IsSuccess)
{
return response.Data;
}
}
}
catch (Exception ex)
{
Log.Error(ex.Message);
}
return retVal;
}
public async Task<CheckListTemplateHeaderDTO> GetCheckListTemplateHeader(int id)
{
var endpoint = $"{_httpClient.BaseAddress}api/CheckList/GetCheckListTemplateHeader/{id}";
var retVal = new CheckListTemplateHeaderDTO() { CheckListTemplateRowDTO = new List<CheckListTemplateRowDTO>() };
try
{
var response = await _httpClient.GetFromJsonAsync<ApiResponseDTO<CheckListTemplateHeaderDTO>>(endpoint);
if (response != null)
{
if (response.IsSuccess)
{
return response.Data;
}
}
}
catch (Exception ex)
{
Log.Error(ex.Message);
}
return retVal;
}
public async Task<ApiResponseDTO<CheckListTemplateHeaderDTO>> UpdateCheckListTemplateHeader(CheckListTemplateHeaderDTO checkListTemplateHeaderDTO) => throw new NotImplementedException();
}
}
@@ -1,56 +0,0 @@
using Serilog;
using System.Net.Http;
using WorkFlowCheck.Common.DTO;
namespace WorkFlowCheck.Web.Services.Interfaces
{
public class CheckListService : BaseService, ICheckListService
{
public CheckListService(HttpClient httpClient, IConfiguration configuration, IHttpContextAccessor httpContextAccessor) : base(httpClient, configuration, httpContextAccessor)
{
}
public async Task<List<CheckListHeaderDTO>> GetAllCheckListHeaderAsync()
{
string endpoint = $"{_httpClient.BaseAddress}api/CheckList/GetAllCheckListHeaders";
var retVal = new List<CheckListHeaderDTO>();
try
{
var response = await _httpClient.GetFromJsonAsync<ApiResponseDTO<List<CheckListHeaderDTO>>>(endpoint);
if (response != null)
{
if (response.IsSuccess)
{
return response.Data;
}
}
}
catch (Exception ex)
{
Log.Error(ex.Message);
}
return retVal;
}
public async Task<CheckListHeaderDTO> GetCheckListHeader(int id)
{
string endpoint = $"{_httpClient.BaseAddress}api/CheckList/GetCheckListHeader/{id}";
var retVal = new CheckListHeaderDTO() { CheckListRowDTO = new List<CheckListRowDTO>() };
try
{
var response = await _httpClient.GetFromJsonAsync<ApiResponseDTO<CheckListHeaderDTO>>(endpoint);
if (response != null)
{
if (response.IsSuccess)
{
return response.Data;
}
}
}
catch (Exception ex)
{
Log.Error(ex.Message);
}
return retVal;
}
public async Task<ApiResponseDTO<CheckListHeaderDTO>> UpdateCheckListHeader(CheckListHeaderDTO checkListHeaderDTO) => throw new NotImplementedException();
}
}
@@ -7,6 +7,10 @@ namespace WorkFlowCheck.Web.Services.Interfaces
Task<CheckListHeaderDTO> GetCheckListHeader(int id);
Task<List<CheckListHeaderDTO>> GetAllCheckListHeaderAsync();
Task<ApiResponseDTO<CheckListHeaderDTO>> UpdateCheckListHeader(CheckListHeaderDTO checkListHeaderDTO);
Task<CheckListTemplateHeaderDTO> GetCheckListTemplateHeader(int id);
Task<List<CheckListTemplateHeaderDTO>> GetAllCheckListTemplateHeaderAsync();
Task<ApiResponseDTO<CheckListTemplateHeaderDTO>> UpdateCheckListTemplateHeader(CheckListTemplateHeaderDTO checkListTemplateHeaderDTO);
}
}