Skip to content

Commit

Permalink
LT-21706: Modify webonary status reporting (#187)
Browse files Browse the repository at this point in the history
* Remove status window and add progress bar for webonary
* Add upload log viewer and status tracking
* Also remove zip file upload code and tests - it is no longer usefull
  • Loading branch information
jasonleenaylor authored Oct 30, 2024
1 parent 65823a5 commit f3354e9
Show file tree
Hide file tree
Showing 13 changed files with 1,503 additions and 1,072 deletions.
346 changes: 115 additions & 231 deletions Src/xWorks/UploadToWebonaryController.cs

Large diffs are not rendered by default.

493 changes: 253 additions & 240 deletions Src/xWorks/UploadToWebonaryDlg.Designer.cs

Large diffs are not rendered by default.

98 changes: 41 additions & 57 deletions Src/xWorks/UploadToWebonaryDlg.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,10 @@
using System.Drawing;
using System.Linq;
using System.Windows.Forms;
using Gecko.WebIDL;
using SIL.FieldWorks.Common.FwUtils;
using SIL.IO;
using SIL.LCModel.Core.Phonology;
using SIL.Windows.Forms;
using SIL.PlatformUtilities;
using PropertyTable = XCore.PropertyTable;
Expand All @@ -23,6 +26,9 @@ public partial class UploadToWebonaryDlg : Form, IUploadToWebonaryView
{
private readonly IHelpTopicProvider m_helpTopicProvider;
private readonly UploadToWebonaryController m_controller;

private WebonaryStatusCondition m_uploadStatus = WebonaryStatusCondition.None;

// Mono 3 handles the display of the size gripper differently than .NET SWF and so the dialog needs to be taller. Part of LT-16433.
private const int m_additionalMinimumHeightForMono = 26;

Expand Down Expand Up @@ -74,7 +80,7 @@ public UploadToWebonaryDlg(UploadToWebonaryController controller, UploadToWebona
// Start with output log area not shown by default
// When a user clicks Publish, it is revealed. This is done within the context of having a resizable table of controls, and having
// the output log area be the vertically growing control when a user increases the height of the dialog
this.Shown += (sender, args) => { ValidateSortingOnAlphaHeaders(); this.Height = this.Height - outputLogTextbox.Height;};
Shown += (sender, args) => { ValidateSortingOnAlphaHeaders(); };

// Handle localizable explanation area with link.
var explanationText = xWorksStrings.toApplyForWebonaryAccountExplanation;
Expand Down Expand Up @@ -192,6 +198,17 @@ private void PopulateReversalsCheckboxListByPublication(string publication)
SetSelectedReversals(selectedReversals);
}

public void UploadCompleted()
{
m_progress.Value = m_progress.Maximum;
m_progress.Style = ProgressBarStyle.Continuous;
reportButton.Enabled = true;
if (m_uploadStatus != WebonaryStatusCondition.Success)
{
reportButton_Click(null, null);
}
}

public UploadToWebonaryModel Model { get; set; }

private void LoadFromModel()
Expand Down Expand Up @@ -226,6 +243,7 @@ private void LoadFromModel()
configurationBox.SelectedIndex = 0;
}
UpdateEntriesToBePublishedLabel();
reportButton.Enabled = Model.CanViewReport;
}
}

Expand Down Expand Up @@ -277,20 +295,10 @@ private void publishButton_Click(object sender, EventArgs e)
{
SaveToModel();

// Increase height of form so the output log is shown.
// Account for situations where the user already increased the height of the form
// or maximized the form, and later reduces the height or unmaximizes the form
// after clicking Publish.

var allButTheLogRowHeight = tableLayoutPanel.GetRowHeights().Sum() - tableLayoutPanel.GetRowHeights().Last();
var fudge = Height - tableLayoutPanel.Height;
var minimumFormHeightToShowLog = allButTheLogRowHeight + outputLogTextbox.MinimumSize.Height + fudge;
if (Platform.IsUnix)
minimumFormHeightToShowLog += m_additionalMinimumHeightForMono;
MinimumSize = new Size(MinimumSize.Width, minimumFormHeightToShowLog);

using (new WaitCursor(this))
{
RobustFile.Delete(Model.LastUploadReport);
m_progress.Style = ProgressBarStyle.Marquee;
m_controller.UploadToWebonary(Model, this);
}
}
Expand All @@ -300,46 +308,31 @@ private void helpButton_Click(object sender, EventArgs e)
ShowHelp.ShowHelpTopic(m_helpTopicProvider, "khtpUploadToWebonary");
}

/// <summary>
/// Add a message to the status area. Make sure the status area is redrawn so the
/// user can see what's going on even if we are working on something.
/// </summary>
public void UpdateStatus(string statusString)
private void closeButton_Click(object sender, EventArgs e)
{
outputLogTextbox.AppendText(Environment.NewLine + statusString);
outputLogTextbox.Refresh();
SaveToModel();
}

/// <summary>
/// Respond to a new status condition by changing the background color of the
/// output log.
/// </summary>
public void SetStatusCondition(WebonaryStatusCondition condition)
private void reportButton_Click(object sender, EventArgs e)
{
Color newColor;
switch (condition)
using(var dlg = new WebonaryLogViewer(Model.LastUploadReport))
{
case WebonaryStatusCondition.Success:
// Green
newColor = ColorTranslator.FromHtml("#b8ffaa");
break;
case WebonaryStatusCondition.Error:
// Red
newColor = ColorTranslator.FromHtml("#ffaaaa");
break;
case WebonaryStatusCondition.None:
// Grey
newColor = ColorTranslator.FromHtml("#dcdad5");
break;
default:
throw new ArgumentException("Unhandled WebonaryStatusCondition", nameof(condition));
dlg.ShowDialog();
}
outputLogTextbox.BackColor = newColor;
}

private void closeButton_Click(object sender, EventArgs e)
/// <summary>
/// Add a message to the status area. Make sure the status area is redrawn so the
/// user can see what's going on even if we are working on something.
/// </summary>
public void UpdateStatus(string statusString, WebonaryStatusCondition c)
{
SaveToModel();
// Set the status to the greater of the current or the new update
m_uploadStatus = (WebonaryStatusCondition)Math.Max(Convert.ToInt32(m_uploadStatus), Convert.ToInt32(c));
// Log the status
Model.Log.AddEntry(c, statusString);
// pump messages
Application.DoEvents();
}

/// <summary>
Expand All @@ -356,25 +349,15 @@ protected override void OnClosing(CancelEventArgs e)
}
base.OnClosing(e);
}

protected override void OnResize(EventArgs e)
{
base.OnResize(e);

// On Linux, when reducing the height of the dialog, the output log doesn't shrink with it.
// Set its height back to something smaller to keep the whole control visible. It will expand as appropriate.
if (Platform.IsUnix)
outputLogTextbox.Size = new Size(outputLogTextbox.Size.Width, outputLogTextbox.MinimumSize.Height);
}
}

/// <summary>
/// Interface for controller to interact with the dialog
/// </summary>
public interface IUploadToWebonaryView
{
void UpdateStatus(string statusString);
void SetStatusCondition(WebonaryStatusCondition condition);
void UpdateStatus(string statusString, WebonaryStatusCondition condition);
void UploadCompleted();
UploadToWebonaryModel Model { get; set; }
}

Expand All @@ -385,6 +368,7 @@ public enum WebonaryStatusCondition
{
None,
Success,
Error
FileRejected,
Error,
}
}
Loading

0 comments on commit f3354e9

Please sign in to comment.