Skip to content

Commit

Permalink
clear data and ui
Browse files Browse the repository at this point in the history
- clearing data and ui after publishing
- clearing data and ui with Cancel button
  • Loading branch information
dnenov committed Oct 23, 2023
1 parent 62c30b6 commit 3df4cce
Show file tree
Hide file tree
Showing 6 changed files with 106 additions and 32 deletions.
24 changes: 12 additions & 12 deletions src/DynamoCoreWpf/UI/Converters.cs
Original file line number Diff line number Diff line change
@@ -1,15 +1,3 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Controls.Primitives;
using System.Windows.Data;
using System.Windows.Media;
using Dynamo.Configuration;
using Dynamo.Graph.Nodes;
using Dynamo.Graph.Workspaces;
Expand All @@ -25,6 +13,18 @@
using Dynamo.Wpf.ViewModels;
using DynamoUnits;
using FontAwesome5;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Controls.Primitives;
using System.Windows.Data;
using System.Windows.Media;
using Color = System.Windows.Media.Color;
using FlowDirection = System.Windows.FlowDirection;
using HorizontalAlignment = System.Windows.HorizontalAlignment;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -569,6 +569,12 @@ public string MarkdownFilesDirectory
/// A command which, when executed, submits the current package</value>
public DelegateCommand SubmitCommand { get; private set; }

/// <summary>
/// CancelCommand property </summary>
/// <value>
/// A command which will clear the user interface and all underlaying data</value>
public DelegateCommand CancelCommand { get; private set; }

/// <summary>
/// PublishLocallyCommand property </summary>
/// <value>
Expand Down Expand Up @@ -795,6 +801,7 @@ internal PublishPackageViewModel()
SelectDirectoryAndAddFilesRecursivelyCommand = new DelegateCommand(SelectDirectoryAndAddFilesRecursively);
SelectMarkdownDirectoryCommand = new DelegateCommand(SelectMarkdownDirectory);
ClearMarkdownDirectoryCommand = new DelegateCommand(ClearMarkdownDirectory);
CancelCommand = new DelegateCommand(Cancel);
RemoveItemCommand = new Dynamo.UI.Commands.DelegateCommand(RemoveItem);
ToggleMoreCommand = new DelegateCommand(() => MoreExpanded = !MoreExpanded, () => true);
Dependencies.CollectionChanged += DependenciesOnCollectionChanged;
Expand Down Expand Up @@ -997,8 +1004,6 @@ private void ClearAllEntries()
this.UploadHandle = null;
this.IsNewVersion = false;
this.MoreExpanded = false;
this.ClearPackageContents();
this.ClearMarkdownDirectory();
this.UploadState = PackageUploadHandle.State.Ready;
this.AdditionalFiles = new ObservableCollection<string>();
this.Dependencies = new ObservableCollection<PackageDependency>();
Expand All @@ -1007,15 +1012,28 @@ private void ClearAllEntries()
this.SelectedHostsString = string.Empty;
this.copyrightHolder = string.Empty;
this.copyrightYear = string.Empty;
this.ClearMarkdownDirectory();
this.ClearPackageContents();
}

private void ClearPackageContents()
{
// this method clears the package contents in the publish package dialog

this.Package = null;
this.CustomNodeDefinitions = new List<CustomNodeDefinition>();
RaisePropertyChanged("PackageContents");
//System.Windows.Application.Current.Dispatcher.Invoke(() =>
//{
// Make changes to your ObservableCollection or other UI-bound collection here.
this.PackageContents.Clear();
this.PreviewPackageContents.Clear();
this.RootContents.Clear();

RaisePropertyChanged(nameof(PackageContents));
RaisePropertyChanged(nameof(PreviewPackageContents));
RaisePropertyChanged(nameof(RootContents));

this.CustomNodeDefinitions = new List<CustomNodeDefinition>();
//});
}

private void ThisPropertyChanged(object sender, PropertyChangedEventArgs e)
Expand Down Expand Up @@ -1524,10 +1542,20 @@ private void RemoveItem (object parameter)

RemoveItemRecursively(packageItemRootViewModel);
RefreshPackageContents();
RaisePropertyChanged(nameof(PackageContents));
RaisePropertyChanged(nameof(PreviewPackageContents));

return;
}

/// <summary>
/// The Cancel command to clear all package data and user interface
/// </summary>
private void Cancel()
{
this.ClearAllEntries();
}

private void RemoveItemRecursively(PackageItemRootViewModel packageItemRootViewModel)
{
DependencyType fileType = packageItemRootViewModel.DependencyType;
Expand Down Expand Up @@ -1813,7 +1841,6 @@ private void PublishLocally()

if (dialogResult == MessageBoxResult.Yes)
{
this.ClearAllEntries();
Uploading = false;
UploadState = PackageUploadHandle.State.Ready;
}
Expand All @@ -1828,6 +1855,9 @@ private void PublishLocally()
},
null, 1200, System.Threading.Timeout.Infinite);
}

// Clear the entries regardless of this choice. What is this chice for anyways?
this.ClearAllEntries();
}
}
catch (Exception e)
Expand Down Expand Up @@ -2182,7 +2212,7 @@ internal PackageItemRootViewModel GetPreBuildRootItemViewModel(string publishPat
if (assembly == null)
{
var extra = new PackageItemRootViewModel(new FileInfo(Path.Combine(binDir, fileName)));
extraItemPreview.AddChild(extra);
binItemPreview.AddChild(extra);
}
else
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -348,7 +348,7 @@

<!-- Main navigation frame hosting the pages -->
<Frame x:Name="mainFrame"
Grid.Row="1"
Grid.Row="1"
NavigationUIVisibility="Hidden"
Navigated="mainFrame_Navigated"/>

Expand All @@ -360,14 +360,26 @@
<StackPanel DockPanel.Dock="Right"
x:Name="PublishPageButtonStack"
Orientation="Horizontal">

<!-- Cancel -->
<Button Command="{Binding Path=CancelCommand}"
Content="{x:Static p:Resources.CancelButton}"
DockPanel.Dock="Right"
Background="Transparent"
Foreground="White"
BorderBrush="{StaticResource DetailsButtonBorderColorBrush}"
Margin="0,0,8,0"
Style="{StaticResource CtaButtonStyle}"
TabIndex="20" />

<!-- Publish Online -->
<Button Command="{Binding Path=SubmitCommand}"
Content="{x:Static p:Resources.PublishPackage}"
DockPanel.Dock="Right"
Background="#0696D7"
Foreground="White"
BorderBrush="#0696D7"
Margin="0,0,-5,0"
Margin="0,0,8,0"
Style="{StaticResource CtaButtonStyle}"
TabIndex="20" />

Expand Down Expand Up @@ -397,7 +409,7 @@
Background="Transparent"
Foreground="White"
BorderBrush="{StaticResource DetailsButtonBorderColorBrush}"
Margin="0,0,-5,0"
Margin="0,0,8,0"
Style="{StaticResource CtaButtonStyle}"
TabIndex="20" />

Expand Down Expand Up @@ -427,10 +439,10 @@
Background="Transparent"
Foreground="White"
BorderBrush="{StaticResource DetailsButtonBorderColorBrush}"
Margin="0,0,-5,0"
Margin="0,0,8,0"
Style="{StaticResource CtaButtonStyle}"
TabIndex="20" />

<!-- Finish -->
<Button Content="Finish"
Tag="Next"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
using Dynamo.Logging;
using Dynamo.UI;
using Dynamo.ViewModels;
using DynamoUtilities;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
using Dynamo.Logging;
using Dynamo.UI;
using Dynamo.ViewModels;
using DynamoUtilities;
using Views.PackageManager.Pages;

namespace Dynamo.PackageManager.UI
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -624,7 +624,10 @@
<!-- Top Row: Buttons and Label -->
<StackPanel Orientation="Horizontal" HorizontalAlignment="Center"
Margin="30"
Visibility="{Binding PreviewPackageContents, Converter={StaticResource EmptyListToVisibilityConverter}}">
Visibility="{Binding PreviewPackageContents,
UpdateSourceTrigger=PropertyChanged,
Mode=TwoWay,
Converter={StaticResource EmptyListToVisibilityConverter}}">

<!-- Add Files -->
<Button Click="NavigationButton_Click"
Expand Down Expand Up @@ -658,15 +661,17 @@
<ToolTip Content="{x:Static p:Resources.PublishPackageViewAddDirectoryButtonTooltip}"
Style="{StaticResource GenericToolTipLight}"></ToolTip>
</Button.ToolTip>
</Button>


</Button>
</StackPanel>

<local:CustomBrowserControl x:Name="previewBrowserControl"
Loaded="previewBrowserControl_Loaded"
IsEnabled="False"
Root="{Binding PreviewPackageContents, UpdateSourceTrigger=PropertyChanged, Mode=OneWay}"
Visibility="{Binding PreviewPackageContents, Converter={StaticResource ListHasMoreThanNItemsToVisibilityConverter}}"/>
Visibility="{Binding PreviewPackageContents,
UpdateSourceTrigger=PropertyChanged,
Mode=TwoWay,
Converter={StaticResource ListHasMoreThanNItemsToVisibilityConverter}}"/>
</Grid>

</Border>
Expand Down
27 changes: 27 additions & 0 deletions test/DynamoCoreWpfTests/PublishPackageViewModelTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -351,6 +351,33 @@ public void RemoveAllChildrenFilesUpdatesContentItem()
}


[Test]
public void CancelCommandClearsAllData()
{
// Arrange
string nodePath = Path.Combine(TestDirectory, "core", "docbrowser\\pkgs\\RootPackageFolder\\PackageWithNodeDocumentation");
var allFiles = Directory.GetFiles(nodePath, "*", SearchOption.AllDirectories).ToList();
var vm = new PublishPackageViewModel(this.ViewModel);

Assert.AreEqual(0, vm.PackageContents.Count);
Assert.AreEqual(0, vm.PreviewPackageContents.Count);

ViewModel.OnRequestPackagePublishDialog(vm);

vm.AddAllFilesAfterSelection(allFiles);

// Act
Assert.AreEqual(1, vm.PackageContents.Count);
Assert.AreEqual(1, vm.PreviewPackageContents.Count);

vm.CancelCommand.Execute();

// Assert
Assert.AreEqual(0, vm.PackageContents.Count);
Assert.AreEqual(0, vm.PreviewPackageContents.Count);
}


[Test, Category("Failure")]
public void NewPackageVersionUpload_DoesNotThrowExceptionWhenDLLIsLoadedSeveralTimes()
{
Expand Down

0 comments on commit 3df4cce

Please sign in to comment.