From 272bd1a3fd91469a55d94eefd3453987e24322d8 Mon Sep 17 00:00:00 2001 From: ivanszabo Date: Wed, 7 May 2025 13:05:28 +0200 Subject: [PATCH] =?UTF-8?q?CheckListTemplateHeader=20kl=C3=B3noz=C3=A1sa?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Controllers/CheckListController.cs | 22 ++++++++ .../Services/CheckListService.cs | 54 +++++++++++++++++-- .../Services/Interfaces/ICheckListService.cs | 1 + src/WorkFlowCheck.Web/Helpers/SystemHelper.cs | 2 +- .../CheckListTemplateHeaderPage.cshtml | 47 +++++++++++++++- .../CheckListTemplateHeaderPage.cshtml.cs | 5 ++ .../Services/CheckListService.cs | 21 ++++++++ .../Services/Interfaces/ICheckListService.cs | 2 + src/WorkFlowCheck.Web/wwwroot/js/site.js | 13 +++++ 9 files changed, 160 insertions(+), 7 deletions(-) diff --git a/src/WorkFlowCheck.API/Controllers/CheckListController.cs b/src/WorkFlowCheck.API/Controllers/CheckListController.cs index 83672b0..6b60296 100644 --- a/src/WorkFlowCheck.API/Controllers/CheckListController.cs +++ b/src/WorkFlowCheck.API/Controllers/CheckListController.cs @@ -301,6 +301,28 @@ namespace WorkFlowCheck.API.Controllers return retVal; } + [HttpGet("CloneCheckListTemplateHeader/{id}")] + public async Task> CloneCheckListTemplateHeader(int id) + { + var retVal = new ApiResponseDTO() + { + IsSuccess = true, + }; + var result = await _checkListService.CloneCheckListTemplateHeaderAsync(id); + + if (result != null) + { + retVal.IsSuccess = true; + retVal.Data = result; + } + else + { + retVal.IsSuccess = false; + retVal.Errors.Add("No data!"); + } + + return retVal; + } [HttpGet("GetCheckListTemplateRow/{id}")] public async Task> GetCheckListTemplateRow(int id) diff --git a/src/WorkFlowCheck.BL/Services/CheckListService.cs b/src/WorkFlowCheck.BL/Services/CheckListService.cs index 83adad8..e29a958 100644 --- a/src/WorkFlowCheck.BL/Services/CheckListService.cs +++ b/src/WorkFlowCheck.BL/Services/CheckListService.cs @@ -24,7 +24,7 @@ namespace WorkFlowCheck.BL.Services { public class CheckListService : BaseService, ICheckListService { - + private readonly INumberGeneratorService _numberGeneratorService; public CheckListService(AppDbContext dbContext, @@ -377,7 +377,7 @@ namespace WorkFlowCheck.BL.Services { checkListHeader.CheckStatus = CheckStatus.Closed; checkListHeader.IsEditable = false; - checkListHeader.AcceptUserId = closeCheckListHeaderCloseDTO.UserId; + checkListHeader.AcceptUserId = closeCheckListHeaderCloseDTO.UserId; Log.ForContext("TAG", "BusinessFlow").Warning($"Ellenőrzési lap lezárva: Ellenőrzés:{closeCheckListHeaderCloseDTO.Id}, " + $"Felhasználó:{closeCheckListHeaderCloseDTO.UserId}, " + @@ -394,7 +394,7 @@ namespace WorkFlowCheck.BL.Services } return retVal; } - + public async Task GetCheckListTemplateHeaderAsync(int Id) { var retVal = new CheckListTemplateHeaderDTO() @@ -491,7 +491,53 @@ namespace WorkFlowCheck.BL.Services } public async Task DeleteCheckListTemplateHeaderAsync(int id) { - return await DeleteEntityByIdAsync(id); + return await DeleteEntityByIdAsync(id); + } + public async Task CloneCheckListTemplateHeaderAsync(int id) + { + var retVal = false; + try + { + var checkListTemplateHeader = await _dbContext.CheckListTemplateHeaders + .Include(i => i.CheckListTemplateRows) + .Where(w => w.Id == id).FirstOrDefaultAsync(); + if (checkListTemplateHeader != null) + { + + var newCheckListTemplateHeader = new CheckListTemplateHeader() + { + CheckListTemplateRows = new List(), + Description = checkListTemplateHeader.Description, + IsDeleted = false, + NumberGenerator1Id = checkListTemplateHeader.NumberGenerator1Id, + NumberGenerator2Id = checkListTemplateHeader.NumberGenerator2Id, + ShortName = $"{checkListTemplateHeader.ShortName} (másolat)", + }; + foreach (var checkListTemplateRow in checkListTemplateHeader.CheckListTemplateRows) + { + var newCheckListTemplateRow = new CheckListTemplateRow() + { + AnswerType = checkListTemplateRow.AnswerType, + CheckListTemplateHeader = newCheckListTemplateHeader, + CheckPointId = checkListTemplateRow.CheckPointId, + EquipmentId = checkListTemplateRow.EquipmentId, + IsDeleted = false, + OperationDescription = checkListTemplateRow.OperationDescription, + RowIndex = checkListTemplateRow.RowIndex, + }; + newCheckListTemplateHeader.CheckListTemplateRows.Add(newCheckListTemplateRow); + } + _dbContext.CheckListTemplateHeaders.Add(newCheckListTemplateHeader); + await _dbContext.SaveChangesAsync(); + } + } + catch (Exception ex) + { + retVal = false; + Log.ForContext("TAG", "BusinessFlow").Error(ex.Message); + } + + return retVal; } public async Task GetCheckListTemplateRowAsync(int id) { diff --git a/src/WorkFlowCheck.BL/Services/Interfaces/ICheckListService.cs b/src/WorkFlowCheck.BL/Services/Interfaces/ICheckListService.cs index a5027cd..b33f7cc 100644 --- a/src/WorkFlowCheck.BL/Services/Interfaces/ICheckListService.cs +++ b/src/WorkFlowCheck.BL/Services/Interfaces/ICheckListService.cs @@ -20,6 +20,7 @@ namespace WorkFlowCheck.BL.Services.Interfaces Task> GetAllCheckListTemplateHeaderAsync(); Task UpdateCheckListTemplateHeaderAsync(CheckListTemplateHeaderDTO checkListTemplateHeaderDTO); Task DeleteCheckListTemplateHeaderAsync(int id); + Task CloneCheckListTemplateHeaderAsync(int id); Task GetCheckListTemplateRowAsync(int id); Task DeleteCheckListTemplateRowAsync(int id); Task UpdateCheckListTemplateRowAsync(CheckListTemplateRowDTO checkListTemplateRowDTO); diff --git a/src/WorkFlowCheck.Web/Helpers/SystemHelper.cs b/src/WorkFlowCheck.Web/Helpers/SystemHelper.cs index 9715705..f6afb23 100644 --- a/src/WorkFlowCheck.Web/Helpers/SystemHelper.cs +++ b/src/WorkFlowCheck.Web/Helpers/SystemHelper.cs @@ -7,7 +7,7 @@ namespace WorkFlowCheck.Web.Helpers public static class SystemHelper { public static string DatabaseName = ""; - public static string ProgramVersion = "v1.1.019"; + public static string ProgramVersion = "v1.1.021"; public async static Task GetAPIInfoAsync(IConfiguration configuration) { diff --git a/src/WorkFlowCheck.Web/Pages/CheckListTemplate/CheckListTemplateHeader/CheckListTemplateHeaderPage.cshtml b/src/WorkFlowCheck.Web/Pages/CheckListTemplate/CheckListTemplateHeader/CheckListTemplateHeaderPage.cshtml index e04889c..83ca451 100644 --- a/src/WorkFlowCheck.Web/Pages/CheckListTemplate/CheckListTemplateHeader/CheckListTemplateHeaderPage.cshtml +++ b/src/WorkFlowCheck.Web/Pages/CheckListTemplate/CheckListTemplateHeader/CheckListTemplateHeaderPage.cshtml @@ -47,7 +47,7 @@ { data: "shortName" }, { data: "description" }, { data: null, render: function (data, type, row) { - return renderActionButtons(row.id); + return renderActionButtonsforCheckListTemplateHeader(row.id); }} ], columnDefs: [ @@ -68,15 +68,58 @@ $('#newCheckListTemplateHeaderBtn').on('click', function () { - console.log('New button clicked!"'); window.location.href = `@Url.Page("./CheckListTemplateHeaderEditPage")?id=0`; }); + $('#tbCheckListTemplateHeadersPage').on('click', '.edit-btn', function () { const row = table.row($(this).closest('tr')).data(); window.location.href = `@Url.Page("./CheckListTemplateHeaderEditPage")?id=${row.id}`; }); + + $('#tbCheckListTemplateHeadersPage').on('click', '.clone-btn', function () + { + const row = table.row($(this).closest('tr')).data(); + const url = './CheckListTemplateHeaderPage?handler=CloneCheckListTemplateHeader'; + showConfirmModal({ + title: 'Klónozás megerősítése', + message: 'Biztosan klónozni szeretnéd ezt az elemet?', + okText: 'Klónozás', + cancelText: 'Mégsem' + }).then(function (result) { + if (result === 'ok') { + $.ajax({ + url: url, + type: 'GET', + data: { id: row.id }, + success: function (data) { + if (data) { + showMessageModal({ + title: 'Információ', + message: 'A klónozás sikerült!', + okText: 'Értettem' + }); + table.ajax.reload(); + } else { + showMessageModal({ + title: 'Hiba!', + message: 'A klónozás NEM sikerült!', + okText: 'Értettem' + }); + } + }, + error: function (xhr, status, error) { + showMessageModal({ + title: 'Hiba!', + message: 'A klónozás NEM sikerült!', + okText: 'Értettem' + }); + } + }); + } + }); + }); $('#tbCheckListTemplateHeadersPage').on('click', '.delete-btn', function () { diff --git a/src/WorkFlowCheck.Web/Pages/CheckListTemplate/CheckListTemplateHeader/CheckListTemplateHeaderPage.cshtml.cs b/src/WorkFlowCheck.Web/Pages/CheckListTemplate/CheckListTemplateHeader/CheckListTemplateHeaderPage.cshtml.cs index 7942c43..7950b2e 100644 --- a/src/WorkFlowCheck.Web/Pages/CheckListTemplate/CheckListTemplateHeader/CheckListTemplateHeaderPage.cshtml.cs +++ b/src/WorkFlowCheck.Web/Pages/CheckListTemplate/CheckListTemplateHeader/CheckListTemplateHeaderPage.cshtml.cs @@ -27,5 +27,10 @@ namespace WorkFlowCheck.Web.Pages.CheckListTemplate.CheckListTemplateHeader var isSuccess = await _checkListService.DeleteCheckListTemplateHeader(id); return new JsonResult(new { result = isSuccess }); } + public async Task OnGetCloneCheckListTemplateHeader(int id) + { + var isSuccess = await _checkListService.CloneCheckListTemplateHeader(id); + return new JsonResult(new { result = isSuccess }); + } } } diff --git a/src/WorkFlowCheck.Web/Services/CheckListService.cs b/src/WorkFlowCheck.Web/Services/CheckListService.cs index 413c5a7..75cbe72 100644 --- a/src/WorkFlowCheck.Web/Services/CheckListService.cs +++ b/src/WorkFlowCheck.Web/Services/CheckListService.cs @@ -264,6 +264,27 @@ namespace WorkFlowCheck.Web.Services } return retVal; } + public async Task CloneCheckListTemplateHeader(int id) + { + string endpoint = $"{_httpClient.BaseAddress}api/CheckList/CloneCheckListTemplateHeader/{id}"; + var retVal = false; + try + { + var response = await _httpClient.GetFromJsonAsync>(endpoint); + if (response != null) + { + if (response.IsSuccess) + { + return response.Data; + } + } + } + catch (Exception ex) + { + Log.Error(ex.Message); + } + return retVal; + } public async Task GetCheckListTemplateRow(int id) diff --git a/src/WorkFlowCheck.Web/Services/Interfaces/ICheckListService.cs b/src/WorkFlowCheck.Web/Services/Interfaces/ICheckListService.cs index d3a48a8..ecd5622 100644 --- a/src/WorkFlowCheck.Web/Services/Interfaces/ICheckListService.cs +++ b/src/WorkFlowCheck.Web/Services/Interfaces/ICheckListService.cs @@ -19,9 +19,11 @@ namespace WorkFlowCheck.Web.Services.Interfaces Task> GetAllCheckListTemplateHeaderAsync(); Task> UpdateCheckListTemplateHeader(CheckListTemplateHeaderDTO checkListTemplateHeaderDTO); Task DeleteCheckListTemplateHeader(int id); + Task CloneCheckListTemplateHeader(int id); Task GetCheckListTemplateRow(int id); Task DeleteCheckListTemplateRow(int id); + Task> UpdateCheckListTemplateRow(CheckListTemplateRowDTO checkListTemplateRowDTO); diff --git a/src/WorkFlowCheck.Web/wwwroot/js/site.js b/src/WorkFlowCheck.Web/wwwroot/js/site.js index 7a5ab1e..a35e974 100644 --- a/src/WorkFlowCheck.Web/wwwroot/js/site.js +++ b/src/WorkFlowCheck.Web/wwwroot/js/site.js @@ -232,6 +232,19 @@ function renderActionButtonsforCheckListHeader(data, rowId) { //`; } +function renderActionButtonsforCheckListTemplateHeader(rowId) { + return ` + + + + `; +} function renderCheckStatus(data) { //Open = 0,