diff options
| author | Roy Ben-Shabat <Roy@Twine-s.com> | 2018-06-14 17:32:09 +0300 |
|---|---|---|
| committer | Roy Ben-Shabat <Roy@Twine-s.com> | 2018-06-14 17:32:09 +0300 |
| commit | 61a68af94273563e1179b49062ac96b8a627a72a (patch) | |
| tree | b435c82b2046ece012b3555afa77c660f0a2b0ca /Software/Visual_Studio/PPC/Tango.PPC.UI | |
| parent | 580cb401e8b31501cb3fbee1b9f59a67ad636633 (diff) | |
| download | Tango-61a68af94273563e1179b49062ac96b8a627a72a.tar.gz Tango-61a68af94273563e1179b49062ac96b8a627a72a.zip | |
Working on PPC.
Diffstat (limited to 'Software/Visual_Studio/PPC/Tango.PPC.UI')
6 files changed, 104 insertions, 7 deletions
diff --git a/Software/Visual_Studio/PPC/Tango.PPC.UI/App.xaml.cs b/Software/Visual_Studio/PPC/Tango.PPC.UI/App.xaml.cs index 1e3a16e3e..4b4c7acb9 100644 --- a/Software/Visual_Studio/PPC/Tango.PPC.UI/App.xaml.cs +++ b/Software/Visual_Studio/PPC/Tango.PPC.UI/App.xaml.cs @@ -18,6 +18,10 @@ namespace Tango.PPC.UI /// </summary> public partial class App : Application { + /// <summary> + /// Raises the <see cref="E:System.Windows.Application.Startup" /> event. + /// </summary> + /// <param name="e">A <see cref="T:System.Windows.StartupEventArgs" /> that contains the event data.</param> protected override void OnStartup(StartupEventArgs e) { base.OnStartup(e); diff --git a/Software/Visual_Studio/PPC/Tango.PPC.UI/Modules/DefaultStudioModuleLoader.cs b/Software/Visual_Studio/PPC/Tango.PPC.UI/Modules/DefaultStudioModuleLoader.cs index bb68f05cd..78ebd8ded 100644 --- a/Software/Visual_Studio/PPC/Tango.PPC.UI/Modules/DefaultStudioModuleLoader.cs +++ b/Software/Visual_Studio/PPC/Tango.PPC.UI/Modules/DefaultStudioModuleLoader.cs @@ -13,6 +13,7 @@ using Tango.PPC.Common.Authentication; using Tango.PPC.Common.Modules; using Tango.PPC.Common; using Tango.PPC.Jobs; +using System.Windows.Data; namespace Tango.PPC.UI.Modules { @@ -23,6 +24,7 @@ namespace Tango.PPC.UI.Modules /// <seealso cref="Tango.PPC.Common.Modules.IPPCModuleLoader" /> public class DefaultPPCModuleLoader : ExtendedObject, IPPCModuleLoader { + private static object _syncObject = new object(); private IAuthenticationProvider _authenticationProvider; private bool _loaded; @@ -40,6 +42,9 @@ namespace Tango.PPC.UI.Modules _authenticationProvider = authenticationProvider; AllModules = new ObservableCollection<IPPCModule>(); UserModules = new ObservableCollection<IPPCModule>(); + + BindingOperations.EnableCollectionSynchronization(UserModules, _syncObject); + _authenticationProvider.CurrentUserChanged += _authenticationProvider_CurrentUserChanged; } diff --git a/Software/Visual_Studio/PPC/Tango.PPC.UI/Navigation/DefaultNavigationManager.cs b/Software/Visual_Studio/PPC/Tango.PPC.UI/Navigation/DefaultNavigationManager.cs index 82640f899..ae1d29bc2 100644 --- a/Software/Visual_Studio/PPC/Tango.PPC.UI/Navigation/DefaultNavigationManager.cs +++ b/Software/Visual_Studio/PPC/Tango.PPC.UI/Navigation/DefaultNavigationManager.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using System.Linq; +using System.Reflection; using System.Text; using System.Threading.Tasks; using System.Windows; @@ -41,6 +42,12 @@ namespace Tango.PPC.UI.Navigation MainView.Instance.NavigationControl.NavigateTo(NavigationView.LayoutView.ToString()); var firstModule = _moduleLoader.UserModules.FirstOrDefault(); LayoutView.Instance.NavigationControl.NavigateTo(firstModule.Name); + var moduleAtt = firstModule.GetType().GetCustomAttribute<PPCModuleAttribute>(); + + if (moduleAtt != null) + { + NavigateTo(firstModule.GetType(), moduleAtt.HomeViewName); + } } else { @@ -88,16 +95,26 @@ namespace Tango.PPC.UI.Navigation /// <param name="viewPath">The view path.</param> public void NavigateTo<T>(params String[] viewPath) where T : IPPCModule { + NavigateTo(typeof(T), viewPath); + } + + /// <summary> + /// Navigates to the specified module using the view path (e.g MainView,JobsView). + /// This method makes it easy to do stuff like NavigateTo(nameof(MainView),nameof(JobsView)); + /// </summary> + /// <param name="viewPath">The view path.</param> + private void NavigateTo(Type moduleType, params String[] viewPath) + { MainView.Instance.NavigationControl.NavigateTo(NavigationView.LayoutView.ToString()); var navigationControl = LayoutView.Instance.NavigationControl; - var module = _moduleLoader.UserModules.SingleOrDefault(x => x.GetType() == typeof(T)); + var module = _moduleLoader.UserModules.SingleOrDefault(x => x.GetType() == moduleType); var moduleView = navigationControl.NavigateTo(module.Name); var moduleNavigation = moduleView.FindChildOffline<NavigationControl>(); - foreach (var view in viewPath) + moduleNavigation.RegisterForLoadedOrNow(async (x, e) => { - moduleNavigation.RegisterForLoadedOrNow(async (x, e) => + foreach (var view in viewPath) { await Task.Delay(100); var v = moduleNavigation.NavigateTo(view); @@ -106,8 +123,8 @@ namespace Tango.PPC.UI.Navigation { moduleNavigation = v.FindChildOffline<NavigationControl>(); } - }); - } + } + }); } } } 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 4e200ada6..8731bc7d9 100644 --- a/Software/Visual_Studio/PPC/Tango.PPC.UI/ViewModels/LayoutViewVM.cs +++ b/Software/Visual_Studio/PPC/Tango.PPC.UI/ViewModels/LayoutViewVM.cs @@ -3,9 +3,11 @@ using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; +using Tango.Core.Commands; using Tango.Core.DI; using Tango.PPC.Common; using Tango.PPC.Common.Modules; +using Tango.PPC.Common.Navigation; using Tango.PPC.UI.ViewsContracts; using Tango.SharedUI; @@ -23,6 +25,54 @@ namespace Tango.PPC.UI.ViewModels [TangoInject] public IPPCModuleLoader ModuleLoader { get; set; } + private bool _isMenuOpened; + /// <summary> + /// Gets or sets a value indicating whether the side menu is opened. + /// </summary> + public bool IsMenuOpened + { + get { return _isMenuOpened; } + set { _isMenuOpened = value; RaisePropertyChangedAuto(); } + } + + /// <summary> + /// Gets or sets the module navigation command. + /// </summary> + public RelayCommand<String> ModuleNavigationCommand { get; set; } + + /// <summary> + /// Gets or sets the home command. + /// </summary> + public RelayCommand HomeCommand { get; set; } + + /// <summary> + /// Initializes a new instance of the <see cref="LayoutViewVM"/> class. + /// </summary> + public LayoutViewVM() + { + ModuleNavigationCommand = new RelayCommand<string>(HandleModuleNavigationCommand); + HomeCommand = new RelayCommand(HandleHomeCommand); + } + + /// <summary> + /// Handles the module navigation command. + /// </summary> + /// <param name="moduleName">Name of the module.</param> + private void HandleModuleNavigationCommand(string moduleName) + { + IsMenuOpened = false; + NavigationManager.NavigateTo(moduleName); + } + + /// <summary> + /// Handles the home command. + /// </summary> + private void HandleHomeCommand() + { + IsMenuOpened = false; + NavigationManager.NavigateTo(NavigationView.HomeModule); + } + /// <summary> /// Called when the application has been started. /// </summary> 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 8baeab6a4..d7c9fc39e 100644 --- a/Software/Visual_Studio/PPC/Tango.PPC.UI/Views/LayoutView.xaml +++ b/Software/Visual_Studio/PPC/Tango.PPC.UI/Views/LayoutView.xaml @@ -15,7 +15,7 @@ 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"> + <touch:TouchSideMenu x:Name="menu" IsOpened="{Binding IsMenuOpened,Mode=TwoWay}"> <touch:TouchSideMenu.MenuContent> <Border x:Name="border" BorderThickness="0 0 1 0" BorderBrush="{StaticResource TangoDividerBrush}"> <DockPanel LastChildFill="False" Background="{StaticResource TangoPrimaryBackgroundBrush}"> @@ -52,13 +52,26 @@ </StackPanel> </Grid> <StackPanel Margin="0 16 0 0"> - <touch:TouchButton Style="{StaticResource TangoFlatButton}"> + <touch:TouchButton Style="{StaticResource TangoFlatButton}" Command="{Binding HomeCommand}"> <StackPanel Orientation="Horizontal" HorizontalAlignment="Left"> <fa:ImageAwesome VerticalAlignment="Center" Icon="Home" Width="32" Height="32"></fa:ImageAwesome> <TextBlock FontSize="16" VerticalAlignment="Center" Margin="10 0 0 0">Home</TextBlock> </StackPanel> </touch:TouchButton> </StackPanel> + + <ItemsControl ItemsSource="{Binding ModuleLoader.UserModules}" Margin="0 20 0 0"> + <ItemsControl.ItemTemplate> + <DataTemplate> + <touch:TouchButton Style="{StaticResource TangoFlatButton}" Command="{Binding RelativeSource={RelativeSource AncestorType=UserControl},Path=DataContext.ModuleNavigationCommand}" CommandParameter="{Binding Name}"> + <StackPanel Orientation="Horizontal" HorizontalAlignment="Left"> + <Image VerticalAlignment="Center" Source="{Binding Image}" Width="32" Height="32"></Image> + <TextBlock FontSize="16" VerticalAlignment="Center" Margin="10 0 0 0" Text="{Binding Name}"></TextBlock> + </StackPanel> + </touch:TouchButton> + </DataTemplate> + </ItemsControl.ItemTemplate> + </ItemsControl> </StackPanel> <StackPanel DockPanel.Dock="Bottom"> diff --git a/Software/Visual_Studio/PPC/Tango.PPC.UI/ViewsContracts/ILayoutView.cs b/Software/Visual_Studio/PPC/Tango.PPC.UI/ViewsContracts/ILayoutView.cs index f79c790ff..f01785d57 100644 --- a/Software/Visual_Studio/PPC/Tango.PPC.UI/ViewsContracts/ILayoutView.cs +++ b/Software/Visual_Studio/PPC/Tango.PPC.UI/ViewsContracts/ILayoutView.cs @@ -7,8 +7,16 @@ using Tango.PPC.Common; namespace Tango.PPC.UI.ViewsContracts { + /// <summary> + /// Represents the <see cref="ILayoutView"/> contract. + /// </summary> + /// <seealso cref="Tango.PPC.Common.IPPCView" /> public interface ILayoutView : IPPCView { + /// <summary> + /// Inserts the specified modules into the navigation system. + /// </summary> + /// <param name="modules">The modules.</param> void ApplyModules(IEnumerable<IPPCModule> modules); } } |
