Skip to content

Commit a98b411

Browse files
committed
Added History item (#669)
1 parent fe3243f commit a98b411

File tree

9 files changed

+189
-8
lines changed

9 files changed

+189
-8
lines changed
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
<UserControl
2+
x:Class="InternetTest.Components.HistoryItem"
3+
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
4+
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
5+
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
6+
xmlns:local="clr-namespace:InternetTest.Components"
7+
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
8+
d:DesignWidth="800"
9+
FontFamily="..\Fonts\#Hauora"
10+
Foreground="{DynamicResource Foreground1}"
11+
mc:Ignorable="d">
12+
<Border
13+
Margin="0 5"
14+
Padding="5"
15+
BorderBrush="{DynamicResource Border}"
16+
BorderThickness="1"
17+
CornerRadius="5">
18+
<Grid>
19+
<Grid.ColumnDefinitions>
20+
<ColumnDefinition Width="*" />
21+
<ColumnDefinition Width="Auto" />
22+
<ColumnDefinition Width="Auto" />
23+
</Grid.ColumnDefinitions>
24+
<TextBlock
25+
VerticalAlignment="Center"
26+
d:Text="Activity Name"
27+
FontWeight="SemiBold"
28+
Text="{Binding Name}" />
29+
30+
<TextBlock
31+
Grid.Column="1"
32+
Margin="0 0 5 0"
33+
VerticalAlignment="Center"
34+
d:Text="Activity Date"
35+
FontSize="11"
36+
Foreground="{DynamicResource DarkGray}"
37+
Text="{Binding DateText}" />
38+
<Border
39+
Grid.Column="2"
40+
MinWidth="50"
41+
Padding="2"
42+
VerticalAlignment="Center"
43+
d:Background="{DynamicResource LightGreen}"
44+
Background="{Binding StatusBackground}"
45+
CornerRadius="2">
46+
<TextBlock
47+
HorizontalAlignment="Center"
48+
VerticalAlignment="Center"
49+
d:Foreground="{DynamicResource ForegroundGreen}"
50+
d:Text="200"
51+
FontWeight="SemiBold"
52+
Foreground="{Binding StatusForeground}"
53+
Text="{Binding StatusText}" />
54+
</Border>
55+
</Grid>
56+
</Border>
57+
</UserControl>
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
/*
2+
MIT License
3+
4+
Copyright (c) Léo Corporation
5+
6+
Permission is hereby granted, free of charge, to any person obtaining a copy
7+
of this software and associated documentation files (the "Software"), to deal
8+
in the Software without restriction, including without limitation the rights
9+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
copies of the Software, and to permit persons to whom the Software is
11+
furnished to do so, subject to the following conditions:
12+
13+
The above copyright notice and this permission notice shall be included in all
14+
copies or substantial portions of the Software.
15+
16+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22+
SOFTWARE.
23+
*/
24+
using System.Windows.Controls;
25+
26+
namespace InternetTest.Components;
27+
/// <summary>
28+
/// Interaction logic for HistoryItem.xaml
29+
/// </summary>
30+
public partial class HistoryItem : UserControl
31+
{
32+
public HistoryItem()
33+
{
34+
InitializeComponent();
35+
}
36+
}

InternetTest/InternetTest/Models/ActivityHistory.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,10 +68,10 @@ public class Activity
6868
{
6969
public string Name { get; init; }
7070
public string Result { get; init; }
71-
public bool Success { get; init; }
71+
public bool? Success { get; init; }
7272
public DateTime Date { get; init; }
7373

74-
public Activity(string name, string result, bool success, DateTime date)
74+
public Activity(string name, string result, bool? success, DateTime date)
7575
{
7676
Name = name;
7777
Result = result;
@@ -83,7 +83,7 @@ public Activity()
8383
{
8484
Name = string.Empty;
8585
Result = string.Empty;
86-
Success = false;
86+
Success = null;
8787
Date = DateTime.MinValue;
8888
}
8989
}
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
/*
2+
MIT License
3+
4+
Copyright (c) Léo Corporation
5+
6+
Permission is hereby granted, free of charge, to any person obtaining a copy
7+
of this software and associated documentation files (the "Software"), to deal
8+
in the Software without restriction, including without limitation the rights
9+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
copies of the Software, and to permit persons to whom the Software is
11+
furnished to do so, subject to the following conditions:
12+
13+
The above copyright notice and this permission notice shall be included in all
14+
copies or substantial portions of the Software.
15+
16+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22+
SOFTWARE.
23+
*/
24+
using InternetTest.Helpers;
25+
using InternetTest.Models;
26+
using System.Windows.Media;
27+
28+
namespace InternetTest.ViewModels.Components;
29+
public class HistoryItemViewModel : ViewModelBase
30+
{
31+
private string _name = string.Empty;
32+
public string Name { get => _name; set { _name = value; OnPropertyChanged(nameof(Name)); } }
33+
34+
private string _statusText = string.Empty;
35+
public string StatusText { get => _statusText; set { _statusText = value; OnPropertyChanged(nameof(StatusText)); } }
36+
37+
private string _dateText = string.Empty;
38+
public string DateText { get => _dateText; set { _dateText = value; OnPropertyChanged(nameof(DateText)); } }
39+
40+
private SolidColorBrush? _statusForeground;
41+
public SolidColorBrush? StatusForeground { get => _statusForeground; set { _statusForeground = value; OnPropertyChanged(nameof(StatusForeground)); } }
42+
43+
private SolidColorBrush? _statusBackground;
44+
public SolidColorBrush? StatusBackground { get => _statusBackground; set { _statusBackground = value; OnPropertyChanged(nameof(StatusBackground)); } }
45+
46+
public HistoryItemViewModel(Activity activity)
47+
{
48+
Name = activity.Name;
49+
StatusText = activity.Result;
50+
DateText = activity.Date.ToString("g");
51+
52+
switch (activity.Success)
53+
{
54+
case true:
55+
StatusBackground = ThemeHelper.GetSolidColorBrush("LightGreen");
56+
StatusForeground = ThemeHelper.GetSolidColorBrush("ForegroundGreen");
57+
break;
58+
case false:
59+
StatusBackground = ThemeHelper.GetSolidColorBrush("LightOrange");
60+
StatusForeground = ThemeHelper.GetSolidColorBrush("ForegroundOrange");
61+
break;
62+
default:
63+
StatusBackground = ThemeHelper.GetSolidColorBrush("LightFAccent");
64+
StatusForeground = ThemeHelper.GetSolidColorBrush("DarkFAccent");
65+
break;
66+
}
67+
}
68+
}

InternetTest/InternetTest/ViewModels/Components/SidebarViewModel.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ public SidebarViewModel(MainViewModel mainViewModel)
6464

6565
private void HomePage(object? obj)
6666
{
67-
_mainViewModel.CurrentViewModel = new HomePageViewModel(_mainViewModel.Settings);
67+
_mainViewModel.CurrentViewModel = new HomePageViewModel(_mainViewModel.Settings, _mainViewModel.History);
6868
}
6969

7070
private void SettingsPage(object? obj)

InternetTest/InternetTest/ViewModels/Components/WebsiteItemViewModel.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,12 @@ internal async void TestAsync()
102102
new(Properties.Resources.TimeElapsed, $"{(endTime - startTime).TotalMilliseconds:0} ms", 0,1 ),
103103
];
104104

105-
_history.Activity.Add(new Activity(Url, statusInfo.StatusCode.ToString(), statusInfo.StatusCode is >= 200 and < 300, DateTime.Now));
105+
_history.Activity.Add(new Activity(Url, statusInfo.StatusCode.ToString(), statusInfo.StatusCode switch
106+
{
107+
>= 400 => false,
108+
>= 300 or <= 100 => null,
109+
_ => true,
110+
}, DateTime.Now));
106111
}
107112
catch { }
108113
ShowStatusCode = true;

InternetTest/InternetTest/ViewModels/HomePageViewModel.cs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,19 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
2424
using InternetTest.Helpers;
2525
using InternetTest.Interfaces;
2626
using InternetTest.Models;
27+
using InternetTest.ViewModels.Components;
2728
using PeyrSharp.Core;
29+
using System.Collections.ObjectModel;
2830
using System.Net.NetworkInformation;
2931
using System.Windows.Media;
3032

3133
namespace InternetTest.ViewModels;
3234

3335
public class HomePageViewModel : ViewModelBase, ISensitiveViewModel
3436
{
37+
private ObservableCollection<HistoryItemViewModel> _history = [];
38+
public ObservableCollection<HistoryItemViewModel> History { get => _history; set { _history = value; OnPropertyChanged(nameof(History)); } }
39+
3540
public string HelloText => DateTime.Now.Hour switch
3641
{
3742
>= 21 or <= 7 => $"{Properties.Resources.GoodNight}, {Environment.UserName}.",
@@ -82,7 +87,7 @@ public class HomePageViewModel : ViewModelBase, ISensitiveViewModel
8287
private readonly Settings _settings;
8388

8489
bool connected = true;
85-
public HomePageViewModel(Settings settings)
90+
public HomePageViewModel(Settings settings, ActivityHistory history)
8691
{
8792
_settings = settings;
8893

@@ -115,6 +120,9 @@ public HomePageViewModel(Settings settings)
115120
Gateway = ipProps?.IPv4Gateway ?? Properties.Resources.Unknown;
116121
Dns = string.Join("\n", networkInterface.GetIPProperties().DnsAddresses.Select(x => x.ToString().Replace("%16", ""))) ?? Properties.Resources.Unknown;
117122
}
123+
124+
// Load history
125+
History = new ObservableCollection<HistoryItemViewModel>(history.Activity.Select(x => new HistoryItemViewModel(x)));
118126
}
119127

120128
internal async void LoadIpAddress()

InternetTest/InternetTest/ViewModels/MainViewModel.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ public MainViewModel(Settings settings, ActivityHistory history, Window mainWind
121121
AppPages.Ping => new PingPageViewModel(Settings),
122122
AppPages.Requests => new RequestsPageViewModel(Settings),
123123
AppPages.TraceRoute => new TraceroutePageViewModel(Settings),
124-
_ => new HomePageViewModel(Settings)
124+
_ => new HomePageViewModel(Settings, History)
125125
};
126126

127127

InternetTest/InternetTest/Views/HomePage.xaml

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,13 @@
22
x:Class="InternetTest.Views.HomePage"
33
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
44
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
5+
xmlns:components="clr-namespace:InternetTest.Components"
56
xmlns:converters="clr-namespace:InternetTest.Converters"
67
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
78
xmlns:lang="clr-namespace:InternetTest.Properties"
89
xmlns:local="clr-namespace:InternetTest.Views"
910
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
11+
xmlns:vm="clr-namespace:InternetTest.ViewModels.Components"
1012
d:DesignHeight="450"
1113
d:DesignWidth="800"
1214
FontFamily="..\Fonts\#Hauora"
@@ -274,12 +276,17 @@
274276
Text="{x:Static lang:Resources.RecentActivity}" />
275277
</StackPanel>
276278
</StackPanel>
277-
<ItemsControl Grid.Row="1">
279+
<ItemsControl Grid.Row="1" ItemsSource="{Binding History}">
278280
<ItemsControl.ItemsPanel>
279281
<ItemsPanelTemplate>
280282
<StackPanel />
281283
</ItemsPanelTemplate>
282284
</ItemsControl.ItemsPanel>
285+
<ItemsControl.ItemTemplate>
286+
<DataTemplate DataType="{x:Type vm:HistoryItemViewModel}">
287+
<components:HistoryItem />
288+
</DataTemplate>
289+
</ItemsControl.ItemTemplate>
283290
</ItemsControl>
284291
</Grid>
285292
</Border>

0 commit comments

Comments
 (0)