Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Analytics Change for Preferences View #11696

Merged
merged 2 commits into from
May 20, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
91 changes: 68 additions & 23 deletions src/DynamoCoreWpf/ViewModels/Menu/PreferencesViewModel.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using Dynamo.Configuration;
using Dynamo.Graph.Workspaces;
using Dynamo.Logging;
using Dynamo.Models;
using Dynamo.Wpf.ViewModels.Core.Converters;
using System;
Expand Down Expand Up @@ -55,7 +56,7 @@ public class PreferencesViewModel : ViewModelBase, INotifyPropertyChanged
private HomeWorkspaceModel homeSpace;
private DynamoViewModel dynamoViewModel;
private bool isWarningEnabled;
private GeometryScalingOptions optionsGeometryScal = null;
private GeometryScalingOptions optionsGeometryScale = null;
#endregion Private Properties

public GeometryScaleSize ScaleSize { get; set; }
Expand Down Expand Up @@ -108,6 +109,7 @@ public string SavedChangesTooltip

}
}

//This includes all the properties that can be set on the General tab
#region General Properties
/// <summary>
Expand All @@ -121,6 +123,13 @@ public string SelectedLanguage
}
set
{
if (selectedLanguage != value && selectedLanguage != null)
{
Dynamo.Logging.Analytics.TrackEvent(
Actions.Switch,
Categories.Preferences,
Res.PreferencesViewLanguageLabel);
Copy link
Contributor Author

@QilongTang QilongTang May 19, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This pattern introduce some repeated code but will be most accurate to avoid logging dialog initialization

}
selectedLanguage = value;
RaisePropertyChanged(nameof(SelectedLanguage));
}
Expand All @@ -137,6 +146,13 @@ public string SelectedFontSize
}
set
{
if (SelectedFontSize != value && SelectedFontSize != null)
{
Dynamo.Logging.Analytics.TrackEvent(
Actions.Switch,
Categories.Preferences,
Res.PreferencesViewFontSizeLabel);
}
selectedFontSize = value;
RaisePropertyChanged(nameof(SelectedFontSize));
}
Expand All @@ -153,6 +169,13 @@ public string SelectedNumberFormat
}
set
{
if(selectedNumberFormat != value && selectedNumberFormat != null)
{
Dynamo.Logging.Analytics.TrackEvent(
Actions.Switch,
Categories.Preferences,
Res.DynamoViewSettingMenuNumberFormat);
}
selectedNumberFormat = value;
preferenceSettings.NumberFormat = value;
RaisePropertyChanged(nameof(SelectedNumberFormat));
Expand Down Expand Up @@ -310,16 +333,16 @@ public StyleItem AddStyleControl
/// <summary>
/// This property is used as a container for the description text (GeometryScalingOptions.DescriptionScaleRange) for each radio button (Visual Settings -> Geometry Scaling section)
/// </summary>
public GeometryScalingOptions OptionsGeometryScal
public GeometryScalingOptions OptionsGeometryScale
{
get
{
return optionsGeometryScal;
return optionsGeometryScale;
}
set
{
optionsGeometryScal = value;
RaisePropertyChanged(nameof(OptionsGeometryScal));
optionsGeometryScale = value;
RaisePropertyChanged(nameof(OptionsGeometryScale));
}
}

Expand Down Expand Up @@ -602,41 +625,57 @@ public PreferencesViewModel(DynamoViewModel dynamoViewModel)
AddStyleControl = new StyleItem() { GroupName = "", HexColorString = "#" + GetRandomHexStringColor() };

//This piece of code will populate all the description text for the RadioButtons in the Geometry Scaling section.
optionsGeometryScal = new GeometryScalingOptions();
optionsGeometryScale = new GeometryScalingOptions();

//This will set the default option for the Geometry Scaling Radio Buttons, the value is comming from the DynamoViewModel
optionsGeometryScal.EnumProperty = (GeometryScaleSize)GeometryScalingOptions.ConvertScaleFactorToUI(dynamoViewModel.ScaleFactorLog);
optionsGeometryScale.EnumProperty = (GeometryScaleSize)GeometryScalingOptions.ConvertScaleFactorToUI(dynamoViewModel.ScaleFactorLog);

optionsGeometryScal.DescriptionScaleRange = new ObservableCollection<string>();
optionsGeometryScal.DescriptionScaleRange.Add(string.Format(Res.ChangeScaleFactorPromptDescriptionContent, scaleRanges[GeometryScaleSize.Small].Item2,
optionsGeometryScale.DescriptionScaleRange = new ObservableCollection<string>();
optionsGeometryScale.DescriptionScaleRange.Add(string.Format(Res.ChangeScaleFactorPromptDescriptionContent, scaleRanges[GeometryScaleSize.Small].Item2,
scaleRanges[GeometryScaleSize.Small].Item3));
optionsGeometryScal.DescriptionScaleRange.Add(string.Format(Res.ChangeScaleFactorPromptDescriptionContent, scaleRanges[GeometryScaleSize.Medium].Item2,
optionsGeometryScale.DescriptionScaleRange.Add(string.Format(Res.ChangeScaleFactorPromptDescriptionContent, scaleRanges[GeometryScaleSize.Medium].Item2,
scaleRanges[GeometryScaleSize.Medium].Item3));
optionsGeometryScal.DescriptionScaleRange.Add(string.Format(Res.ChangeScaleFactorPromptDescriptionContent, scaleRanges[GeometryScaleSize.Large].Item2,
optionsGeometryScale.DescriptionScaleRange.Add(string.Format(Res.ChangeScaleFactorPromptDescriptionContent, scaleRanges[GeometryScaleSize.Large].Item2,
scaleRanges[GeometryScaleSize.Large].Item3));
optionsGeometryScal.DescriptionScaleRange.Add(string.Format(Res.ChangeScaleFactorPromptDescriptionContent, scaleRanges[GeometryScaleSize.ExtraLarge].Item2,
optionsGeometryScale.DescriptionScaleRange.Add(string.Format(Res.ChangeScaleFactorPromptDescriptionContent, scaleRanges[GeometryScaleSize.ExtraLarge].Item2,
scaleRanges[GeometryScaleSize.ExtraLarge].Item3));

SavedChangesLabel = string.Empty;
SavedChangesTooltip = string.Empty;

this.PropertyChanged += model_PropertyChanged;
this.PropertyChanged += Model_PropertyChanged;
}

/// <summary>
/// Listen for the PropertyChanged event and updates the saved changes label accordingly
/// </summary>
private void model_PropertyChanged(object sender, PropertyChangedEventArgs e)
private void Model_PropertyChanged(object sender, PropertyChangedEventArgs e)
{
string description = string.Empty;
// C# does not support going through all cases when one of the case is true
switch (e.PropertyName)
{
case "SelectedLanguage":
case "SelectedFontSize":
case "SelectedNumberFormat":
case "RunSettingsIsChecked":
case "RunPreviewIsChecked":
case "StyleItemsList":
case "OptionsGeometryScal":
case nameof(SelectedLanguage):
// Do nothing for now
break;
case nameof(SelectedFontSize):
// Do nothing for now
break;
case nameof(SelectedNumberFormat):
description = Res.DynamoViewSettingMenuNumberFormat;
goto default;
case nameof(RunSettingsIsChecked):
description = Res.PreferencesViewRunSettingsLabel;
goto default;
case nameof(RunPreviewIsChecked):
description = Res.DynamoViewSettingShowRunPreview;
goto default;
case nameof(StyleItemsList):
// Do nothing for now
break;
case nameof(OptionsGeometryScale):
description = Res.DynamoViewSettingsMenuChangeScaleFactor;
goto default;
case "ShowEdges":
case "IsolateSelectedGeometry":
case "TessellationDivisions":
Expand All @@ -645,9 +684,15 @@ private void model_PropertyChanged(object sender, PropertyChangedEventArgs e)
case "ShowWhitespaceIsChecked":
case "NodeAutocompleteIsChecked":
case "EnableTSplineIsChecked":
UpdateSavedChangesLabel();
break;
description = Res.PreferencesViewEnableTSplineNodes;
goto default;
default:
// Log switch on each setting and use description equals to label name
Dynamo.Logging.Analytics.TrackEvent(
Actions.Switch,
Categories.Preferences,
description);
Copy link
Contributor Author

@QilongTang QilongTang May 19, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This way of logging is more code efficient.. But can't seem to rule out the cases for dialog initialization, because in those cases Dynamo raise property changes regardless if it's user change.. Will look a bit more on best way

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I take it back, since Model_PropertyChanged bind after dialog initialization, this approach should be accurate

UpdateSavedChangesLabel();
break;
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/DynamoCoreWpf/Views/Menu/PreferencesView.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -527,7 +527,7 @@
<!--Geometry Scaling Expander-->
<Expander x:Name="Scale"
Grid.Row="1"
DataContext="{Binding OptionsGeometryScal}"
DataContext="{Binding OptionsGeometryScale}"
Style="{StaticResource MenuExpanderStyle}"
Expanded="Expander_Expanded"
Header="{x:Static p:Resources.PreferencesViewVisualSettingsGeoScaling}">
Expand Down
49 changes: 38 additions & 11 deletions src/DynamoCoreWpf/Views/Menu/PreferencesView.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using Dynamo.Configuration;
using System.Windows.Media;
using Dynamo.Logging;
using Dynamo.ViewModels;
using Res = Dynamo.Wpf.Properties.Resources;
using System.Linq;
using Dynamo.Logging;

namespace Dynamo.Wpf.Views
{
Expand All @@ -18,16 +16,23 @@ namespace Dynamo.Wpf.Views
/// </summary>
public partial class PreferencesView : Window
{
private PreferencesViewModel viewModel;
private DynamoViewModel dynViewModel;
private readonly PreferencesViewModel viewModel;
private readonly DynamoViewModel dynViewModel;

/// <summary>
/// Constructor of Preferences View
/// </summary>
/// <param name="dynamoViewModel"> Dynamo ViewModel</param>
public PreferencesView(DynamoViewModel dynamoViewModel)
{
DataContext = new PreferencesViewModel(dynamoViewModel);
dynViewModel = dynamoViewModel;


InitializeComponent();
Dynamo.Logging.Analytics.TrackEvent(
Actions.Open,
Categories.Preferences);

//If we want the PreferencesView window to be modal, we need to assign the owner (since we created a new Style and not following the common Style)
this.Owner = Application.Current.MainWindow;
Expand All @@ -40,30 +45,48 @@ public PreferencesView(DynamoViewModel dynamoViewModel)
InitRadioButtonsDescription();
}

/// <summary>
/// Add inline description for each geometry scalling radio button
/// </summary>
private void InitRadioButtonsDescription()
{
RadioSmallDesc.Inlines.Add(viewModel.OptionsGeometryScal.DescriptionScaleRange[0]);
RadioSmallDesc.Inlines.Add(viewModel.OptionsGeometryScale.DescriptionScaleRange[0]);

RadioMediumDesc.Inlines.Add(new Run(Res.ChangeScaleFactorPromptDescriptionDefaultSetting) { FontWeight = FontWeights.Bold });
RadioMediumDesc.Inlines.Add(" " + viewModel.OptionsGeometryScal.DescriptionScaleRange[1]);
RadioMediumDesc.Inlines.Add(" " + viewModel.OptionsGeometryScale.DescriptionScaleRange[1]);

RadioLargeDesc.Inlines.Add(viewModel.OptionsGeometryScal.DescriptionScaleRange[1]);
RadioLargeDesc.Inlines.Add(viewModel.OptionsGeometryScale.DescriptionScaleRange[1]);

RadioExtraLargeDesc.Inlines.Add(viewModel.OptionsGeometryScal.DescriptionScaleRange[2]);
RadioExtraLargeDesc.Inlines.Add(viewModel.OptionsGeometryScale.DescriptionScaleRange[2]);
}

/// <summary>
/// Dialog close button handler
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void CloseButton_Click(object sender, RoutedEventArgs e)
{
Dynamo.Logging.Analytics.TrackEvent(
Actions.Close,
Categories.Preferences);
this.Close();
}

//When the TitleBar is clicked this method will be executed
/// <summary>
/// handler for preferences dialog dragging action. When the TitleBar is clicked this method will be executed.
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void PreferencesPanel_MouseDown(object sender, MouseButtonEventArgs e)
{
//Drag functionality when the TitleBar is clicked with the left button and dragged to another place
if (e.ChangedButton == MouseButton.Left)
{
this.DragMove();
Dynamo.Logging.Analytics.TrackEvent(
Actions.Move,
Categories.Preferences);
}
}

Expand Down Expand Up @@ -190,6 +213,10 @@ private void Geometry_Scaling_Checked(object sender, RoutedEventArgs e)
{
Log(String.Format("Geometry working range changed to {0} ({1}, {2})",
viewModel.ScaleRange.Item1, viewModel.ScaleRange.Item2, viewModel.ScaleRange.Item3));
Dynamo.Logging.Analytics.TrackEvent(
Actions.Switch,
Categories.Preferences,
Res.PreferencesViewVisualSettingsGeoScaling);
}

var allNodes = dynViewModel.HomeSpace.Nodes;
Expand Down
2 changes: 1 addition & 1 deletion src/NodeServices/IAnalyticsClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ public enum Actions
Delete,

/// <summary>
/// Move Event, such as Node move
/// Move Event, such as Node move, dialog move
/// </summary>
Move,

Expand Down