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

Publish Package with Host Multi-Selection #9850

Merged
merged 9 commits into from
Jul 30, 2019
Merged
Show file tree
Hide file tree
Changes from 6 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
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>
116 changes: 116 additions & 0 deletions src/DynamoCoreWpf/ViewModels/PackageManager/PublishPackageViewModel.cs
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,76 @@ 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("KnownHosts");
QilongTang marked this conversation as resolved.
Show resolved Hide resolved
}
}
}

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; }
QilongTang marked this conversation as resolved.
Show resolved Hide resolved
set
{
if (_selectedHosts != value)
{
_selectedHosts = value;
foreach (var host in KnownHosts)
{
if (_selectedHosts.Contains(host.HostName)) host.IsSelected = true;
}
RaisePropertyChanged("SelectedHosts");
}
}
}

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("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 +604,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 +623,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 +650,7 @@ private void BeginInvoke(Action action)
public PublishPackageViewModel( DynamoViewModel dynamoViewModel ) : this()
{
this.dynamoViewModel = dynamoViewModel;
KnownHosts = initializeHostSelections();
}

private void ClearAllEntries()
Expand All @@ -563,6 +676,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 @@ -1197,6 +1312,7 @@ private IEnumerable<string> BuildPackage()
Package.License = License;
Package.SiteUrl = SiteUrl;
Package.RepositoryUrl = RepositoryUrl;
Package.HostDependencies = SelectedHosts;

AppendPackageContents();

Expand Down
Loading