diff options
| author | Roy Ben-Shabat <Roy@Twine-s.com> | 2018-06-17 19:06:13 +0300 |
|---|---|---|
| committer | Roy Ben-Shabat <Roy@Twine-s.com> | 2018-06-17 19:06:13 +0300 |
| commit | 7658a8546a9c33a76376dff3ab646f2aceaf0a01 (patch) | |
| tree | 10c2cee7f96268e9052e19901f49f3e0a1e75d41 /Software/Visual_Studio/PPC/Tango.PPC.UI | |
| parent | 22853e394b878578084db1062664c38c40e88d07 (diff) | |
| download | Tango-7658a8546a9c33a76376dff3ab646f2aceaf0a01.tar.gz Tango-7658a8546a9c33a76376dff3ab646f2aceaf0a01.zip | |
Working on PPC !!!
Diffstat (limited to 'Software/Visual_Studio/PPC/Tango.PPC.UI')
10 files changed, 293 insertions, 11 deletions
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 Binary files differnew file mode 100644 index 000000000..a845b1226 --- /dev/null +++ b/Software/Visual_Studio/PPC/Tango.PPC.UI/Images/warning-test.png 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 { @@ -22,6 +24,11 @@ namespace Tango.PPC.UI.Notifications public class DefaultNotificationProvider : ExtendedObject, INotificationProvider { /// <summary> + /// Gets the collection of notification items. + /// </summary> + public ObservableCollection<NotificationItem> NotificationItems { get; private set; } + + /// <summary> /// Represents a pending message box. /// </summary> private class PendingMessageBox @@ -44,7 +51,10 @@ namespace Tango.PPC.UI.Notifications /// </summary> public DefaultNotificationProvider() { + NotificationItems = new ObservableCollection<NotificationItem>(); _pendingMessageBoxes = new ConcurrentQueue<PendingMessageBox>(); + + PopNotificationCommand = new RelayCommand<NotificationItem>((x) => PopNotification(x)); } private MessageBoxVM _currentMessageBox; @@ -182,5 +192,96 @@ namespace Tango.PPC.UI.Notifications } } } + + /// <summary> + /// Inserts the notification item to the bottom of the notifications collection. + /// </summary> + /// <param name="item">The item.</param> + /// <returns></returns> + public NotificationItem PushNotification(NotificationItem item) + { + return PushNotification(item, null, false, null); + } + + /// <summary> + /// Inserts the notification item to the bottom of the notifications collection. + /// </summary> + /// <param name="item">The item.</param> + /// <param name="condition">A condition which determines if this item is still relevant.</param> + /// <param name="autoCheck">Determines whether to perform automatic checking of the condition.</param> + /// <param name="checkInterval">Determines how frequently the condition function will be invoked. (Default 1 second)</param> + /// <returns></returns> + public NotificationItem PushNotification(NotificationItem item, Func<bool> 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; + } + + /// <summary> + /// Removed the specified notification item. + /// </summary> + /// <param name="item">The item.</param> + public void PopNotification(NotificationItem item) + { + if (item.Timer != null) + { + item.Timer.Stop(); + } + + NotificationItems.Remove(item); + + RaisePropertyChanged(nameof(HasNotificationItems)); + } + + /// <summary> + /// Invokes the notification items conditions. + /// </summary> + public void InvokeNotificationItemsConditions() + { + var list = NotificationItems.ToList(); + + foreach (var item in list.Where(x => x.Condition != null)) + { + if (!item.Condition()) + { + PopNotification(item); + } + } + } + + /// <summary> + /// Gets a value indicating whether this instance has notification items. + /// </summary> + public bool HasNotificationItems + { + get + { + return NotificationItems.Count > 0; + } + } + + public RelayCommand<NotificationItem> 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<LiquidType> LiquidTypes { get; set; } + + public EmptyCartridgesNotification() + { + Message = "Cartridges are empty, please replace cartridges"; + } + + public EmptyCartridgesNotification(IEnumerable<LiquidType> 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 @@ +<UserControl x:Class="Tango.PPC.UI.Notifications.NotificationItems.EmptyCartridgesNotificationView" + xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" + xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" + xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" + xmlns:d="http://schemas.microsoft.com/expression/blend/2008" + xmlns:local="clr-namespace:Tango.PPC.UI.Notifications.NotificationItems" + mc:Ignorable="d" + d:DesignHeight="60" d:DesignWidth="400" MinHeight="50" Background="Transparent" Foreground="#FF7777" d:DataContext="{d:DesignInstance Type=local:EmptyCartridgesNotification, IsDesignTimeCreatable=True}"> + <Grid Margin="10"> + <DockPanel> + <Image Source="/Images/warning-test.png" Width="24" /> + <TextBlock Margin="10 0 0 0" VerticalAlignment="Center" TextWrapping="Wrap" Text="{Binding Message}"></TextBlock> + </DockPanel> + </Grid> +</UserControl> 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 +{ + /// <summary> + /// Interaction logic for EmptyCartridgesNotification.xaml + /// </summary> + 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 @@ <Link>PPCVersionInfo.cs</Link> </Compile> <Compile Include="Authentication\DefaultAuthenticationProvider.cs" /> + <Compile Include="Converters\NotificationItemConverter.cs" /> <Compile Include="Modules\DefaultStudioModuleLoader.cs" /> <Compile Include="Navigation\DefaultNavigationManager.cs" /> <Compile Include="Notifications\DefaultNotificationProvider.cs" /> <Compile Include="Notifications\MessageBox.xaml.cs"> <DependentUpon>MessageBox.xaml</DependentUpon> </Compile> + <Compile Include="Notifications\NotificationItems\EmptyCartridgesNotification.cs" /> + <Compile Include="Notifications\NotificationItems\EmptyCartridgesNotificationView.xaml.cs"> + <DependentUpon>EmptyCartridgesNotificationView.xaml</DependentUpon> + </Compile> <Compile Include="PPCApplication\DefaultPPCApplicationManager.cs" /> <Compile Include="ViewModelLocator.cs" /> <Compile Include="ViewModels\LayoutViewVM.cs" /> @@ -130,6 +135,10 @@ <SubType>Designer</SubType> <Generator>MSBuild:Compile</Generator> </Page> + <Page Include="Notifications\NotificationItems\EmptyCartridgesNotificationView.xaml"> + <SubType>Designer</SubType> + <Generator>MSBuild:Compile</Generator> + </Page> <Page Include="Resources\Colors.xaml"> <SubType>Designer</SubType> <Generator>MSBuild:Compile</Generator> @@ -169,6 +178,7 @@ <DependentUpon>Settings.settings</DependentUpon> <DesignTimeSharedInput>True</DesignTimeSharedInput> </Compile> + <Resource Include="Images\warning-test.png" /> <EmbeddedResource Include="Properties\Resources.resx"> <Generator>ResXFileCodeGenerator</Generator> <LastGenOutput>Resources.Designer.cs</LastGenOutput> 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; + /// <summary> + /// Gets or sets a value indicating whether to display all notifications. + /// </summary> + public bool IsNotificationsOpened + { + get { return _isNotificationsOpened; } + set { _isNotificationsOpened = value; RaisePropertyChangedAuto(); } + } + /// <summary> /// Gets or sets the module navigation command. /// </summary> @@ -51,6 +62,11 @@ namespace Tango.PPC.UI.ViewModels public RelayCommand HomeCommand { get; set; } /// <summary> + /// Gets or sets the notifications area pressed command. + /// </summary> + public RelayCommand NotificationsAreaPressedCommand { get; set; } + + /// <summary> /// Initializes a new instance of the <see cref="LayoutViewVM"/> class. /// </summary> public LayoutViewVM() @@ -58,6 +74,7 @@ namespace Tango.PPC.UI.ViewModels ModuleNavigationCommand = new RelayCommand<string>(NavigateToModule); HomeCommand = new RelayCommand(NavigateHome); MenuOrBackCommand = new RelayCommand(OpenMenuOrNavigateBack); + NotificationsAreaPressedCommand = new RelayCommand(OpenFirstNotificationOrDisplayAll); } /// <summary> @@ -73,6 +90,8 @@ namespace Tango.PPC.UI.ViewModels { IsMenuOpened = true; } + + NotificationProvider.PushNotification(new EmptyCartridgesNotification()); } /// <summary> @@ -118,7 +137,22 @@ namespace Tango.PPC.UI.ViewModels /// </summary> public override void OnViewAttached() { - + + } + + /// <summary> + /// Opens the first notification or display all. + /// </summary> + 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}"> - <Grid> - <touch:TouchSideMenu x:Name="menu" IsOpened="{Binding IsMenuOpened,Mode=TwoWay}"> + <UserControl.Resources> + <localConverters:NotificationItemConverter x:Key="NotificationItemConverter" /> + </UserControl.Resources> + + <touch:TouchNotificationBar HasNotifications="{Binding NotificationProvider.HasNotificationItems}" Notifications="{Binding NotificationProvider.NotificationItems}"> + <touch:TouchNotificationBar.NotificationTemplate> + <DataTemplate> + <Grid> + <ContentControl Content="{Binding Converter={StaticResource NotificationItemConverter}}" /> + <touch:TouchIconButton Background="Transparent" Padding="20" Style="{StaticResource TangoRoundTouchIconButton}" Command="{Binding RelativeSource={RelativeSource AncestorType=UserControl},Path=DataContext.NotificationProvider.PopNotificationCommand}" CommandParameter="{Binding}" HorizontalAlignment="Right" Width="60" Icon="Close" Foreground="White" /> + </Grid> + </DataTemplate> + </touch:TouchNotificationBar.NotificationTemplate> + + <touch:TouchSideMenu x:Name="menu" IsOpened="{Binding IsMenuOpened,Mode=TwoWay}" Grid.Row="1"> <touch:TouchSideMenu.MenuContent> <Border x:Name="border" BorderThickness="0 0 1 0" BorderBrush="{StaticResource TangoDividerBrush}"> <DockPanel LastChildFill="False" Background="{StaticResource TangoPrimaryBackgroundBrush}"> @@ -59,7 +73,7 @@ </StackPanel> </touch:TouchButton> </StackPanel> - + <ItemsControl ItemsSource="{Binding ModuleLoader.UserModules}" Margin="0 20 0 0"> <ItemsControl.ItemTemplate> <DataTemplate> @@ -98,11 +112,13 @@ </touch:TouchHamburgerButton> </Border> <Grid> - <StackPanel HorizontalAlignment="Right" Margin="30 0" Orientation="Horizontal"> - <touch:TouchButton Height="54" Padding="0" Width="184" CornerRadius="30" BlurRadius="20"> - DYE - </touch:TouchButton> - </StackPanel> + <DockPanel> + <StackPanel DockPanel.Dock="Right" HorizontalAlignment="Right" Margin="30 0" Orientation="Horizontal"> + <touch:TouchButton Height="54" Padding="0" Width="184" CornerRadius="30" BlurRadius="20"> + DYE + </touch:TouchButton> + </StackPanel> + </DockPanel> </Grid> </DockPanel> </Border> @@ -111,12 +127,12 @@ <Grid> <keyboard:KeyboardView> <controls:NavigationControl x:Name="NavigationControl" x:FieldModifier="public" TransitionAlwaysFades="False" TransitionType="Zoom"> - + </controls:NavigationControl> </keyboard:KeyboardView> </Grid> </Grid> </DockPanel> </touch:TouchSideMenu> - </Grid> + </touch:TouchNotificationBar> </UserControl> 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; |
