Skip to content

Commit

Permalink
Added an "historic" button in DownDetector page (#202)
Browse files Browse the repository at this point in the history
  • Loading branch information
Leo-Peyronnet committed May 14, 2021
1 parent ea05d05 commit 46c4ebe
Show file tree
Hide file tree
Showing 8 changed files with 202 additions and 9 deletions.
48 changes: 39 additions & 9 deletions InternetTest/InternetTest/Pages/DownDetectorPage.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,44 @@
</Grid.RowDefinitions>

<StackPanel Margin="10,40,10,10" Grid.Row="0">
<TextBlock Text="{x:Static lang:Resources.DownDetector}" Foreground="{Binding Source={StaticResource Foreground1}}" FontSize="16"/>
<TextBlock x:Name="InternetIconTxt" Text="&#xF4AB;" HorizontalAlignment="Center" FontWeight="Normal" FontSize="78" Margin="0 10 0 0" Foreground="{Binding Source={StaticResource Gray}}" FontFamily="..\Fonts\#FluentSystemIcons-Filled"/>
<TextBlock x:Name="ConnectionStatusTxt" Text="{x:Static lang:Resources.EnterURLToCheck}" HorizontalAlignment="Center" FontWeight="Bold" FontSize="16" Margin="0 10 0 0" Foreground="{Binding Source={StaticResource Foreground1}}"/>
<TextBox x:Name="WebsiteTxt" Style="{DynamicResource TextBoxStyle1}" Margin="10" Padding="5" Background="{x:Null}" BorderBrush="{Binding Source={StaticResource AccentColor}}" SelectionBrush="{Binding Source={StaticResource AccentColor}}" CaretBrush="{Binding Source={StaticResource Foreground1}}" Foreground="{Binding Source={StaticResource Foreground1}}"/>
<StackPanel Orientation="Horizontal" VerticalAlignment="Center" HorizontalAlignment="Center">
<Button x:Name="CheckBtn" Click="CheckBtn_Click" Content="{x:Static lang:Resources.Check}" HorizontalAlignment="Center" Padding="10,5,10,5" Style="{StaticResource TabButtonStyle}" Foreground="{Binding Source={StaticResource WindowButtonsHoverForeground1}}" Background="{Binding Source={StaticResource AccentColor}}" FontWeight="Bold" Margin="0,10,10,0"/>
<Button x:Name="OpenBrowserBtn" Click="OpenBrowserBtn_Click" Content="{x:Static lang:Resources.OpenInBrowser}" HorizontalAlignment="Center" Padding="10,5,10,5" Style="{StaticResource TabButtonStyle}" Foreground="{Binding Source={StaticResource Foreground1}}" Background="{Binding Source={StaticResource Background2}}" FontWeight="Bold" Margin="0,10,0,0"/>
</StackPanel>
</StackPanel>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition/>
<ColumnDefinition Width="Auto"/>
</Grid.ColumnDefinitions>
<TextBlock Text="{x:Static lang:Resources.DownDetector}" Foreground="{Binding Source={StaticResource Foreground1}}" FontSize="16"/>
<Button Content="&#xF47F;" Padding="5" x:Name="HistoryBtn" Click="HistoryBtn_Click" FontFamily="..\Fonts\#FluentSystemIcons-Regular" Grid.Column="1" Style="{DynamicResource TabButtonStyle}" Background="{Binding Source={StaticResource AccentColor}}" Foreground="{Binding Source={StaticResource WindowButtonsHoverForeground1}}" FontSize="14"/>
</Grid>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition/>
<ColumnDefinition Width="Auto"/>
</Grid.ColumnDefinitions>

<StackPanel Grid.Column="0" Grid.ColumnSpan="2" Orientation="Vertical">
<TextBlock x:Name="InternetIconTxt" Text="&#xF4AB;" HorizontalAlignment="Center" FontWeight="Normal" FontSize="78" Margin="0 10 0 0" Foreground="{Binding Source={StaticResource Gray}}" FontFamily="..\Fonts\#FluentSystemIcons-Filled"/>
<TextBlock x:Name="ConnectionStatusTxt" Text="{x:Static lang:Resources.EnterURLToCheck}" HorizontalAlignment="Center" FontWeight="Bold" FontSize="16" Margin="0 10 0 0" Foreground="{Binding Source={StaticResource Foreground1}}"/>
<TextBox x:Name="WebsiteTxt" Style="{DynamicResource TextBoxStyle1}" Margin="10" Padding="5" Background="{x:Null}" BorderBrush="{Binding Source={StaticResource AccentColor}}" SelectionBrush="{Binding Source={StaticResource AccentColor}}" CaretBrush="{Binding Source={StaticResource Foreground1}}" Foreground="{Binding Source={StaticResource Foreground1}}"/>
<StackPanel Orientation="Horizontal" VerticalAlignment="Center" HorizontalAlignment="Center">
<Button x:Name="CheckBtn" Click="CheckBtn_Click" Content="{x:Static lang:Resources.Check}" HorizontalAlignment="Center" Padding="10,5,10,5" Style="{StaticResource TabButtonStyle}" Foreground="{Binding Source={StaticResource WindowButtonsHoverForeground1}}" Background="{Binding Source={StaticResource AccentColor}}" FontWeight="Bold" Margin="0,10,10,0"/>
<Button x:Name="OpenBrowserBtn" Click="OpenBrowserBtn_Click" Content="{x:Static lang:Resources.OpenInBrowser}" HorizontalAlignment="Center" Padding="10,5,10,5" Style="{StaticResource TabButtonStyle}" Foreground="{Binding Source={StaticResource Foreground1}}" Background="{Binding Source={StaticResource Background2}}" FontWeight="Bold" Margin="0,10,0,0"/>
</StackPanel>
</StackPanel>

<Grid x:Name="HistoricPanel" Visibility="Collapsed" Grid.Column="1" Background="{Binding Source={StaticResource Background1}}">
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition/>
</Grid.RowDefinitions>
<TextBlock Text="{x:Static lang:Resources.Historic}" FontWeight="Bold" Margin="5"/>

<ScrollViewer HorizontalScrollBarVisibility="Disabled" VerticalScrollBarVisibility="Auto" Grid.Row="1" Height="180">
<StackPanel x:Name="HistoricDisplayer" Orientation="Vertical" Grid.Row="1">
<!-- Items loaded on start -->
</StackPanel>
</ScrollViewer>
</Grid>
</Grid>
</StackPanel>
</Grid>
</Page>
28 changes: 28 additions & 0 deletions InternetTest/InternetTest/Pages/DownDetectorPage.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ MIT License
SOFTWARE.
*/
using InternetTest.Classes;
using InternetTest.UserControls;
using LeoCorpLibrary;
using System;
using System.Collections.Generic;
Expand Down Expand Up @@ -86,6 +87,7 @@ private async void Test(string customSite)
InternetIconTxt.Foreground = new SolidColorBrush { Color = (Color)ColorConverter.ConvertFromString(App.Current.Resources["Red"].ToString()) }; // Set the foreground
}
}
HistoricDisplayer.Children.Add(new HistoricItem(customSite, ConnectionStatusTxt.Text, HistoricDisplayer)); // Add
}

private string FormatURL(string url)
Expand Down Expand Up @@ -116,5 +118,31 @@ private void OpenBrowserBtn_Click(object sender, RoutedEventArgs e)
Global.OpenLinkInBrowser(FormatURL(WebsiteTxt.Text)); // Open in a browser
}
}

internal void HistoryBtn_Click(object sender, RoutedEventArgs e)
{
if (HistoricDisplayer.Children.Count > 0)
{
if (HistoricPanel.Visibility == Visibility.Visible)
{
HistoricPanel.Visibility = Visibility.Collapsed; // Set
HistoryBtn.Content = "\uF47F"; // Set text
}
else
{
HistoricPanel.Visibility = Visibility.Visible; // Set
HistoryBtn.Content = "\uF36A"; // Set text
}
}
else
{
HistoricPanel.Visibility = Visibility.Collapsed; // Set
HistoryBtn.Content = "\uF47F"; // Set text
if (sender is not HistoricItem)
{
MessageBox.Show(Properties.Resources.EmptyHistory, Properties.Resources.InternetTest, MessageBoxButton.OK, MessageBoxImage.Information); // Show message
}
}
}
}
}
18 changes: 18 additions & 0 deletions InternetTest/InternetTest/Properties/Resources.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions InternetTest/InternetTest/Properties/Resources.en-US.resx
Original file line number Diff line number Diff line change
Expand Up @@ -315,4 +315,10 @@
<data name="StartupPage" xml:space="preserve">
<value>Startup page</value>
</data>
<data name="Historic" xml:space="preserve">
<value>History</value>
</data>
<data name="EmptyHistory" xml:space="preserve">
<value>The history is empty.</value>
</data>
</root>
6 changes: 6 additions & 0 deletions InternetTest/InternetTest/Properties/Resources.fr-FR.resx
Original file line number Diff line number Diff line change
Expand Up @@ -315,4 +315,10 @@
<data name="StartupPage" xml:space="preserve">
<value>Page par défaut lors du démarrage</value>
</data>
<data name="Historic" xml:space="preserve">
<value>Historique</value>
</data>
<data name="EmptyHistory" xml:space="preserve">
<value>L'historique est vide.</value>
</data>
</root>
6 changes: 6 additions & 0 deletions InternetTest/InternetTest/Properties/Resources.resx
Original file line number Diff line number Diff line change
Expand Up @@ -295,4 +295,10 @@
<data name="StartupPage" xml:space="preserve">
<value>Startup page</value>
</data>
<data name="Historic" xml:space="preserve">
<value>History</value>
</data>
<data name="EmptyHistory" xml:space="preserve">
<value>The history is empty.</value>
</data>
</root>
25 changes: 25 additions & 0 deletions InternetTest/InternetTest/UserControls/HistoricItem.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<UserControl x:Class="InternetTest.UserControls.HistoricItem"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:InternetTest.UserControls"
xmlns:lang="clr-namespace:InternetTest.Properties"
mc:Ignorable="d" FontFamily="..\Fonts\#Montserrat"
d:DesignHeight="50" d:DesignWidth="200" Margin="0,0,0,5">
<Border CornerRadius="10" Padding="5" Background="{Binding Source={StaticResource Background2}}">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition/>
<ColumnDefinition Width="Auto"/>
</Grid.ColumnDefinitions>

<StackPanel Grid.Column="0" VerticalAlignment="Center">
<TextBlock x:Name="SiteNameTxt" Foreground="{Binding Source={StaticResource Foreground1}}" d:Text="https://leocorporation.dev" TextWrapping="Wrap"/>
<TextBlock x:Name="StateTxt" Foreground="{Binding Source={StaticResource Foreground1}}" d:Text="Up" FontWeight="Bold"/>
</StackPanel>

<Button Content="&#xF36A;" Margin="5" x:Name="DismissBtn" Click="DismissBtn_Click" Grid.Column="1" FontFamily="..\Fonts\#FluentSystemIcons-Regular" Foreground="{Binding Source={StaticResource Foreground1}}" Background="{Binding Source={StaticResource Background2}}" Style="{DynamicResource TabButtonStyle}" Padding="5" Width="25" Height="25"/>
</Grid>
</Border>
</UserControl>
74 changes: 74 additions & 0 deletions InternetTest/InternetTest/UserControls/HistoricItem.xaml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
/*
MIT License
Copyright (c) Léo Corporation
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
using InternetTest.Classes;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace InternetTest.UserControls
{
/// <summary>
/// Interaction logic for HistoricItem.xaml
/// </summary>
public partial class HistoricItem : UserControl
{
string URL { get; init; }
string Status { get; init; }
StackPanel StackPanel { get; init; }
public HistoricItem(string url, string status, StackPanel stackPanel)
{
InitializeComponent();
URL = url;
Status = status;
StackPanel = stackPanel;
InitUI();
}

private void InitUI()
{
SiteNameTxt.Text = URL; // Set text
StateTxt.Text = Status; // Set text
}

private void DismissBtn_Click(object sender, RoutedEventArgs e)
{
StackPanel.Children.Remove(this); // Remove
if (StackPanel.Children.Count == 0)
{
Global.DownDetectorPage.HistoryBtn_Click(this, null);
}
}
}
}

0 comments on commit 46c4ebe

Please sign in to comment.