Skip to content

Commit

Permalink
chore: refactor LoginView and enhance data loading
Browse files Browse the repository at this point in the history
Signed-off-by: Russell Camo <[email protected]>
  • Loading branch information
russkyc committed Aug 29, 2023
1 parent a6f838b commit bdb51a3
Show file tree
Hide file tree
Showing 13 changed files with 333 additions and 118 deletions.
8 changes: 8 additions & 0 deletions GroomWise.Application/Events/LoginEvent.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
// Copyright (C) 2023 Russell Camo (Russkyc).- All Rights Reserved
//
// Unauthorized copying or redistribution of all files, in source and binary forms via any medium
// without written, signed consent from the author is strictly prohibited.

namespace GroomWise.Application.Events;

public record LoginEvent();
6 changes: 3 additions & 3 deletions GroomWise.Application/Observables/ObservableCustomer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
// Unauthorized copying or redistribution of all files, in source and binary forms via any medium
// without written, signed consent from the author is strictly prohibited.

using System.Collections.ObjectModel;
using GroomWise.Domain.Entities;
using Lombok.NET;
using Swordfish.NET.Collections;

namespace GroomWise.Application.Observables;

Expand All @@ -28,8 +28,8 @@ public partial class ObservableCustomer
private string _email;

[Property(PropertyChangeType = PropertyChangeType.PropertyChanged)]
private ObservableCollection<Appointment> _appointments;
private ConcurrentObservableCollection<Appointment> _appointments = new();

[Property(PropertyChangeType = PropertyChangeType.PropertyChanged)]
private ObservableCollection<Pet> _pets;
private ConcurrentObservableCollection<Pet> _pets = new();
}
1 change: 1 addition & 0 deletions GroomWise.Application/ViewModels/AppViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ private async Task Logout()
await Task.Delay(300);
if (result.Equals(AuthenticationStatus.NotAuthenticated))
{
DialogService.CloseDialogs(NavigationService);
NavigationService.Navigate(AppViews.Login);
EventAggregator.Publish(new LogoutEvent());
}
Expand Down
41 changes: 40 additions & 1 deletion GroomWise.Application/ViewModels/DashboardViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,50 @@
// Unauthorized copying or redistribution of all files, in source and binary forms via any medium
// without written, signed consent from the author is strictly prohibited.

using GroomWise.Application.Events;
using GroomWise.Application.Mappers;
using GroomWise.Application.Observables;
using GroomWise.Infrastructure.Authentication.Interfaces;
using GroomWise.Infrastructure.Database;
using Injectio.Attributes;
using MvvmGen;
using MvvmGen.Events;
using Swordfish.NET.Collections;

namespace GroomWise.Application.ViewModels;

[ViewModel]
[RegisterSingleton]
public partial class DashboardViewModel { }
[Inject(typeof(IAuthenticationService))]
[Inject(typeof(GroomWiseDbContext))]
public partial class DashboardViewModel : IEventSubscriber<LoginEvent>
{
[Property]
private ConcurrentObservableCollection<ObservableAppointment> _appointments;

[Property]
private string _user;

partial void OnInitialize()
{
PopulateCollections();
}

private async void PopulateCollections()
{
await Task.Run(() =>
{
var appointments = GroomWiseDbContext.Appointments
.GetMultiple(appointment => appointment.Date >= DateTime.Today)
.Select(AppointmentMapper.ToObservable)
.OrderBy(appointment => appointment.Date)
.Take(10);
Appointments = new ConcurrentObservableCollection<ObservableAppointment>(appointments);
});
}

public void OnEvent(LoginEvent eventData)
{
User = AuthenticationService.GetSession()?.FirstName!;
}
}
2 changes: 2 additions & 0 deletions GroomWise.Application/ViewModels/LoginViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ namespace GroomWise.Application.ViewModels;

[ViewModel]
[ViewModelGenerateInterface]
[Inject(typeof(IEventAggregator))]
[Inject(typeof(INavigationService))]
[Inject(typeof(IAuthenticationService))]
[RegisterSingleton]
Expand Down Expand Up @@ -118,6 +119,7 @@ private async Task Login()
await Task.Delay(300);
Notifications.RemoveLast();
EventAggregator.Publish(new LoginEvent());
NavigationService.Navigate(AppViews.Main);
});
}
Expand Down
10 changes: 6 additions & 4 deletions GroomWise.WPF/App.xaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
<Application x:Class="GroomWise.App"
xmlns="http:https://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http:https://schemas.microsoft.com/winfx/2006/xaml"
ShutdownMode="OnExplicitShutdown">
<Application
x:Class="GroomWise.App"
xmlns="http:https://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http:https://schemas.microsoft.com/winfx/2006/xaml"
ShutdownMode="OnExplicitShutdown">
<Application.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
Expand All @@ -10,6 +11,7 @@
<ResourceDictionary Source="pack:https://application:,,,/Russkyc.ModernControls.WPF;component/Themes/BaseThemes/Light.xaml" />
<ResourceDictionary Source="pack:https://application:,,,/Russkyc.ModernControls.WPF;component/Themes/ColorThemes/Teal.xaml" />
<ResourceDictionary Source="pack:https://application:,,,/Russkyc.ModernControls.WPF;component/Themes/Generic.xaml" />
<ResourceDictionary Source="Views/Resources/Styles/ScrollbarStyles.xaml" />
<!-- Custom Styles -->
<ResourceDictionary Source="Views/Resources/Styles/WindowStyles.xaml" />
<ResourceDictionary Source="Views/Resources/Styles/TooltipStyles.xaml" />
Expand Down
5 changes: 5 additions & 0 deletions GroomWise.WPF/GroomWise.WPF.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,11 @@
<XamlRuntime>Wpf</XamlRuntime>
<SubType>Designer</SubType>
</Page>
<Page Update="Views\Resources\Styles\ScrollbarStyles.xaml">
<Generator>MSBuild:Compile</Generator>
<XamlRuntime>Wpf</XamlRuntime>
<SubType>Designer</SubType>
</Page>
</ItemGroup>

<ItemGroup>
Expand Down
24 changes: 12 additions & 12 deletions GroomWise.WPF/Views/Dialogs/LoginView.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@
x:Class="GroomWise.Views.Dialogs.LoginView"
xmlns="http:https://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http:https://schemas.microsoft.com/winfx/2006/xaml"
xmlns:b="http:https://schemas.microsoft.com/xaml/behaviors"
xmlns:d="http:https://schemas.microsoft.com/expression/blend/2008"
xmlns:dialogs="clr-namespace:GroomWise.Views.Dialogs"
xmlns:helpers="clr-namespace:org.russkyc.moderncontrols.Helpers;assembly=Russkyc.ModernControls.WPF"
xmlns:icons="clr-namespace:Material.Icons.WPF;assembly=Material.Icons.WPF"
xmlns:mc="http:https://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:russkyc="clr-namespace:org.russkyc.moderncontrols;assembly=Russkyc.ModernControls.WPF"
Expand Down Expand Up @@ -1152,19 +1153,18 @@
LeftIcon="{icons:MaterialIconExt Kind=User}"
Placeholder="Username"
Text="{Binding Username, UpdateSourceTrigger=PropertyChanged, ValidatesOnDataErrors=True}" />
<russkyc:ModernTextBox
<PasswordBox
x:Name="PasswordBox"
Margin="12,5,12,0"
CornerRadius="5"
HelperText="Required"
IsPasswordBox="True"
LeftIcon="{icons:MaterialIconExt Kind=Password}"
Placeholder="Password"
Text="{Binding Password, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}">
<russkyc:ModernTextBox.InputBindings>
<KeyBinding Key="Enter" Command="{Binding LoginCommand}" />
</russkyc:ModernTextBox.InputBindings>
</russkyc:ModernTextBox>
helpers:PasswordBoxHelper.CornerRadius="5"
helpers:PasswordBoxHelper.HelperText="Required"
helpers:PasswordBoxHelper.LeftIcon="{icons:MaterialIconExt Kind=Password}"
helpers:PasswordBoxHelper.Placeholder="Password"
PasswordChanged="PasswordBox_OnPasswordChanged">
<PasswordBox.InputBindings>
<KeyBinding Key="Enter" Command="{Binding DataContext.LoginCommand, RelativeSource={RelativeSource FindAncestor, AncestorType=dialogs:LoginView}}" />
</PasswordBox.InputBindings>
</PasswordBox>
<ItemsControl
Margin="12,5,12,0"
IsTabStop="False"
Expand Down
17 changes: 10 additions & 7 deletions GroomWise.WPF/Views/Dialogs/LoginView.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
// without written, signed consent from the author is strictly prohibited.

using System;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
using GroomWise.Application.ViewModels;
using GroomWise.Infrastructure.Navigation.Interfaces;
Expand All @@ -18,16 +20,9 @@ public LoginView(LoginViewModel vm)
{
DataContext = vm;
InitializeComponent();
ClearFields();
UsernameBox.Focus();
}

public void ClearFields()
{
UsernameBox.Clear();
PasswordBox.Clear();
}

protected override void OnClosed(EventArgs e)
{
System.Windows.Application.Current.Shutdown();
Expand All @@ -40,4 +35,12 @@ private void UsernameBox_OnKeyDown(object sender, KeyEventArgs keyEventArgs)
if (keyEventArgs.Key == Key.Enter)
PasswordBox.Focus();
}

private void PasswordBox_OnPasswordChanged(object sender, RoutedEventArgs e)
{
if (DataContext != null)
{
((dynamic)DataContext).Password = ((PasswordBox)sender).Password;
}
}
}
58 changes: 35 additions & 23 deletions GroomWise.WPF/Views/Pages/AppointmentsView.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -34,29 +34,41 @@
Margin="0,0,0,12"
FontSize="16"
Text="Schedule" />
<ScrollViewer
Grid.Row="1"
VerticalAlignment="Stretch"
HorizontalContentAlignment="Stretch"
VerticalScrollBarVisibility="Auto">
<ItemsControl ItemsSource="{Binding Appointments.EditableCollectionView, UpdateSourceTrigger=PropertyChanged}">
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<VirtualizingStackPanel IsVirtualizing="True" VirtualizationMode="Recycling" />
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
<ItemsControl.ItemTemplate>
<DataTemplate>
<templates:AppointmentCardTemplate />
</DataTemplate>
</ItemsControl.ItemTemplate>
<ItemsControl.ItemContainerStyle>
<Style TargetType="{x:Type FrameworkElement}">
<Setter Property="Margin" Value="0,0,0,10" />
</Style>
</ItemsControl.ItemContainerStyle>
</ItemsControl>
</ScrollViewer>
<ItemsControl Grid.Row="1" ItemsSource="{Binding Appointments.EditableCollectionView, UpdateSourceTrigger=PropertyChanged}">
<ItemsControl.ItemTemplate>
<DataTemplate>
<templates:AppointmentCardTemplate />
</DataTemplate>
</ItemsControl.ItemTemplate>

<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<VirtualizingStackPanel IsVirtualizing="True" VirtualizationMode="Recycling" />
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>

<ItemsControl.ItemContainerStyle>
<Style TargetType="{x:Type FrameworkElement}">
<Setter Property="Margin" Value="0,0,0,10" />
</Style>
</ItemsControl.ItemContainerStyle>

<ItemsControl.Template>
<ControlTemplate TargetType="ItemsControl">
<Border
Background="{TemplateBinding Background}"
BorderBrush="{TemplateBinding BorderBrush}"
BorderThickness="{TemplateBinding BorderThickness}">
<ScrollViewer
Padding="{TemplateBinding Padding}"
CanContentScroll="True"
Focusable="False">
<ItemsPresenter />
</ScrollViewer>
</Border>
</ControlTemplate>
</ItemsControl.Template>
</ItemsControl>
</Grid>
</Grid>
<Grid
Expand Down
58 changes: 35 additions & 23 deletions GroomWise.WPF/Views/Pages/CustomersView.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -72,29 +72,41 @@
IconSize="18"
LeftIcon="{icons:MaterialIconExt Kind=AddBold}" />
</Grid>
<ScrollViewer
Grid.Row="1"
VerticalAlignment="Stretch"
HorizontalContentAlignment="Stretch"
VerticalScrollBarVisibility="Auto">
<ItemsControl ItemsSource="{Binding Customers.EditableCollectionView, UpdateSourceTrigger=PropertyChanged}">
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<VirtualizingStackPanel IsVirtualizing="True" VirtualizationMode="Recycling" />
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
<ItemsControl.ItemTemplate>
<DataTemplate>
<templates:CustomerListCardTemplate />
</DataTemplate>
</ItemsControl.ItemTemplate>
<ItemsControl.ItemContainerStyle>
<Style TargetType="{x:Type FrameworkElement}">
<Setter Property="Margin" Value="0,0,0,10" />
</Style>
</ItemsControl.ItemContainerStyle>
</ItemsControl>
</ScrollViewer>
<ItemsControl Grid.Row="1" ItemsSource="{Binding Customers.EditableCollectionView, UpdateSourceTrigger=PropertyChanged}">
<ItemsControl.ItemTemplate>
<DataTemplate>
<templates:CustomerListCardTemplate />
</DataTemplate>
</ItemsControl.ItemTemplate>

<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<VirtualizingStackPanel IsVirtualizing="True" VirtualizationMode="Recycling" />
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>

<ItemsControl.ItemContainerStyle>
<Style TargetType="{x:Type FrameworkElement}">
<Setter Property="Margin" Value="0,0,0,10" />
</Style>
</ItemsControl.ItemContainerStyle>

<ItemsControl.Template>
<ControlTemplate TargetType="ItemsControl">
<Border
Background="{TemplateBinding Background}"
BorderBrush="{TemplateBinding BorderBrush}"
BorderThickness="{TemplateBinding BorderThickness}">
<ScrollViewer
Padding="{TemplateBinding Padding}"
CanContentScroll="True"
Focusable="False">
<ItemsPresenter />
</ScrollViewer>
</Border>
</ControlTemplate>
</ItemsControl.Template>
</ItemsControl>
</Grid>
</Grid>
</UserControl>
Loading

0 comments on commit bdb51a3

Please sign in to comment.