Skip to content

Commit 3517b77

Browse files
committed
[VEX-105]: Added ability to add seasons manually
1 parent 09fa2b7 commit 3517b77

File tree

10 files changed

+258
-4
lines changed

10 files changed

+258
-4
lines changed

VexTrack/App.xaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,10 @@
124124
<DataTemplate DataType="{x:Type popupViewModel:DeleteGoalGroupConfirmationPopupViewModel}">
125125
<popupView:DeleteGoalGroupConfirmationPopup/>
126126
</DataTemplate>
127+
128+
<DataTemplate DataType="{x:Type popupViewModel:SeasonEndConfirmationPopupViewModel}">
129+
<popupView:SeasonEndConfirmationPopup/>
130+
</DataTemplate>
127131
</ResourceDictionary>
128132
</Application.Resources>
129133
</Application>

VexTrack/Core/TrackingData.cs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ public static Season CurrentSeasonData
141141
DateTimeOffset today = DateTimeOffset.Now.ToLocalTime().Date;
142142

143143
int remainingDays = (endDate - today).Days;
144-
if ((endDate - today).Hours > 0) { remainingDays += 1; }
144+
if ((endDate - today).Hours > 12) { remainingDays += 1; }
145145
if (remainingDays < 0) remainingDays = 0;
146146

147147
return remainingDays;
@@ -153,7 +153,7 @@ public static int GetDuration(string sUUID)
153153
DateTimeOffset startDate = DateTimeOffset.FromUnixTimeSeconds(Data.Seasons.Find(s => s.UUID == sUUID).History.First().Time).ToLocalTime().Date;
154154

155155
int duration = (endDate - startDate).Days;
156-
if ((endDate - startDate).Hours > 0) { duration += 1; }
156+
if ((endDate - startDate).Hours > 12) { duration += 1; }
157157
if (duration < 0) duration = 0;
158158

159159
return duration;
@@ -751,6 +751,13 @@ public static void EditSeason(string uuid, Season data)
751751
CallUpdate();
752752
}
753753

754+
public static void EndSeason(string uuid)
755+
{
756+
// Set end date to today
757+
Data.Seasons[Data.Seasons.FindIndex(s => s.UUID == uuid)].EndDate = DateTime.Today.ToLocalTime().Date.ToString("d");
758+
CallUpdate();
759+
}
760+
754761

755762
public static void CreateSeasonInitPopup()
756763
{
Lines changed: 163 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,163 @@
1+
<UserControl x:Class="VexTrack.MVVM.View.Popups.SeasonEndConfirmationPopup"
2+
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
3+
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
4+
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
5+
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
6+
xmlns:local="clr-namespace:VexTrack.MVVM.View.Popups"
7+
mc:Ignorable="d"
8+
d:DesignHeight="812" d:DesignWidth="872">
9+
10+
<Grid Height="Auto"
11+
Width="640"
12+
VerticalAlignment="Center">
13+
<Grid.RowDefinitions>
14+
<RowDefinition Height="Auto"/>
15+
</Grid.RowDefinitions>
16+
17+
<Border Background="{DynamicResource Background}"
18+
CornerRadius="8">
19+
<Grid Margin="16">
20+
<Grid.RowDefinitions>
21+
<RowDefinition Height="*"/>
22+
<RowDefinition Height="Auto"/>
23+
</Grid.RowDefinitions>
24+
25+
<Grid.ColumnDefinitions>
26+
<ColumnDefinition Width="*"/>
27+
<ColumnDefinition Width="Auto"/>
28+
</Grid.ColumnDefinitions>
29+
30+
<Grid Grid.Row="0"
31+
Grid.Column="0"
32+
Margin="0, 4, 0, 0">
33+
34+
<Grid.RowDefinitions>
35+
<RowDefinition Height="Auto"/>
36+
<RowDefinition Height="Auto"/>
37+
<RowDefinition Height="Auto"/>
38+
<RowDefinition Height="Auto"/>
39+
</Grid.RowDefinitions>
40+
41+
<TextBlock Text="End Season"
42+
Grid.Column="0"
43+
Grid.Row="0"
44+
Grid.ColumnSpan="2"
45+
FontSize="20"
46+
FontWeight="Bold"
47+
Foreground="{DynamicResource Foreground}"
48+
Margin="0, 0, 0, 16"/>
49+
50+
<TextBlock Grid.Row="1"
51+
Grid.Column="0"
52+
FontSize="14"
53+
TextWrapping="Wrap"
54+
Foreground="{DynamicResource Foreground}"
55+
Margin="0, 0, 0, 4">
56+
This operation will end the current season and start a new one. History entries cannot be added to an ended season.
57+
</TextBlock>
58+
59+
<TextBlock Grid.Row="2"
60+
Grid.Column="0"
61+
FontSize="14"
62+
TextWrapping="Wrap"
63+
Foreground="{DynamicResource Foreground}"
64+
Margin="0, 0, 0, 4">
65+
This operation cannot be reverted. Are you sure you want to continue?
66+
</TextBlock>
67+
68+
<Grid Grid.Row="3"
69+
Grid.Column="0"
70+
Margin="0, 16, 0, 0">
71+
<Grid.RowDefinitions>
72+
<RowDefinition Height="Auto"/>
73+
<RowDefinition Height="Auto"/>
74+
<RowDefinition Height="Auto"/>
75+
</Grid.RowDefinitions>
76+
77+
<Grid.ColumnDefinitions>
78+
<ColumnDefinition Width="*"/>
79+
<ColumnDefinition Width="*"/>
80+
</Grid.ColumnDefinitions>
81+
82+
<TextBlock Grid.Row="0"
83+
Grid.Column="0"
84+
Grid.ColumnSpan="2"
85+
FontSize="14"
86+
TextWrapping="Wrap"
87+
Foreground="{DynamicResource Foreground}"
88+
Margin="0, 0, 0, 4">
89+
<Bold>Current Season:</Bold>
90+
</TextBlock>
91+
92+
<TextBlock Grid.Row="1"
93+
Grid.Column="0"
94+
FontSize="14"
95+
TextWrapping="Wrap"
96+
FontWeight="Bold"
97+
Text="Name"
98+
Foreground="{DynamicResource Foreground}"
99+
Margin="0, 0, 0, 4"/>
100+
101+
<TextBlock Grid.Row="2"
102+
Grid.Column="0"
103+
FontSize="14"
104+
TextWrapping="Wrap"
105+
FontWeight="Bold"
106+
Text="End Date"
107+
Foreground="{DynamicResource Foreground}"
108+
Margin="0, 0, 0, 4"/>
109+
110+
111+
112+
113+
<TextBlock Text="{Binding Name}"
114+
Grid.Row="1"
115+
Grid.Column="1"
116+
FontSize="14"
117+
TextWrapping="Wrap"
118+
Foreground="{DynamicResource Foreground}"
119+
Margin="0, 0, 0, 4"/>
120+
121+
<TextBlock Text="{Binding EndDate}"
122+
Grid.Row="2"
123+
Grid.Column="1"
124+
Foreground="{DynamicResource Foreground}"
125+
FontSize="14"
126+
Margin="0, 0, 0, 4"/>
127+
</Grid>
128+
</Grid>
129+
130+
<Grid Grid.Row="1"
131+
Grid.ColumnSpan="2"
132+
Margin="0, 16, 0, 0">
133+
<Grid.ColumnDefinitions>
134+
<ColumnDefinition Width="*"/>
135+
<ColumnDefinition Width="*"/>
136+
</Grid.ColumnDefinitions>
137+
138+
<Button Content="No"
139+
Background="{DynamicResource Background}"
140+
Foreground="{DynamicResource Foreground}"
141+
Width="80"
142+
Height="30"
143+
HorizontalAlignment="Left"
144+
VerticalAlignment="Bottom"
145+
Style="{DynamicResource ButtonTheme}"
146+
Command="{Binding OnNoClicked}"/>
147+
148+
<Button Content="Yes"
149+
Background="{DynamicResource AccRed}"
150+
Foreground="{DynamicResource White}"
151+
Grid.Column="1"
152+
HorizontalAlignment="Right"
153+
Width="80"
154+
Height="30"
155+
VerticalAlignment="Bottom"
156+
Style="{DynamicResource ButtonTheme}"
157+
Command="{Binding OnYesClicked}"
158+
Margin="0, 0, 4, 0"/>
159+
</Grid>
160+
</Grid>
161+
</Border>
162+
</Grid>
163+
</UserControl>
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
using System.Windows.Controls;
2+
3+
namespace VexTrack.MVVM.View.Popups
4+
{
5+
/// <summary>
6+
/// Interaction logic for SeasonEndConfirmationPopup.xaml
7+
/// </summary>
8+
public partial class SeasonEndConfirmationPopup : UserControl
9+
{
10+
public SeasonEndConfirmationPopup()
11+
{
12+
InitializeComponent();
13+
}
14+
}
15+
}

VexTrack/MVVM/View/SeasonView.xaml

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,14 @@
5050
</ItemsControl.ItemTemplate>
5151
</ItemsControl>
5252
</Grid>
53-
</ScrollViewer>
54-
</Grid>
53+
</ScrollViewer>
54+
55+
<Button Grid.Row="0"
56+
Width="48" Height="48"
57+
HorizontalAlignment="Right"
58+
VerticalAlignment="Center"
59+
Margin="0, 0, 16, 0"
60+
Style="{DynamicResource AddButtonTheme}"
61+
Command="{Binding OnAddClicked}"/>
62+
</Grid>
5563
</UserControl>

VexTrack/MVVM/ViewModel/MainViewModel.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ class MainViewModel : ObservableObject
4141
private EditableGoalGroupPopupViewModel EditableGoalGroupPopup { get; set; }
4242
private DeleteGoalConfirmationPopupViewModel DeleteGoalConfirmationPopup { get; set; }
4343
private DeleteGoalGroupConfirmationPopupViewModel DeleteGoalGroupConfirmationPopup { get; set; }
44+
private SeasonEndConfirmationPopupViewModel SeasonEndConfirmationPopup { get; set; }
4445

4546
private object _currentView;
4647
private bool _epilogue;
@@ -217,6 +218,9 @@ private void InitPopupViewModels()
217218

218219
EditableGoalGroupPopup = new EditableGoalGroupPopupViewModel();
219220
ViewModelManager.ViewModels.Add("EditableGoalGroupPopup", EditableGoalGroupPopup);
221+
222+
SeasonEndConfirmationPopup = new SeasonEndConfirmationPopupViewModel();
223+
ViewModelManager.ViewModels.Add("SeasonEndConfirmationPopup", SeasonEndConfirmationPopup);
220224
}
221225

222226
public void SetView(object view)
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
using VexTrack.Core;
2+
3+
namespace VexTrack.MVVM.ViewModel.Popups
4+
{
5+
class SeasonEndConfirmationPopupViewModel : BasePopupViewModel
6+
{
7+
public RelayCommand OnYesClicked { get; set; }
8+
public RelayCommand OnNoClicked { get; set; }
9+
10+
private string UUID = "";
11+
public string Name {get; set; }
12+
public string EndDate { get; set; }
13+
14+
15+
public SeasonEndConfirmationPopupViewModel()
16+
{
17+
CanCancel = true;
18+
19+
OnYesClicked = new RelayCommand(o =>
20+
{
21+
TrackingDataHelper.EndSeason(UUID);
22+
Close();
23+
});
24+
OnNoClicked = new RelayCommand(o => Close());
25+
}
26+
27+
public void SetData(string seasonUUID)
28+
{
29+
UUID = seasonUUID;
30+
Name = TrackingDataHelper.GetSeason(UUID).Name;
31+
EndDate = TrackingDataHelper.GetSeason(UUID).EndDate;
32+
}
33+
}
34+
}

VexTrack/MVVM/ViewModel/SeasonViewModel.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,10 @@ namespace VexTrack.MVVM.ViewModel
88
class SeasonViewModel : ObservableObject
99
{
1010
public RelayCommand SeasonButtonClick { get; set; }
11+
public RelayCommand OnAddClicked { get; set; }
1112

1213
public SeasonPopupViewModel SeasonPopup { get; set; }
14+
private SeasonEndConfirmationPopupViewModel SeasonEndPopup { get; set; }
1315
private MainViewModel MainVM { get; set; }
1416
private bool Epilogue { get; set; }
1517

@@ -31,8 +33,15 @@ public SeasonViewModel()
3133
{
3234
MainVM = (MainViewModel)ViewModelManager.ViewModels["Main"];
3335
SeasonPopup = (SeasonPopupViewModel)ViewModelManager.ViewModels["SeasonPopup"];
36+
SeasonEndPopup = (SeasonEndConfirmationPopupViewModel)ViewModelManager.ViewModels["SeasonEndConfirmationPopup"];
3437

3538
SeasonButtonClick = new RelayCommand(OnSeasonButtonClick);
39+
OnAddClicked = new RelayCommand(o =>
40+
{
41+
SeasonEndPopup.SetData(TrackingDataHelper.CurrentSeasonUUID);
42+
MainVM.QueuePopup(SeasonEndPopup);
43+
});
44+
3645
Update(false);
3746
}
3847

VexTrack/VexTrack.csproj

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,9 @@
4545
</ItemGroup>
4646

4747
<ItemGroup>
48+
<Compile Update="MVVM\View\Popups\SeasonEndConfirmationPopup.xaml.cs">
49+
<SubType>Code</SubType>
50+
</Compile>
4851
<Compile Update="MVVM\View\Popups\DeleteGoalGroupConfirmationPopup.xaml.cs">
4952
<SubType>Code</SubType>
5053
</Compile>
@@ -70,6 +73,10 @@
7073
</ItemGroup>
7174

7275
<ItemGroup>
76+
<Page Update="MVVM\View\Popups\SeasonEndConfirmationPopup.xaml">
77+
<XamlRuntime>$(DefaultXamlRuntime)</XamlRuntime>
78+
<SubType>Designer</SubType>
79+
</Page>
7380
<Page Update="MVVM\View\Popups\DeleteGoalGroupConfirmationPopup.xaml">
7481
<XamlRuntime>$(DefaultXamlRuntime)</XamlRuntime>
7582
<SubType>Designer</SubType>

VexTrack/VexTrack.csproj.user

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,9 @@
8080
<Page Update="MVVM\View\Popups\AboutPopup.xaml">
8181
<SubType>Designer</SubType>
8282
</Page>
83+
<Page Update="MVVM\View\Popups\SeasonEndConfirmationPopup.xaml">
84+
<SubType>Designer</SubType>
85+
</Page>
8386
<Page Update="MVVM\View\Popups\DeleteGoalGroupConfirmationPopup.xaml">
8487
<SubType>Designer</SubType>
8588
</Page>

0 commit comments

Comments
 (0)