From dfe0f72d04d27aac950ca592b1aeeecad249459a Mon Sep 17 00:00:00 2001 From: Natlinux81 <97396587+Natlinux81@users.noreply.github.com> Date: Sun, 28 Aug 2022 01:58:33 +0200 Subject: [PATCH] Finish LoadingSpinner --- .../Commands/CreateTournamentCommand.cs | 3 +- .../Commands/UpdateTournamentCommand.cs | 2 +- .../TournamentsDBContext.cs | 1 - Apollon.WPF/Apollon.WPF.csproj | 1 + Apollon.WPF/App.xaml.cs | 7 +- Apollon.WPF/Commands/AddTournamentCommand.cs | 13 ++- Apollon.WPF/Commands/AsyncCommandBase.cs | 24 ++++- .../Commands/DeleteTournamentCommand.cs | 24 +++-- Apollon.WPF/Commands/EditTournamentCommand.cs | 7 ++ .../Commands/OpenWarningDeleteCommand.cs | 3 +- .../ViewModels/AddEditDetailsViewModel.cs | 28 +++--- Apollon.WPF/ViewModels/MainViewModel.cs | 10 +-- .../ViewModels/OverviewDetailsViewModel.cs | 1 - .../ViewModels/OverviewListingViewModel.cs | 1 - Apollon.WPF/ViewModels/OverviewViewModel.cs | 2 +- .../ViewModels/WarningDeleteViewModel.cs | 17 +++- .../Views/Components/AddEditDetails.xaml | 11 ++- .../Views/Components/OverViewListing.xaml | 10 +-- Apollon.WPF/Views/OverviewView.xaml | 90 ++++++++++++------- Apollon.WPF/Views/WarningDeleteView.xaml | 11 ++- 20 files changed, 181 insertions(+), 85 deletions(-) diff --git a/Apollon.EntityFramework/Commands/CreateTournamentCommand.cs b/Apollon.EntityFramework/Commands/CreateTournamentCommand.cs index 3c3a3f9..8f92275 100644 --- a/Apollon.EntityFramework/Commands/CreateTournamentCommand.cs +++ b/Apollon.EntityFramework/Commands/CreateTournamentCommand.cs @@ -11,7 +11,6 @@ using System.Threading.Tasks; namespace Apollon.EntityFramework.Commands { public class CreateTournamentCommand : ICreateTournamentCommand - { private readonly TournamentsDbContextFactory _contextFactory; @@ -23,7 +22,7 @@ namespace Apollon.EntityFramework.Commands public async Task Execute(Tournament tournament) { using (TournamentsDbContext context = _contextFactory.Create()) - { + { TournamentDto tournamentDto = new TournamentDto() { Id = tournament.Id, diff --git a/Apollon.EntityFramework/Commands/UpdateTournamentCommand.cs b/Apollon.EntityFramework/Commands/UpdateTournamentCommand.cs index e90567f..a46473e 100644 --- a/Apollon.EntityFramework/Commands/UpdateTournamentCommand.cs +++ b/Apollon.EntityFramework/Commands/UpdateTournamentCommand.cs @@ -21,7 +21,7 @@ namespace Apollon.EntityFramework.Commands public async Task Execute(Tournament tournament) { using (TournamentsDbContext context = _contextFactory.Create()) - { + { TournamentDto tournamentDto = new TournamentDto() { Id = tournament.Id, diff --git a/Apollon.EntityFramework/TournamentsDBContext.cs b/Apollon.EntityFramework/TournamentsDBContext.cs index 4db141f..a439d8a 100644 --- a/Apollon.EntityFramework/TournamentsDBContext.cs +++ b/Apollon.EntityFramework/TournamentsDBContext.cs @@ -13,7 +13,6 @@ namespace Apollon.EntityFramework public TournamentsDbContext(DbContextOptions options) : base(options) { } - public DbSet Tournaments { get; set; } } } diff --git a/Apollon.WPF/Apollon.WPF.csproj b/Apollon.WPF/Apollon.WPF.csproj index 6f15bfc..06af9ed 100644 --- a/Apollon.WPF/Apollon.WPF.csproj +++ b/Apollon.WPF/Apollon.WPF.csproj @@ -8,6 +8,7 @@ + diff --git a/Apollon.WPF/App.xaml.cs b/Apollon.WPF/App.xaml.cs index e71b1c0..691574c 100644 --- a/Apollon.WPF/App.xaml.cs +++ b/Apollon.WPF/App.xaml.cs @@ -30,8 +30,7 @@ namespace Apollon.WPF private readonly IUpdateTournamentCommand _updateTournamentCommand; private readonly IDeleteTournamentCommand _deleteTournamentCommand; private readonly TournamentsStore _tournamentStore; - private readonly SelectedTournamentsStore _selectedTournamentStore; - + private readonly SelectedTournamentsStore _selectedTournamentStore; public App() { @@ -61,10 +60,10 @@ namespace Apollon.WPF _tournamentStore, _navigationStore); - _navigationStore.CurrentViewModel = new OverviewViewModel( - _tournamentStore, + _navigationStore.CurrentViewModel = OverviewViewModel.LoadViewModel( _selectedTournamentStore, _modalNavigationStore, + _tournamentStore, _navigationStore); MainWindow = new MainWindow() diff --git a/Apollon.WPF/Commands/AddTournamentCommand.cs b/Apollon.WPF/Commands/AddTournamentCommand.cs index bf6ce4c..26230be 100644 --- a/Apollon.WPF/Commands/AddTournamentCommand.cs +++ b/Apollon.WPF/Commands/AddTournamentCommand.cs @@ -13,8 +13,7 @@ namespace Apollon.WPF.Commands { private readonly TournamentsStore _tournamentStore; private readonly ModalNavigationStore _modalNavigationStore; - private AddTournamentViewModel _addTournamentViewModel; - + private AddTournamentViewModel _addTournamentViewModel; public AddTournamentCommand(TournamentsStore tournamentStore, ModalNavigationStore modalNavigationStore) { @@ -32,6 +31,9 @@ namespace Apollon.WPF.Commands public override async Task ExecuteAsync(object parameter) { AddEditDetailsViewModel detailsViewModel = _addTournamentViewModel.AddEditDetailsViewModel; + + detailsViewModel.IsSubmitting = true; + Tournament tournament = new Tournament( Guid.NewGuid(), detailsViewModel.Organisation, @@ -51,9 +53,12 @@ namespace Apollon.WPF.Commands } catch (Exception) { - throw; - } + } + finally + { + detailsViewModel.IsSubmitting = false; + } } } } diff --git a/Apollon.WPF/Commands/AsyncCommandBase.cs b/Apollon.WPF/Commands/AsyncCommandBase.cs index abdf4b6..0fae089 100644 --- a/Apollon.WPF/Commands/AsyncCommandBase.cs +++ b/Apollon.WPF/Commands/AsyncCommandBase.cs @@ -8,13 +8,35 @@ namespace Apollon.WPF.Commands { public abstract class AsyncCommandBase : CommandBase { + private bool _isExecuring; + public bool IsExecuting + { + get + { + return _isExecuring; + } + set + { + _isExecuring = value; + OnCanExecutedChanged(); + } + } + public override bool CanExecute(object parameter) + { + return !IsExecuting && base.CanExecute(parameter); + } public override async void Execute(object parameter) { + IsExecuting = true; try { await ExecuteAsync(parameter); } - catch (Exception) { } + catch (Exception) { } + finally + { + IsExecuting = false; + } } public abstract Task ExecuteAsync(object parameter); } diff --git a/Apollon.WPF/Commands/DeleteTournamentCommand.cs b/Apollon.WPF/Commands/DeleteTournamentCommand.cs index e8e8ada..11eef16 100644 --- a/Apollon.WPF/Commands/DeleteTournamentCommand.cs +++ b/Apollon.WPF/Commands/DeleteTournamentCommand.cs @@ -10,20 +10,29 @@ using System.Threading.Tasks; namespace Apollon.WPF.Commands { public class DeleteTournamentCommand : AsyncCommandBase - { + { private readonly OverviewListingItemViewModel _overviewListingItemViewModel; private readonly TournamentsStore _tournamentStore; private readonly ModalNavigationStore _modalNavigationStore; + private readonly WarningDeleteViewModel _warningDeleteViewModel; - public DeleteTournamentCommand(OverviewListingItemViewModel overviewListingItemViewModel, TournamentsStore tournamentStore, ModalNavigationStore modalNavigationStore) + public DeleteTournamentCommand(WarningDeleteViewModel warningDeleteViewModel, OverviewListingItemViewModel overviewListingItemViewModel, TournamentsStore tournamentsStore, ModalNavigationStore modalNavigationStore) { + _warningDeleteViewModel = warningDeleteViewModel; _overviewListingItemViewModel = overviewListingItemViewModel; - _tournamentStore = tournamentStore; + _tournamentStore = tournamentsStore; _modalNavigationStore = modalNavigationStore; } - + + public OverviewListingItemViewModel OverviewListingItemViewModel { get; } + public TournamentsStore TournamentsStore { get; } + public ModalNavigationStore ModalNavigationStore { get; } + public WarningDeleteViewModel WarningDeleteViewModel { get; } + public override async Task ExecuteAsync(object parameter) { + _warningDeleteViewModel.IsDeleting = true; + Tournament tournament = _overviewListingItemViewModel.Tournament; try @@ -35,7 +44,12 @@ namespace Apollon.WPF.Commands catch (Exception) { throw; - } + } + finally + { + _warningDeleteViewModel.IsDeleting = false; + + } } } } diff --git a/Apollon.WPF/Commands/EditTournamentCommand.cs b/Apollon.WPF/Commands/EditTournamentCommand.cs index f36c4ef..aea09c3 100644 --- a/Apollon.WPF/Commands/EditTournamentCommand.cs +++ b/Apollon.WPF/Commands/EditTournamentCommand.cs @@ -25,6 +25,9 @@ namespace Apollon.WPF.Commands public override async Task ExecuteAsync(object parameter) { AddEditDetailsViewModel detailsViewModel = _editTournamentViewModel.AddEditDetailsViewModel; + + detailsViewModel.IsSubmitting = true; + Tournament tournament = new Tournament( _editTournamentViewModel.TournamentId, detailsViewModel.Organisation, @@ -46,6 +49,10 @@ namespace Apollon.WPF.Commands throw; } + finally + { + detailsViewModel.IsSubmitting = false; + } } } } diff --git a/Apollon.WPF/Commands/OpenWarningDeleteCommand.cs b/Apollon.WPF/Commands/OpenWarningDeleteCommand.cs index b66980e..9a67bc6 100644 --- a/Apollon.WPF/Commands/OpenWarningDeleteCommand.cs +++ b/Apollon.WPF/Commands/OpenWarningDeleteCommand.cs @@ -10,7 +10,7 @@ using System.Threading.Tasks; namespace Apollon.WPF.Commands { public class OpenWarningDeleteCommand : CommandBase - { + { private readonly OverviewListingItemViewModel _overviewListingItemViewModel; private readonly ModalNavigationStore _modalNavigationStore; private readonly TournamentsStore _tournamentsStore; @@ -24,7 +24,6 @@ namespace Apollon.WPF.Commands public override void Execute(object parameter) { - Tournament tournament =_overviewListingItemViewModel.Tournament; WarningDeleteViewModel warningDeleteViewModel = new WarningDeleteViewModel(_modalNavigationStore,_tournamentsStore,_overviewListingItemViewModel); _modalNavigationStore.CurrentViewModel = warningDeleteViewModel; } diff --git a/Apollon.WPF/ViewModels/AddEditDetailsViewModel.cs b/Apollon.WPF/ViewModels/AddEditDetailsViewModel.cs index b7c97ff..4ec5ada 100644 --- a/Apollon.WPF/ViewModels/AddEditDetailsViewModel.cs +++ b/Apollon.WPF/ViewModels/AddEditDetailsViewModel.cs @@ -21,8 +21,7 @@ namespace Apollon.WPF.ViewModels _organisation = value; OnPropertyChanged(nameof(Organisation)); } - } - + } private string _tournamentName; public string TournamentName @@ -53,10 +52,7 @@ namespace Apollon.WPF.ViewModels } } - private DateTime _startDate = DateTime.Today; - - - + private DateTime _startDate = DateTime.Today; public DateTime StartDate { @@ -115,7 +111,21 @@ namespace Apollon.WPF.ViewModels } } - public bool CanSubmit => !string.IsNullOrEmpty(TournamentName); + private bool _isSubmitting; + public bool IsSubmitting + { + get + { + return _isSubmitting; + } + set + { + _isSubmitting = value; + OnPropertyChanged(nameof(IsSubmitting)); + } + } + + public bool CanSubmit => !string.IsNullOrEmpty(TournamentName); public ICommand SubmitCommand { get; } public ICommand CancelCommand { get; } @@ -125,8 +135,6 @@ namespace Apollon.WPF.ViewModels SubmitCommand = submitCommand; CancelCommand = cancelCommand; } - } - - + } } diff --git a/Apollon.WPF/ViewModels/MainViewModel.cs b/Apollon.WPF/ViewModels/MainViewModel.cs index d03b352..fd2f0b6 100644 --- a/Apollon.WPF/ViewModels/MainViewModel.cs +++ b/Apollon.WPF/ViewModels/MainViewModel.cs @@ -15,19 +15,16 @@ namespace Apollon.WPF.ViewModels public ViewModelBase CurrentModalViewModel => _modalNavigationStore.CurrentViewModel; public ViewModelBase CurrentViewModel => _navigationStore.CurrentViewModel; public bool IsModalOpen => _modalNavigationStore.IsOpen; - public OverviewViewModel OverviewViewModel { get; } - + public OverviewViewModel OverviewViewModel { get; } public MainViewModel(ModalNavigationStore modalNavigationStore, OverviewViewModel overviewViewModel, NavigationStore navigationStore) { _navigationStore = navigationStore; _modalNavigationStore = modalNavigationStore; - OverviewViewModel = overviewViewModel; - + OverviewViewModel = overviewViewModel; _navigationStore.CurrentViewModelChanged += NavigationStore_CurrentViewModelChanged; - _modalNavigationStore.CurrentViewModelChanged += ModalNavigationStore_CurrentViewModelChanged; - + _modalNavigationStore.CurrentViewModelChanged += ModalNavigationStore_CurrentViewModelChanged; } protected override void Dispose() @@ -45,7 +42,6 @@ namespace Apollon.WPF.ViewModels { OnPropertyChanged(nameof(CurrentModalViewModel)); OnPropertyChanged(nameof(IsModalOpen)); - } } } diff --git a/Apollon.WPF/ViewModels/OverviewDetailsViewModel.cs b/Apollon.WPF/ViewModels/OverviewDetailsViewModel.cs index 57f0d88..6ee62bc 100644 --- a/Apollon.WPF/ViewModels/OverviewDetailsViewModel.cs +++ b/Apollon.WPF/ViewModels/OverviewDetailsViewModel.cs @@ -11,7 +11,6 @@ namespace Apollon.WPF.ViewModels public class OverviewDetailsViewModel : ViewModelBase { private readonly SelectedTournamentsStore _selectedTournamentStore; - private Tournament SelectedTournament => _selectedTournamentStore.SelectedTournament; public bool HasSelectedTournament => SelectedTournament != null; diff --git a/Apollon.WPF/ViewModels/OverviewListingViewModel.cs b/Apollon.WPF/ViewModels/OverviewListingViewModel.cs index b236f3a..81585cd 100644 --- a/Apollon.WPF/ViewModels/OverviewListingViewModel.cs +++ b/Apollon.WPF/ViewModels/OverviewListingViewModel.cs @@ -33,7 +33,6 @@ namespace Apollon.WPF.ViewModels } } - public OverviewListingViewModel(SelectedTournamentsStore selectedTournamentStore, ModalNavigationStore modalNavigationStore, TournamentsStore tournamentStore) { _tournamentStore = tournamentStore; diff --git a/Apollon.WPF/ViewModels/OverviewViewModel.cs b/Apollon.WPF/ViewModels/OverviewViewModel.cs index c88d71a..7689172 100644 --- a/Apollon.WPF/ViewModels/OverviewViewModel.cs +++ b/Apollon.WPF/ViewModels/OverviewViewModel.cs @@ -20,7 +20,7 @@ namespace Apollon.WPF.ViewModels { get { - return IsLoading; + return _isLoading; } set { diff --git a/Apollon.WPF/ViewModels/WarningDeleteViewModel.cs b/Apollon.WPF/ViewModels/WarningDeleteViewModel.cs index eb61a8a..c0745a6 100644 --- a/Apollon.WPF/ViewModels/WarningDeleteViewModel.cs +++ b/Apollon.WPF/ViewModels/WarningDeleteViewModel.cs @@ -11,12 +11,25 @@ namespace Apollon.WPF.ViewModels { public class WarningDeleteViewModel : ViewModelBase { - public ICommand WarningCloseCommand { get;} + private bool _isDeleting; + public bool IsDeleting + { + get + { + return _isDeleting; + } + set + { + _isDeleting = value; + OnPropertyChanged(nameof(IsDeleting)); + } + } + public ICommand WarningCloseCommand { get;} public ICommand DeleteCommand { get; } public WarningDeleteViewModel(ModalNavigationStore modalNavigationStore,TournamentsStore tournamentsStore, OverviewListingItemViewModel overviewListingItemViewModel) { WarningCloseCommand = new CloseModalCommand(modalNavigationStore); - DeleteCommand = new DeleteTournamentCommand(overviewListingItemViewModel, tournamentsStore, modalNavigationStore); + DeleteCommand = new DeleteTournamentCommand(this, overviewListingItemViewModel, tournamentsStore, modalNavigationStore); } } } diff --git a/Apollon.WPF/Views/Components/AddEditDetails.xaml b/Apollon.WPF/Views/Components/AddEditDetails.xaml index 411ed70..42c4f6d 100644 --- a/Apollon.WPF/Views/Components/AddEditDetails.xaml +++ b/Apollon.WPF/Views/Components/AddEditDetails.xaml @@ -3,7 +3,8 @@ 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.Components" + xmlns:local="clr-namespace:Apollon.WPF.Views.Components" + xmlns:custom="clr-namespace:LoadingSpinnerControl;assembly=LoadingSpinnerControl" mc:Ignorable="d"> @@ -133,6 +134,7 @@ HorizontalAlignment="Center"> + @@ -150,7 +152,12 @@ Width="120" Height="35" FontSize="16" - Grid.Column="1"/> + Grid.Column="2"/> + diff --git a/Apollon.WPF/Views/Components/OverViewListing.xaml b/Apollon.WPF/Views/Components/OverViewListing.xaml index f75aea2..c8fe435 100644 --- a/Apollon.WPF/Views/Components/OverViewListing.xaml +++ b/Apollon.WPF/Views/Components/OverViewListing.xaml @@ -65,15 +65,11 @@ Grid.Column="1" Foreground="Red"/> - - - - - + + - - + diff --git a/Apollon.WPF/Views/OverviewView.xaml b/Apollon.WPF/Views/OverviewView.xaml index 6be5df1..027c57f 100644 --- a/Apollon.WPF/Views/OverviewView.xaml +++ b/Apollon.WPF/Views/OverviewView.xaml @@ -4,7 +4,8 @@ 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" + xmlns:components="clr-namespace:Apollon.WPF.Views.Components" + xmlns:custom="clr-namespace:LoadingSpinnerControl;assembly=LoadingSpinnerControl" mc:Ignorable="d" d:DesignHeight="680" d:DesignWidth="1080" Background="Transparent"> @@ -18,20 +19,7 @@ - - - + - + @@ -75,39 +63,75 @@ Cursor="Hand" Command="{Binding AddTournamentCommand}"/> - - - - + + + - - - - - + + + + + + + + + + + - - + + + + - - -