Skip to content

Commit

Permalink
feat(host-settings): Add ability to edit host configurations #45
Browse files Browse the repository at this point in the history
  • Loading branch information
luandersonn committed Apr 18, 2024
1 parent 73141f8 commit 9e37467
Show file tree
Hide file tree
Showing 14 changed files with 612 additions and 187 deletions.
1 change: 1 addition & 0 deletions MyFTP.Core/Models/StorageClientOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ namespace MyFTP.Core.Models;

public record StorageClientOptions
{
public Guid Id { get; init; } = Guid.NewGuid();
public required string Host { get; init; }
public required int Port { get; init; }
public string Username { get; init; }
Expand Down
3 changes: 1 addition & 2 deletions MyFTP.WinUI/App.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
using MyFTP.Core.Logger;
using MyFTP.Core.Managers;
using MyFTP.Core.Utils;
using MyFTP.ViewModels;
using MyFTP.WinUI.Extensions;
using MyFTP.WinUI.Pages;
using MyFTP.WinUI.Services.Logger;
Expand Down Expand Up @@ -126,7 +125,7 @@ private static ServiceProvider ConfigureServices()
services.AddSingleton<IMessenger>(WeakReferenceMessenger.Default)
.AddSingleton<StorageClientManager>()
.AddSingleton<IStorageClientFactory, StorageClientFactory>()
.AddSingleton<IHostCredentialLocker, RecentConnectionCredential>()
.AddSingleton<IHostCredentialLocker, HostCredentialLocker>()
.AddSingleton<ILogger, ConsoleLogger>()
.AddTransient<LoginViewModel>()
.AddSingleton<MainViewModel>()
Expand Down
6 changes: 6 additions & 0 deletions MyFTP.WinUI/MyFTP.WinUI.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
<None Remove="Controls\TitleBarControl\TitleBarControl.xaml" />
<None Remove="Generic.xaml" />
<None Remove="Pages\FileListViewPage.xaml" />
<None Remove="Pages\HostSettingsViewPage.xaml" />
<None Remove="Pages\LoginViewPage.xaml" />
<None Remove="Pages\MainViewPage.xaml" />
<None Remove="Pages\SettingsViewPage.xaml" />
Expand Down Expand Up @@ -53,6 +54,11 @@
<ItemGroup>
<ProjectReference Include="..\MyFTP.Core\MyFTP.Core.csproj" />
</ItemGroup>
<ItemGroup>
<Page Update="Pages\HostSettingsViewPage.xaml">
<Generator>MSBuild:Compile</Generator>
</Page>
</ItemGroup>
<ItemGroup>
<Page Update="Pages\SettingsViewPage.xaml">
<Generator>MSBuild:Compile</Generator>
Expand Down
214 changes: 214 additions & 0 deletions MyFTP.WinUI/Pages/HostSettingsViewPage.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,214 @@
<?xml version="1.0" encoding="utf-8" ?>
<Page x:Class="MyFTP.WinUI.Pages.HostSettingsViewPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:controls="using:MyFTP.WinUI.Controls"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="using:MyFTP.WinUI.Pages"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d">

<Page.Resources>
<x:Double x:Key="ContentMaxWidth">820</x:Double>

<Style x:Key="GridItemContent" TargetType="Grid">
<Setter Property="Margin" Value="0,2" />
<Setter Property="Padding" Value="18,12" />
<Setter Property="Background" Value="{ThemeResource ExpanderBackground}" />
<Setter Property="BorderBrush" Value="{ThemeResource NavigationViewItemSeparatorForeground}" />
<Setter Property="BorderThickness" Value="{ThemeResource ExpanderHeaderBorderThickness}" />
<Setter Property="ColumnSpacing" Value="12" />
<Setter Property="CornerRadius" Value="4" />
<Setter Property="Shadow">
<Setter.Value>
<ThemeShadow />
</Setter.Value>
</Setter>
</Style>

<Style x:Key="OptionToggleSwitch"
BasedOn="{StaticResource DefaultToggleSwitchStyle}"
TargetType="ToggleSwitch">
<Setter Property="Grid.RowSpan" Value="2" />
<Setter Property="Grid.Column" Value="1" />
<Setter Property="MinWidth" Value="0" />
<Setter Property="HorizontalAlignment" Value="Right" />
<Setter Property="VerticalAlignment" Value="Center" />
<Setter Property="HorizontalContentAlignment" Value="Center" />
<Setter Property="KeyTipPlacementMode" Value="Right" />
</Style>

<Style x:Key="OptionHeader" TargetType="TextBlock">
<Setter Property="VerticalAlignment" Value="Center" />
<Setter Property="TextWrapping" Value="Wrap" />
<Setter Property="FontWeight" Value="SemiBold" />
</Style>

<Style x:Key="OptionSubtitle" TargetType="TextBlock">
<Setter Property="Opacity" Value="0.6" />
<Setter Property="FontSize" Value="12" />
<Setter Property="TextWrapping" Value="Wrap" />
</Style>
</Page.Resources>

<Grid x:DefaultBindMode="OneWay">

<Grid.RowDefinitions>
<RowDefinition Height="auto" />
<RowDefinition Height="auto" />
<RowDefinition Height="*" />
<RowDefinition Height="auto" />
</Grid.RowDefinitions>

<controls:TitleBarControl Title="{x:Bind ViewModel.DisplayName}"
BorderBrush="{ThemeResource NavigationViewItemSeparatorForeground}"
BorderThickness="0,0,0,1" />

<InfoBar Title="Saved successfully"
Grid.Row="1"
Canvas.ZIndex="1"
IsOpen="{x:Bind ViewModel.SaveChangesCommand.ExecutionTask.IsCompletedSuccessfully}"
Message="The changes have been saved successfully"
Severity="Success" />


<Grid Grid.Row="2" Background="{ThemeResource LayerFillColorDefaultBrush}">
<Grid.Transitions>
<TransitionCollection>
<RepositionThemeTransition />
</TransitionCollection>
</Grid.Transitions>
<ScrollViewer VerticalScrollBarVisibility="Auto">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="100*" MaxWidth="{StaticResource ContentMaxWidth}" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>

<StackPanel Grid.Column="1"
Padding="18,8,18,8"
Spacing="4">
<StackPanel.Shadow>
<ThemeShadow />
</StackPanel.Shadow>

<TextBlock FontSize="20" FontWeight="SemiBold">
<Run Text="Host settings" />
</TextBlock>

<RadioButtons Header="Protocol"
ItemsSource="{x:Bind ViewModel.AllProtocols.Type1Values}"
MaxColumns="4"
SelectedItem="{x:Bind ViewModel.Protocol, Mode=TwoWay}" />

<Grid ColumnSpacing="8">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="150" />
</Grid.ColumnDefinitions>

<TextBox Grid.Column="0"
Header="Host"
Text="{x:Bind ViewModel.Host, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" />

<NumberBox Grid.Column="1"
Header="Port"
Minimum="0"
SpinButtonPlacementMode="Compact"
Value="{x:Bind ViewModel.Port, Mode=TwoWay}" />

</Grid>

<TextBox Header="Nickname" Text="{x:Bind ViewModel.DisplayName, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" />

<TextBox Header="Username" Text="{x:Bind ViewModel.Username, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" />

<PasswordBox Header="Password"
Password="{x:Bind ViewModel.Password, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
Visibility="Collapsed" />

<Rectangle Height="1"
Margin="0,12"
Fill="{ThemeResource NavigationViewItemSeparatorForeground}" />

<TextBlock Text="Advanced options" />


<Grid Style="{StaticResource GridItemContent}" Translation="0,0,8">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="auto" />
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition />
<RowDefinition />
</Grid.RowDefinitions>


<TextBlock Style="{StaticResource OptionHeader}" Text="Accept invalid certificates" />

<TextBlock Grid.Row="1"
Style="{StaticResource OptionSubtitle}"
Text="This option allows the FTP client to connect to servers even if their SSL/TLS certificates have issues. Be aware that enabling this bypasses critical security checks, so it should be used with a clear understanding of the potential risks" />

<ToggleSwitch IsOn="{x:Bind ViewModel.AcceptInvalidCertificates, Mode=TwoWay}" Style="{StaticResource OptionToggleSwitch}" />

</Grid>

</StackPanel>
</Grid>
</ScrollViewer>
</Grid>

<Border Grid.Row="3">
<Grid Padding="12"
BorderBrush="{ThemeResource NavigationViewItemSeparatorForeground}"
BorderThickness="0,1,0,0">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="130" />
<ColumnDefinition Width="auto" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>

<Button MinWidth="120" Click="OnButtonClick">
<StackPanel Orientation="Horizontal" Spacing="4">
<FontIcon FontFamily="Segoe Fluent Icons"
FontSize="15"
Glyph="&#xE74D;" />
<TextBlock Text="Delete" />
</StackPanel>
</Button>

<ProgressRing Grid.Column="1"
Width="20"
Height="20"
HorizontalAlignment="Right"
IsActive="{x:Bind ViewModel.SaveChangesCommand.IsRunning, Mode=OneWay}" />

<StackPanel Grid.Column="2"
HorizontalAlignment="Right"
VerticalAlignment="Center"
Orientation="Horizontal"
Spacing="4">

<Button MinWidth="120"
Click="{x:Bind GoBackOrCloseWindow, Mode=OneTime}"
Content="Back" />

<Button MinWidth="120"
Command="{x:Bind ViewModel.SaveChangesCommand}"
Style="{ThemeResource AccentButtonStyle}">
<StackPanel Orientation="Horizontal" Spacing="4">
<FontIcon FontFamily="Segoe Fluent Icons"
FontSize="15"
Glyph="&#xE74E;" />
<TextBlock Text="Save" />
</StackPanel>
</Button>
</StackPanel>
</Grid>
</Border>

</Grid>
</Page>
47 changes: 47 additions & 0 deletions MyFTP.WinUI/Pages/HostSettingsViewPage.xaml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
using Microsoft.Extensions.DependencyInjection;
using Microsoft.UI.Xaml;
using Microsoft.UI.Xaml.Controls;
using Microsoft.UI.Xaml.Navigation;
using MyFTP.WinUI.Services.Security;
using MyFTP.WinUI.ViewModels;
using System.ComponentModel;

namespace MyFTP.WinUI.Pages;

public sealed partial class HostSettingsViewPage : Page, INotifyPropertyChanged
{
public HostSettingsViewPage() => InitializeComponent();

public HostOptionsViewModel ViewModel { get; set; }

public event PropertyChangedEventHandler PropertyChanged;

protected override void OnNavigatedTo(NavigationEventArgs e)
{
ViewModel = (HostOptionsViewModel)e.Parameter;
OnPropertyChanged(nameof(ViewModel));
}

private void OnPropertyChanged(string propertyName) => PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));

private async void OnButtonClick(object sender, RoutedEventArgs e)
{
await App.Current.Services
.GetRequiredService<IHostCredentialLocker>()
.RemoveCredentialAsync(ViewModel.Id);

GoBackOrCloseWindow();
}

private void GoBackOrCloseWindow()
{
if (Frame.CanGoBack)
{
Frame.GoBack();
}
else
{
App.WindowManager.GetWindow(XamlRoot).Close();
}
}
}
8 changes: 4 additions & 4 deletions MyFTP.WinUI/Pages/LoginViewPage.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
xmlns:controls="using:MyFTP.WinUI.Controls"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:models="using:MyFTP.Core.Models"
xmlns:viewmodels="using:MyFTP.WinUI.ViewModels"
mc:Ignorable="d">

<Grid>
Expand Down Expand Up @@ -48,7 +48,7 @@
ItemsSource="{x:Bind ViewModel.SavedHosts}"
SelectionMode="None">
<ListViewBase.ItemTemplate>
<DataTemplate x:DataType="models:StorageClientOptions">
<DataTemplate x:DataType="viewmodels:HostOptionsViewModel">
<Grid Background="Transparent">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="30" />
Expand All @@ -61,8 +61,8 @@

<Grid.ContextFlyout>
<MenuFlyout>
<MenuFlyoutItem Icon="Edit"
IsEnabled="False"
<MenuFlyoutItem Click="OnEditHostMenuFlyoutItemClick"
Icon="Edit"
Text="Edit" />

<MenuFlyoutItem Command="{Binding ElementName=LoginPage, Path=ViewModel.DeleteSavedHostCommand}"
Expand Down
Loading

0 comments on commit 9e37467

Please sign in to comment.