Skip to content

Commit

Permalink
Excel report: statuses shown on separate lines
Browse files Browse the repository at this point in the history
Sync ribbon: correct status of SyncOn button
  • Loading branch information
ealbu committed Feb 20, 2025
1 parent 07b1edf commit 0aa1480
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using Sdl.Community.PostEdit.Versions.HTMLReportIntegration.ReportManaging;
using Sdl.Community.PostEdit.Versions.HTMLReportIntegration.ReportView;
using Sdl.Community.PostEdit.Versions.HTMLReportIntegration.ReportView.Model;
using Sdl.Community.PostEdit.Versions.HTMLReportIntegration.Ribbon;
using Sdl.Community.PostEdit.Versions.HTMLReportIntegration.Studio;
using Sdl.Community.PostEdit.Versions.HTMLReportIntegration.Studio.Components;
using Sdl.TranslationStudioAutomation.IntegrationApi;
Expand All @@ -23,6 +24,7 @@ public class Integration

private static ReportViewController ReportViewController => _reportViewController ??=
SdlTradosStudio.Application.GetController<ReportViewController>();

private static StudioController StudioController { get; } = new();

public static async Task ExportReport()
Expand Down Expand Up @@ -61,6 +63,8 @@ public static void HandleReportRequest(string jsonMessage)

public static void InitializeReportFilter(string projectId)
{
if (projectId == null) return;

var reportFilter = SdlTradosStudio.Application.GetController<ReportViewFilterController>();
reportFilter.Activate();

Expand Down Expand Up @@ -138,5 +142,10 @@ private static void EditorEventListener_CommentsChanged(List<CommentInfo> commen

private static void EditorEventListener_StatusChanged(string newStatus, string segmentId, string fileId) =>
ReportViewController.UpdateStatus(newStatus, segmentId, fileId);

public static void ToggleSyncRibbon(bool state)
{
SdlTradosStudio.Application.GetAction<SyncReportProjectOn>().Enabled = state;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -79,18 +79,31 @@ private static void SaveTableToExcel(List<HtmlNode> tableNodes, string filePath)

private static void AddRowToWorksheet(ExcelWorksheet ws, HtmlNodeCollection cells, int excelRow)
{
var excelCol = 1;
int excelCol = 1;
foreach (var cell in cells)
{
var cellText = HttpUtility.HtmlDecode(cell.InnerText.Trim());
var cellRef = ws.Cells[excelRow, excelCol];

if (cellText.EndsWith("%") && double.TryParse(cellText.TrimEnd('%'), NumberStyles.Any, CultureInfo.InvariantCulture, out var percentageValue))
if (excelRow > 1 && excelCol == 6)
{
// Extract inner HTML and parse it to get text content from <span> elements
var innerHtml = cell.InnerHtml;
var doc = new HtmlDocument();
doc.LoadHtml(innerHtml);
var statusParts = doc.DocumentNode.SelectNodes("//span")
.Select(span => HttpUtility.HtmlDecode(span.InnerText.Trim()))
.Where(part => !string.IsNullOrWhiteSpace(part))
.ToArray();
cellText = string.Join("\n", statusParts);
}

if (cellText.EndsWith("%") && double.TryParse(cellText.TrimEnd('%'), NumberStyles.Any, CultureInfo.InvariantCulture, out double percentageValue))
{
cellRef.Value = percentageValue / 100;
cellRef.Style.Numberformat.Format = "0.00%";
}
else if (double.TryParse(cellText, NumberStyles.Any, CultureInfo.InvariantCulture, out var numericValue))
else if (double.TryParse(cellText, NumberStyles.Any, CultureInfo.InvariantCulture, out double numericValue))
{
cellRef.Value = numericValue;
cellRef.Style.Numberformat.Format = "#,##0.00";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,25 +78,27 @@ protected override void Initialize(IViewContext context)

private void AttachEvents()
{
ReportExplorer.SelectedReportChanged += ExplorerOnSelectedReportChanged;
ReportExplorer.SelectedReportChanged += Explorer_SelectedReportChanged;
ReportViewer.WebMessageReceived += WebView2Browser_WebMessageReceived;
}

private async void ExplorerOnSelectedReportChanged()
private async void Explorer_SelectedReportChanged()
{
try
{
var selectedReport = GetSelectedReport();
Integration.ToggleSyncRibbon(selectedReport is not null);

await ReportViewer.Navigate(ReportExplorerViewModel.SelectedReport?.ReportPath);
await Task.Delay(500);
var projectId = await ReportViewer.GetProjectId();
if (projectId == null) return;

var projectId = await ReportViewer.GetProjectId();
Integration.InitializeReportFilter(projectId);
}
catch (Exception e)
{
ReportExplorerViewModel.SelectedReport = null;
ErrorHandler.ShowError($"Error loading the selected report: {e.Message}", null);
ErrorHandler.ShowError($"Error loading the selected report: {e.Message}");
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,11 @@ protected override void Execute()
[ActionLayout(typeof(SynchronizationRibbonGroup), 10, DisplayType.Large)]
public class SyncReportProjectOn : AbstractAction
{
public SyncReportProjectOn()
{
Enabled = false;
}

protected override void Execute()
{
SdlTradosStudio.Application.GetAction<SyncReportProjectOff>().Enabled = true;
Expand Down

0 comments on commit 0aa1480

Please sign in to comment.