From 17fca589ea91309c3e117126e37b7312a56b3984 Mon Sep 17 00:00:00 2001 From: Dara Keon Date: Fri, 23 Aug 2024 00:47:19 +0100 Subject: [PATCH] site: add cancel line --- core/BusinessLogic/Services/RobotService.cs | 4 +++- core/Language/Language/Site/wizard.json | 2 ++ docs/todo/importer-exporter.md | 2 +- site/MVC/Controllers/ArchivesController.cs | 11 ++++++++++- site/MVC/Models/ArchivesLinesModel.cs | 10 ++++++++-- site/MVC/Views/Archives/LineRow.cshtml | 21 +++++++++++++++++++-- site/MVC/Views/Archives/Lines.cshtml | 9 +++++---- 7 files changed, 48 insertions(+), 11 deletions(-) diff --git a/core/BusinessLogic/Services/RobotService.cs b/core/BusinessLogic/Services/RobotService.cs index 7863e57f9..75519fc83 100644 --- a/core/BusinessLogic/Services/RobotService.cs +++ b/core/BusinessLogic/Services/RobotService.cs @@ -721,7 +721,7 @@ public LineInfo RetryLine(Guid archiveGuid, Int16 linePosition) return LineInfo.Convert(line); } - public void CancelLine(Guid archiveGuid, Int16 linePosition) + public LineInfo CancelLine(Guid archiveGuid, Int16 linePosition) { var user = parent.Auth.VerifyUser(); var line = repos.Line.Get(archiveGuid, linePosition); @@ -737,6 +737,8 @@ public void CancelLine(Guid archiveGuid, Int16 linePosition) line.Status = ImportStatus.Canceled; repos.Line.SaveOrUpdate(line); }); + + return LineInfo.Convert(line); } public ArchiveInfo CancelArchive(Guid archiveGuid) diff --git a/core/Language/Language/Site/wizard.json b/core/Language/Language/Site/wizard.json index c73b02448..a5b958979 100644 --- a/core/Language/Language/Site/wizard.json +++ b/core/Language/Language/Site/wizard.json @@ -175,6 +175,7 @@ "It is possible to check the line position in the original file.", "The importation status will appear for each line.", "In case of error, you will see a button for retry.", + "It is also possible to cancel a line not imported yet.", "So now you will only need to wait to the System to finish importing everything.", "We have more options in the system, let's check Settings > Main Options.", null @@ -661,6 +662,7 @@ "É possível ver a posição da linha no arquivo original.", "O estado de importação aparecerá para cada linha.", "Em caso de erro, você verá um botão para tentar novamente.", + "Também é possível cancelar uma linha que ainda não tenha sido importada.", "Agora tudo que você precisa fazer é esperar o Sistema terminar de importar tudo.", "Existem mais opções no sistema, vamos até Configurações > Opções Gerais.", null diff --git a/docs/todo/importer-exporter.md b/docs/todo/importer-exporter.md index 1032bc40b..58748cff3 100644 --- a/docs/todo/importer-exporter.md +++ b/docs/todo/importer-exporter.md @@ -13,7 +13,7 @@ - [x] Allow cancel lines - [x] Allow cancel files - [x] Record datetime archive was uploaded and show -- [ ] Integrate to site +- [x] Integrate to site - [ ] Integrate to robot ## Exporter diff --git a/site/MVC/Controllers/ArchivesController.cs b/site/MVC/Controllers/ArchivesController.cs index 17f43da28..056e7ba55 100644 --- a/site/MVC/Controllers/ArchivesController.cs +++ b/site/MVC/Controllers/ArchivesController.cs @@ -1,6 +1,5 @@ using System; using System.Threading.Tasks; -using DFM.Entities.Enums; using DFM.MVC.Helpers.Authorize; using DFM.MVC.Helpers.Controllers; using DFM.MVC.Models; @@ -65,4 +64,14 @@ public IActionResult RetryLine(Guid id, Int16 position) return PartialView("LineRow", model.Line); } + + [JsonAuth, HttpPost, ValidateAntiForgeryToken, Wizard.Avoid] + public IActionResult CancelLine(Guid id, Int16 position) + { + var model = new ArchivesLinesModel(id, false); + + model.Cancel(position); + + return PartialView("LineRow", model.Line); + } } diff --git a/site/MVC/Models/ArchivesLinesModel.cs b/site/MVC/Models/ArchivesLinesModel.cs index 44d937ec4..191552bb2 100644 --- a/site/MVC/Models/ArchivesLinesModel.cs +++ b/site/MVC/Models/ArchivesLinesModel.cs @@ -29,7 +29,13 @@ public ArchivesLinesModel(Guid guid, Boolean loadArchive = true) public void Retry(Int16 position) { - var line = service.Robot.RetryLine(ArchiveGuid, position); - Line = new LineRowModel(ArchiveGuid, line, Language); + var line = service.Robot.RetryLine(ArchiveGuid, position); + Line = new LineRowModel(ArchiveGuid, line, Language); + } + + public void Cancel(Int16 position) + { + var line = service.Robot.CancelLine(ArchiveGuid, position); + Line = new LineRowModel(ArchiveGuid, line, Language); } } diff --git a/site/MVC/Views/Archives/LineRow.cshtml b/site/MVC/Views/Archives/LineRow.cshtml index 12b39bdb2..83b3e448a 100644 --- a/site/MVC/Views/Archives/LineRow.cshtml +++ b/site/MVC/Views/Archives/LineRow.cshtml @@ -31,7 +31,7 @@ @line.Category - + @await Html.PartialAsync( "Extensions/ValueWithSign", new ValueWithSign(value, Model.Language) @@ -45,7 +45,7 @@ - @if (line.Status == ImportStatus.Error) + @if (line.Status == ImportStatus.Canceled || line.Status == ImportStatus.Error) { @await Html.PartialAsync( "Extensions/MicroForm", @@ -60,4 +60,21 @@ @noAction } + + + @if (line.Status == ImportStatus.Pending || line.Status == ImportStatus.Error) + { + @await Html.PartialAsync( + "Extensions/MicroForm", + MicroForm.WithGlyph(Context, "ban-circle", "Cancel") + .AddIdUrl("Archives", "CancelLine", Model.ArchiveGuid) + .AddHidden("position", line.Position) + .AsAjax($"l{line.Position}") + ) + } + else + { + @noAction + } + diff --git a/site/MVC/Views/Archives/Lines.cshtml b/site/MVC/Views/Archives/Lines.cshtml index b3d620648..058060bb6 100644 --- a/site/MVC/Views/Archives/Lines.cshtml +++ b/site/MVC/Views/Archives/Lines.cshtml @@ -16,8 +16,9 @@ .AddBox("Position", 2, null) .AddBox("Status", 3, null) .AddBox("Retry", 4, null) - .AddBox("SettingsMenu", 6, 2) - .AddBox("SettingsMainMenu", 6, 2) + .AddBox("Cancel", 5, null) + .AddBox("SettingsMenu", 7, 2) + .AddBox("SettingsMainMenu", 7, 2) .AddBox("NoContent", null, 0) .AddBox("Contact", null, 1) ; @@ -37,9 +38,9 @@ @Context.Translate("Description") @Context.Translate("Account") @Context.Translate("Category") - @Context.Translate("Value") + @Context.Translate("Value") @Context.Translate("Status") - @Context.Translate("TODO") + @Context.Translate("TODO") }