Equipment is kész.

This commit is contained in:
2025-03-20 13:12:05 +01:00
parent bd60138a89
commit ae7ba2342e
19 changed files with 639 additions and 79 deletions
@@ -25,7 +25,14 @@ namespace WorkFlowCheck.Web.Middleware
{
context.User = new ClaimsPrincipal(new ClaimsIdentity(claims, "jwt"));
}
else
{
// Ha token van, de invalid, töröljük a cookiet
if (!string.IsNullOrEmpty(token))
{
context.Response.Cookies.Delete("AuthToken");
}
}
await _next(context);
}
private bool ValidateToken(string token, out Claim[] claims)
@@ -1,4 +1,96 @@
@page
@model WorkFlowCheck.Web.Pages.BaseStock.Equipments.EquipmentEditPageModel
@using Microsoft.AspNetCore.Antiforgery
@inject IAntiforgery Antiforgery
@{
ViewData["Title"] = "Berendezés";
var EquipmentId = Model.EquipmentDTO.Id;
var urlPost = Url.Page("./EquipmentEditPage", "Save");
}
<h1>@ViewData["Title"]</h1>
<input type="hidden" id="EquipmentEditPostUrl" value="@urlPost" />
<div class="card shadow p-4">
<form method="post" id="EquipmentForm">
<meta name="csrf-token" content="@Antiforgery.GetAndStoreTokens(HttpContext).RequestToken" />
<input type="hidden" asp-for="EquipmentDTO.Id" />
<div class="mb-3">
<label asp-for="EquipmentDTO.ShortName"></label>
<input asp-for="EquipmentDTO.ShortName" class="form-control" />
<span asp-validation-for="EquipmentDTO.ShortName" class="text-danger"></span>
</div>
<div class="mb-3">
<label asp-for="EquipmentDTO.EquipmentNumber"></label>
<input asp-for="EquipmentDTO.EquipmentNumber" class="form-control" />
<span asp-validation-for="EquipmentDTO.EquipmentNumber" class="text-danger"></span>
</div>
<div class="mb-3 d-flex justify-content-between">
<button type="button" id="saveEquipment" class="btn btn-primary">Mentés</button>
<button type="button" class="btn btn-secondary" onclick="history.back()">Mégsem</button>
</div>
</form>
</div>
@section Scripts {
<script>
$("#saveEquipment").click(function () {
const csrfToken = document.querySelector('meta[name="csrf-token"]').getAttribute('content');
var formData = getFormAsNestedObject('#EquipmentForm');
const $form = $('#EquipmentForm');
console.log(formData.Equipment);
if ($form.valid())
{
$.ajax({
url: $('#EquipmentEditPostUrl').val(),
type: 'POST',
headers: {
'X-CSRF-TOKEN': csrfToken,
'Content-Type': 'application/json'
},
data: JSON.stringify(formData.EquipmentDTO),
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 = $("#EquipmentForm");
$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,49 @@
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.RazorPages;
using Serilog;
using WorkFlowCheck.Common.DTO;
using WorkFlowCheck.Web.Services.Interfaces;
namespace WorkFlowCheck.Web.Pages.BaseStock.Equipments
{
public class EquipmentEditPageModel : PageModel
{
public void OnGet()
private readonly ILogger<IndexModel> _logger;
private readonly IBaseStockService _baseStockService;
[BindProperty]
public EquipmentDTO EquipmentDTO { get; set; }
public EquipmentEditPageModel(ILogger<IndexModel> logger, IBaseStockService baseStockService)
{
_baseStockService = baseStockService;
_logger = logger;
}
public async Task OnGet(int id)
{
EquipmentDTO = await _baseStockService.GetEquipment(id);
}
public async Task<IActionResult> OnPostSave([FromBody] EquipmentDTO equipmentDTO)
{
try
{
var result = await _baseStockService.UpdateEquipment(equipmentDTO);
if (result.IsSuccess)
{
return new JsonResult(new { success = true });
}
else
{
return new JsonResult(new { success = false });
}
}
catch (Exception ex)
{
Log.Error(ex.Message);
}
return new JsonResult(new { success = false });
}
}
}
@@ -7,13 +7,16 @@
<div class="card shadow p-4">
<div class="d-flex justify-content-end">
<button class="btn btn-primary float-right">Új elem hozzáadása</button>
<button id="newEquipmentBtn" class="btn btn-primary float-right new-btn" data-bs-toggle="tooltip" data-bs-placement="top" title="Új berendezés">
<i class="bi bi-plus-square"></i>
</button>
</div>
<table id="tbEquipmentsPage" class="table table-bordered table-hover table-sm" style="width:100%">
<thead class="table-primary">
<tr>
<th>ID</th>
<th>Short Name</th>
<th>Equipment Number</th>
<th class="text-center">Action</th>
</tr>
</thead>
@@ -21,6 +24,7 @@
<tr>
<th>ID</th>
<th>Short Name</th>
<th>Equipment Number</th>
<th>Action</th>
</tr>
</tfoot>
@@ -38,6 +42,7 @@
columns: [
{ data: "id" },
{ data: "shortName" },
{ data: "equipmentNumber" },
{ data: null, render: function (data, type, row) {
return renderActionButtons(row.id);
}}
@@ -48,9 +53,9 @@
"visible": false
},
{
"targets": 2,
"targets": 3,
"className": "text-center",
"width": "10"
"width": "10%"
}
],
@@ -58,6 +63,11 @@
language: { url: '//cdn.datatables.net/plug-ins/2.2.2/i18n/hu.json',}
});
$('#newEquipmentBtn').on('click', function ()
{
window.location.href = `@Url.Page("/BaseStock/Equipments/EquipmentEditPage")?id=0`;
});
$('#tbEquipmentsPage').on('click', '.edit-btn', function ()
{
const row = table.row($(this).closest('tr')).data();
@@ -31,7 +31,7 @@
<br></br>
<div class="card shadow p-4">
<div class="d-flex justify-content-end">
<button id="newCheckListTemplateHeaderBtn" class="btn btn-primary float-right new-btn" data-bs-toggle="tooltip" data-bs-placement="top" title="Új elem hozzáadása">
<button id="newCheckListTemplateRowBtn" 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>
@@ -91,11 +91,19 @@
processing:true,
language: { url: '//cdn.datatables.net/plug-ins/2.2.2/i18n/hu.json',}
});
$('#newCheckListTemplateRowBtn').on('click', function () {
const parentId = @CheckListTemplateHeaderId;
window.location.href = '@Url.Page("/CheckListTemplate/CheckListTemplateRows/CheckListTemplateRowEditPage", "New")' + `&parentId=${parentId}`;
});
$('#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 ()
@@ -1,4 +1,4 @@
@page
@page
@model WorkFlowCheck.Web.Pages.CheckListTemplate.CheckListTemplateRows.CheckListTemplateRowEditPageModel
@using Microsoft.AspNetCore.Antiforgery
@inject IAntiforgery Antiforgery
@@ -70,7 +70,7 @@
'X-CSRF-TOKEN': csrfToken,
'Content-Type': 'application/json'
},
data: JSON.stringify(formData.CheckPoint),
data: JSON.stringify(formData.CheckListTemplateRow),
success: function (response) {
showMessageModal({
title: 'Figyelmem!',
@@ -1,6 +1,7 @@
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.RazorPages;
using Microsoft.AspNetCore.Mvc.Rendering;
using Serilog;
using WorkFlowCheck.Common.DTO;
using WorkFlowCheck.Web.Services.Interfaces;
@@ -9,6 +10,7 @@ namespace WorkFlowCheck.Web.Pages.CheckListTemplate.CheckListTemplateRows
public class CheckListTemplateRowEditPageModel : PageModel
{
private readonly ILogger<IndexModel> _logger;
private readonly ICheckListService _checkListService;
private readonly IBaseStockService _baseStockService;
@@ -27,8 +29,9 @@ namespace WorkFlowCheck.Web.Pages.CheckListTemplate.CheckListTemplateRows
[BindProperty]
public List<SelectListItem> Equipments { get; set; }
public CheckListTemplateRowEditPageModel(ILogger<IndexModel> logger, IBaseStockService baseStockService)
public CheckListTemplateRowEditPageModel(ILogger<IndexModel> logger, ICheckListService checkListService, IBaseStockService baseStockService)
{
_checkListService = checkListService;
_baseStockService = baseStockService;
_logger = logger;
}
@@ -36,7 +39,64 @@ namespace WorkFlowCheck.Web.Pages.CheckListTemplate.CheckListTemplateRows
public async Task OnGet(int id)
{
await InitSelectItems();
CheckListTemplateRow = await _baseStockService.GetCheckListTemplateRow(id);
CheckListTemplateRow = await _checkListService.GetCheckListTemplateRow(id);
}
public async Task OnGetNew(int parentId)
{
await InitSelectItems();
var checkListTemplateHeader = await _checkListService.GetCheckListTemplateHeader(parentId);
if (checkListTemplateHeader != null)
{
int rowIndex = 1;
int equipmentId = 0;
int checkPointId = 0;
if (checkListTemplateHeader.CheckListTemplateRowDTO.Count() > 0)
{
var checkListTemplateRowMax = checkListTemplateHeader.CheckListTemplateRowDTO.OrderByDescending(o => o.RowIndex).FirstOrDefault();
if (checkListTemplateRowMax != null)
{
rowIndex = checkListTemplateRowMax.RowIndex + 1;
checkPointId=checkListTemplateRowMax.CheckPointId;
equipmentId= checkListTemplateRowMax.EquipmentId;
}
}
CheckListTemplateRow = new CheckListTemplateRowDTO()
{
Id = 0,
CheckListTemplateHeaderId = parentId,
RowIndex = rowIndex,
EquipmentId = equipmentId,
CheckPointId = checkPointId,
AnswerType = "I-N"
};
}
}
public async Task<IActionResult> OnPostSave([FromBody] CheckListTemplateRowDTO checkListTemplateRowDTO)
{
try
{
var result = await _checkListService.UpdateCheckListTemplateRow(checkListTemplateRowDTO);
if (result.IsSuccess)
{
return new JsonResult(new { success = true });
}
else
{
return new JsonResult(new { success = false });
}
}
catch (Exception ex)
{
Log.Error(ex.Message);
}
return new JsonResult(new { success = false });
}
private async Task InitSelectItems()
{
@@ -53,5 +113,6 @@ namespace WorkFlowCheck.Web.Pages.CheckListTemplate.CheckListTemplateRows
this.Equipments.Add(new SelectListItem() { Value = equipment.Id.ToString(), Text = equipment.ShortName });
}
}
}
}
+10 -2
View File
@@ -75,8 +75,16 @@ app.UseAuthorization();
app.Use(async (context, next) =>
{
if (string.IsNullOrEmpty(context.User?.Identity?.Name) &&
context.Request.Path == "/")
//if (string.IsNullOrEmpty(context.User?.Identity?.Name) &&
// context.Request.Path == "/")
//{
// context.Response.Redirect("/Account/Login");
// return;
//}
var isAuthenticated = context.User?.Identity?.IsAuthenticated == true;
var path = context.Request.Path.Value?.ToLower();
if (!isAuthenticated && !path.StartsWith("/account/login"))
{
context.Response.Redirect("/Account/Login");
return;
@@ -80,7 +80,7 @@ namespace WorkFlowCheck.Web.Services
public async Task<CheckPointDTO> GetCheckPoint(int id)
{
string endpoint = $"{_httpClient.BaseAddress}api/Sync/GetCheckPoints/{id}";
string endpoint = $"{_httpClient.BaseAddress}api/Sync/GetCheckPoint/{id}";
var retVal = new CheckPointDTO();
try
{
@@ -142,28 +142,7 @@ namespace WorkFlowCheck.Web.Services
return retVal;
}
public async Task<CheckListTemplateRowDTO> GetCheckListTemplateRow(int id)
{
string endpoint = $"{_httpClient.BaseAddress}api/CheckList/GetCheckListTemplateRow/{id}";
var retVal = new CheckListTemplateRowDTO();
try
{
var response = await _httpClient.GetFromJsonAsync<ApiResponseDTO<CheckListTemplateRowDTO>>(endpoint);
if (response != null)
{
if (response.IsSuccess)
{
return response.Data;
}
}
}
catch (Exception ex)
{
Log.Error(ex.Message);
}
return retVal;
}
public async Task<ApiResponseDTO<CheckPointDTO>> UpdateCheckPoint(CheckPointDTO checkPointDTO)
{
try
@@ -1,4 +1,5 @@
using Serilog;
using Newtonsoft.Json;
using Serilog;
using System.Net.Http;
using WorkFlowCheck.Common.DTO;
using WorkFlowCheck.Web.Services.Interfaces;
@@ -99,5 +100,56 @@ namespace WorkFlowCheck.Web.Services
return retVal;
}
public async Task<ApiResponseDTO<CheckListTemplateHeaderDTO>> UpdateCheckListTemplateHeader(CheckListTemplateHeaderDTO checkListTemplateHeaderDTO) => throw new NotImplementedException();
public async Task<CheckListTemplateRowDTO> GetCheckListTemplateRow(int id)
{
string endpoint = $"{_httpClient.BaseAddress}api/CheckList/GetCheckListTemplateRow/{id}";
var retVal = new CheckListTemplateRowDTO();
try
{
var response = await _httpClient.GetFromJsonAsync<ApiResponseDTO<CheckListTemplateRowDTO>>(endpoint);
if (response != null)
{
if (response.IsSuccess)
{
return response.Data;
}
}
}
catch (Exception ex)
{
Log.Error(ex.Message);
}
return retVal;
}
public async Task<ApiResponseDTO<CheckListTemplateRowDTO>> UpdateCheckListTemplateRow(CheckListTemplateRowDTO checkListTemplateRowDTO)
{
try
{
string endpoint = $"{_httpClient.BaseAddress}api/CheckList/UpdateCheckListTemplateRow";
using (HttpResponseMessage httpResponseMessage = await _httpClient.PostAsJsonAsync(endpoint, checkListTemplateRowDTO))
{
httpResponseMessage.EnsureSuccessStatusCode();
var jsonString = await httpResponseMessage.Content.ReadAsStringAsync();
var response = JsonConvert.DeserializeObject<ApiResponseDTO<CheckListTemplateRowDTO>>(jsonString);
return response ?? new ApiResponseDTO<CheckListTemplateRowDTO>
{
IsSuccess = false,
};
}
}
catch (Exception ex)
{
// Hiba visszaadása
return new ApiResponseDTO<CheckListTemplateRowDTO>
{
IsSuccess = false
};
}
}
}
}
@@ -4,11 +4,18 @@ namespace WorkFlowCheck.Web.Services.Interfaces
{
public interface IBaseStockService
{
Task<List<CheckPointDTO>> GetAllCheckPoints();
Task<List<EquipmentDTO>> GetAllEquipments();
Task<List<LocationDTO>> GetAllLocations();
Task<CheckPointDTO> GetCheckPoint(int id);
Task<CheckListTemplateRowDTO> GetCheckListTemplateRow(int id);
Task<ApiResponseDTO<CheckPointDTO>> UpdateCheckPoint(CheckPointDTO checkPoint);
Task<List<CheckPointDTO>> GetAllCheckPoints();
Task<ApiResponseDTO<CheckPointDTO>> UpdateCheckPoint(CheckPointDTO checkPointDTO);
Task<EquipmentDTO> GetEquipment(int id);
Task<List<EquipmentDTO>> GetAllEquipments();
Task<ApiResponseDTO<EquipmentDTO>> UpdateEquipment(EquipmentDTO equipmentDTO);
Task<LocationDTO> GetLocation(int id);
Task<List<LocationDTO>> GetAllLocations();
Task<ApiResponseDTO<LocationDTO>> UpdateLocation(LocationDTO LocationDTO);
}
}
@@ -12,5 +12,8 @@ namespace WorkFlowCheck.Web.Services.Interfaces
Task<List<CheckListTemplateHeaderDTO>> GetAllCheckListTemplateHeaderAsync();
Task<ApiResponseDTO<CheckListTemplateHeaderDTO>> UpdateCheckListTemplateHeader(CheckListTemplateHeaderDTO checkListTemplateHeaderDTO);
Task<CheckListTemplateRowDTO> GetCheckListTemplateRow(int id);
Task<ApiResponseDTO<CheckListTemplateRowDTO>> UpdateCheckListTemplateRow(CheckListTemplateRowDTO checkListTemplateRowDTO);
}
}