Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
14 changes: 14 additions & 0 deletions src/DynamoCoreWpf/Controls/NodeAutoCompleteSearchControl.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
xmlns:p="clr-namespace:Dynamo.Wpf.Properties"
xmlns:uicontrols="clr-namespace:Dynamo.UI.Controls"
xmlns:resx="clr-namespace:Dynamo.Properties;assembly=DynamoCore"
xmlns:local="clr-namespace:Dynamo.PackageManager.UI"
xmlns:dynconverters="clr-namespace:Dynamo.Controls"
mc:Ignorable="d"
WindowStyle="None"
AllowsTransparency="True"
Expand Down Expand Up @@ -43,6 +45,7 @@
Value="{StaticResource LibraryScrollViewerControlTemplate}" />
</Style>
<BooleanToVisibilityConverter x:Key="BooleanToVisibilityConverter" />
<dynconverters:InverseBoolToVisibilityConverter x:Key="InverseBooleanToVisibilityConverter" />
Comment thread
johnpierson marked this conversation as resolved.
</ResourceDictionary>
</Window.Resources>

Expand Down Expand Up @@ -256,7 +259,17 @@
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<local:LoadingAnimationStripeControl
Grid.Column="0"
VerticalAlignment="Center"
Height="35"
MinWidth="240"
AnimationSpeed="10"
Visibility="{Binding ResultsLoaded, UpdateSourceTrigger=PropertyChanged, Converter={StaticResource InverseBooleanToVisibilityConverter}}"
Margin="8,8,0,8"
/>
<Border BorderThickness="1"
Visibility="{Binding ResultsLoaded, UpdateSourceTrigger=PropertyChanged, Converter={StaticResource BooleanToVisibilityConverter}}"
Background="{StaticResource WorkspaceBackgroundHomeBrush}"
CornerRadius="5"
Padding="5"
Expand Down Expand Up @@ -311,6 +324,7 @@
</Border>

<Button x:Name="btnSuggestions"
IsEnabled="{Binding ResultsLoaded}"
Click="DisplaySuggestions"
Grid.Column="1">
<Button.ToolTip>
Expand Down
2 changes: 2 additions & 0 deletions src/DynamoCoreWpf/PublicAPI.Unshipped.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2468,6 +2468,8 @@ Dynamo.ViewModels.NodeAutoCompleteSearchViewModel.DisplayLowConfidence.set -> vo
Dynamo.ViewModels.NodeAutoCompleteSearchViewModel.HideAutocompleteMethodOptions.get -> bool
Dynamo.ViewModels.NodeAutoCompleteSearchViewModel.IsDisplayingMLRecommendation.get -> bool
Dynamo.ViewModels.NodeAutoCompleteSearchViewModel.IsMLAutocompleteTOUApproved.get -> bool
Dynamo.ViewModels.NodeAutoCompleteSearchViewModel.ResultsLoaded.get -> bool
Dynamo.ViewModels.NodeAutoCompleteSearchViewModel.ResultsLoaded.set -> void
Dynamo.ViewModels.NodeDialogEventArgs
Dynamo.ViewModels.NodeDialogEventArgs.Handled.get -> bool
Dynamo.ViewModels.NodeDialogEventArgs.Handled.set -> void
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using System.IO;
using System.Linq;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using Dynamo.Configuration;
using Dynamo.Engine;
using Dynamo.Graph.Connectors;
Expand Down Expand Up @@ -47,6 +48,23 @@ public class NodeAutoCompleteSearchViewModel : SearchViewModel
private const string nodeClusterAutocompleteMLEndpoint = "MLNodeClusterAutocomplete";
internal bool IsOpen { get; set; }

private bool resultsLoaded;

/// <summary>
/// Flag that indicates whether results are loading (false) or they have loaded (true).
/// This is set as true for both succesfully and unsuccessfully loading the results.
/// </summary>
[Obsolete("This method will be removed in a future version of Dynamo")]
public bool ResultsLoaded

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Looks like we need this to be public due to the binding. Let's add a comment an d also make it obsolete.

{
get { return resultsLoaded; }
set
{
resultsLoaded = value;
RaisePropertyChanged(nameof(ResultsLoaded));
}
}

// Lucene search utility to perform indexing operations just for NodeAutocomplete.
internal LuceneSearchUtility LuceneUtility
{
Expand Down Expand Up @@ -161,6 +179,7 @@ public bool DisplayLowConfidence
}

internal event Action<NodeModel> ParentNodeRemoved;
private Guid LastRequestGuid;

/// <summary>
/// Constructor
Expand Down Expand Up @@ -290,27 +309,55 @@ internal MLNodeAutoCompletionRequest GenerateRequestForMLAutocomplete()

internal void ShowNodeAutocompleMLResults()
{
//this should run on the UI thread, so thread safety is not a concern
LastRequestGuid = Guid.NewGuid();
var myRequest = LastRequestGuid;

MLNodeAutoCompletionResponse MLresults = null;

var request = GenerateRequestForMLAutocomplete();

string jsonRequest = JsonConvert.SerializeObject(request);

// Get results from the ML API.
try
ResultsLoaded = false;
Comment thread
chubakueno marked this conversation as resolved.
Task.Run(() =>
{
MLresults = GetMLNodeAutocompleteResults(jsonRequest);
try
{
MLresults = GetMLNodeAutocompleteResults(jsonRequest);
this.dynamoViewModel.UIDispatcher.BeginInvoke(() => UpdateUIWithRresults(MLresults, myRequest));
}
catch (Exception ex)
{
this.dynamoViewModel.UIDispatcher.BeginInvoke(() =>
{
ResultsLoaded = true; //fail gracefully
dynamoViewModel.Model.Logger.Log("Unable to fetch ML Node autocomplete results: " + ex.Message);
DisplayAutocompleteMLStaticPage = true;
AutocompleteMLTitle = Resources.LoginNeededTitle;
AutocompleteMLMessage = Resources.LoginNeededMessage;
Analytics.TrackEvent(Actions.View, Categories.NodeAutoCompleteOperations, "UnabletoFetch");
return;
});
}
});
}
private void UpdateUIWithRresults(MLNodeAutoCompletionResponse MLresults, Guid myRequest)
{
if (LastRequestGuid != myRequest)
{
//a newer request came, we're no longer interested in the results of this one
//only latest request has the right to be committed to the UI and internal data structures
return;
}
catch (Exception ex)
if (!IsOpen)
{
dynamoViewModel.Model.Logger.Log("Unable to fetch ML Node autocomplete results: " + ex.Message);
DisplayAutocompleteMLStaticPage = true;
AutocompleteMLTitle = Resources.LoginNeededTitle;
AutocompleteMLMessage = Resources.LoginNeededMessage;
Analytics.TrackEvent(Actions.View, Categories.NodeAutoCompleteOperations, "UnabletoFetch");
// view disappeared while the background thread was waiting for the server response.
// Ignore the results as we're no longer interested.
return;
}

ResultsLoaded = true;
// no results
if (MLresults == null || MLresults.Results.Count() == 0)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -994,7 +994,7 @@ internal void PopulateAutoComplete()
if (!IsOpen)
{
// view disappeared while the background thread was waiting for the server response.
// Ignore the results are we're no longer interested.
// Ignore the results as we're no longer interested.
return;
}

Expand Down
Loading