Finish LoadingSpinner

This commit is contained in:
Natlinux81
2022-08-28 01:58:33 +02:00
parent 7fe2fd08ea
commit dfe0f72d04
20 changed files with 181 additions and 85 deletions

View File

@@ -11,7 +11,6 @@ using System.Threading.Tasks;
namespace Apollon.EntityFramework.Commands namespace Apollon.EntityFramework.Commands
{ {
public class CreateTournamentCommand : ICreateTournamentCommand public class CreateTournamentCommand : ICreateTournamentCommand
{ {
private readonly TournamentsDbContextFactory _contextFactory; private readonly TournamentsDbContextFactory _contextFactory;

View File

@@ -13,7 +13,6 @@ namespace Apollon.EntityFramework
public TournamentsDbContext(DbContextOptions options) : base(options) public TournamentsDbContext(DbContextOptions options) : base(options)
{ {
} }
public DbSet<TournamentDto> Tournaments { get; set; } public DbSet<TournamentDto> Tournaments { get; set; }
} }
} }

View File

@@ -8,6 +8,7 @@
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
<PackageReference Include="LoadingSpinner.WPF" Version="1.0.0" />
<PackageReference Include="MahApps.Metro.IconPacks.Material" Version="4.11.0" /> <PackageReference Include="MahApps.Metro.IconPacks.Material" Version="4.11.0" />
<PackageReference Include="SimpleModal.WPF" Version="1.0.0" /> <PackageReference Include="SimpleModal.WPF" Version="1.0.0" />
</ItemGroup> </ItemGroup>

View File

@@ -32,7 +32,6 @@ namespace Apollon.WPF
private readonly TournamentsStore _tournamentStore; private readonly TournamentsStore _tournamentStore;
private readonly SelectedTournamentsStore _selectedTournamentStore; private readonly SelectedTournamentsStore _selectedTournamentStore;
public App() public App()
{ {
string connectionString = "Server=NATHALIE-PC\\NATLINUXDB;Database=Apollon;Trusted_Connection=True;MultipleActiveResultSets=true"; string connectionString = "Server=NATHALIE-PC\\NATLINUXDB;Database=Apollon;Trusted_Connection=True;MultipleActiveResultSets=true";
@@ -61,10 +60,10 @@ namespace Apollon.WPF
_tournamentStore, _tournamentStore,
_navigationStore); _navigationStore);
_navigationStore.CurrentViewModel = new OverviewViewModel( _navigationStore.CurrentViewModel = OverviewViewModel.LoadViewModel(
_tournamentStore,
_selectedTournamentStore, _selectedTournamentStore,
_modalNavigationStore, _modalNavigationStore,
_tournamentStore,
_navigationStore); _navigationStore);
MainWindow = new MainWindow() MainWindow = new MainWindow()

View File

@@ -15,7 +15,6 @@ namespace Apollon.WPF.Commands
private readonly ModalNavigationStore _modalNavigationStore; private readonly ModalNavigationStore _modalNavigationStore;
private AddTournamentViewModel _addTournamentViewModel; private AddTournamentViewModel _addTournamentViewModel;
public AddTournamentCommand(TournamentsStore tournamentStore, ModalNavigationStore modalNavigationStore) public AddTournamentCommand(TournamentsStore tournamentStore, ModalNavigationStore modalNavigationStore)
{ {
_tournamentStore = tournamentStore; _tournamentStore = tournamentStore;
@@ -32,6 +31,9 @@ namespace Apollon.WPF.Commands
public override async Task ExecuteAsync(object parameter) public override async Task ExecuteAsync(object parameter)
{ {
AddEditDetailsViewModel detailsViewModel = _addTournamentViewModel.AddEditDetailsViewModel; AddEditDetailsViewModel detailsViewModel = _addTournamentViewModel.AddEditDetailsViewModel;
detailsViewModel.IsSubmitting = true;
Tournament tournament = new Tournament( Tournament tournament = new Tournament(
Guid.NewGuid(), Guid.NewGuid(),
detailsViewModel.Organisation, detailsViewModel.Organisation,
@@ -51,9 +53,12 @@ namespace Apollon.WPF.Commands
} }
catch (Exception) catch (Exception)
{ {
throw; throw;
} }
finally
{
detailsViewModel.IsSubmitting = false;
}
} }
} }
} }

View File

@@ -8,13 +8,35 @@ namespace Apollon.WPF.Commands
{ {
public abstract class AsyncCommandBase : CommandBase 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) public override async void Execute(object parameter)
{ {
IsExecuting = true;
try try
{ {
await ExecuteAsync(parameter); await ExecuteAsync(parameter);
} }
catch (Exception) { } catch (Exception) { }
finally
{
IsExecuting = false;
}
} }
public abstract Task ExecuteAsync(object parameter); public abstract Task ExecuteAsync(object parameter);
} }

View File

@@ -14,16 +14,25 @@ namespace Apollon.WPF.Commands
private readonly OverviewListingItemViewModel _overviewListingItemViewModel; private readonly OverviewListingItemViewModel _overviewListingItemViewModel;
private readonly TournamentsStore _tournamentStore; private readonly TournamentsStore _tournamentStore;
private readonly ModalNavigationStore _modalNavigationStore; 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; _overviewListingItemViewModel = overviewListingItemViewModel;
_tournamentStore = tournamentStore; _tournamentStore = tournamentsStore;
_modalNavigationStore = modalNavigationStore; _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) public override async Task ExecuteAsync(object parameter)
{ {
_warningDeleteViewModel.IsDeleting = true;
Tournament tournament = _overviewListingItemViewModel.Tournament; Tournament tournament = _overviewListingItemViewModel.Tournament;
try try
@@ -36,6 +45,11 @@ namespace Apollon.WPF.Commands
{ {
throw; throw;
} }
finally
{
_warningDeleteViewModel.IsDeleting = false;
}
} }
} }
} }

View File

@@ -25,6 +25,9 @@ namespace Apollon.WPF.Commands
public override async Task ExecuteAsync(object parameter) public override async Task ExecuteAsync(object parameter)
{ {
AddEditDetailsViewModel detailsViewModel = _editTournamentViewModel.AddEditDetailsViewModel; AddEditDetailsViewModel detailsViewModel = _editTournamentViewModel.AddEditDetailsViewModel;
detailsViewModel.IsSubmitting = true;
Tournament tournament = new Tournament( Tournament tournament = new Tournament(
_editTournamentViewModel.TournamentId, _editTournamentViewModel.TournamentId,
detailsViewModel.Organisation, detailsViewModel.Organisation,
@@ -46,6 +49,10 @@ namespace Apollon.WPF.Commands
throw; throw;
} }
finally
{
detailsViewModel.IsSubmitting = false;
}
} }
} }
} }

View File

@@ -24,7 +24,6 @@ namespace Apollon.WPF.Commands
public override void Execute(object parameter) public override void Execute(object parameter)
{ {
Tournament tournament =_overviewListingItemViewModel.Tournament;
WarningDeleteViewModel warningDeleteViewModel = new WarningDeleteViewModel(_modalNavigationStore,_tournamentsStore,_overviewListingItemViewModel); WarningDeleteViewModel warningDeleteViewModel = new WarningDeleteViewModel(_modalNavigationStore,_tournamentsStore,_overviewListingItemViewModel);
_modalNavigationStore.CurrentViewModel = warningDeleteViewModel; _modalNavigationStore.CurrentViewModel = warningDeleteViewModel;
} }

View File

@@ -23,7 +23,6 @@ namespace Apollon.WPF.ViewModels
} }
} }
private string _tournamentName; private string _tournamentName;
public string TournamentName public string TournamentName
{ {
@@ -54,9 +53,6 @@ namespace Apollon.WPF.ViewModels
} }
private DateTime _startDate = DateTime.Today; private DateTime _startDate = DateTime.Today;
public DateTime StartDate public DateTime StartDate
{ {
@@ -115,6 +111,20 @@ namespace Apollon.WPF.ViewModels
} }
} }
private bool _isSubmitting;
public bool IsSubmitting
{
get
{
return _isSubmitting;
}
set
{
_isSubmitting = value;
OnPropertyChanged(nameof(IsSubmitting));
}
}
public bool CanSubmit => !string.IsNullOrEmpty(TournamentName); public bool CanSubmit => !string.IsNullOrEmpty(TournamentName);
public ICommand SubmitCommand { get; } public ICommand SubmitCommand { get; }
@@ -127,6 +137,4 @@ namespace Apollon.WPF.ViewModels
} }
} }
} }

View File

@@ -17,17 +17,14 @@ namespace Apollon.WPF.ViewModels
public bool IsModalOpen => _modalNavigationStore.IsOpen; public bool IsModalOpen => _modalNavigationStore.IsOpen;
public OverviewViewModel OverviewViewModel { get; } public OverviewViewModel OverviewViewModel { get; }
public MainViewModel(ModalNavigationStore modalNavigationStore, OverviewViewModel overviewViewModel, NavigationStore navigationStore) public MainViewModel(ModalNavigationStore modalNavigationStore, OverviewViewModel overviewViewModel, NavigationStore navigationStore)
{ {
_navigationStore = navigationStore; _navigationStore = navigationStore;
_modalNavigationStore = modalNavigationStore; _modalNavigationStore = modalNavigationStore;
OverviewViewModel = overviewViewModel; OverviewViewModel = overviewViewModel;
_navigationStore.CurrentViewModelChanged += NavigationStore_CurrentViewModelChanged; _navigationStore.CurrentViewModelChanged += NavigationStore_CurrentViewModelChanged;
_modalNavigationStore.CurrentViewModelChanged += ModalNavigationStore_CurrentViewModelChanged; _modalNavigationStore.CurrentViewModelChanged += ModalNavigationStore_CurrentViewModelChanged;
} }
protected override void Dispose() protected override void Dispose()
@@ -45,7 +42,6 @@ namespace Apollon.WPF.ViewModels
{ {
OnPropertyChanged(nameof(CurrentModalViewModel)); OnPropertyChanged(nameof(CurrentModalViewModel));
OnPropertyChanged(nameof(IsModalOpen)); OnPropertyChanged(nameof(IsModalOpen));
} }
} }
} }

View File

@@ -11,7 +11,6 @@ namespace Apollon.WPF.ViewModels
public class OverviewDetailsViewModel : ViewModelBase public class OverviewDetailsViewModel : ViewModelBase
{ {
private readonly SelectedTournamentsStore _selectedTournamentStore; private readonly SelectedTournamentsStore _selectedTournamentStore;
private Tournament SelectedTournament => _selectedTournamentStore.SelectedTournament; private Tournament SelectedTournament => _selectedTournamentStore.SelectedTournament;
public bool HasSelectedTournament => SelectedTournament != null; public bool HasSelectedTournament => SelectedTournament != null;

View File

@@ -33,7 +33,6 @@ namespace Apollon.WPF.ViewModels
} }
} }
public OverviewListingViewModel(SelectedTournamentsStore selectedTournamentStore, ModalNavigationStore modalNavigationStore, TournamentsStore tournamentStore) public OverviewListingViewModel(SelectedTournamentsStore selectedTournamentStore, ModalNavigationStore modalNavigationStore, TournamentsStore tournamentStore)
{ {
_tournamentStore = tournamentStore; _tournamentStore = tournamentStore;

View File

@@ -20,7 +20,7 @@ namespace Apollon.WPF.ViewModels
{ {
get get
{ {
return IsLoading; return _isLoading;
} }
set set
{ {

View File

@@ -11,12 +11,25 @@ namespace Apollon.WPF.ViewModels
{ {
public class WarningDeleteViewModel : ViewModelBase public class WarningDeleteViewModel : ViewModelBase
{ {
private bool _isDeleting;
public bool IsDeleting
{
get
{
return _isDeleting;
}
set
{
_isDeleting = value;
OnPropertyChanged(nameof(IsDeleting));
}
}
public ICommand WarningCloseCommand { get;} public ICommand WarningCloseCommand { get;}
public ICommand DeleteCommand { get; } public ICommand DeleteCommand { get; }
public WarningDeleteViewModel(ModalNavigationStore modalNavigationStore,TournamentsStore tournamentsStore, OverviewListingItemViewModel overviewListingItemViewModel) public WarningDeleteViewModel(ModalNavigationStore modalNavigationStore,TournamentsStore tournamentsStore, OverviewListingItemViewModel overviewListingItemViewModel)
{ {
WarningCloseCommand = new CloseModalCommand(modalNavigationStore); WarningCloseCommand = new CloseModalCommand(modalNavigationStore);
DeleteCommand = new DeleteTournamentCommand(overviewListingItemViewModel, tournamentsStore, modalNavigationStore); DeleteCommand = new DeleteTournamentCommand(this, overviewListingItemViewModel, tournamentsStore, modalNavigationStore);
} }
} }
} }

View File

@@ -4,6 +4,7 @@
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 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"> mc:Ignorable="d">
<Grid> <Grid>
<Grid.RowDefinitions> <Grid.RowDefinitions>
@@ -133,6 +134,7 @@
HorizontalAlignment="Center"> HorizontalAlignment="Center">
<Grid.ColumnDefinitions> <Grid.ColumnDefinitions>
<ColumnDefinition/> <ColumnDefinition/>
<ColumnDefinition Width="35"/>
<ColumnDefinition/> <ColumnDefinition/>
</Grid.ColumnDefinitions> </Grid.ColumnDefinitions>
@@ -150,7 +152,12 @@
Width="120" Width="120"
Height="35" Height="35"
FontSize="16" FontSize="16"
Grid.Column="1"/> Grid.Column="2"/>
<custom:LoadingSpinner Grid.Column="1"
Diameter="25"
Thickness="2"
Color="{StaticResource BrushPrimary1}"
IsLoading="{Binding IsSubmitting}"/>
</Grid> </Grid>
</Grid> </Grid>
</UserControl> </UserControl>

View File

@@ -66,14 +66,10 @@
Foreground="Red"/> Foreground="Red"/>
</Button> </Button>
</WrapPanel> </WrapPanel>
</Grid> </Grid>
</DataTemplate> </DataTemplate>
</ListView.ItemTemplate> </ListView.ItemTemplate>
</ListView> </ListView>
</Border> </Border>
</Grid> </Grid>
</UserControl> </UserControl>

View File

@@ -5,6 +5,7 @@
xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 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" xmlns:components="clr-namespace:Apollon.WPF.Views.Components"
xmlns:custom="clr-namespace:LoadingSpinnerControl;assembly=LoadingSpinnerControl"
mc:Ignorable="d" mc:Ignorable="d"
d:DesignHeight="680" d:DesignWidth="1080" d:DesignHeight="680" d:DesignWidth="1080"
Background="Transparent"> Background="Transparent">
@@ -20,19 +21,6 @@
<ColumnDefinition/> <ColumnDefinition/>
</Grid.ColumnDefinitions> </Grid.ColumnDefinitions>
<!--<Border BorderThickness="4"
BorderBrush="#0000a0"
CornerRadius="5"
Grid.RowSpan="2"
Grid.ColumnSpan="3">
<Border.Background>
<LinearGradientBrush StartPoint="0.5,0" EndPoint="0.5,1">
<GradientStop Color="{StaticResource ColorPrimary4}" Offset="0.2"/>
<GradientStop Color="{StaticResource ColorPrimary5}" Offset="0.8"/>
</LinearGradientBrush>
</Border.Background>
</Border>-->
<StackPanel Grid.ColumnSpan="3"> <StackPanel Grid.ColumnSpan="3">
<TextBlock <TextBlock
Text="Apollon" Text="Apollon"
@@ -76,9 +64,10 @@
Command="{Binding AddTournamentCommand}"/> Command="{Binding AddTournamentCommand}"/>
</StackPanel> </StackPanel>
<StackPanel Grid.Column="1" <Grid Grid.Column="1"
Grid.Row="1" Grid.Row="1"
Margin="20"> Margin="20">
<StackPanel>
<TextBlock Margin="20" <TextBlock Margin="20"
Text="Liste der erstellten Turniere" Text="Liste der erstellten Turniere"
@@ -88,15 +77,49 @@
FontSize="16" FontSize="16"
Foreground="{StaticResource BrushPrimary1}"/> Foreground="{StaticResource BrushPrimary1}"/>
<components:OverViewListing Height="400" <components:OverViewListing Height="400"
Width="400" Width="400"
DataContext="{Binding OverviewListingViewModel}"/> DataContext="{Binding OverviewListingViewModel}"/>
</StackPanel>
<StackPanel Grid.Column="2"
</StackPanel>
<StackPanel VerticalAlignment="Center">
<StackPanel.Style>
<Style TargetType="StackPanel">
<Setter Property="Visibility" Value="Collapsed"/>
<Style.Triggers>
<DataTrigger Binding="{Binding IsLoading}" Value="true">
<Setter Property="Visibility" Value="Visible"/>
</DataTrigger>
</Style.Triggers>
</Style>
</StackPanel.Style>
<TextBlock Text="Daten werden geladen...."
TextAlignment="Center"
VerticalAlignment="Center"
Foreground="{StaticResource BrushPrimary1}"
Margin="0 0 0 30"
FontSize="14">
</TextBlock>
<custom:LoadingSpinner Diameter="50" IsLoading="True" Thickness="3" Color="{StaticResource BrushPrimary1}"/>
</StackPanel>
</Grid>
<Grid Grid.Column="2"
Grid.Row="1" Grid.Row="1"
VerticalAlignment="Center"> VerticalAlignment="Center">
<Grid.Style>
<Style TargetType="Grid">
<Setter Property="Visibility" Value="Hidden"/>
<Style.Triggers>
<DataTrigger Binding="{Binding IsLoading}" Value="false">
<Setter Property="Visibility" Value="Visible"/>
</DataTrigger>
</Style.Triggers>
</Style>
</Grid.Style>
<StackPanel>
<TextBlock Margin="20" <TextBlock Margin="20"
Text="Turnieredetails" Text="Turnieredetails"
TextAlignment="Center" TextAlignment="Center"
@@ -104,6 +127,7 @@
FontWeight="Bold" FontWeight="Bold"
FontSize="16" FontSize="16"
Foreground="{StaticResource BrushPrimary1}"/> Foreground="{StaticResource BrushPrimary1}"/>
<components:OverviewDetails Width="320" <components:OverviewDetails Width="320"
DataContext="{Binding OverviewDetailsViewModel}"/> DataContext="{Binding OverviewDetailsViewModel}"/>
@@ -116,6 +140,8 @@
Cursor="Hand" Cursor="Hand"
Command="{Binding NavigateNavBarCommand}"/> Command="{Binding NavigateNavBarCommand}"/>
</StackPanel> </StackPanel>
</Grid>
</Grid> </Grid>
</UserControl> </UserControl>

View File

@@ -4,6 +4,7 @@
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:Apollon.WPF.Views" xmlns:local="clr-namespace:Apollon.WPF.Views"
xmlns:custom="clr-namespace:LoadingSpinnerControl;assembly=LoadingSpinnerControl"
mc:Ignorable="d" mc:Ignorable="d"
d:DesignHeight="450" d:DesignWidth="800"> d:DesignHeight="450" d:DesignWidth="800">
<Grid> <Grid>
@@ -25,6 +26,7 @@
<Grid> <Grid>
<Grid.ColumnDefinitions> <Grid.ColumnDefinitions>
<ColumnDefinition/> <ColumnDefinition/>
<ColumnDefinition Width="35"/>
<ColumnDefinition/> <ColumnDefinition/>
</Grid.ColumnDefinitions> </Grid.ColumnDefinitions>
<Button Grid.Column="0" <Button Grid.Column="0"
@@ -36,13 +38,18 @@
FontSize="14" FontSize="14"
/> />
<Button Grid.Column="1" <Button Grid.Column="2"
Content="Abbrechen" Content="Abbrechen"
Command="{Binding WarningCloseCommand}" Command="{Binding WarningCloseCommand}"
Style="{StaticResource ModernButton}" Style="{StaticResource ModernButton}"
Width="100" Width="100"
Height="30" Height="30"
FontSize="14"/> FontSize="14"/>
<custom:LoadingSpinner Grid.Column="1"
Diameter="25"
Thickness="2"
Color="{StaticResource BrushPrimary1}"
IsLoading="{Binding IsDeleting}"/>
</Grid> </Grid>
</StackPanel> </StackPanel>
</Grid> </Grid>