From cff4a8079c4d352cfd47793c701650e62337ed6e Mon Sep 17 00:00:00 2001 From: Roy Ben-Shabat Date: Wed, 6 Jun 2018 18:39:17 +0300 Subject: Working on PPC.. --- .../Notifications/INotificationProvider.cs | 2 +- .../Tango.PPC.Common/Notifications/MessageBoxVM.cs | 7 ++ .../PPC/Tango.PPC.Common/PPCViewModel.cs | 20 +++-- Software/Visual_Studio/PPC/Tango.PPC.UI/App.xaml | 8 +- .../Images/MessageBox Icons/information.png | Bin 1348 -> 2869 bytes .../Visual_Studio/PPC/Tango.PPC.UI/MainWindow.xaml | 8 +- .../Notifications/DefaultNotificationProvider.cs | 93 +++++++++++++++++++-- .../PPC/Tango.PPC.UI/Notifications/MessageBox.xaml | 27 +++--- .../PPC/Tango.PPC.UI/Resources/Colors.xaml | 5 ++ .../PPC/Tango.PPC.UI/Resources/Fonts.xaml | 2 + .../PPC/Tango.PPC.UI/Resources/Styles.xaml | 13 +++ .../PPC/Tango.PPC.UI/ViewModels/JobsViewVM.cs | 31 +++---- .../PPC/Tango.PPC.UI/ViewModels/LoadingViewVM.cs | 5 -- .../PPC/Tango.PPC.UI/ViewModels/MainViewVM.cs | 12 +-- .../PPC/Tango.PPC.UI/Views/MainView.xaml | 24 ++++++ 15 files changed, 202 insertions(+), 55 deletions(-) (limited to 'Software/Visual_Studio/PPC') 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 e5a825013..917a3e168 100644 --- a/Software/Visual_Studio/PPC/Tango.PPC.Common/Notifications/INotificationProvider.cs +++ b/Software/Visual_Studio/PPC/Tango.PPC.Common/Notifications/INotificationProvider.cs @@ -15,7 +15,7 @@ namespace Tango.PPC.Common.Notifications public interface INotificationProvider { /// - /// Gets or sets the current message box. + /// Gets the current message box. /// MessageBoxVM CurrentMessageBox { get; } diff --git a/Software/Visual_Studio/PPC/Tango.PPC.Common/Notifications/MessageBoxVM.cs b/Software/Visual_Studio/PPC/Tango.PPC.Common/Notifications/MessageBoxVM.cs index dbb1d0346..b626df880 100644 --- a/Software/Visual_Studio/PPC/Tango.PPC.Common/Notifications/MessageBoxVM.cs +++ b/Software/Visual_Studio/PPC/Tango.PPC.Common/Notifications/MessageBoxVM.cs @@ -4,6 +4,7 @@ using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; +using System.Windows.Media; using System.Windows.Media.Imaging; using Tango.PPC.Common.Notifications; @@ -11,8 +12,14 @@ namespace Tango.PPC.Common.Notifications { public class MessageBoxVM : DialogViewVM { + public String Title { get; set; } + public BitmapSource Icon { get; set; } + public Brush Brush { get; set; } + public String Message { get; set; } + + public bool HasCancel { get; set; } } } diff --git a/Software/Visual_Studio/PPC/Tango.PPC.Common/PPCViewModel.cs b/Software/Visual_Studio/PPC/Tango.PPC.Common/PPCViewModel.cs index 58ad2fbed..d9d7097e0 100644 --- a/Software/Visual_Studio/PPC/Tango.PPC.Common/PPCViewModel.cs +++ b/Software/Visual_Studio/PPC/Tango.PPC.Common/PPCViewModel.cs @@ -3,6 +3,7 @@ using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; +using Tango.Core.DI; using Tango.PPC.Common.Application; using Tango.PPC.Common.Authentication; using Tango.PPC.Common.Navigation; @@ -14,13 +15,17 @@ namespace Tango.PPC.Common { public abstract class PPCViewModel : ViewModel { - public IPPCApplicationManager ApplicationManager { get; private set; } + [TangoInject] + public IPPCApplicationManager ApplicationManager { get; set; } - public IAuthenticationProvider AuthenticationProvider { get; private set; } + [TangoInject] + public IAuthenticationProvider AuthenticationProvider { get; set; } - public INavigationManager NavigationManager { get; private set; } + [TangoInject] + public INavigationManager NavigationManager { get; set; } - public INotificationProvider NotificationProvider { get; private set; } + [TangoInject] + public INotificationProvider NotificationProvider { get; set; } private PPCSettings _settings; public PPCSettings Settings @@ -37,12 +42,9 @@ namespace Tango.PPC.Common private set { _settings = value; } } - public PPCViewModel(IPPCApplicationManager application, IAuthenticationProvider authentication, INavigationManager navigation, INotificationProvider notification) + public PPCViewModel() { - ApplicationManager = application; - AuthenticationProvider = authentication; - NavigationManager = navigation; - NotificationProvider = notification; + } public abstract void OnApplicationStarted(); diff --git a/Software/Visual_Studio/PPC/Tango.PPC.UI/App.xaml b/Software/Visual_Studio/PPC/Tango.PPC.UI/App.xaml index 5616ff68f..863a424a0 100644 --- a/Software/Visual_Studio/PPC/Tango.PPC.UI/App.xaml +++ b/Software/Visual_Studio/PPC/Tango.PPC.UI/App.xaml @@ -1,7 +1,8 @@  @@ -20,6 +21,11 @@ + + + + + diff --git a/Software/Visual_Studio/PPC/Tango.PPC.UI/Images/MessageBox Icons/information.png b/Software/Visual_Studio/PPC/Tango.PPC.UI/Images/MessageBox Icons/information.png index c56906674..c1c638c6b 100644 Binary files a/Software/Visual_Studio/PPC/Tango.PPC.UI/Images/MessageBox Icons/information.png and b/Software/Visual_Studio/PPC/Tango.PPC.UI/Images/MessageBox Icons/information.png differ diff --git a/Software/Visual_Studio/PPC/Tango.PPC.UI/MainWindow.xaml b/Software/Visual_Studio/PPC/Tango.PPC.UI/MainWindow.xaml index c80a1473c..289d0cdf2 100644 --- a/Software/Visual_Studio/PPC/Tango.PPC.UI/MainWindow.xaml +++ b/Software/Visual_Studio/PPC/Tango.PPC.UI/MainWindow.xaml @@ -12,9 +12,9 @@ Foreground="{StaticResource TangoDarkForegroundBrush}"> - - - - + + + + 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 dbaafa6bb..02e41e087 100644 --- a/Software/Visual_Studio/PPC/Tango.PPC.UI/Notifications/DefaultNotificationProvider.cs +++ b/Software/Visual_Studio/PPC/Tango.PPC.UI/Notifications/DefaultNotificationProvider.cs @@ -8,16 +8,37 @@ using System.Windows; using System.Windows.Media; using Tango.PPC.Common.Notifications; using Tango.Core; +using System.Collections.Concurrent; +using System.Windows.Media.Imaging; +using Tango.SharedUI.Helpers; namespace Tango.PPC.UI.Notifications { public class DefaultNotificationProvider : ExtendedObject, INotificationProvider { + private class PendingMessageBox + { + public MessageBoxVM VM { get; set; } + public TaskCompletionSource CompletionSource { get; set; } + } + + private ConcurrentQueue _pendingMessageBoxes; + + public DefaultNotificationProvider() + { + _pendingMessageBoxes = new ConcurrentQueue(); + } + private MessageBoxVM _currentMessageBox; public MessageBoxVM CurrentMessageBox { get { return _currentMessageBox; } - private set { _currentMessageBox = value; RaisePropertyChangedAuto(); } + private set + { + _currentMessageBox = value; + RaisePropertyChangedAuto(); + RaisePropertyChanged(nameof(HasMessageBox)); + } } public bool HasMessageBox @@ -30,22 +51,84 @@ namespace Tango.PPC.UI.Notifications public Task ShowError(string message) { - throw new NotImplementedException(); + return ShowMessageBox(new MessageBoxVM() + { + Message = message, + Icon = ResourceHelper.GetImageFromResources("Images/MessageBox Icons/information.png"), + Title = "Error", + Brush = Application.Current.Resources["TangoMessageBoxErrorBrush"] as Brush, + }); } public Task ShowInfo(string message) { - throw new NotImplementedException(); + return ShowMessageBox(new MessageBoxVM() + { + Message = message, + Icon = ResourceHelper.GetImageFromResources("Images/MessageBox Icons/information.png"), + Title = "Information", + Brush = Application.Current.Resources["TangoMessageBoxInfoBrush"] as Brush, + }); } public Task ShowWarning(string message) { - throw new NotImplementedException(); + return ShowMessageBox(new MessageBoxVM() + { + Message = message, + Icon = ResourceHelper.GetImageFromResources("Images/MessageBox Icons/information.png"), + Title = "Warning", + Brush = Application.Current.Resources["TangoMessageBoxWarningBrush"] as Brush, + }); } public Task ShowQuestion(string message) { - throw new NotImplementedException(); + return ShowMessageBox(new MessageBoxVM() + { + Message = message, + Icon = ResourceHelper.GetImageFromResources("Images/MessageBox Icons/information.png"), + Title = "Confirm", + HasCancel = true, + Brush = Application.Current.Resources["TangoMessageBoxQuestionBrush"] as Brush, + }); + } + + private Task ShowMessageBox(MessageBoxVM vm) + { + TaskCompletionSource source = new TaskCompletionSource(); + + vm.Accepted += () => { OnMessageBoxClosed(); source.SetResult(true); }; + vm.Canceled += () => { OnMessageBoxClosed(); source.SetResult(false); }; + + if (CurrentMessageBox == null) + { + CurrentMessageBox = vm; + } + else + { + _pendingMessageBoxes.Enqueue(new PendingMessageBox() + { + VM = vm, + CompletionSource = source, + }); + } + + return source.Task; + } + + private void OnMessageBoxClosed() + { + CurrentMessageBox = null; + + if (_pendingMessageBoxes.Count > 0) + { + PendingMessageBox p = null; + if (_pendingMessageBoxes.TryDequeue(out p)) + { + CurrentMessageBox = p.VM; + } + } } } } diff --git a/Software/Visual_Studio/PPC/Tango.PPC.UI/Notifications/MessageBox.xaml b/Software/Visual_Studio/PPC/Tango.PPC.UI/Notifications/MessageBox.xaml index a699902b8..07d3b11ac 100644 --- a/Software/Visual_Studio/PPC/Tango.PPC.UI/Notifications/MessageBox.xaml +++ b/Software/Visual_Studio/PPC/Tango.PPC.UI/Notifications/MessageBox.xaml @@ -8,30 +8,37 @@ xmlns:vm="clr-namespace:Tango.PPC.Common.Notifications;assembly=Tango.PPC.Common" xmlns:local="clr-namespace:Tango.PanelPC.UI.Notifications" mc:Ignorable="d" - d:DesignHeight="200" d:DesignWidth="500" d:DataContext="{d:DesignInstance vm:MessageBoxVM,IsDesignTimeCreatable=False}"> + d:DesignHeight="400" d:DesignWidth="800" d:DataContext="{d:DesignInstance vm:MessageBoxVM,IsDesignTimeCreatable=False}"> - + - + + - + - - + + - - CANCEL - OK - + + + + + + + + CANCEL + OK + diff --git a/Software/Visual_Studio/PPC/Tango.PPC.UI/Resources/Colors.xaml b/Software/Visual_Studio/PPC/Tango.PPC.UI/Resources/Colors.xaml index 1c24d118b..3b9ccf2fa 100644 --- a/Software/Visual_Studio/PPC/Tango.PPC.UI/Resources/Colors.xaml +++ b/Software/Visual_Studio/PPC/Tango.PPC.UI/Resources/Colors.xaml @@ -4,4 +4,9 @@ + + + + + \ No newline at end of file diff --git a/Software/Visual_Studio/PPC/Tango.PPC.UI/Resources/Fonts.xaml b/Software/Visual_Studio/PPC/Tango.PPC.UI/Resources/Fonts.xaml index 46deceb85..659970db2 100644 --- a/Software/Visual_Studio/PPC/Tango.PPC.UI/Resources/Fonts.xaml +++ b/Software/Visual_Studio/PPC/Tango.PPC.UI/Resources/Fonts.xaml @@ -11,5 +11,7 @@ 18 30 20 + 30 + 20 \ No newline at end of file diff --git a/Software/Visual_Studio/PPC/Tango.PPC.UI/Resources/Styles.xaml b/Software/Visual_Studio/PPC/Tango.PPC.UI/Resources/Styles.xaml index a82e1acb4..f83d71e92 100644 --- a/Software/Visual_Studio/PPC/Tango.PPC.UI/Resources/Styles.xaml +++ b/Software/Visual_Studio/PPC/Tango.PPC.UI/Resources/Styles.xaml @@ -22,4 +22,17 @@ + + + + \ No newline at end of file diff --git a/Software/Visual_Studio/PPC/Tango.PPC.UI/ViewModels/JobsViewVM.cs b/Software/Visual_Studio/PPC/Tango.PPC.UI/ViewModels/JobsViewVM.cs index b5e3e18fc..2af15b1ad 100644 --- a/Software/Visual_Studio/PPC/Tango.PPC.UI/ViewModels/JobsViewVM.cs +++ b/Software/Visual_Studio/PPC/Tango.PPC.UI/ViewModels/JobsViewVM.cs @@ -51,20 +51,6 @@ namespace Tango.PPC.UI.ViewModels public RelayCommand OnDragAndDropCommand { get; set; } - public JobsViewVM(IPPCApplicationManager application, IAuthenticationProvider authentication, INavigationManager navigation, INotificationProvider notification) : base(application, authentication, navigation, notification) - { - Jobs = new ObservableCollection(); - - JobSelectedCommand = new RelayCommand((x) => JobSelected(x as Job)); - OnDragAndDropCommand = new RelayCommand((e) => - { - Job draggedJob = e.Draggable.DataContext as Job; - Job droppedJob = e.Droppable.DataContext as Job; - - OnDragAndDropJobs(draggedJob, droppedJob); - }); - } - private void OnDragAndDropJobs(Job draggedJob, Job droppedJob) { Debug.WriteLine(draggedJob.Name + " Dragged on to " + droppedJob.Name); @@ -88,9 +74,24 @@ namespace Tango.PPC.UI.ViewModels JobsCollectionView.Refresh(); } - private void JobSelected(Job job) + private async void JobSelected(Job job) { Debug.WriteLine(job.Name); + await NotificationProvider.ShowInfo("Job details not yet implemented..."); + } + + public JobsViewVM() + { + Jobs = new ObservableCollection(); + + JobSelectedCommand = new RelayCommand((x) => JobSelected(x as Job)); + OnDragAndDropCommand = new RelayCommand((e) => + { + Job draggedJob = e.Draggable.DataContext as Job; + Job droppedJob = e.Droppable.DataContext as Job; + + OnDragAndDropJobs(draggedJob, droppedJob); + }); } public override void OnApplicationStarted() diff --git a/Software/Visual_Studio/PPC/Tango.PPC.UI/ViewModels/LoadingViewVM.cs b/Software/Visual_Studio/PPC/Tango.PPC.UI/ViewModels/LoadingViewVM.cs index 37940b2f8..a33dc25d7 100644 --- a/Software/Visual_Studio/PPC/Tango.PPC.UI/ViewModels/LoadingViewVM.cs +++ b/Software/Visual_Studio/PPC/Tango.PPC.UI/ViewModels/LoadingViewVM.cs @@ -17,11 +17,6 @@ namespace Tango.PPC.UI.ViewModels { public class LoadingViewVM : PPCViewModel { - public LoadingViewVM(IPPCApplicationManager application, IAuthenticationProvider authentication, INavigationManager navigation, INotificationProvider notification) : base(application, authentication, navigation, notification) - { - - } - public async override void OnApplicationStarted() { await Task.Delay(500); diff --git a/Software/Visual_Studio/PPC/Tango.PPC.UI/ViewModels/MainViewVM.cs b/Software/Visual_Studio/PPC/Tango.PPC.UI/ViewModels/MainViewVM.cs index c75e031f1..d1fc4c015 100644 --- a/Software/Visual_Studio/PPC/Tango.PPC.UI/ViewModels/MainViewVM.cs +++ b/Software/Visual_Studio/PPC/Tango.PPC.UI/ViewModels/MainViewVM.cs @@ -3,18 +3,20 @@ using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; +using Tango.PPC.Common; using Tango.PPC.Common.Application; +using Tango.PPC.Common.Authentication; +using Tango.PPC.Common.Navigation; +using Tango.PPC.Common.Notifications; using Tango.SharedUI; namespace Tango.PPC.UI.ViewModels { - public class MainViewVM : ViewModel + public class MainViewVM : PPCViewModel { - public String Test { get; set; } - - public MainViewVM(IPPCApplicationManager application) + public override void OnApplicationStarted() { - Test = "This is a binding test"; + } } } diff --git a/Software/Visual_Studio/PPC/Tango.PPC.UI/Views/MainView.xaml b/Software/Visual_Studio/PPC/Tango.PPC.UI/Views/MainView.xaml index 9d264afae..8da05f0dd 100644 --- a/Software/Visual_Studio/PPC/Tango.PPC.UI/Views/MainView.xaml +++ b/Software/Visual_Studio/PPC/Tango.PPC.UI/Views/MainView.xaml @@ -7,6 +7,7 @@ xmlns:vm="clr-namespace:Tango.PPC.UI.ViewModels" xmlns:global="clr-namespace:Tango.PPC.UI" xmlns:local="clr-namespace:Tango.PPC.UI.Views" + xmlns:notifications="clr-namespace:Tango.PanelPC.UI.Notifications" mc:Ignorable="d" d:DesignHeight="1280" d:DesignWidth="800" d:DataContext="{d:DesignInstance Type=vm:MainViewVM, IsDesignTimeCreatable=False}" DataContext="{x:Static global:ViewModelLocator.MainViewVM}"> @@ -14,5 +15,28 @@ + + + + + + + + -- cgit v1.3.1