Skip to content

Commit

Permalink
Publish Package with Host Multi-Selection (#9850)
Browse files Browse the repository at this point in the history
* Initial Commit

* Add hosts selections

* Add the multi selection

* Multiple Host Selection Display

* Correct Host Dependencies in Json for publishing and download

* Code Clean up

* More Cleanup and Comments

* Bug fixing - publish version

* More comments and regression
  • Loading branch information
QilongTang authored Jul 30, 2019
1 parent 0786921 commit 073d2c5
Show file tree
Hide file tree
Showing 11 changed files with 296 additions and 38 deletions.
4 changes: 2 additions & 2 deletions src/DynamoCoreWpf/Controls/RunSettingsControl.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@
<Style TargetType="Label">
<Style.Triggers>
<DataTrigger Binding="{Binding Enabled}" Value="True">
<Setter Property="Foreground" Value="#bbbbbb"></Setter>
<Setter Property="Foreground" Value="{StaticResource DynamoStandardLableTextBrush}"></Setter>
</DataTrigger>
<DataTrigger Binding="{Binding Enabled}" Value="False">
<Setter Property="Foreground" Value="#444444"></Setter>
Expand Down Expand Up @@ -92,7 +92,7 @@
Visibility="{Binding RunPeriodInputVisibility}"
Width="80" FontSize="14px"
Style="{DynamicResource ResourceKey=SDarkTextBox}"
Foreground="#bbbbbb"
Foreground="{StaticResource DynamoStandardLableTextBrush}"
KeyDown="UIElement_OnKeyDown" Margin="2.5,0,0,0"/>

<CheckBox Margin="10" x:FieldModifier="public"
Expand Down
18 changes: 18 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.

8 changes: 7 additions & 1 deletion src/DynamoCoreWpf/Properties/Resources.en-US.resx
Original file line number Diff line number Diff line change
Expand Up @@ -2224,8 +2224,14 @@ Uninstall the following packages: {0}?</value>
</data>
<data name="PackageHostDependencyFilterContextItem" xml:space="preserve">
<value>Packages requires the specified host to run.</value>
</data>
</data>
<data name="MessageUninstallSamePackage" xml:space="preserve">
<value>"The package {0} is already installed. To reinstall it, you must first uninstall it and restart to complete the uninstall. Would you like to mark {0} for uninstall?"</value>
</data>
<data name="PublishPackageViewPackageHostDependency" xml:space="preserve">
<value>Host Dependency (optional)</value>
</data>
<data name="PublishPackageViewPackageHostDependencyTooltip" xml:space="preserve">
<value>One or multiple host dependencies help to specify this package contains nodes for these integrations, and as a result will only run in these hosts.</value>
</data>
</root>
6 changes: 6 additions & 0 deletions src/DynamoCoreWpf/Properties/Resources.resx
Original file line number Diff line number Diff line change
Expand Up @@ -2231,4 +2231,10 @@ Uninstall the following packages: {0}?</value>
<data name="MessageUninstallSamePackage" xml:space="preserve">
<value>"The package {0} is already installed. To reinstall it, you must first uninstall it and restart to complete the uninstall. Would you like to mark {0} for uninstall?"</value>
</data>
<data name="PublishPackageViewPackageHostDependency" xml:space="preserve">
<value>Host Dependency (optional)</value>
</data>
<data name="PublishPackageViewPackageHostDependencyTooltip" xml:space="preserve">
<value>One or multiple host dependencies help to specify this package contains nodes for these integrations, and as a result will only run in these hosts.</value>
</data>
</root>
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
<!--a good color picker-->
<!--http://www.colorspire.com/rgb-color-wheel/-->

<!--Universal-->
<SolidColorBrush Color="#BBBBBB" x:Key="DynamoStandardLableTextBrush"></SolidColorBrush>

<!--Workspaces-->
<SolidColorBrush Color="#353535" x:Key="DynamoWindowBrush"/>
<SolidColorBrush Color="#232323" x:Key="WorkspaceBackgroundBrush"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,41 @@ public class PublishPackageViewModel : NotificationObject
#region Properties/Fields

private readonly DynamoViewModel dynamoViewModel;

/// <summary>
/// reference of DynamoViewModel
/// </summary>
public DynamoViewModel DynamoViewModel
{
get { return dynamoViewModel; }
}

/// <summary>
/// Package Publish entry, binded to the host multi-selection option
/// </summary>
public class HostComboboxEntry
{
/// <summary>
/// Name of the host
/// </summary>
public string HostName { get; set; }

/// <summary>
/// Boolean indicates if the host entry is selected
/// </summary>
public bool IsSelected { get; set; }

/// <summary>
/// Constructor
/// </summary>
/// <param name="hostName">Name of the host</param>
public HostComboboxEntry(string hostName)
{
HostName = hostName;
IsSelected = false;
}
}

/// <summary>
/// A event called when publishing was a success
/// </summary>
Expand Down Expand Up @@ -387,11 +418,86 @@ public bool MoreExpanded
}
}

private List<HostComboboxEntry> knownHosts;

/// <summary>
/// Know hosts received from package manager.
/// Data binded to the multi-selection host dependency option.
/// </summary>
public List<HostComboboxEntry> KnownHosts
{
get { return knownHosts; }
set
{
if (knownHosts != value)
{
knownHosts = value;
RaisePropertyChanged(nameof(KnownHosts));
}
}
}

private List<string> selectedHosts = new List<String>();
/// <summary>
/// Current selected hosts as dependencies.
/// Will be passed for serialization when publishing package.
/// </summary>
public List<string> SelectedHosts
{
get { return selectedHosts; }
set
{
if (selectedHosts != value && value != null)
{
selectedHosts = value;
// The following logic is mainly for publishing from an existing package with
// pre-serialized host dependencies. We set the selection state so user do not have
// to replicate the selection again
foreach (var host in KnownHosts)
{
if (selectedHosts.Contains(host.HostName))
{
host.IsSelected = true;
SelectedHostsString += host.HostName + ", ";
}
}
// Format string since it will be displayed
SelectedHostsString = SelectedHostsString.Trim().TrimEnd(',');
RaisePropertyChanged( nameof(SelectedHosts));
RaisePropertyChanged( nameof(SelectedHostsString));
}
}
}

private string selectedHostsString = string.Empty;
/// <summary>
/// Current selected hosts as dependencies string for display
/// </summary>
public string SelectedHostsString
{
get { return selectedHostsString; }
set
{
if (selectedHostsString != value)
{
selectedHostsString = value;
RaisePropertyChanged(nameof(SelectedHostsString));
}
}
}

/// <summary>
/// Boolean indicating if the current publishing package is depending on other package
/// </summary>
public bool HasDependencies
{
get { return Dependencies.Count > 0; }
}

/// <summary>
/// This property seems dup with HasDependencies
/// TODO: Remove in Dynamo 3.0
/// </summary>
public bool HasNoDependencies
{
get { return !HasDependencies; }
Expand Down Expand Up @@ -508,6 +614,7 @@ public PackageUploadRequestBody BaseVersionHeader
BuildVersion = versionSplit[2];
Name = value.name;
Keywords = String.Join(" ", value.keywords);
SelectedHosts = value.host_dependencies as List<string>;
_dynamoBaseHeader = value;
}
}
Expand All @@ -526,6 +633,21 @@ internal PublishPackageViewModel()
PropertyChanged += ThisPropertyChanged;
}

/// <summary>
/// Return a list of HostComboboxEntry describing known hosts from PM.
/// Return an empty list if PM is down.
/// </summary>
/// <returns>A list of HostComboboxEntry describing known hosts from PM.</returns>
private List<HostComboboxEntry> initializeHostSelections()
{
var hostSelections = new List<HostComboboxEntry>();
foreach (var host in dynamoViewModel.PackageManagerClientViewModel.Model.GetKnownHosts())
{
hostSelections.Add(new HostComboboxEntry(host));
}
return hostSelections;
}

private void BeginInvoke(Action action)
{
// dynamoViewModel.UIDispatcher can be null in unit tests.
Expand All @@ -538,6 +660,7 @@ private void BeginInvoke(Action action)
public PublishPackageViewModel( DynamoViewModel dynamoViewModel ) : this()
{
this.dynamoViewModel = dynamoViewModel;
KnownHosts = initializeHostSelections();
}

private void ClearAllEntries()
Expand All @@ -563,6 +686,8 @@ private void ClearAllEntries()
this.AdditionalFiles = new ObservableCollection<string>();
this.Dependencies = new ObservableCollection<PackageDependency>();
this.Assemblies = new List<PackageAssembly>();
this.SelectedHosts = new List<String>();
this.SelectedHostsString = string.Empty;
}

private void ClearPackageContents()
Expand Down Expand Up @@ -610,7 +735,8 @@ public static PublishPackageViewModel FromLocalPackage(DynamoViewModel dynamoVie
RepositoryUrl = l.RepositoryUrl ?? "",
SiteUrl = l.SiteUrl ?? "",
Package = l,
License = l.License
License = l.License,
SelectedHosts = l.HostDependencies as List<string>
};

// add additional files
Expand Down Expand Up @@ -1197,6 +1323,7 @@ private IEnumerable<string> BuildPackage()
Package.License = License;
Package.SiteUrl = SiteUrl;
Package.RepositoryUrl = RepositoryUrl;
Package.HostDependencies = SelectedHosts;

AppendPackageContents();

Expand Down
4 changes: 2 additions & 2 deletions src/DynamoCoreWpf/Views/About/AboutWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
Foreground="#898989"
FontSize="14">
<Run Text="Dynamo Core"/>
<Run Foreground="#bbbbbb" Text="{Binding Version, Mode=OneWay}"/>
<Run Foreground="{StaticResource DynamoStandardLableTextBrush}" Text="{Binding Version, Mode=OneWay}"/>
</TextBlock>

<TextBlock Name="GenericHostVersion"
Expand All @@ -68,7 +68,7 @@
Margin="0,-10,0,0"
Visibility="{Binding HostVersion, Converter={StaticResource NullValueToCollapsedConverter}}">
<Run Text="{Binding HostName, Mode=OneWay}"/>
<Run Foreground="#bbbbbb" Text= "{Binding HostVersion, Mode=OneWay}"/>
<Run Foreground="{StaticResource DynamoStandardLableTextBrush}" Text= "{Binding HostVersion, Mode=OneWay}"/>
</TextBlock>
<TextBlock x:Name ="UpdateInfo"
HorizontalAlignment="Center"
Expand Down
Loading

0 comments on commit 073d2c5

Please sign in to comment.