From 7658a8546a9c33a76376dff3ab646f2aceaf0a01 Mon Sep 17 00:00:00 2001 From: Roy Ben-Shabat Date: Sun, 17 Jun 2018 19:06:13 +0300 Subject: Working on PPC !!! --- .../Tango.PPC.Jobs/ViewModels/JobsViewVM.cs | 16 ++-- .../Notifications/INotificationProvider.cs | 42 +++++++++ .../Notifications/NotificationItem.cs | 69 ++++++++++++++ .../Tango.PPC.Common/Properties/AssemblyInfo.cs | 3 + .../PPC/Tango.PPC.Common/Tango.PPC.Common.csproj | 1 + .../Converters/NotificationItemConverter.cs | 41 +++++++++ .../PPC/Tango.PPC.UI/Images/warning-test.png | Bin 0 -> 2121 bytes .../Notifications/DefaultNotificationProvider.cs | 101 +++++++++++++++++++++ .../EmptyCartridgesNotification.cs | 34 +++++++ .../EmptyCartridgesNotificationView.xaml | 15 +++ .../EmptyCartridgesNotificationView.xaml.cs | 28 ++++++ .../PPC/Tango.PPC.UI/Tango.PPC.UI.csproj | 10 ++ .../PPC/Tango.PPC.UI/ViewModels/LayoutViewVM.cs | 36 +++++++- .../PPC/Tango.PPC.UI/Views/LayoutView.xaml | 36 ++++++-- .../PPC/Tango.PPC.UI/Views/LayoutView.xaml.cs | 3 + 15 files changed, 418 insertions(+), 17 deletions(-) create mode 100644 Software/Visual_Studio/PPC/Tango.PPC.Common/Notifications/NotificationItem.cs create mode 100644 Software/Visual_Studio/PPC/Tango.PPC.UI/Converters/NotificationItemConverter.cs create mode 100644 Software/Visual_Studio/PPC/Tango.PPC.UI/Images/warning-test.png create mode 100644 Software/Visual_Studio/PPC/Tango.PPC.UI/Notifications/NotificationItems/EmptyCartridgesNotification.cs create mode 100644 Software/Visual_Studio/PPC/Tango.PPC.UI/Notifications/NotificationItems/EmptyCartridgesNotificationView.xaml create mode 100644 Software/Visual_Studio/PPC/Tango.PPC.UI/Notifications/NotificationItems/EmptyCartridgesNotificationView.xaml.cs (limited to 'Software/Visual_Studio/PPC') diff --git a/Software/Visual_Studio/PPC/Modules/Tango.PPC.Jobs/ViewModels/JobsViewVM.cs b/Software/Visual_Studio/PPC/Modules/Tango.PPC.Jobs/ViewModels/JobsViewVM.cs index f03c7070a..dde587b84 100644 --- a/Software/Visual_Studio/PPC/Modules/Tango.PPC.Jobs/ViewModels/JobsViewVM.cs +++ b/Software/Visual_Studio/PPC/Modules/Tango.PPC.Jobs/ViewModels/JobsViewVM.cs @@ -203,12 +203,16 @@ namespace Tango.PPC.Jobs.ViewModels _jobsContext = ObservablesContext.CreateDefault(); - Jobs = _jobsContext.Jobs.Where(x => x.Machine.SerialNumber == Settings.MachineSerialNumber).ToObservableCollection(); - JobsCollectionView = CollectionViewSource.GetDefaultView(Jobs); - JobsCollectionView.SortDescriptions.Add(new SortDescription(nameof(Job.LastUpdated), ListSortDirection.Descending)); - FilterJobCategory(FilterCategory); + var jobs = _jobsContext.Jobs.Where(x => x.Machine.Guid == ApplicationManager.Machine.Guid).ToObservableCollection(); - IsLoadingJobs = false; + InvokeUI(() => + { + Jobs = _jobsContext.Jobs.Where(x => x.Machine.Guid == ApplicationManager.Machine.Guid).ToObservableCollection(); + JobsCollectionView = CollectionViewSource.GetDefaultView(Jobs); + JobsCollectionView.SortDescriptions.Add(new SortDescription(nameof(Job.LastUpdated), ListSortDirection.Descending)); + FilterJobCategory(FilterCategory); + IsLoadingJobs = false; + }); }); } @@ -227,7 +231,7 @@ namespace Tango.PPC.Jobs.ViewModels /// The job category. public void FilterJobCategory(JobCategories jobCategory) { - JobsCollectionView.Filter = (job) => + JobsCollectionView.Filter = (job) => { return (job as Job).JobCategories.Contains(jobCategory); }; diff --git a/Software/Visual_Studio/PPC/Tango.PPC.Common/Notifications/INotificationProvider.cs b/Software/Visual_Studio/PPC/Tango.PPC.Common/Notifications/INotificationProvider.cs index 9fc42c155..303392a68 100644 --- a/Software/Visual_Studio/PPC/Tango.PPC.Common/Notifications/INotificationProvider.cs +++ b/Software/Visual_Studio/PPC/Tango.PPC.Common/Notifications/INotificationProvider.cs @@ -6,6 +6,7 @@ using System.Text; using System.Threading.Tasks; using System.Windows; using System.Windows.Media; +using Tango.Core.Commands; namespace Tango.PPC.Common.Notifications { @@ -14,6 +15,16 @@ namespace Tango.PPC.Common.Notifications /// public interface INotificationProvider { + /// + /// Gets the collection of notification items. + /// + ObservableCollection NotificationItems { get; } + + /// + /// Gets a value indicating whether this instance has notification items. + /// + bool HasNotificationItems { get; } + /// /// Gets the current message box. /// @@ -47,5 +58,36 @@ namespace Tango.PPC.Common.Notifications /// /// The message. Task ShowQuestion(String message); + + /// + /// Inserts the notification item to the bottom of the notifications collection. + /// + /// The item. + NotificationItem PushNotification(NotificationItem item); + + /// + /// Inserts the notification item to the bottom of the notifications collection. + /// + /// The item. + /// A condition which determines if this item is still relevant. + /// Determines whether to perform automatic checking of the condition. + /// Determines how frequently the condition function will be invoked. (Default 1 second) + NotificationItem PushNotification(NotificationItem item, Func condition, bool autoCheck = true, TimeSpan? checkInterval = null); + + /// + /// Removed the specified notification item. + /// + /// The item. + void PopNotification(NotificationItem item); + + /// + /// Invokes the notification items conditions. + /// + void InvokeNotificationItemsConditions(); + + /// + /// Gets the pop notification command. + /// + RelayCommand PopNotificationCommand { get; } } } diff --git a/Software/Visual_Studio/PPC/Tango.PPC.Common/Notifications/NotificationItem.cs b/Software/Visual_Studio/PPC/Tango.PPC.Common/Notifications/NotificationItem.cs new file mode 100644 index 000000000..f5e319fa0 --- /dev/null +++ b/Software/Visual_Studio/PPC/Tango.PPC.Common/Notifications/NotificationItem.cs @@ -0,0 +1,69 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Timers; +using System.Windows.Media; +using Tango.Core; + +namespace Tango.PPC.Common.Notifications +{ + /// + /// Represents a base notification item. + /// + /// + public abstract class NotificationItem : ExtendedObject, IDisposable + { + /// + /// Gets or sets the condition. + /// + internal Func Condition { get; set; } + + /// + /// Gets or sets a value indicating whether [automatic check]. + /// + internal bool AutoCheck { get; set; } + + /// + /// Gets or sets the automatic check interval. + /// + internal TimeSpan AutoCheckInterval { get; set; } + + /// + /// Gets or sets the remove action. + /// + internal Action RemoveAction { get; set; } + + /// + /// Gets or sets the check timer. + /// + internal Timer Timer { get; set; } + + private String _message; + /// + /// Gets or sets the notification message. + /// + public String Message + { + get { return _message; } + set { _message = value; RaisePropertyChangedAuto(); } + } + + /// + /// Gets or sets the type of the view associated with this notification item. + /// + public abstract Type ViewType { get; } + + /// + /// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources. + /// + public void Dispose() + { + if (RemoveAction != null) + { + RemoveAction(); + } + } + } +} diff --git a/Software/Visual_Studio/PPC/Tango.PPC.Common/Properties/AssemblyInfo.cs b/Software/Visual_Studio/PPC/Tango.PPC.Common/Properties/AssemblyInfo.cs index 636916a53..47bb0427f 100644 --- a/Software/Visual_Studio/PPC/Tango.PPC.Common/Properties/AssemblyInfo.cs +++ b/Software/Visual_Studio/PPC/Tango.PPC.Common/Properties/AssemblyInfo.cs @@ -17,3 +17,6 @@ using System.Windows; //(used if a resource is not found in the page, // app, or any theme specific resource dictionaries) )] + +//Friends With +[assembly: InternalsVisibleTo("Tango.PPC.UI")] diff --git a/Software/Visual_Studio/PPC/Tango.PPC.Common/Tango.PPC.Common.csproj b/Software/Visual_Studio/PPC/Tango.PPC.Common/Tango.PPC.Common.csproj index c64e56b44..9b530be9c 100644 --- a/Software/Visual_Studio/PPC/Tango.PPC.Common/Tango.PPC.Common.csproj +++ b/Software/Visual_Studio/PPC/Tango.PPC.Common/Tango.PPC.Common.csproj @@ -95,6 +95,7 @@ + diff --git a/Software/Visual_Studio/PPC/Tango.PPC.UI/Converters/NotificationItemConverter.cs b/Software/Visual_Studio/PPC/Tango.PPC.UI/Converters/NotificationItemConverter.cs new file mode 100644 index 000000000..4e3291b97 --- /dev/null +++ b/Software/Visual_Studio/PPC/Tango.PPC.UI/Converters/NotificationItemConverter.cs @@ -0,0 +1,41 @@ +using System; +using System.Collections.Generic; +using System.Globalization; +using System.Linq; +using System.Reflection; +using System.Text; +using System.Threading.Tasks; +using System.Windows; +using System.Windows.Data; +using Tango.PPC.Common.Notifications; + +namespace Tango.PPC.UI.Converters +{ + public class NotificationItemConverter : IValueConverter + { + public object Convert(object value, Type targetType, object parameter, CultureInfo culture) + { + NotificationItem item = value as NotificationItem; + + if (item != null) + { + var view = Activator.CreateInstance(item.ViewType) as FrameworkElement; + + if (view == null) + { + throw new InvalidOperationException("The type " + item.ViewType + " is not a framework element."); + } + + view.DataContext = item; + return view; + } + + return null; + } + + public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) + { + throw new NotImplementedException(); + } + } +} diff --git a/Software/Visual_Studio/PPC/Tango.PPC.UI/Images/warning-test.png b/Software/Visual_Studio/PPC/Tango.PPC.UI/Images/warning-test.png new file mode 100644 index 000000000..a845b1226 Binary files /dev/null and b/Software/Visual_Studio/PPC/Tango.PPC.UI/Images/warning-test.png differ diff --git a/Software/Visual_Studio/PPC/Tango.PPC.UI/Notifications/DefaultNotificationProvider.cs b/Software/Visual_Studio/PPC/Tango.PPC.UI/Notifications/DefaultNotificationProvider.cs index 5e4bd7c30..cbdbab848 100644 --- a/Software/Visual_Studio/PPC/Tango.PPC.UI/Notifications/DefaultNotificationProvider.cs +++ b/Software/Visual_Studio/PPC/Tango.PPC.UI/Notifications/DefaultNotificationProvider.cs @@ -11,6 +11,8 @@ using Tango.Core; using System.Collections.Concurrent; using System.Windows.Media.Imaging; using Tango.SharedUI.Helpers; +using System.Timers; +using Tango.Core.Commands; namespace Tango.PPC.UI.Notifications { @@ -21,6 +23,11 @@ namespace Tango.PPC.UI.Notifications /// public class DefaultNotificationProvider : ExtendedObject, INotificationProvider { + /// + /// Gets the collection of notification items. + /// + public ObservableCollection NotificationItems { get; private set; } + /// /// Represents a pending message box. /// @@ -44,7 +51,10 @@ namespace Tango.PPC.UI.Notifications /// public DefaultNotificationProvider() { + NotificationItems = new ObservableCollection(); _pendingMessageBoxes = new ConcurrentQueue(); + + PopNotificationCommand = new RelayCommand((x) => PopNotification(x)); } private MessageBoxVM _currentMessageBox; @@ -182,5 +192,96 @@ namespace Tango.PPC.UI.Notifications } } } + + /// + /// Inserts the notification item to the bottom of the notifications collection. + /// + /// The item. + /// + public NotificationItem PushNotification(NotificationItem item) + { + return PushNotification(item, null, false, null); + } + + /// + /// Inserts the notification item to the bottom of the notifications collection. + /// + /// The item. + /// A condition which determines if this item is still relevant. + /// Determines whether to perform automatic checking of the condition. + /// Determines how frequently the condition function will be invoked. (Default 1 second) + /// + public NotificationItem PushNotification(NotificationItem item, Func condition, bool autoCheck = true, TimeSpan? checkInterval = default(TimeSpan?)) + { + item.Condition = condition; + item.AutoCheck = autoCheck; + item.AutoCheckInterval = checkInterval != null ? checkInterval.Value : TimeSpan.FromSeconds(1); + item.RemoveAction = () => { PopNotification(item); }; + NotificationItems.Insert(0, item); + + if (autoCheck && condition != null) + { + Timer timer = new Timer(); + item.Timer = timer; + timer.Interval = item.AutoCheckInterval.TotalMilliseconds; + timer.Elapsed += (x, y) => + { + if (!item.Condition()) + { + PopNotification(item); + } + }; + timer.Start(); + } + + RaisePropertyChanged(nameof(HasNotificationItems)); + + return item; + } + + /// + /// Removed the specified notification item. + /// + /// The item. + public void PopNotification(NotificationItem item) + { + if (item.Timer != null) + { + item.Timer.Stop(); + } + + NotificationItems.Remove(item); + + RaisePropertyChanged(nameof(HasNotificationItems)); + } + + /// + /// Invokes the notification items conditions. + /// + public void InvokeNotificationItemsConditions() + { + var list = NotificationItems.ToList(); + + foreach (var item in list.Where(x => x.Condition != null)) + { + if (!item.Condition()) + { + PopNotification(item); + } + } + } + + /// + /// Gets a value indicating whether this instance has notification items. + /// + public bool HasNotificationItems + { + get + { + return NotificationItems.Count > 0; + } + } + + public RelayCommand PopNotificationCommand { get; private set; } } } diff --git a/Software/Visual_Studio/PPC/Tango.PPC.UI/Notifications/NotificationItems/EmptyCartridgesNotification.cs b/Software/Visual_Studio/PPC/Tango.PPC.UI/Notifications/NotificationItems/EmptyCartridgesNotification.cs new file mode 100644 index 000000000..49a0c03eb --- /dev/null +++ b/Software/Visual_Studio/PPC/Tango.PPC.UI/Notifications/NotificationItems/EmptyCartridgesNotification.cs @@ -0,0 +1,34 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Tango.BL.Entities; +using Tango.BL.Enumerations; +using Tango.PPC.Common.Notifications; + +namespace Tango.PPC.UI.Notifications.NotificationItems +{ + public class EmptyCartridgesNotification : NotificationItem + { + public List LiquidTypes { get; set; } + + public EmptyCartridgesNotification() + { + Message = "Cartridges are empty, please replace cartridges"; + } + + public EmptyCartridgesNotification(IEnumerable liquidTypes) : this() + { + LiquidTypes = liquidTypes.ToList(); + } + + public override Type ViewType + { + get + { + return typeof(EmptyCartridgesNotificationView); + } + } + } +} diff --git a/Software/Visual_Studio/PPC/Tango.PPC.UI/Notifications/NotificationItems/EmptyCartridgesNotificationView.xaml b/Software/Visual_Studio/PPC/Tango.PPC.UI/Notifications/NotificationItems/EmptyCartridgesNotificationView.xaml new file mode 100644 index 000000000..7ce525337 --- /dev/null +++ b/Software/Visual_Studio/PPC/Tango.PPC.UI/Notifications/NotificationItems/EmptyCartridgesNotificationView.xaml @@ -0,0 +1,15 @@ + + + + + + + + diff --git a/Software/Visual_Studio/PPC/Tango.PPC.UI/Notifications/NotificationItems/EmptyCartridgesNotificationView.xaml.cs b/Software/Visual_Studio/PPC/Tango.PPC.UI/Notifications/NotificationItems/EmptyCartridgesNotificationView.xaml.cs new file mode 100644 index 000000000..5fab4ab44 --- /dev/null +++ b/Software/Visual_Studio/PPC/Tango.PPC.UI/Notifications/NotificationItems/EmptyCartridgesNotificationView.xaml.cs @@ -0,0 +1,28 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows; +using System.Windows.Controls; +using System.Windows.Data; +using System.Windows.Documents; +using System.Windows.Input; +using System.Windows.Media; +using System.Windows.Media.Imaging; +using System.Windows.Navigation; +using System.Windows.Shapes; + +namespace Tango.PPC.UI.Notifications.NotificationItems +{ + /// + /// Interaction logic for EmptyCartridgesNotification.xaml + /// + public partial class EmptyCartridgesNotificationView : UserControl + { + public EmptyCartridgesNotificationView() + { + InitializeComponent(); + } + } +} diff --git a/Software/Visual_Studio/PPC/Tango.PPC.UI/Tango.PPC.UI.csproj b/Software/Visual_Studio/PPC/Tango.PPC.UI/Tango.PPC.UI.csproj index fdeff4fc4..c74e76b50 100644 --- a/Software/Visual_Studio/PPC/Tango.PPC.UI/Tango.PPC.UI.csproj +++ b/Software/Visual_Studio/PPC/Tango.PPC.UI/Tango.PPC.UI.csproj @@ -93,12 +93,17 @@ PPCVersionInfo.cs + MessageBox.xaml + + + EmptyCartridgesNotificationView.xaml + @@ -130,6 +135,10 @@ Designer MSBuild:Compile + + Designer + MSBuild:Compile + Designer MSBuild:Compile @@ -169,6 +178,7 @@ Settings.settings True + ResXFileCodeGenerator Resources.Designer.cs diff --git a/Software/Visual_Studio/PPC/Tango.PPC.UI/ViewModels/LayoutViewVM.cs b/Software/Visual_Studio/PPC/Tango.PPC.UI/ViewModels/LayoutViewVM.cs index 99841516e..d65dfc11c 100644 --- a/Software/Visual_Studio/PPC/Tango.PPC.UI/ViewModels/LayoutViewVM.cs +++ b/Software/Visual_Studio/PPC/Tango.PPC.UI/ViewModels/LayoutViewVM.cs @@ -8,6 +8,7 @@ using Tango.Core.DI; using Tango.PPC.Common; using Tango.PPC.Common.Modules; using Tango.PPC.Common.Navigation; +using Tango.PPC.UI.Notifications.NotificationItems; using Tango.PPC.UI.ViewsContracts; using Tango.SharedUI; @@ -35,6 +36,16 @@ namespace Tango.PPC.UI.ViewModels set { _isMenuOpened = value; RaisePropertyChangedAuto(); } } + private bool _isNotificationsOpened; + /// + /// Gets or sets a value indicating whether to display all notifications. + /// + public bool IsNotificationsOpened + { + get { return _isNotificationsOpened; } + set { _isNotificationsOpened = value; RaisePropertyChangedAuto(); } + } + /// /// Gets or sets the module navigation command. /// @@ -50,6 +61,11 @@ namespace Tango.PPC.UI.ViewModels /// public RelayCommand HomeCommand { get; set; } + /// + /// Gets or sets the notifications area pressed command. + /// + public RelayCommand NotificationsAreaPressedCommand { get; set; } + /// /// Initializes a new instance of the class. /// @@ -58,6 +74,7 @@ namespace Tango.PPC.UI.ViewModels ModuleNavigationCommand = new RelayCommand(NavigateToModule); HomeCommand = new RelayCommand(NavigateHome); MenuOrBackCommand = new RelayCommand(OpenMenuOrNavigateBack); + NotificationsAreaPressedCommand = new RelayCommand(OpenFirstNotificationOrDisplayAll); } /// @@ -73,6 +90,8 @@ namespace Tango.PPC.UI.ViewModels { IsMenuOpened = true; } + + NotificationProvider.PushNotification(new EmptyCartridgesNotification()); } /// @@ -118,7 +137,22 @@ namespace Tango.PPC.UI.ViewModels /// public override void OnViewAttached() { - + + } + + /// + /// Opens the first notification or display all. + /// + private void OpenFirstNotificationOrDisplayAll() + { + if (NotificationProvider.NotificationItems.Count == 1) + { + //Open first + } + else + { + IsNotificationsOpened = true; + } } } } diff --git a/Software/Visual_Studio/PPC/Tango.PPC.UI/Views/LayoutView.xaml b/Software/Visual_Studio/PPC/Tango.PPC.UI/Views/LayoutView.xaml index 2b4c68060..524550b94 100644 --- a/Software/Visual_Studio/PPC/Tango.PPC.UI/Views/LayoutView.xaml +++ b/Software/Visual_Studio/PPC/Tango.PPC.UI/Views/LayoutView.xaml @@ -8,14 +8,28 @@ xmlns:fa="http://schemas.fontawesome.io/icons/" xmlns:vm="clr-namespace:Tango.PPC.UI.ViewModels" xmlns:global="clr-namespace:Tango.PPC.UI" + xmlns:localConverters="clr-namespace:Tango.PPC.UI.Converters" xmlns:touch="clr-namespace:Tango.Touch.Controls;assembly=Tango.Touch" xmlns:controls="clr-namespace:Tango.SharedUI.Controls;assembly=Tango.SharedUI" xmlns:keyboard="clr-namespace:Tango.Touch.Keyboard;assembly=Tango.Touch" mc:Ignorable="d" d:DesignHeight="1280" d:DesignWidth="800" d:DataContext="{d:DesignInstance Type=vm:LayoutViewVM, IsDesignTimeCreatable=False}" DataContext="{x:Static global:ViewModelLocator.LayoutViewVM}"> - - + + + + + + + + + + + + + + + @@ -59,7 +73,7 @@ - + @@ -98,11 +112,13 @@ - - - DYE - - + + + + DYE + + + @@ -111,12 +127,12 @@ - + - + diff --git a/Software/Visual_Studio/PPC/Tango.PPC.UI/Views/LayoutView.xaml.cs b/Software/Visual_Studio/PPC/Tango.PPC.UI/Views/LayoutView.xaml.cs index 18ffa8ab2..9ef698656 100644 --- a/Software/Visual_Studio/PPC/Tango.PPC.UI/Views/LayoutView.xaml.cs +++ b/Software/Visual_Studio/PPC/Tango.PPC.UI/Views/LayoutView.xaml.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.Diagnostics; using System.Linq; using System.Text; using System.Threading.Tasks; @@ -9,9 +10,11 @@ using System.Windows.Data; using System.Windows.Documents; using System.Windows.Input; using System.Windows.Media; +using System.Windows.Media.Animation; using System.Windows.Media.Imaging; using System.Windows.Navigation; using System.Windows.Shapes; +using Tango.Core.EventArguments; using Tango.Logging; using Tango.PPC.Common; using Tango.PPC.UI.ViewsContracts; -- cgit v1.3.1