CheckListRow megjelenítése

This commit is contained in:
2025-03-26 09:14:27 +01:00
parent ace4130f31
commit 83980667d7
4 changed files with 215 additions and 2 deletions
@@ -38,9 +38,22 @@ namespace WorkFlowCheck.BL.Services
var res = await _dbContext.CheckListHeaders var res = await _dbContext.CheckListHeaders
.Where(w => w.Id == Id) .Where(w => w.Id == Id)
.Include(i => i.CheckListRows) .Include(i => i.CheckListRows)
.ThenInclude(r => r.CheckListTemplateRow)
.ThenInclude(r => r.CheckPoint)
.Include(i => i.CheckListRows)
.ThenInclude(r => r.CheckListTemplateRow)
.ThenInclude(r => r.Equipment)
.AsNoTracking() .AsNoTracking()
.FirstOrDefaultAsync(); .FirstOrDefaultAsync();
if (res != null)
{
res.CheckListRows = res.CheckListRows
.OrderBy(r => r.CheckListTemplateRow.CheckPoint?.ShortName ?? string.Empty)
.ThenBy(r => r.CheckListTemplateRow.RowIndex)
.ToList();
}
if (res != null) if (res != null)
{ {
retVal = _mapper.Map<CheckListHeaderDTO>(res); retVal = _mapper.Map<CheckListHeaderDTO>(res);
@@ -12,7 +12,7 @@ namespace WorkFlowCheck.Common.DTO
public int CheckListHeaderId { get; set; } public int CheckListHeaderId { get; set; }
public int CheckListTemplateRowId { get; set; } public int CheckListTemplateRowId { get; set; }
public CheckListTemplateRowDTO CheckListTemplateRowDTO { get; set; } public CheckListTemplateRowDTO CheckListTemplateRowDTO { get; set; }
public string GroupName => $"AnswerGroup_{CheckListTemplateRowDTO.RowIndex}"; public string GroupName => $"AnswerGroup_{CheckListTemplateRowDTO?.RowIndex ?? 0}";
public string Answer { get; set; } = null!; public string Answer { get; set; } = null!;
public bool? AnswerYes { get; set; } = null!; public bool? AnswerYes { get; set; } = null!;
public bool? AnswerNo { get; set; } = null!; public bool? AnswerNo { get; set; } = null!;
@@ -1,4 +1,184 @@
@page @page
@model WorkFlowCheck.Web.Pages.CheckList.CheckListHeader.CheckListHeaderEditPageModel @model WorkFlowCheck.Web.Pages.CheckList.CheckListHeader.CheckListHeaderEditPageModel
@using Microsoft.AspNetCore.Antiforgery
@inject IAntiforgery Antiforgery
@{ @{
ViewData["Title"] = "Ellenőrzés sablon";
var CheckListHeaderId = Model.CheckListHeaderDTO.Id;
var url = Url.Page("./CheckListHeaderEditPage", "LoadCheckListRows", new { id = CheckListHeaderId });
var urlPost = Url.Page("./CheckListHeaderEditPage", "Save");
}
<h1>@ViewData["Title"]</h1>
<input type="hidden" id="CheckListHeaderEditUrl" value="@url" />
<input type="hidden" id="CheckListHeaderEditPostUrl" value="@urlPost" />
<div class="card shadow p-4">
<form method="post" id="CheckListHeaderForm">
<meta name="csrf-token" content="@Antiforgery.GetAndStoreTokens(HttpContext).RequestToken" />
<input type="hidden" asp-for="CheckListHeaderDTO.Id" />
<div class="mb-3">
<label asp-for="CheckListHeaderDTO.ShortName"></label>
<input asp-for="CheckListHeaderDTO.ShortName" class="form-control" />
<span asp-validation-for="CheckListHeaderDTO.ShortName" class="text-danger"></span>
</div>
<div class="mb-3 d-flex justify-content-between">
<button type="button" id="saveCheckListHeader" 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">
<div class="d-flex justify-content-end">
<button id="newCheckListRowBtn" class="btn btn-primary float-right new-btn" data-bs-toggle="tooltip" data-bs-placement="top" title="Új elem hozzáadása">
<i class="bi bi-plus-square"></i>
</button>
</div>
<table id="tbCheckListHeaderPage" class="table table-bordered table-hover table-sm" style="width:100%">
<thead class="table-primary">
<tr>
<th>ID</th>
<th>Short Name</th>
<th>Checkpoint</th>
<th>OperationDescription</th>
<th>AnswerType</th>
<th>Answer</th>
<th class="text-center">Action</th>
</tr>
</thead>
<tfoot class="table-light">
<tr>
<th>ID</th>
<th>Short Name</th>
<th>Checkpoint</th>
<th>OperationDescription</th>
<th>AnswerType</th>
<th>Answer</th>
<th class="text-center">Action</th>
</tr>
</tfoot>
</table>
</div>
@section Scripts {
<script>
const table = new DataTable('#tbCheckListHeaderPage', {
ajax: {
url: $('#CheckListHeaderEditUrl').val(),
type: "GET",
dataSrc : "data"
},
columns: [
{ data: "id" },
{ data: "checkListTemplateRowDTO.rowIndex" },
{ data: "checkListTemplateRowDTO.checkPointDTO.shortName" },
{ data: "checkListTemplateRowDTO.operationDescription" },
{ data: "checkListTemplateRowDTO.answerType" },
{ data: "answer" },
{ data: null, render: function (data, type, row) {
return renderActionButtons(row.id);
}}
],
columnDefs: [
{
"targets": 0,
"visible": false
},
{
"targets": 6,
"className": "text-center",
"width": "10%"
}
],
processing:true,
language: { url: '//cdn.datatables.net/plug-ins/2.2.2/i18n/hu.json',}
});
$('#newCheckListRowBtn').on('click', function () {
const parentId = @CheckListHeaderId;
window.location.href = '@Url.Page("/CheckList/CheckListRow/CheckListRowEditPage", "New")' + `&parentId=${parentId}`;
});
$('#tbCheckListHeaderPage').on('click', '.edit-btn', function ()
{
const row = table.row($(this).closest('tr')).data();
window.location.href = `@Url.Page("/CheckList/CheckListRow/CheckListRowEditPage")?id=${row.id}`;
});
$('#tbCheckListHeaderPage').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');
}
});
});
$("#saveCheckListHeader").click(function () {
const csrfToken = document.querySelector('meta[name="csrf-token"]').getAttribute('content');
var formData = getFormAsNestedObject('#CheckListHeaderForm');
const $form = $('#CheckListHeaderForm');
formData.CheckListHeader.RoleDTO=[];
if ($form.valid())
{
$.ajax({
url: $('#CheckListHeaderEditPostUrl').val(),
type: 'POST',
headers: {
'X-CSRF-TOKEN': csrfToken,
'Content-Type': 'application/json'
},
data: JSON.stringify(formData.CheckListHeader),
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 = $("#CheckListHeaderForm");
$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;
using Microsoft.AspNetCore.Mvc.RazorPages; using Microsoft.AspNetCore.Mvc.RazorPages;
using WorkFlowCheck.Common.DTO;
using WorkFlowCheck.Web.Services.Interfaces;
namespace WorkFlowCheck.Web.Pages.CheckList.CheckListHeader namespace WorkFlowCheck.Web.Pages.CheckList.CheckListHeader
{ {
public class CheckListHeaderEditPageModel : PageModel public class CheckListHeaderEditPageModel : PageModel
{ {
public void OnGet() private readonly ILogger<IndexModel> _logger;
private readonly ICheckListService _checkListService;
[BindProperty]
public CheckListHeaderDTO CheckListHeaderDTO { get; set; }
public CheckListHeaderEditPageModel(ILogger<IndexModel> logger, ICheckListService checkListService)
{ {
_logger = logger;
_checkListService = checkListService;
}
public async Task OnGet(int id)
{
CheckListHeaderDTO = await _checkListService.GetCheckListHeader(id);
}
public async Task<JsonResult> OnGetLoadCheckListRows(int id)
{
CheckListHeaderDTO = await _checkListService.GetCheckListHeader(id);
return new JsonResult(new { data = CheckListHeaderDTO.CheckListRowDTO });
} }
} }
} }