Skip to content

Commit

Permalink
chore: add new extensions and enhance interface design
Browse files Browse the repository at this point in the history
Signed-off-by: Russell Camo <[email protected]>
  • Loading branch information
russkyc committed Sep 3, 2023
1 parent cd2c5fe commit c88c5f8
Show file tree
Hide file tree
Showing 23 changed files with 640 additions and 170 deletions.
15 changes: 15 additions & 0 deletions GroomWise.Application/Extensions/NameExtensions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// 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.Extensions;

public static class NameExtensions
{
public static string GetFirstName(this string fullName)
{
var nameSections = fullName.Split(" ");
return nameSections[0];
}
}
7 changes: 4 additions & 3 deletions GroomWise.Application/ViewModels/CustomerViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
// without written, signed consent from the author is strictly prohibited.

using GroomWise.Application.Events;
using GroomWise.Application.Extensions;
using GroomWise.Application.Mappers;
using GroomWise.Application.Observables;
using GroomWise.Domain.Enums;
Expand Down Expand Up @@ -156,7 +157,7 @@ private async Task RemoveSelectedCustomerPet(object param)
await Task.Run(() =>
{
var dialogResult = DialogService.Create(
$"{SelectedCustomer.FullName.Split(" ")[0]}'s Pets",
$"{SelectedCustomer.FullName.GetFirstName()}'s Pets",
$"Are you sure you want to remove {pet.Name}?",
NavigationService
);
Expand All @@ -181,7 +182,7 @@ await Task.Run(() =>
{
var dialogResult = DialogService.Create(
"GroomWise",
$"Update {SelectedCustomer.FullName}?",
$"Update {SelectedCustomer.FullName.GetFirstName()}?",
NavigationService
);
if (dialogResult is true)
Expand Down Expand Up @@ -214,7 +215,7 @@ await Task.Run(() =>
{
var dialogResult = DialogService.Create(
"Customers",
$"Are you sure you want to delete {observableCustomer.FullName}?",
$"Are you sure you want to delete {observableCustomer.FullName.GetFirstName()}?",
NavigationService
);
if (dialogResult is true)
Expand Down
20 changes: 18 additions & 2 deletions GroomWise.Application/ViewModels/DashboardViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,10 @@ public partial class DashboardViewModel
IEventSubscriber<DeleteAppointmentEvent>
{
[Property]
private ConcurrentObservableCollection<ObservableAppointment> _appointments;
private ConcurrentObservableCollection<ObservableAppointment> _appointments = new();

[Property]
private ConcurrentObservableCollection<ObservableAppointment> _upcomingAppointments = new();

[Property]
private string _user;
Expand All @@ -43,11 +46,24 @@ await Task.Run(() =>
.GetMultiple(
appointment =>
appointment.Date == DateTime.Today
&& appointment.StartTime >= TimeOnly.FromDateTime(DateTime.Now)
)
.Select(AppointmentMapper.ToObservable)
.OrderBy(appointment => appointment.Date);
var upcomingApointments = GroomWiseDbContext.Appointments
.GetMultiple(
appointment =>
appointment.Date >= DateTime.Today
&& appointment.Date < DateTime.Today.AddDays(7)
)
.Select(AppointmentMapper.ToObservable)
.OrderBy(appointment => appointment.Date)
.ThenBy(appointment => appointment.StartTime);
Appointments = new ConcurrentObservableCollection<ObservableAppointment>(appointments);
UpcomingAppointments = new ConcurrentObservableCollection<ObservableAppointment>(
upcomingApointments
);
});
}

Expand Down
36 changes: 36 additions & 0 deletions GroomWise.WPF/Converters/StringSecondsToDoubleConverter.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
// 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.

using System;
using System.Globalization;
using System.Windows.Data;

namespace GroomWise.Converters;

[ValueConversion(typeof(double), typeof(string))]
public class StringSecondsToDoubleConverter : IValueConverter
{
public static StringSecondsToDoubleConverter Instance = new();

public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
if (value is double seconds)
{
return $"{seconds:1F}s";
}

return "0.0s";
}

public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
if (value is string seconds)
{
return double.Parse(seconds.Remove(seconds.Length - 1, 1));
}

return 0.0;
}
}
68 changes: 59 additions & 9 deletions GroomWise.WPF/Services/DialogService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,65 @@ public class DialogService : IDialogService
{
return Task.Run(async () =>
{
return await App.Current.Dispatcher.InvokeAsync(
() =>
new DialogView(messageBoxText, caption)
{
ShowInTaskbar = false,
WindowStartupLocation = WindowStartupLocation.CenterOwner,
Owner = (Window)navigationService.CurrentWindow!
}.ShowDialog()
);
return await App.Current.Dispatcher.InvokeAsync(() =>
{
if (
App.Current.Windows
.OfType<DialogView>()
.FirstOrDefault(
dialog =>
dialog.Owner == navigationService.CurrentWindow
&& dialog.Caption.Equals(caption)
&& dialog.MessageBoxText.Equals(messageBoxText)
) is
{ } window
)
{
return false;
}
return new DialogView(messageBoxText, caption)
{
ShowInTaskbar = false,
WindowStartupLocation = WindowStartupLocation.CenterOwner,
Owner = (Window)navigationService.CurrentWindow!
}.ShowDialog();
});
}).Result;
}

public bool? CreateOk(
string messageBoxText,
string caption,
INavigationService navigationService
)
{
return Task.Run(async () =>
{
return await App.Current.Dispatcher.InvokeAsync(() =>
{
if (
App.Current.Windows
.OfType<DialogView>()
.FirstOrDefault(
dialog =>
dialog.Owner == navigationService.CurrentWindow
&& dialog.Caption.Equals(caption)
&& dialog.MessageBoxText.Equals(messageBoxText)
) is
{ } window
)
{
return false;
}
return new DialogView(messageBoxText, caption, MessageBoxButton.OK)
{
ShowInTaskbar = false,
WindowStartupLocation = WindowStartupLocation.CenterOwner,
Owner = (Window)navigationService.CurrentWindow!
}.ShowDialog();
});
}).Result;
}

Expand Down
46 changes: 37 additions & 9 deletions GroomWise.WPF/Views/Controls/CalendarControl.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,37 +8,66 @@
using System.Collections.ObjectModel;
using System.Threading.Tasks;
using System.Windows;
using Lombok.NET;
using org.russkyc.moderncontrols;
using Swordfish.NET.Collections.Auxiliary;

namespace GroomWise.Views.Controls;

public partial class CalendarControl
{
// Define the DateChangedEvent
public static readonly RoutedEvent DateChangedEvent = EventManager.RegisterRoutedEvent(
"DateChanged",
RoutingStrategy.Bubble,
typeof(RoutedEventHandler),
typeof(CalendarControl)
);

// .NET event wrapper for the DateChangedEvent
public event RoutedEventHandler DateChanged
{
add { AddHandler(DateChangedEvent, value); }
remove { RemoveHandler(DateChangedEvent, value); }
}

public static readonly DependencyProperty SelectedDateProperty = DependencyProperty.Register(
nameof(SelectedDate),
typeof(DateTime),
typeof(CalendarControl),
new FrameworkPropertyMetadata(
default(DateTime),
FrameworkPropertyMetadataOptions.BindsTwoWayByDefault
FrameworkPropertyMetadataOptions.BindsTwoWayByDefault,
OnSelectedDateChanged // Added property changed callback
)
);

public DateTime SelectedDate
{
get => (DateTime)GetValue(SelectedDateProperty);
set => SetValue(SelectedDateProperty, value);
}

private static void OnSelectedDateChanged(
DependencyObject d,
DependencyPropertyChangedEventArgs e
)
{
var control = d as CalendarControl;
if (control != null)
{
// Raise the DateChanged event
var args = new RoutedEventArgs(DateChangedEvent);
control.RaiseEvent(args);
}
}

public static readonly DependencyProperty IsEditableProperty = DependencyProperty.Register(
nameof(IsEditable),
typeof(bool),
typeof(CalendarControl),
new FrameworkPropertyMetadata(false)
);

public DateTime SelectedDate
{
get => (DateTime)GetValue(SelectedDateProperty);
set => SetValue(SelectedDateProperty, value);
}

public bool IsEditable
{
get => (bool)GetValue(IsEditableProperty);
Expand Down Expand Up @@ -67,7 +96,6 @@ public CalendarControl()
InitializeComponent();
CurrentMonth = new DateTime(DateTime.Now.Year, DateTime.Now.Month, 1);
_dates = new ObservableCollection<CalendarDate>();
IsEditable = false;
DisplayDates();
}

Expand Down
Loading

0 comments on commit c88c5f8

Please sign in to comment.