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

DYN-5189 update notifications number #13232

Merged
Merged
Show file tree
Hide file tree
Changes from all 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
4 changes: 2 additions & 2 deletions src/DynamoCoreWpf/Controls/ShortcutToolbar.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -208,13 +208,13 @@
Width="14"
VerticalAlignment="Center"
HorizontalAlignment="Center">
<!--TODO insert data bind for the notifications -->
<TextBlock Name="NotificationCount"
FontFamily="{StaticResource ArtifaktElementRegular}"
Foreground="White"
FontWeight="DemiBold"
TextAlignment="Center"
FontSize="9">8
Text="{Binding NotificationsNumber}"
FontSize="9">
</TextBlock>
</Border>
</DockPanel>
Expand Down
4 changes: 4 additions & 0 deletions src/DynamoCoreWpf/Controls/ShortcutToolbar.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using Dynamo.UI.Commands;
using Dynamo.Updates;
using Dynamo.ViewModels;
using Dynamo.Wpf.ViewModels.Core;
using Microsoft.Practices.Prism.ViewModel;

namespace Dynamo.UI.Controls
Expand Down Expand Up @@ -45,6 +46,9 @@ public ShortcutToolbar(IUpdateManager updateManager)

InitializeComponent();
UpdateControl.DataContext = updateManager;

var shortcutToolbar = new ShortcutToolbarViewModel();
DataContext = shortcutToolbar;
}

private void exportMenu_MouseEnter(object sender, System.Windows.Input.MouseEventArgs e)
Expand Down
1 change: 1 addition & 0 deletions src/DynamoCoreWpf/DynamoCoreWpf.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,7 @@
<Compile Include="ViewModels\Core\InPortViewModel.cs" />
<Compile Include="ViewModels\Core\OutPortViewModel.cs" />
<Compile Include="ViewModels\Core\SerializationExtensions.cs" />
<Compile Include="ViewModels\Core\ShortcutToolbarViewModel.cs" />
<Compile Include="ViewModels\FileTrust\FileTrustWarningViewModel.cs" />
<Compile Include="ViewModels\GuidedTour\ExitGuideWindowViewModel.cs" />
<Compile Include="ViewModels\GuidedTour\PopupWindowViewModel.cs" />
Expand Down
17 changes: 17 additions & 0 deletions src/DynamoCoreWpf/ViewModels/Core/ShortcutToolbarViewModel.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
using Dynamo.ViewModels;

namespace Dynamo.Wpf.ViewModels.Core
{
internal class ShortcutToolbarViewModel : ViewModelBase
{
public ShortcutToolbarViewModel()
{
NotificationsNumber = 0;
}

/// <summary>
/// This property represents the number of new notifications
/// </summary>
public int NotificationsNumber { get; set; }
}
}
50 changes: 48 additions & 2 deletions src/Notifications/NotificationCenterController.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
using System;
using System.Diagnostics;
using System.Collections.Generic;
using System.Configuration;
using System.IO;
using System.Linq;
using System.Net;
using System.Reflection;
using System.Windows;
using System.Windows.Controls;
Expand All @@ -9,6 +13,8 @@
using Dynamo.Logging;
using Dynamo.Notifications.View;
using Dynamo.ViewModels;
using Dynamo.Wpf.ViewModels.Core;
using Newtonsoft.Json;

namespace Dynamo.Notifications
{
Expand All @@ -26,7 +32,11 @@ public class NotificationCenterController
private static readonly string jsEmbeddedFile = "Dynamo.Notifications.node_modules._dynamods.notifications_center.build.index.bundle.js";
private static readonly string NotificationCenterButtonName = "notificationsButton";

private readonly DynamoLogger logger;
private DynamoLogger logger;
private static readonly DateTime notificationsCenterCreatedTime = DateTime.UtcNow;
private static System.Timers.Timer timer;
private string jsonStringFile;
private NotificationsModel notificationsModel;

internal NotificationCenterController(DynamoView view, DynamoLogger dynLogger)
{
Expand All @@ -46,9 +56,45 @@ internal NotificationCenterController(DynamoView view, DynamoLogger dynLogger)
HorizontalOffset = notificationPopupHorizontalOffset,
VerticalOffset = notificationPopupVerticalOffset
};

notificationUIPopup.webView.EnsureCoreWebView2Async();
notificationUIPopup.webView.CoreWebView2InitializationCompleted += WebView_CoreWebView2InitializationCompleted;
logger = dynLogger;

RequestNotifications();
}

private void WebView_NavigationCompleted(object sender, Microsoft.Web.WebView2.Core.CoreWebView2NavigationCompletedEventArgs e)
{
AddNotifications(notificationsModel.Notifications);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

We make sure navigation is completed before calling the js function

Copy link
Contributor

Choose a reason for hiding this comment

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

Is this because otherwise the js function may not exist?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, the navigation completed subscription makes sure the page content is loaded.

}

private void AddNotifications(List<NotificationItemModel> notifications)
{
var notificationsList = JsonConvert.SerializeObject(notifications);
InvokeJS($"window.setNotifications({notificationsList});");
}

private void RequestNotifications()
{
var uri = DynamoUtilities.PathHelper.getServiceBackendAddress(this, "notificationAddress");
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(uri);
request.AutomaticDecompression = DecompressionMethods.GZip | DecompressionMethods.Deflate;

using (HttpWebResponse response = (HttpWebResponse)request.GetResponse())
using (Stream stream = response.GetResponseStream())
using (StreamReader reader = new StreamReader(stream))
{
jsonStringFile = reader.ReadToEnd();
notificationsModel = JsonConvert.DeserializeObject<NotificationsModel>(jsonStringFile);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Setting the notifications to a defined model


var notificationsNumber = notificationsModel.Notifications.Count();
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is counting all the notifications, but we may add a comparison between the read notification and the new ones.


var shortcutToolbarViewModel = (ShortcutToolbarViewModel)dynamoView.ShortcutBar.DataContext;
shortcutToolbarViewModel.NotificationsNumber = notificationsNumber;
}

notificationUIPopup.webView.NavigationCompleted += WebView_NavigationCompleted;
}

// Handler for new Webview2 tab window request
Expand Down Expand Up @@ -84,7 +130,6 @@ private void WebView_CoreWebView2InitializationCompleted(object sender, Microsof
// Opening hyper-links using default system browser instead of WebView2 tab window
notificationUIPopup.webView.CoreWebView2.NewWindowRequested += WebView_NewWindowRequested;
notificationUIPopup.webView.CoreWebView2.NavigateToString(htmlString);
RefreshNotifications();
}
}

Expand All @@ -98,6 +143,7 @@ internal void Dispose()
dynamoView.SizeChanged -= DynamoView_SizeChanged;
dynamoView.LocationChanged -= DynamoView_LocationChanged;
notificationsButton.Click -= NotificationsButton_Click;
notificationUIPopup.webView.NavigationCompleted -= WebView_NavigationCompleted;
}

private void DynamoView_LocationChanged(object sender, EventArgs e)
Expand Down
65 changes: 65 additions & 0 deletions src/Notifications/NotificationsModel.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.Text;
using System.Threading.Tasks;

namespace Dynamo.Notifications
{
[DataContract]
internal class NotificationsModel
{
[DataMember(Name = "version")]
internal string Version { get; set; }

[DataMember(Name = "last_update_timestamp")]
internal DateTime LastUpdate { get; set; }

[DataMember(Name = "notifications")]
internal List<NotificationItemModel> Notifications { get; set; }
}

[DataContract]
internal class NotificationItemModel
{
[DataMember(Name = "id")]
internal string Id { get; set; }

[DataMember(Name = "title")]
internal string Title { get; set; }

[DataMember(Name = "link")]
internal string Link { get; set; }

[DataMember(Name = "linkTitle")]
internal string LinkTitle { get; set; }

[DataMember(Name = "longDescription")]
internal string LongDescription { get; set; }

[DataMember(Name = "created")]
internal DateTime Created { get; set; }

[DataMember(Name = "thumbnail")]
internal string Thumbnail { get; set; }

[DataMember(Name = "priority")]
internal string Priority { get; set; }

[DataMember(Name = "type")]
internal string Type { get; set; }

[DataMember(Name = "scope")]
internal string Scope { get; set; }

[DataMember(Name = "source")]
internal string Source { get; set; }

[DataMember(Name = "status")]
internal string Status { get; set; }

[DataMember(Name = "isPinned")]
internal bool IsPinned { get; set; }
}
}