Skip to content

Commit

Permalink
Dynamo new homepage implementation (#14879)
Browse files Browse the repository at this point in the history
* initial WIP

- initial structure to create a homePage user control replacing the current home page
- currently loads graphs to the web app ui

* initial changes

- incorporated the new home page web app

* moved loading to frontend

- now the front end will prompt the loading moment using useEffects rather than relying on the component being loaded after the webView2 was done loading

* guided tours implemented

- implemented guided tours to the landing page

* samples backend code

- implemented samples backend implementation
- reuses existing viewmodel logic

* added ShowSampleFilesInFolder

- added ShowSampleFilesInFolder existing in the current Home Page experience

* local bundle files added to source for testing purposes

- added bundle.js and index.html to source control for testing purposes and while implementation takes place

* resolving build issues

- remove WIP bundle.js to try to resolve building for upstream

* replaced .net6 complient API method

- net6 build error fix

* added guides description

- added localization description to user guides
- trimming the '_' from the start of the guides names (happens on the back end)

* send image author data test

- internal mock-up on testing graph image data

* set sidebar width relative to user

- the sidebar in Dynamo is resizable, so there is no 'default' value
- we are setting the initial width based on the current value
- will not update live, but will update on the next run (when initializing the StartPage from DynamoView)

* remove coupling to sidebar width, implemented Template API

- added Template call
- removed sidebar width sync between backend and front end
- added the ability to grip-resize sidebar in frontend NOT PERSISTED

* for review

- publish for review

* tests added

- added test coverage on all interaction logic between the back and the front end

* remove old code

* npm build implementation

- now builds from the latest npm package
- webView2 swapped to DynamoWebView2 class

* update dynamohome build

- the new build was interfering with SplashScreen build

* comments

- dynamically adding locale to front end
- extracted repeated webView2 to DynamoUtilities helper methods (inside the PathHelper)
- fixed dynamically loading of the Artifakt font resource
- added new public functions to the respective API text files
- removed unneeded stopwatch in StartPage.xaml.cs

* tests for new helper methods

- added tests for the new public helper methods
- added null checks handling

* checks for valid json dyn input

- now correctly checks if the recent file is of valid json input
- it assumes that any other format but json is an old dynamo 1.0 format (not checking if xml or anything else)

* swap 1.0 for 1.x

- swap dynamo 1.0 message in favor of 1.x

* update

* Update

---------

Co-authored-by: Aaron (Qilong) <[email protected]>
  • Loading branch information
dnenov and QilongTang authored Feb 28, 2024
1 parent 66a734e commit dad37a6
Show file tree
Hide file tree
Showing 17 changed files with 1,668 additions and 35 deletions.
78 changes: 75 additions & 3 deletions src/DynamoCoreWpf/Controls/StartPage.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
using Dynamo.Utilities;
using Dynamo.ViewModels;
using Dynamo.Wpf.Properties;
using Newtonsoft.Json;
using NotificationObject = Dynamo.Core.NotificationObject;

namespace Dynamo.UI.Controls
Expand Down Expand Up @@ -72,6 +73,10 @@ internal StartPageListItem(string caption, string iconPath)
public string Caption { get; private set; }
public string SubScript { get; set; }
public string ToolTip { get; set; }
public string DateModified { get; set; }
public string Description { get; internal set; }
public string Thumbnail { get; set; }
public string Author { get; internal set; }
public string ContextData { get; set; }
public Action ClickAction { get; set; }

Expand Down Expand Up @@ -371,27 +376,94 @@ private void RefreshFileList(ObservableCollection<StartPageListItem> files,
{
try
{
// Skip files which were moved or deleted (consistent with Revit behavior)
if (!DynamoUtilities.PathHelper.IsValidPath(filePath)) continue;

var extension = Path.GetExtension(filePath).ToUpper();
// If not extension specified and code reach here, this means this is still a valid file
// only without file type. Otherwise, simply take extension substring skipping the 'dot'.
var subScript = extension.IndexOf(".") == 0 ? extension.Substring(1) : "";
var subScript = extension.StartsWith(".") ? extension.Substring(1) : "";
var caption = Path.GetFileNameWithoutExtension(filePath);

// deserializes the file only once
var jsonObject = DeserializeJsonFile(filePath);
var description = jsonObject != null ? GetGraphDescription(jsonObject) : string.Empty;
var thumbnail = jsonObject != null ? GetGraphThumbnail(jsonObject) : string.Empty;
var author = jsonObject != null ? GetGraphAuthor(jsonObject) : Resources.DynamoXmlFileFormat;

var date = DynamoUtilities.PathHelper.GetDateModified(filePath);

files.Add(new StartPageListItem(caption)
{
ContextData = filePath,
ToolTip = filePath,
SubScript = subScript,
ClickAction = StartPageListItem.Action.FilePath
});
Description = description,
Thumbnail = thumbnail,
Author = author,
DateModified = date,
ClickAction = StartPageListItem.Action.FilePath,

});
}
catch (ArgumentException ex)
{
DynamoViewModel.Model.Logger.Log("File path is not valid: " + ex.StackTrace);
}
catch (Exception ex)
{
DynamoViewModel.Model.Logger.Log("Error loading the file: " + ex.StackTrace);
}
}
}

private Dictionary<string, object> DeserializeJsonFile(string filePath)
{
if (DynamoUtilities.PathHelper.isValidJson(filePath, out string jsonString, out Exception ex))
{
return JsonConvert.DeserializeObject<Dictionary<string, object>>(jsonString);
}
else
{
if(ex is JsonReaderException)
{
DynamoViewModel.Model.Logger.Log("File is not a valid json format.");
}
else
{
DynamoViewModel.Model.Logger.Log("File is not valid: " + ex.StackTrace);
}
return null;
}
}

private const string BASE64PREFIX = "data:image/png;base64,";

private string GetGraphThumbnail(Dictionary<string, object> jsonObject)
{
jsonObject.TryGetValue("Thumbnail", out object thumbnail);

if (string.IsNullOrEmpty(thumbnail as string)) return string.Empty;

var base64 = String.Format("{0}{1}", BASE64PREFIX, thumbnail as string);

return base64;
}

private string GetGraphDescription(Dictionary<string, object> jsonObject)
{
jsonObject.TryGetValue("Description", out object description);

return description as string;
}

private string GetGraphAuthor(Dictionary<string, object> jsonObject)
{
jsonObject.TryGetValue("Author", out object author);

return author as string;
}

private void HandleRegularCommand(StartPageListItem item)
{
var dvm = this.DynamoViewModel;
Expand Down
58 changes: 54 additions & 4 deletions src/DynamoCoreWpf/DynamoCoreWpf.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">
<PropertyGroup>
<UILib>true</UILib>
</PropertyGroup>
Expand Down Expand Up @@ -50,11 +50,46 @@

<!--Deletes the tgz file-->
<Delete Files="$(MSBuildProjectDirectory)\$(Last).tgz" />
</Target>

<ItemGroup>
</Target>


<Target Name="NpmRunBuildHomePage" BeforeTargets="BeforeBuild">
<!--This command updates the npm registry configuration if necessary-->
<Exec Command="$(PowerShellCommand) -ExecutionPolicy ByPass -Command $(SolutionDir)\setnpmreg.ps1" />
<!--Download the latest build of the Dynamo Home package-->
<Exec Command="npm pack @dynamods/dynamo-home@latest" />
</Target>

<Target Name="ExtractTGZFileDynamoHome" DependsOnTargets="NpmRunBuildHomePage" BeforeTargets="BeforeBuild">
<!--Locate the .tgz files for the Dynamo Home package-->
<ItemGroup>
<TGZFilesDynamoHome Include="./dynamods-dynamo-home-*.tgz" />
</ItemGroup>

<!--Reverse the order of the files to get the higher version-->
<ItemGroup>
<ReversedDynamoHome Include="@(TGZFilesDynamoHome-&gt;Reverse())" />
</ItemGroup>

<PropertyGroup>
<Last>%(TGZFilesDynamoHome.Filename)</Last>
</PropertyGroup>

<!--Create the folder for the Dynamo Home package-->
<MakeDir Directories="Packages/DynamoHome" />

<!--Extract the file to the specified directory-->
<Exec Command="tar -xzf $(MSBuildProjectDirectory)\$(Last).tgz --strip-components=1 --directory=Packages/DynamoHome"></Exec>

<!--Delete the tgz file-->
<Delete Files="$(MSBuildProjectDirectory)\$(Last).tgz" />
</Target>

<ItemGroup>
<None Remove="Packages\SplashScreen\build\index.bundle.js" />
<None Remove="Packages\SplashScreen\build\index.html" />
<None Remove="Packages\DynamoHome\build\index.bundle.js" />
<None Remove="Packages\DynamoHome\build\index.html" />
<None Remove="UI\Images\Canvas\canvas-button-geometry-scaling.png" />
<None Remove="UI\Images\checkmark_16px.png" />
<None Remove="UI\Images\close_16px.png" />
Expand Down Expand Up @@ -90,6 +125,8 @@
<EmbeddedResource Include="Packages\SplashScreen\build\index.bundle.js" />
<EmbeddedResource Include="Packages\SplashScreen\build\index.html" />
<EmbeddedResource Include="Views\SplashScreen\WebApp\splashScreenBackground.png" />
<EmbeddedResource Include="Packages\DynamoHome\build\index.bundle.js" />
<EmbeddedResource Include="Packages\DynamoHome\build\index.html" />
</ItemGroup>

<ItemGroup>
Expand Down Expand Up @@ -447,6 +484,7 @@
<Compile Include="Views\GuidedTour\SurveyPopupWindow.xaml.cs">
<DependentUpon>SurveyPopupWindow.xaml</DependentUpon>
</Compile>
<Compile Include="Views\HomePage\HomePage.xaml.cs" />
<Compile Include="Views\Input\ParameterEditor.cs" />
<Compile Include="Views\PackageManager\Controls\CustomBrowserControl.xaml.cs" />
<Compile Include="Views\PackageManager\Controls\FilterTagControl.xaml.cs" />
Expand Down Expand Up @@ -503,6 +541,9 @@
<Compile Include="Views\SplashScreen\SplashScreen.xaml.cs">
<DependentUpon>SplashScreen.xaml</DependentUpon>
</Compile>
<Compile Include="Views\HomePage\HomePage.xaml.cs">
<DependentUpon>HomePage.xaml</DependentUpon>
</Compile>
<Compile Include="Views\Core\NodeView.xaml.cs">
<DependentUpon>NodeView.xaml</DependentUpon>
</Compile>
Expand Down Expand Up @@ -1558,6 +1599,12 @@
<SubType>Designer</SubType>
</Page>
</ItemGroup>
<ItemGroup>
<Page Include="Views\HomePage\HomePage.xaml">
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>
</Page>
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\DynamoCore\DynamoCore.csproj">
<Project>{7858fa8c-475f-4b8e-b468-1f8200778cf8}</Project>
Expand Down Expand Up @@ -1770,6 +1817,9 @@
<Resource Include="UI\Images\not-authenticated.png" />
</ItemGroup>
<ItemGroup>
<None Update="Views\HomePage\HomePage.xaml">
<Generator>MSBuild:Compile</Generator>
</None>
<None Update="Views\PackageManager\Controls\CustomBrowserControl.xaml">
<Generator>MSBuild:Compile</Generator>
</None>
Expand Down
36 changes: 36 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.

12 changes: 12 additions & 0 deletions src/DynamoCoreWpf/Properties/Resources.en-US.resx
Original file line number Diff line number Diff line change
Expand Up @@ -2619,6 +2619,15 @@ Do you wish to uninstall {1}? Restart {2} to complete the uninstall and try down
<value>_User Interface Tour</value>
<comment>Get Started Dynamo Tour</comment>
</data>
<data name="GetStartedGuideDescription" xml:space="preserve">
<value>Start your visual programming journey with this short guide. Here you'll learn some basics about the Dynamo interface and features.</value>
</data>
<data name="OnboardingGuideDescription" xml:space="preserve">
<value>Learn about the basic building blocks of Dynamo. Get hands-on practice working with a graph.</value>
</data>
<data name="PackagesGuideDescription" xml:space="preserve">
<value>A package is a toolkit of utilities that let you do more with Dynamo, beyond its core functionality. This guide shows how to find, install, and use packages. It installs a sample Autodesk package for you to explore.</value>
</data>
<data name="InteractiveGuides" xml:space="preserve">
<value>_Interactive Guides</value>
<comment>Dynamo Guided Tours</comment>
Expand Down Expand Up @@ -3922,4 +3931,7 @@ In certain complex graphs or host program scenarios, Automatic mode may cause in
<value>Enable Paneling nodes</value>
<comment>Preferences | Features | Experimental | Enable Paneling nodes</comment>
</data>
<data name="DynamoXmlFileFormat" xml:space="preserve">
<value>Dynamo 1.x file format</value>
</data>
</root>
12 changes: 12 additions & 0 deletions src/DynamoCoreWpf/Properties/Resources.resx
Original file line number Diff line number Diff line change
Expand Up @@ -2938,6 +2938,15 @@ Do you wish to uninstall {1}? Restart {2} to complete the uninstall and try down
<value>_Interactive Guides</value>
<comment>Dynamo Guided Tours</comment>
</data>
<data name="GetStartedGuideDescription" xml:space="preserve">
<value>Start your visual programming journey with this short guide. Here you'll learn some basics about the Dynamo interface and features.</value>
</data>
<data name="OnboardingGuideDescription" xml:space="preserve">
<value>Learn about the basic building blocks of Dynamo. Get hands-on practice working with a graph.</value>
</data>
<data name="PackagesGuideDescription" xml:space="preserve">
<value>A package is a toolkit of utilities that let you do more with Dynamo, beyond its core functionality. This guide shows how to find, install, and use packages. It installs a sample Autodesk package for you to explore.</value>
</data>
<data name="GetStartedGuideLibraryText" xml:space="preserve">
<value>The library contains all default functions #(nodes)=https://primer2.dynamobim.org/4_nodes_and_wires of Dynamo, as well as custom nodes you may have loaded. \n\nTo find a node, search the library or browse its categories.</value>
</data>
Expand Down Expand Up @@ -3909,4 +3918,7 @@ In certain complex graphs or host program scenarios, Automatic mode may cause in
<value>Enable Paneling nodes</value>
<comment>Preferences | Features | Experimental | Enable Paneling nodes</comment>
</data>
<data name="DynamoXmlFileFormat" xml:space="preserve">
<value>Dynamo 1.x file format</value>
</data>
</root>
1 change: 1 addition & 0 deletions src/DynamoCoreWpf/PublicAPI.Unshipped.txt
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,7 @@ Dynamo.Controls.DynamoView.ExtensionsCollapsed.get -> bool
Dynamo.Controls.DynamoView.InitializeComponent() -> void
Dynamo.Controls.DynamoView.LibraryCollapsed.get -> bool
Dynamo.Controls.DynamoView.PlacePopup(System.Windows.Size popupSize, System.Windows.Size targetSize, System.Windows.Point offset) -> System.Windows.Controls.Primitives.CustomPopupPlacement[]
Dynamo.Controls.DynamoView.IsNewAppHomeEnabled.get -> bool
Dynamo.Controls.ElementGroupToColorConverter
Dynamo.Controls.ElementGroupToColorConverter.Convert(object value, System.Type targetType, object parameter, System.Globalization.CultureInfo culture) -> object
Dynamo.Controls.ElementGroupToColorConverter.ConvertBack(object value, System.Type targetType, object parameter, System.Globalization.CultureInfo culture) -> object
Expand Down
Loading

0 comments on commit dad37a6

Please sign in to comment.