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

Pm search for packages - votes #14390

Merged
merged 15 commits into from
Oct 27, 2023
Merged
Show file tree
Hide file tree
Changes from 12 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
6 changes: 3 additions & 3 deletions src/AssemblySharedInfoGenerator/AssemblySharedInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
// associated with an assembly.
[assembly: AssemblyCompany("Autodesk, Inc")]
[assembly: AssemblyProduct("Dynamo")]
[assembly: AssemblyCopyright("Copyright © Autodesk, Inc 2023")]
[assembly: AssemblyCopyright("Copyright © Autodesk, Inc 2023")]
Copy link
Contributor

Choose a reason for hiding this comment

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

This file shouldn't be added, that is why the self-serve is failing.

[assembly: AssemblyTrademark("")]

//In order to begin building localizable applications, set
Expand Down Expand Up @@ -45,7 +45,7 @@
// to distinguish one build from another. AssemblyFileVersion is specified
// in AssemblyVersionInfo.cs so that it can be easily incremented by the
// automated build process.
[assembly: AssemblyVersion("3.0.0.5795")]
[assembly: AssemblyVersion("3.0.0.6622")]


// By default, the "Product version" shown in the file properties window is
Expand All @@ -64,4 +64,4 @@
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyFileVersion("3.0.0.5795")]
[assembly: AssemblyFileVersion("3.0.0.6622")]
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,12 @@ public string Username

public ICommand ToggleLoginStateCommand { get; private set; }

/// <summary>
/// Contains all votes the user has been submitted.
/// Will allow the user to vote for a package they have not upvoted before
/// </summary>
private List<string> Uservotes { get; set; }

internal PackageManagerClientViewModel(DynamoViewModel dynamoViewModel, PackageManagerClient model )
{
this.DynamoViewModel = dynamoViewModel;
Expand All @@ -276,6 +282,11 @@ internal PackageManagerClientViewModel(DynamoViewModel dynamoViewModel, PackageM
RaisePropertyChanged("Username");
};
}

if (AuthenticationManager.LoginState.Equals(LoginState.LoggedIn))
{
this.Uservotes = this.Model.UserVotes();
}
}

private void ToggleLoginState()
Expand Down Expand Up @@ -485,6 +496,11 @@ public List<PackageManagerSearchElement> ListAll()
var ele = new PackageManagerSearchElement(header);

ele.UpvoteRequested += this.Model.Upvote;
if (Uservotes != null)
{
ele.HasUpvote = Uservotes.Contains(header._id);
}

CachedPackageList.Add( ele );
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -154,18 +154,16 @@
SelectedIndex="{Binding Path=SelectedIndex}"
VirtualizingPanel.ScrollUnit="Pixel">

<ListBox.Resources>
<ListBox.Resources>
<SolidColorBrush x:Key="ForegroundGrayBrush" Color="#D8D8D8" />
<SolidColorBrush x:Key="HasVotedBlueBrush" Color="#84D7CE" />
<!-- Local style used for labels on result, e.g. Number of Installs -->
<Style x:Key="resultLabelStyle"
TargetType="TextBlock">
<Setter Property="FontFamily"
Value="{StaticResource ArtifaktElementRegular}" />
<Setter Property="FontSize"
Value="10" />
<Setter Property="Foreground"
Value="#C7C7C7" />
<Setter Property="VerticalAlignment"
Value="Center" />
<Setter Property="FontFamily" Value="{StaticResource ArtifaktElementRegular}" />
<Setter Property="FontSize" Value="10" />
<Setter Property="Foreground" Value="#C7C7C7" />
<Setter Property="VerticalAlignment" Value="Center" />
<Style.Triggers>
<DataTrigger Binding="{Binding Model.IsDeprecated}"
Value="True">
Expand Down Expand Up @@ -564,15 +562,19 @@
DockPanel.Dock="Right"
Style="{StaticResource resultLabelStyle}"
Text="{Binding Path=Model.Votes, Converter={StaticResource NegativeIntToZeroConverter}}" />
<Rectangle Width="12"
Height="11"
Margin="5,0,0,2"
VerticalAlignment="Center"
DockPanel.Dock="Right">
<Rectangle.Fill>
<ImageBrush ImageSource="/DynamoCoreWpf;component/UI/Images/Favorite.png" />
</Rectangle.Fill>
</Rectangle>


<Viewbox Width="12"
Height="12"
Margin="5,0,0,2"
VerticalAlignment="Center"
DockPanel.Dock="Right">
<Path x:Name="heartIcon"
Data="M13.91,6.75c-1.17,2.25-4.3,5.31-6.07,6.94c-0.1903,0.1718-0.4797,0.1718-0.67,0C5.39,12.06,2.26,9,1.09,6.75&#xA;&#x9;C-1.48,1.8,5-1.5,7.5,3.45C10-1.5,16.48,1.8,13.91,6.75z"
Stroke="{StaticResource ForegroundGrayBrush}"
StrokeThickness="1"
VerticalAlignment="Center" />
</Viewbox>

<!-- The version combobox -->
<StackPanel Margin="5,0,5,0"
Expand Down Expand Up @@ -626,6 +628,17 @@
Fill="{StaticResource DarkMidGreyBrush}" />

</Grid>
<DataTemplate.Triggers>
<DataTrigger Binding="{Binding Path=Model.HasUpvote}"
Value="True">
<Setter TargetName="heartIcon"
Property="Fill"
Value="{StaticResource HasVotedBlueBrush}" />
<Setter TargetName="heartIcon"
Property="Stroke"
Value="{StaticResource HasVotedBlueBrush}" />
</DataTrigger>
</DataTemplate.Triggers>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
Expand Down
2 changes: 1 addition & 1 deletion src/DynamoPackages/DynamoPackages.csproj
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">
<ImportGroup Label="PropertySheets">
<Import Project="$(SolutionDir)Config\CS_SDK.props" />
</ImportGroup>
Expand Down
14 changes: 13 additions & 1 deletion src/DynamoPackages/PackageManagerClient.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Dynamo.Graph.Workspaces;
using Greg;
using Greg.Requests;
using Greg.Responses;
using System.Linq;

namespace Dynamo.PackageManager
{
Expand Down Expand Up @@ -65,6 +65,18 @@ internal bool Upvote(string packageId)
}, false);
}

internal List<string> UserVotes()
{
var votes = FailFunc.TryExecute(() =>
{
var nv = new GetUserVotes();
var pkgResponse = this.client.ExecuteAndDeserializeWithContent<UserVotes>(nv);
return pkgResponse.content;
}, null);

return votes.has_upvoted;
Copy link
Contributor

Choose a reason for hiding this comment

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

the local variable votes will be null when the function fails. Check for null before returning its property.

}

internal PackageManagerResult DownloadPackage(string packageId, string version, out string pathToPackage)
{
try
Expand Down
21 changes: 21 additions & 0 deletions src/DynamoPackages/PackageManagerSearchElement.cs
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,25 @@ public string HostsString
public string InfectedPackageVersion { get; set; }
public string InfectedPackageCreationDate { get; set; }

private bool hasUpvote;
/// <summary>
/// Shows if the current user has upvoted this package
/// </summary>
public bool HasUpvote
{
get
{
return hasUpvote;
}

internal set
{
hasUpvote = value;
RaisePropertyChanged(nameof(HasUpvote));
}
}


#endregion

/// <summary>
Expand Down Expand Up @@ -167,6 +186,8 @@ public void Upvote()
}
}
, TaskScheduler.FromCurrentSynchronizationContext());

HasUpvote = true;
}

[Obsolete("This API will no longer decrease package votes and will be removed in Dynamo 3.0")]
Expand Down
101 changes: 82 additions & 19 deletions src/PackageDetailsViewExtension/PackageDetailsView.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,16 @@
<controls:BoolToVisibilityConverter x:Key="BoolToVisibilityConverter" />
<controls:PrettyDateConverter x:Key="PrettyDateConverter" />
<controls:EmptyStringToHiddenConverter x:Key="EmptyStringToHiddenConverter" />
<SolidColorBrush x:Key="ForegroundGrayBrush" Color="#D8D8D8" />
<SolidColorBrush x:Key="HoverBorderGrayBrush" Color="#6d6d6d" />
<SolidColorBrush x:Key="PressedBorderGrayBrush" Color="#7e7e7e" />
<SolidColorBrush x:Key="HasVotedBlueBrush" Color="#84D7CE" />
<Style x:Key="LabelStyle" TargetType="TextBlock">
<Setter Property="FontFamily" Value="{StaticResource ArtifaktElementBold}" />
<Setter Property="FontWeight" Value="Bold" />
<Setter Property="FontSize" Value="14px" />
<Setter Property="MinWidth" Value="200px" />
<Setter Property="Foreground" Value="#D8D8D8" />
<Setter Property="Foreground" Value="{StaticResource ForegroundGrayBrush}" />
<Setter Property="HorizontalAlignment" Value="Left" />
<Setter Property="Margin" Value="0,0,0,5" />
<Setter Property="TextWrapping" Value="Wrap" />
Expand Down Expand Up @@ -58,6 +62,76 @@
<Setter Property="Padding" Value="8,0" />
<Setter Property="Height" Value="22px" />
</Style>
<Style TargetType="{x:Type Hyperlink}">
<Setter Property="Foreground"
Value="{StaticResource Blue300Brush}" />
<Style.Triggers>
<Trigger Property="IsMouseOver"
Value="True">
<Setter Property="Foreground"
Value="{StaticResource Blue400Brush}" />
</Trigger>
</Style.Triggers>
</Style>

<Style x:Key="ImageButton" TargetType="{x:Type Button}">
<Setter Property="UseLayoutRounding" Value="True" />
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type Button}">
<Border Style="{StaticResource BorderStyle}"
x:Name="buttonBorder"
BorderBrush="{StaticResource ExtensionButtonBackgroundColor}"
BorderThickness="2">
<Grid x:Name="container">
<StackPanel Orientation="Horizontal">
<Viewbox Width="12"
Height="12"
VerticalAlignment="Center">
<Path x:Name="heartIcon"
Data="M13.91,6.75c-1.17,2.25-4.3,5.31-6.07,6.94c-0.1903,0.1718-0.4797,0.1718-0.67,0C5.39,12.06,2.26,9,1.09,6.75&#xA;&#x9;C-1.48,1.8,5-1.5,7.5,3.45C10-1.5,16.48,1.8,13.91,6.75z"
Stroke="{StaticResource ForegroundGrayBrush}"
StrokeThickness="1"
VerticalAlignment="Center"/>
</Viewbox>
<TextBlock Name="VotesLabel"
Margin="5,2,0,0"
VerticalAlignment="Center"
Style="{StaticResource BodyTextStyle}"
Text="{Binding Path=Content, RelativeSource={RelativeSource TemplatedParent}}" />
</StackPanel>
</Grid>
</Border>
<ControlTemplate.Triggers>
<Trigger Property="IsMouseOver" Value="True">
<Setter TargetName="heartIcon"
Property="Stroke"
Value="{StaticResource HasVotedBlueBrush}" />
<Setter TargetName="buttonBorder"
Property="BorderBrush"
Value="{StaticResource HoverBorderGrayBrush}" />
</Trigger>
<Trigger Property="Button.IsPressed" Value="true">
<Setter TargetName="heartIcon"
Property="Stroke"
Value="{StaticResource ForegroundGrayBrush}" />
<Setter TargetName="buttonBorder"
Property="BorderBrush"
Value="{StaticResource PressedBorderGrayBrush}" />
</Trigger>
<DataTrigger Binding="{Binding Path=HasVoted}" Value="True">
<Setter TargetName="heartIcon"
Property="Fill"
Value="{StaticResource HasVotedBlueBrush}" />
<Setter TargetName="heartIcon"
Property="Stroke"
Value="{StaticResource HasVotedBlueBrush}" />
</DataTrigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>

<!-- DataGrid -->
<Style x:Key="DataGridCellStyle" TargetType="DataGridCell">
Expand All @@ -75,7 +149,7 @@
FontFamily="{StaticResource ArtifaktElementRegular}"
FontSize="14px"
FontWeight="Regular"
Foreground="#D8D8D8"
Foreground="{StaticResource ForegroundGrayBrush}"
Text="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=Content.Text}"
TextWrapping="Wrap"
ToolTipService.ShowDuration="30000">
Expand Down Expand Up @@ -228,20 +302,9 @@
Orientation="Horizontal">

<!-- Votes -->
<Border Style="{StaticResource BorderStyle}">
<StackPanel Orientation="Horizontal">
<Rectangle Width="10" Height="10">
<Rectangle.Fill>
<ImageBrush ImageSource="/DynamoCoreWpf;component/UI/Images/Favorite.png" />
</Rectangle.Fill>
</Rectangle>
<TextBlock Name="VotesLabel"
Margin="5,2,0,0"
VerticalAlignment="Center"
Style="{StaticResource BodyTextStyle}"
Text="{Binding NumberVotes, Converter={StaticResource NegativeIntToZeroConverter}}" />
</StackPanel>
</Border>
<Button Style="{StaticResource ImageButton}"
Content="{Binding NumberVotes, Converter={StaticResource NegativeIntToZeroConverter}}"
Command="{Binding UpvoteCommand}" />

<!-- Downloads -->
<Border Style="{StaticResource BorderStyle}">
Expand Down Expand Up @@ -333,7 +396,7 @@
<Grid Background="{StaticResource ExtensionBackgroundColor}" IsHitTestVisible="True">
<StackPanel Margin="12,8,10,5">
<TextBlock HorizontalAlignment="Left"
Foreground="#D8D8D8"
Foreground="{StaticResource ForegroundGrayBrush}"
Text="{Binding PackageVersionNumber}" />
<Button Name="installButton"
Command="{Binding ElementName=PackageDetailsWindow, Path=DataContext.TryInstallPackageVersionCommand}"
Expand Down Expand Up @@ -417,7 +480,7 @@
</Trigger>
<DataTrigger Binding="{Binding ElementName=PackageDetailsWindow, Path=DataContext.IsPackageDeprecated}" Value="True">
<Setter Property="TextBlock.Opacity" Value="0.5" />
<Setter Property="TextBlock.Foreground" Value="#84D7CE" />
<Setter Property="TextBlock.Foreground" Value="{StaticResource HasVotedBlueBrush}" />
<Setter Property="ToolTip" Value="{x:Static p:Resources.PackageDeprecatedTooltip}" />
</DataTrigger>
<DataTrigger Binding="{Binding Path=CanInstall, UpdateSourceTrigger=PropertyChanged}" Value="False">
Expand All @@ -435,7 +498,7 @@
<Condition Binding="{Binding ElementName=PackageDetailsWindow, Path=DataContext.IsEnabledForInstall}" Value="True" />
</MultiDataTrigger.Conditions>
<Setter Property="TextBlock.Opacity" Value="1" />
<Setter Property="TextBlock.Foreground" Value="#84D7CE" />
<Setter Property="TextBlock.Foreground" Value="{StaticResource HasVotedBlueBrush}" />
</MultiDataTrigger>
</ControlTemplate.Triggers>
</ControlTemplate>
Expand Down
Loading
Loading