Skip to content

Commit

Permalink
site: add cancel line
Browse files Browse the repository at this point in the history
  • Loading branch information
darakeon committed Aug 23, 2024
1 parent ef2f98c commit 17fca58
Show file tree
Hide file tree
Showing 7 changed files with 48 additions and 11 deletions.
4 changes: 3 additions & 1 deletion core/BusinessLogic/Services/RobotService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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)
Expand Down
2 changes: 2 additions & 0 deletions core/Language/Language/Site/wizard.json
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion docs/todo/importer-exporter.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
11 changes: 10 additions & 1 deletion site/MVC/Controllers/ArchivesController.cs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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);
}
}
10 changes: 8 additions & 2 deletions site/MVC/Models/ArchivesLinesModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
21 changes: 19 additions & 2 deletions site/MVC/Views/Archives/LineRow.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
@line.Category
</td>

<td class="col-sm-2 text-right">
<td class="col-sm-1 text-right">
@await Html.PartialAsync(
"Extensions/ValueWithSign",
new ValueWithSign(value, Model.Language)
Expand All @@ -45,7 +45,7 @@
</td>

<td class="col-sm-1 text-center @hl?["Retry"]">
@if (line.Status == ImportStatus.Error)
@if (line.Status == ImportStatus.Canceled || line.Status == ImportStatus.Error)
{
@await Html.PartialAsync(
"Extensions/MicroForm",
Expand All @@ -60,4 +60,21 @@
@noAction
}
</td>

<td class="col-sm-1 text-center @hl?["Cancel"]">
@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
}
</td>
</tr>
9 changes: 5 additions & 4 deletions site/MVC/Views/Archives/Lines.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -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)
;
Expand All @@ -37,9 +38,9 @@
<th class="col-sm-3">@Context.Translate("Description")</th>
<th class="col-sm-2 text-center">@Context.Translate("Account")</th>
<th class="col-sm-2 text-center">@Context.Translate("Category")</th>
<th class="col-sm-2 text-center">@Context.Translate("Value")</th>
<th class="col-sm-1 text-center">@Context.Translate("Value")</th>
<th class="col-sm-1 text-center">@Context.Translate("Status")</th>
<th class="col-sm-1 text-center">@Context.Translate("TODO")</th>
<th class="col-sm-2 text-center" colspan="2">@Context.Translate("TODO")</th>
</tr>
}

Expand Down

0 comments on commit 17fca58

Please sign in to comment.