Made the profile history page read better.

This commit is contained in:
Lars Brubaker 2016-07-22 17:49:03 -07:00
parent fe6bbbf9e8
commit e949c7b52f
4 changed files with 47 additions and 12 deletions

View file

@ -4,6 +4,7 @@ using MatterHackers.MatterControl.CustomWidgets;
using MatterHackers.MatterControl.SlicerConfiguration;
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
@ -14,6 +15,7 @@ namespace MatterHackers.MatterControl.SetupWizard
{
List<RadioButton> radioButtonList = new List<RadioButton>();
Dictionary<string, string> printerProfileData = new Dictionary<string, string>();
List<string> orderedProfiles = new List<string>();
ScrollableWidget scrollWindow;
public PrinterProfileHistoryPage()
@ -34,10 +36,11 @@ namespace MatterHackers.MatterControl.SetupWizard
footerRow.AddChild(cancelButton);
revertButton.Click += async (s, e) =>
{
var checkedButton = radioButtonList.Where(r => r.Checked).FirstOrDefault();
if (checkedButton != null)
int index = radioButtonList.IndexOf(radioButtonList.Where(r => r.Checked).FirstOrDefault());
if (index != -1)
{
string profileToken = printerProfileData[checkedButton.Text];
string profileToken = printerProfileData[orderedProfiles[index]];
var activeProfile = ProfileManager.Instance.ActiveProfile;
@ -61,23 +64,49 @@ namespace MatterHackers.MatterControl.SetupWizard
TextWidget loadingText = new TextWidget("Retrieving History from Web...");
loadingText.TextColor = ActiveTheme.Instance.PrimaryTextColor;
scrollWindow.AddChild(loadingText);
var results = await ApplicationController.GetProfileHistory(ProfileManager.Instance.ActiveProfile.DeviceToken);
printerProfileData = results;
if(printerProfileData != null)
{
FlowLayoutWidget radioButtonLayout = new FlowLayoutWidget(FlowDirection.TopToBottom);
loadingText.Visible= false;
List<DateTime> sourceTimes = new List<DateTime>();
foreach (var printerProfile in results.OrderByDescending(d => d.Key))
{
// AppEngine results are current in the form of: "2016-07-21 00:43:30.965830"
sourceTimes.Add(Convert.ToDateTime(printerProfile.Key).ToLocalTime());
}
var groupedTimes = RelativeTime.GroupTimes(DateTime.Now, sourceTimes);
FlowLayoutWidget topToBottomStuff = new FlowLayoutWidget(FlowDirection.TopToBottom);
scrollWindow.AddChild(topToBottomStuff);
foreach (var group in groupedTimes)
{
// add in the group header
topToBottomStuff.AddChild(new TextWidget(RelativeTime.BlockDescriptions[group.Key], textColor: ActiveTheme.Instance.PrimaryTextColor)
{
Margin = new BorderDouble(0, 0, 0, 5),
});
foreach (var time in group.Value)
{
// add in the radio buttons
var profileVersionButton = new RadioButton(time.Value, textColor: ActiveTheme.Instance.PrimaryTextColor)
{
Margin = new BorderDouble(5, 0),
};
profileVersionButton.Checked = false;
radioButtonList.Add(profileVersionButton);
topToBottomStuff.AddChild(profileVersionButton);
}
}
foreach(var printerProfile in results)
{
var profileVersionButton = new RadioButton(printerProfile.Key.ToString(), textColor: ActiveTheme.Instance.PrimaryTextColor);
profileVersionButton.Checked = false;
radioButtonLayout.AddChild(profileVersionButton);
radioButtonList.Add(profileVersionButton);
orderedProfiles.Add(printerProfile.Key.ToString());
}
scrollWindow.AddChild(radioButtonLayout);
}
else
{