Skip to content

Commit

Permalink
publish retain folder done
Browse files Browse the repository at this point in the history
- finished workflow for publishing package reatining folder
- changed UI finish screen to work differently depending on which workflow was taken - publish locally or online
- tests added
  • Loading branch information
dnenov committed Nov 6, 2023
1 parent c1ff965 commit d0df247
Show file tree
Hide file tree
Showing 11 changed files with 184 additions and 23 deletions.
9 changes: 9 additions & 0 deletions src/DynamoCoreWpf/Properties/Resources.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions src/DynamoCoreWpf/Properties/Resources.en-US.resx
Original file line number Diff line number Diff line change
Expand Up @@ -1585,6 +1585,9 @@ Next assemblies were loaded several times:
<data name="PackageManagerFinishedPackageFilesUploadedMessage" xml:space="preserve">
<value> files uploaded</value>
</data>
<data name="PackageManagerFinishedPackageFilesPublishedMessage" xml:space="preserve">
<value> files published</value>
</data>
<data name="PackagePathAutoAddNotificationTitle" xml:space="preserve">
<value>Package Path Added</value>
</data>
Expand Down
3 changes: 3 additions & 0 deletions src/DynamoCoreWpf/Properties/Resources.resx
Original file line number Diff line number Diff line change
Expand Up @@ -2230,6 +2230,9 @@ Do you want to install the latest Dynamo update?</value>
<data name="PackageManagerFinishedPackageFilesUploadedMessage" xml:space="preserve">
<value> files uploaded</value>
</data>
<data name="PackageManagerFinishedPackageFilesPublishedMessage" xml:space="preserve">
<value> files published</value>
</data>
<data name="PackagePathAutoAddNotificationTitle" xml:space="preserve">
<value>Package Path Added</value>
</data>
Expand Down
53 changes: 53 additions & 0 deletions src/DynamoCoreWpf/UI/Converters.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3856,4 +3856,57 @@ public object[] ConvertBack(object value, Type[] targetTypes, object parameter,
return null;
}
}


/// <summary>
/// Convers PackageUploadHandle UploadType enum value to visibility
/// </summary>
public class PackageUploadHandleUploadTypeToVisibilityConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
if (value is PackageUploadHandle.UploadType uploadType)
{
if (parameter != null && parameter.ToString().ToLower() == "invert")
{
return uploadType != PackageUploadHandle.UploadType.Submit ? Visibility.Visible : Visibility.Hidden;
}
else
{
return uploadType == PackageUploadHandle.UploadType.Submit ? Visibility.Visible : Visibility.Hidden;
}
}

return Visibility.Hidden;
}

public object ConvertBack(object value, Type targetType, object parameter,
CultureInfo culture)
{
return null;
}
}

/// <summary>
/// ReadyToPublish message to visibility converter
/// </summary>
public class ReadyToPublishToVisibilityCollapsedConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
if (value is string errorMessage && errorMessage.Equals(Resources.PackageManagerReadyToPublish))
{
return Visibility.Visible;
}

return Visibility.Collapsed;
}

public object ConvertBack(object value, Type targetType, object parameter,
CultureInfo culture)
{
return null;
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -107,11 +107,15 @@ public bool Uploading
{
_uploading = value;
RaisePropertyChanged("Uploading");
BeginInvoke(() =>
{
SubmitCommand.RaiseCanExecuteChanged();
PublishLocallyCommand.RaiseCanExecuteChanged();
});
// Can we try commenting out the can execute?
// The way async works here, when an error is returned from the response
// The Uploadling flag is set back to 'false' before the CanExecute code has reached it,
// as a result the error message is overriden.
//BeginInvoke(() =>
//{
// SubmitCommand.RaiseCanExecuteChanged();
// PublishLocallyCommand.RaiseCanExecuteChanged();
//});
}
}

Expand Down Expand Up @@ -181,6 +185,25 @@ public PackageUploadHandle.State UploadState
}
}

/// <summary>
/// UploadType property </summary>
/// <value>
/// The type of the upload - local or online
/// </value>
private PackageUploadHandle.UploadType _uploadType = PackageUploadHandle.UploadType.Local;
public PackageUploadHandle.UploadType UploadType
{
get { return _uploadType; }
set
{
if (_uploadType != value)
{
_uploadType = value;
RaisePropertyChanged("UploadType");
}
}
}

/// <summary>
/// Name property </summary>
/// <value>
Expand Down Expand Up @@ -250,7 +273,7 @@ public string Keywords
/// KeywordList property </summary>
/// <value>
/// A list of keywords, usually produced by parsing Keywords</value>
public List<string> KeywordList { get; set; }
public List<string> KeywordList { get; set; } = new List<string>();

/// <summary>
/// FullVersion property </summary>
Expand Down Expand Up @@ -1010,7 +1033,8 @@ private void ClearAllEntries()
this.Uploading = false;
// Clearing the UploadHandle when using Submit currently throws - check trheading
try
{
{
this._uploadHandle.PropertyChanged += UploadHandleOnPropertyChanged;
this.UploadHandle = null;
}
catch { Exception ex; }
Expand Down Expand Up @@ -1193,17 +1217,21 @@ public void OnPublishSuccess()

private void UploadHandleOnPropertyChanged(object sender, PropertyChangedEventArgs propertyChangedEventArgs)
{
if (propertyChangedEventArgs.PropertyName == "UploadState")
if (propertyChangedEventArgs.PropertyName == nameof(PackageUploadHandle.UploadState))
{
UploadState = ((PackageUploadHandle)sender).UploadState;

if (((PackageUploadHandle)sender).UploadState == PackageUploadHandle.State.Uploaded)
{
OnPublishSuccess();
BeginInvoke(() =>
{
OnPublishSuccess();
ClearAllEntries();
});
}

}
else if (propertyChangedEventArgs.PropertyName == "ErrorString")
else if (propertyChangedEventArgs.PropertyName == nameof(PackageUploadHandle.ErrorString))
{
UploadState = PackageUploadHandle.State.Error;
ErrorString = ((PackageUploadHandle)sender).ErrorString;
Expand Down Expand Up @@ -1435,7 +1463,7 @@ public string ErrorString
get { return _errorString; }
set
{
_errorString = value;
_errorString = value;
RaisePropertyChanged("ErrorString");
}
}
Expand Down Expand Up @@ -1783,6 +1811,9 @@ private void Submit()
{
return;
}

UploadType = PackageUploadHandle.UploadType.Submit;

var contentFiles = BuildPackage();

//do not create the updatedFiles used for retain folder route unless needed
Expand Down Expand Up @@ -1852,6 +1883,8 @@ private void PublishLocally()
if (string.IsNullOrEmpty(publishPath))
return;

UploadType = PackageUploadHandle.UploadType.Local;

var files = BuildPackage();

try
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
<ui:SharedResourceDictionary Source="{x:Static ui:SharedDictionaryManager.DynamoColorsAndBrushesDictionaryUri}" />
</ResourceDictionary.MergedDictionaries>
<controls:EmptyStringToFalseConverter x:Key="EmptyStringToFalseConverter" />
<controls:ReadyToPublishToVisibilityCollapsedConverter x:Key="ReadyToPublishToVisibilityCollapsedConverter" />
<BooleanToVisibilityConverter x:Key="BooleanToVisibilityConverter" />
<SolidColorBrush x:Key="DetailsButtonBorderColorBrush" Color="#808080" Opacity="0.5"/>
<ControlTemplate x:Key="ComboBoxToggleButton"
Expand Down Expand Up @@ -401,9 +402,9 @@
Height="18px"
Margin="5,0"
UseLayoutRounding="True"
HorizontalAlignment="Center"
HorizontalAlignment="Center"
VerticalAlignment="Center"
Visibility="{Binding ElementName=publishButton, Path=IsEnabled, Converter={StaticResource BooleanToVisibilityConverter}}"
Visibility="{Binding ErrorString, Converter={StaticResource ReadyToPublishToVisibilityCollapsedConverter}}"
Source="/DynamoCoreWpf;component/UI/Images/checkmark_16px.png" />
<TextBlock Margin="0,4,0,0"
VerticalAlignment="Center"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,8 @@ private void PackageViewModelOnPublishSuccess(PublishPackageViewModel sender)
statusLabel.Visibility = Visibility.Collapsed;

currentPage = 3;

// Trigger load events manually for the Finish Page to get the count of published files
if (PublishPages[currentPage] is PublishPackageFinishPage)
(PublishPages[currentPage] as PublishPackageFinishPage).LoadEvents();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:Views.PackageManager.Pages"
xmlns:controls="clr-namespace:Dynamo.Controls"
mc:Ignorable="d"
xmlns:p="clr-namespace:Dynamo.Wpf.Properties"
xmlns:ui="clr-namespace:Dynamo.UI"
Expand All @@ -16,12 +17,13 @@
<ui:SharedResourceDictionary Source="{x:Static ui:SharedDictionaryManager.DynamoConvertersDictionaryUri}" />
<ui:SharedResourceDictionary Source="{x:Static ui:SharedDictionaryManager.DynamoColorsAndBrushesDictionaryUri}" />
</ResourceDictionary.MergedDictionaries>
<Style x:Key="FinishedPageTextStyle" TargetType="TextBlock">
<controls:PackageUploadHandleUploadTypeToVisibilityConverter x:Key="PackageUploadHandleUploadTypeToVisibilityConverter" />
<Style x:Key="FinishedPageTextStyle" TargetType="TextBlock">
<Setter Property="Foreground" Value="#F5F5F5"/>
<Setter Property="FontFamily" Value="{StaticResource ArtifaktElementRegular}"/>
<Setter Property="HorizontalAlignment" Value="Center"/>
<Setter Property="VerticalAlignment" Value="Center"/>
</Style>
</Style>
</ResourceDictionary>
</Page.Resources>
<Grid>
Expand Down Expand Up @@ -49,14 +51,17 @@
FontSize="12"
Style="{StaticResource FinishedPageTextStyle}"/>


<TextBlock Text="{x:Static p:Resources.PackageManagerPublishOnlineFinishedMessage}"
Margin="0 3"
FontSize="12"
Style="{StaticResource FinishedPageTextStyle}"/>
Style="{StaticResource FinishedPageTextStyle}"
Visibility="{Binding UploadType, Converter={StaticResource PackageUploadHandleUploadTypeToVisibilityConverter} }"/>
</StackPanel>

<StackPanel Grid.Row="1">
<StackPanel Grid.Row="1"
Visibility="{Binding UploadType,
Converter={StaticResource PackageUploadHandleUploadTypeToVisibilityConverter},
ConverterParameter=invert }">

<TextBlock Text="{x:Static p:Resources.PackageManagerFinishedPackagePackagePath}"
Margin="15 0"
Expand All @@ -65,7 +70,7 @@
Style="{StaticResource FinishedPageTextStyle}"/>
<Grid Margin="15 5"
Height="36"
Background="Transparent">
Background="Transparent" >
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="Auto" />
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
using Dynamo.PackageManager;
using Dynamo.PackageManager.UI;
using System;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Windows;
using System.Windows.Controls;
using Dynamo.PackageManager;
using Dynamo.PackageManager.UI;

namespace Views.PackageManager.Pages
{
Expand All @@ -26,10 +26,16 @@ public PublishPackageFinishPage()

internal void LoadEvents()
{
if ( PublishPackageViewModel == null ) { return; }

var uploadType = PublishPackageViewModel.UploadType;
var publishedFiles = PackageItemRootViewModel.GetFiles(PublishPackageViewModel.PackageContents.ToList());
var count = publishedFiles.Count(x => x.DependencyType != DependencyType.Folder);
var message = uploadType.Equals(PackageUploadHandle.UploadType.Local) ?
Dynamo.Wpf.Properties.Resources.PackageManagerFinishedPackageFilesPublishedMessage :
Dynamo.Wpf.Properties.Resources.PackageManagerFinishedPackageFilesUploadedMessage;

this.filesUploadedMessage.Text = String.Format("{0} {1}", count.ToString(), Dynamo.Wpf.Properties.Resources.PackageManagerFinishedPackageFilesUploadedMessage);
this.filesUploadedMessage.Text = String.Format("{0} {1}", count.ToString(), message);
this.packagePathTextBlox.Text = PublishPackageViewModel.RootFolder;
}

Expand Down
10 changes: 10 additions & 0 deletions src/DynamoPackages/PackageUploadHandle.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,16 @@ public enum State
Ready, Copying, Compressing, Uploading, Uploaded, Error
}

/// <summary>
/// Tracks the type of publish, which can be local or online
/// </summary>
public enum UploadType
{
Local, Submit
}



private string _errorString = "";
public string ErrorString { get { return _errorString; } set { _errorString = value; RaisePropertyChanged("ErrorString"); } }

Expand Down
36 changes: 36 additions & 0 deletions test/DynamoCoreWpfTests/PublishPackageViewModelTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -701,7 +701,43 @@ public void PublishingACustomNodeSetsPackageInfoCorrectly_()
public void PublishingCustomNodeAsNewVersionWorks_SetsPackageInfoCorrectly()
{
throw new NotImplementedException();
}


[Test]
public void AssertPublishLocalHandleType()
{
var packageName = "SingleFolderPublishPackage";
var pathManager = this.ViewModel.Model.PathManager as PathManager;
var publishPath = Path.Combine(pathManager.DefaultPackagesDirectory, packageName);

string nodePath = Path.Combine(TestDirectory, "core", "docbrowser\\pkgs\\SingleFolderPublishPackageDocs");
var allFiles = Directory.GetFiles(nodePath, "*", SearchOption.AllDirectories).ToList();

//now lets publish this package.
var newPkgVm = new PublishPackageViewModel(this.ViewModel);
newPkgVm.RetainFolderStructureOverride = true;

ViewModel.OnRequestPackagePublishDialog(newPkgVm);

newPkgVm.AddAllFilesAfterSelection(allFiles);

var previewFilesAndFolders = PackageItemRootViewModel.GetFiles(newPkgVm.PreviewPackageContents.ToList());
var previewFiles = previewFilesAndFolders.Where(x => !x.DependencyType.Equals(DependencyType.Folder));
var previewFolders = previewFilesAndFolders.Where(x => x.DependencyType.Equals(DependencyType.Folder));

newPkgVm.Name = "SingleFolderPublishPackage";
newPkgVm.MajorVersion = "0";
newPkgVm.MinorVersion = "0";
newPkgVm.BuildVersion = "1";
newPkgVm.PublishLocallyCommand.Execute();

// Assert
Assert.AreEqual(PackageUploadHandle.UploadType.Local, newPkgVm.UploadType);

// Clean up
Directory.Delete(publishPath, true);
}

}
}

0 comments on commit d0df247

Please sign in to comment.