From 56a433876ea3b97005f5e26354622dba3f3a28b1 Mon Sep 17 00:00:00 2001 From: Natlinux <97396587+Natlinux81@users.noreply.github.com> Date: Sun, 27 Nov 2022 21:52:18 +0100 Subject: [PATCH] Navigation Service and Cleanup UI --- Apollon.WPF/Commands/NavigateCommand.cs | 15 +- Apollon.WPF/MainWindow.xaml | 6 + Apollon.WPF/Services/NavigationService.cs | 28 + Apollon.WPF/ViewModels/ArchersViewModel.cs | 6 + Apollon.WPF/ViewModels/ClassesViewModel.cs | 6 + Apollon.WPF/ViewModels/GroupsViewModel.cs | 8 +- .../ViewModels/NavBarPreparationViewModel.cs | 14 +- .../ViewModels/OverviewDetailsViewModel.cs | 4 +- Apollon.WPF/ViewModels/OverviewViewModel.cs | 10 +- Apollon.WPF/Views/ArchersView.xaml | 23 +- Apollon.WPF/Views/ClassesView.xaml | 23 +- .../Components/NavBarPreparationView.xaml | 598 +++++++++--------- .../Views/Components/TournamentDetails.xaml | 8 +- Apollon.WPF/Views/GroupsView.xaml | 37 +- 14 files changed, 441 insertions(+), 345 deletions(-) create mode 100644 Apollon.WPF/Services/NavigationService.cs diff --git a/Apollon.WPF/Commands/NavigateCommand.cs b/Apollon.WPF/Commands/NavigateCommand.cs index 30dc6ec..6a20234 100644 --- a/Apollon.WPF/Commands/NavigateCommand.cs +++ b/Apollon.WPF/Commands/NavigateCommand.cs @@ -1,4 +1,5 @@ -using Apollon.WPF.Stores; +using Apollon.WPF.Services; +using Apollon.WPF.Stores; using Apollon.WPF.ViewModels; using System; using System.Collections.Generic; @@ -11,18 +12,16 @@ namespace Apollon.WPF.Commands public class NavigateCommand : CommandBase where TViewModel : ViewModelBase { - private readonly NavigationStore _navigationStore; - private readonly Func _createViewModel; + private readonly NavigationService _navigationService; - public NavigateCommand(NavigationStore navigationStore, Func createViewModel) + public NavigateCommand(NavigationService navigationService) { - _navigationStore = navigationStore; - _createViewModel = createViewModel; + _navigationService = navigationService; } public override void Execute(object parameter) - { - _navigationStore.CurrentViewModel = _createViewModel(); + { + _navigationService.Navigate(); } } } diff --git a/Apollon.WPF/MainWindow.xaml b/Apollon.WPF/MainWindow.xaml index 1bc1bc0..c00c74e 100644 --- a/Apollon.WPF/MainWindow.xaml +++ b/Apollon.WPF/MainWindow.xaml @@ -49,6 +49,12 @@ + + + + + + diff --git a/Apollon.WPF/Services/NavigationService.cs b/Apollon.WPF/Services/NavigationService.cs new file mode 100644 index 0000000..8154cbd --- /dev/null +++ b/Apollon.WPF/Services/NavigationService.cs @@ -0,0 +1,28 @@ +using Apollon.WPF.Stores; +using Apollon.WPF.ViewModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Apollon.WPF.Services +{ + public class NavigationService + where TViewModel : ViewModelBase + { + private readonly NavigationStore _navigationStore; + private readonly Func _createViewModel; + + public NavigationService(NavigationStore navigationStore, Func createViewModel) + { + _navigationStore = navigationStore; + _createViewModel = createViewModel; + } + + public void Navigate() + { + _navigationStore.CurrentViewModel = _createViewModel(); + } + } +} diff --git a/Apollon.WPF/ViewModels/ArchersViewModel.cs b/Apollon.WPF/ViewModels/ArchersViewModel.cs index 6395209..bcc6dc1 100644 --- a/Apollon.WPF/ViewModels/ArchersViewModel.cs +++ b/Apollon.WPF/ViewModels/ArchersViewModel.cs @@ -8,5 +8,11 @@ namespace Apollon.WPF.ViewModels { public class ArchersViewModel : ViewModelBase { + public NavBarPreparationViewModel NavBarPreparationViewModel { get; } + + public ArchersViewModel(NavBarPreparationViewModel navBarPreparationViewModel) + { + NavBarPreparationViewModel = navBarPreparationViewModel; + } } } diff --git a/Apollon.WPF/ViewModels/ClassesViewModel.cs b/Apollon.WPF/ViewModels/ClassesViewModel.cs index 16480c5..ca180a9 100644 --- a/Apollon.WPF/ViewModels/ClassesViewModel.cs +++ b/Apollon.WPF/ViewModels/ClassesViewModel.cs @@ -8,5 +8,11 @@ namespace Apollon.WPF.ViewModels { public class ClassesViewModel : ViewModelBase { + public NavBarPreparationViewModel NavBarPreparationViewModel { get; } + + public ClassesViewModel(NavBarPreparationViewModel navBarPreparationViewModel) + { + NavBarPreparationViewModel = navBarPreparationViewModel; + } } } diff --git a/Apollon.WPF/ViewModels/GroupsViewModel.cs b/Apollon.WPF/ViewModels/GroupsViewModel.cs index 2a5c4bc..bbbb639 100644 --- a/Apollon.WPF/ViewModels/GroupsViewModel.cs +++ b/Apollon.WPF/ViewModels/GroupsViewModel.cs @@ -1,5 +1,6 @@ using Apollon.Domain.Models; using Apollon.WPF.Commands; +using Apollon.WPF.Services; using Apollon.WPF.Stores; using System; using System.Collections.Generic; @@ -14,13 +15,14 @@ namespace Apollon.WPF.ViewModels { public TournamentDetailsViewModel TournamentDetailsViewModel { get; } + public NavBarPreparationViewModel NavBarPreparationViewModel { get; } public ICommand NavigateOverviewCommand { get; } public GroupsViewModel(SelectedTournamentsStore selectedTournamentStore, NavigationStore navigationStore, ModalNavigationStore modalNavigationStore, TournamentsStore tournamentsStore) - { + { TournamentDetailsViewModel = new TournamentDetailsViewModel(selectedTournamentStore); - - NavigateOverviewCommand = new NavigateCommand(navigationStore, () => OverviewViewModel.LoadViewModel(selectedTournamentStore, modalNavigationStore, tournamentsStore, navigationStore)); + + NavigateOverviewCommand = new NavigateCommand(new NavigationService(navigationStore, () => OverviewViewModel.LoadViewModel(selectedTournamentStore, modalNavigationStore, tournamentsStore, navigationStore))); } } } diff --git a/Apollon.WPF/ViewModels/NavBarPreparationViewModel.cs b/Apollon.WPF/ViewModels/NavBarPreparationViewModel.cs index 9d3e5be..7579e95 100644 --- a/Apollon.WPF/ViewModels/NavBarPreparationViewModel.cs +++ b/Apollon.WPF/ViewModels/NavBarPreparationViewModel.cs @@ -1,4 +1,5 @@ using Apollon.WPF.Commands; +using Apollon.WPF.Services; using System; using System.Collections.Generic; using System.Linq; @@ -12,7 +13,16 @@ namespace Apollon.WPF.ViewModels { public ICommand NavigateOverviewCommand { get;} public ICommand NavigateGroupsCommand { get;} - public ICommand NavigateClassesCommand { get;} - public ICommand NavigateArchersCommand { get;} + public ICommand NavigateClassesCommand { get;} + public ICommand NavigateArchersCommand { get;} + + public NavBarPreparationViewModel(NavigationService overviewNavigationService, NavigationService groupNavigationService, + NavigationService classNavigationService, NavigationService archersNavigationService) + { + NavigateOverviewCommand = new NavigateCommand(overviewNavigationService); + NavigateGroupsCommand = new NavigateCommand(groupNavigationService); + NavigateClassesCommand = new NavigateCommand(classNavigationService); + NavigateArchersCommand = new NavigateCommand(archersNavigationService); + } } } diff --git a/Apollon.WPF/ViewModels/OverviewDetailsViewModel.cs b/Apollon.WPF/ViewModels/OverviewDetailsViewModel.cs index 3dd5455..d2e91c9 100644 --- a/Apollon.WPF/ViewModels/OverviewDetailsViewModel.cs +++ b/Apollon.WPF/ViewModels/OverviewDetailsViewModel.cs @@ -1,5 +1,6 @@ using Apollon.Domain.Models; using Apollon.WPF.Commands; +using Apollon.WPF.Services; using Apollon.WPF.Stores; using System; using System.Collections.Generic; @@ -35,7 +36,8 @@ namespace Apollon.WPF.ViewModels _selectedTournamentStore.SelectedTournamentChanged += SelectedTournamentStore_SelectedTournamentChanged; - NavigatePreparationCommand = new NavigateCommand(navigationStore, () => new GroupsViewModel(selectedTournamentStore, navigationStore, modalNavigationStore, tournamentsStore)); + NavigatePreparationCommand = new NavigateCommand(new NavigationService ( + navigationStore, () => new GroupsViewModel( _selectedTournamentStore, navigationStore, modalNavigationStore, tournamentsStore))); } protected override void Dispose() diff --git a/Apollon.WPF/ViewModels/OverviewViewModel.cs b/Apollon.WPF/ViewModels/OverviewViewModel.cs index 5006320..f38afc2 100644 --- a/Apollon.WPF/ViewModels/OverviewViewModel.cs +++ b/Apollon.WPF/ViewModels/OverviewViewModel.cs @@ -1,12 +1,7 @@ using Apollon.WPF.Commands; -using Apollon.Domain.Models; using Apollon.WPF.Stores; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; using System.Windows.Input; +using Apollon.WPF.Services; namespace Apollon.WPF.ViewModels { @@ -58,7 +53,8 @@ namespace Apollon.WPF.ViewModels LoadTournamentsCommand = new LoadTournamentsCommand(this, tournamentStore); OpenAddTournamentCommand = new OpenAddTournamentCommand(tournamentStore, modalNavigationStore, navigationStore, selectedTournamentStore); - NavigateNameListCommand = new NavigateCommand(navigationStore, () => new NameListViewModel()); + NavigateNameListCommand = new NavigateCommand(new NavigationService( + navigationStore, () => new NameListViewModel())); } diff --git a/Apollon.WPF/Views/ArchersView.xaml b/Apollon.WPF/Views/ArchersView.xaml index 96d9aff..2992830 100644 --- a/Apollon.WPF/Views/ArchersView.xaml +++ b/Apollon.WPF/Views/ArchersView.xaml @@ -3,10 +3,25 @@ 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:Apollon.WPF.Views" + xmlns:local="clr-namespace:Apollon.WPF.Views" xmlns:components="clr-namespace:Apollon.WPF.Views.Components" mc:Ignorable="d" - d:DesignHeight="450" d:DesignWidth="800"> - - + d:DesignHeight="680" d:DesignWidth="1100"> + + + + + + + + + + + + + + + diff --git a/Apollon.WPF/Views/ClassesView.xaml b/Apollon.WPF/Views/ClassesView.xaml index a33f8c4..1d5e42d 100644 --- a/Apollon.WPF/Views/ClassesView.xaml +++ b/Apollon.WPF/Views/ClassesView.xaml @@ -4,9 +4,26 @@ xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:local="clr-namespace:Apollon.WPF.Views" + xmlns:components="clr-namespace:Apollon.WPF.Views.Components" mc:Ignorable="d" - d:DesignHeight="450" d:DesignWidth="800"> - - + d:DesignHeight="680" d:DesignWidth="1100"> + + + + + + + + + + + + + + + + diff --git a/Apollon.WPF/Views/Components/NavBarPreparationView.xaml b/Apollon.WPF/Views/Components/NavBarPreparationView.xaml index 88dc0e3..e36540d 100644 --- a/Apollon.WPF/Views/Components/NavBarPreparationView.xaml +++ b/Apollon.WPF/Views/Components/NavBarPreparationView.xaml @@ -6,8 +6,12 @@ xmlns:local="clr-namespace:Apollon.WPF.Views.Components" xmlns:iconPacks="http://metro.mahapps.com/winfx/xaml/iconpacks" mc:Ignorable="d" - d:DesignHeight="450" d:DesignWidth="800"> + d:DesignHeight="680" d:DesignWidth="1100"> + + + + - + + - - - - - - + + + + + + + Margin="0 20"> + + + + - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Apollon.WPF/Views/Components/TournamentDetails.xaml b/Apollon.WPF/Views/Components/TournamentDetails.xaml index 271cb1d..ec5e921 100644 --- a/Apollon.WPF/Views/Components/TournamentDetails.xaml +++ b/Apollon.WPF/Views/Components/TournamentDetails.xaml @@ -5,8 +5,8 @@ xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:local="clr-namespace:Apollon.WPF.Views.Components" mc:Ignorable="d" - d:DesignHeight="100" d:DesignWidth="800"> - + d:DesignHeight="680" d:DesignWidth="1100"> + @@ -14,7 +14,8 @@ @@ -81,6 +82,7 @@ diff --git a/Apollon.WPF/Views/GroupsView.xaml b/Apollon.WPF/Views/GroupsView.xaml index a147938..84b0275 100644 --- a/Apollon.WPF/Views/GroupsView.xaml +++ b/Apollon.WPF/Views/GroupsView.xaml @@ -3,34 +3,25 @@ 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:components="clr-namespace:Apollon.WPF.Views.Components" - xmlns:iconPacks="http://metro.mahapps.com/winfx/xaml/iconpacks" - xmlns:local="clr-namespace:Apollon.WPF.Views" + xmlns:components="clr-namespace:Apollon.WPF.Views.Components" mc:Ignorable="d" - d:DesignHeight="450" d:DesignWidth="800"> - - - + d:DesignHeight="680" d:DesignWidth="1100"> + - - + + - + - - - - - - - - - - + + + + + +