Added: First Try of Server Page

This commit is contained in:
TheJoKlLa 2021-01-27 01:04:08 +01:00
parent 1209796099
commit 658b753673
26 changed files with 266 additions and 95 deletions

View File

@ -4,9 +4,11 @@ using Borepin.PageModel;
using Borepin.Page;
using Xamarin.Forms;
using Borepin.Service;
using Borepin.Service.ServerInstances;
using Borepin.Service.Instances;
using Borepin.View;
using Borepin.ViewModel;
using Borepin.Dialog;
using Borepin.DialogModel;
namespace Borepin
{
@ -22,7 +24,8 @@ namespace Borepin
InitializeComponent();
//var result = await NavigationService.NavigateAsync("/NavigationPage/HostSelectPage");
var result = await NavigationService.NavigateAsync("/ListPage");
var result = await NavigationService.NavigateAsync("/MainPage/NavigationPage/ServerListPage");
//var result = await NavigationService.NavigateAsync("/ListPage");
if (!result.Success)
{
@ -40,14 +43,15 @@ namespace Borepin
containerRegistry.RegisterForNavigation<LoginPasswordPage, LoginPasswordPageModel>();
containerRegistry.RegisterForNavigation<HostSelectPage, HostSelectPageModel>();
containerRegistry.RegisterForNavigation<LoginChoosePage, LoginChoosePageModel>();
containerRegistry.RegisterForNavigation<BFFHInstancesPage, BFFHInstancesPageModel>();
containerRegistry.RegisterForNavigation<ServerListPage, ServerListPageModel>();
containerRegistry.RegisterForNavigation<ListPage, ListPageModel>();
containerRegistry.RegisterDialog<ConfirmDialog, ConfirmDialogModel>();
BFFHInstanceService bffhInstanceService = new BFFHInstanceService();
containerRegistry.RegisterInstance<IBFFHInstanceService>(bffhInstanceService);
InstanceService bffhInstanceService = new InstanceService();
containerRegistry.RegisterInstance<IInstanceService>(bffhInstanceService);
containerRegistry.RegisterInstance<BFFHService>(new BFFHService(bffhInstanceService));
}

View File

@ -31,9 +31,6 @@
<Compile Update="Page\MachinesPage.xaml.cs">
<DependentUpon>MachinesPage.xaml</DependentUpon>
</Compile>
<Compile Update="Page\BFFHInstancesPage.xaml.cs">
<DependentUpon>BFFHInstancesPage.xaml</DependentUpon>
</Compile>
<Compile Update="Page\SettingsPage.xaml.cs">
<DependentUpon>SettingsPage.xaml</DependentUpon>
</Compile>
@ -50,21 +47,21 @@
<Compile Update="Styles\LightTheme.xaml.cs">
<DependentUpon>LightTheme.xaml</DependentUpon>
</Compile>
<Compile Update="View\BFFHInstanceEntryView.xaml.cs">
<DependentUpon>BFFHInstanceEntryView.xaml</DependentUpon>
</Compile>
</ItemGroup>
<ItemGroup>
<EmbeddedResource Update="Page\HostSelectPage.xaml">
<EmbeddedResource Update="Dialog\ConfirmDialog.xaml">
<Generator>MSBuild:UpdateDesignTimeXaml</Generator>
</EmbeddedResource>
<EmbeddedResource Update="Page\AddServerDialog\HostSelectPage.xaml">
<Generator>MSBuild:UpdateDesignTimeXaml</Generator>
</EmbeddedResource>
<EmbeddedResource Update="Page\ListPage.xaml">
<Generator>MSBuild:UpdateDesignTimeXaml</Generator>
</EmbeddedResource>
<EmbeddedResource Update="Page\LoginChoosePage.xaml">
<EmbeddedResource Update="Page\AddServerDialog\LoginChoosePage.xaml">
<Generator>MSBuild:UpdateDesignTimeXaml</Generator>
</EmbeddedResource>
<EmbeddedResource Update="Page\LoginPasswordPage.xaml">
<EmbeddedResource Update="Page\AddServerDialog\LoginPasswordPage.xaml">
<Generator>MSBuild:UpdateDesignTimeXaml</Generator>
</EmbeddedResource>
<EmbeddedResource Update="Page\MachinePage.xaml">
@ -76,7 +73,7 @@
<EmbeddedResource Update="Page\MainPage.xaml">
<Generator>MSBuild:UpdateDesignTimeXaml</Generator>
</EmbeddedResource>
<EmbeddedResource Update="Page\BFFHInstancesPage.xaml">
<EmbeddedResource Update="Page\ServerListPage.xaml">
<Generator>MSBuild:UpdateDesignTimeXaml</Generator>
</EmbeddedResource>
<EmbeddedResource Update="Page\SettingsPage.xaml">
@ -93,17 +90,16 @@
<EmbeddedResource Update="Styles\LightTheme.xaml">
<Generator>MSBuild:UpdateDesignTimeXaml</Generator>
</EmbeddedResource>
<EmbeddedResource Update="View\BFFHInstanceEntryView.xaml">
<EmbeddedResource Update="View\ListItemView.xaml">
<Generator>MSBuild:UpdateDesignTimeXaml</Generator>
</EmbeddedResource>
<EmbeddedResource Update="View\ListItemView.xaml">
<EmbeddedResource Update="View\ServerListItemView.xaml">
<Generator>MSBuild:UpdateDesignTimeXaml</Generator>
</EmbeddedResource>
</ItemGroup>
<ItemGroup>
<Folder Include="Base\" />
<Folder Include="Behaviour\" />
<Folder Include="Page\LoginDialog\" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\FabAccessAPI\FabAccessAPI.csproj" />

View File

@ -0,0 +1,14 @@
<?xml version="1.0" encoding="UTF-8"?>
<ContentView xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="Borepin.Dialog.ConfirmDialog"
BackgroundColor="White">
<ContentView.Content>
<StackLayout>
<Label Text="{Binding Title}"/>
<Label Text="{Binding Message}"/>
<Button Text="Confirm" Command="{Binding ConfirmCommand}"/>
<Button Text="Abort" Command="{Binding AbortCommand}"/>
</StackLayout>
</ContentView.Content>
</ContentView>

View File

@ -0,0 +1,20 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Xamarin.Forms;
using Xamarin.Forms.Xaml;
namespace Borepin.Dialog
{
[XamlCompilation(XamlCompilationOptions.Compile)]
public partial class ConfirmDialog : ContentView
{
public ConfirmDialog()
{
InitializeComponent();
}
}
}

View File

@ -0,0 +1,76 @@
using Prism.Commands;
using Prism.Mvvm;
using Prism.Services.Dialogs;
using System;
using System.Windows.Input;
namespace Borepin.DialogModel
{
public class ConfirmDialogModel : BindableBase, IDialogAware
{
public ConfirmDialogModel()
{
ConfirmCommand = new DelegateCommand(ConfirmCommandExecute);
AbortCommand = new DelegateCommand(AbortCommandExecute);
}
#region Properties
private string _Title;
public string Title
{
get => _Title;
set => SetProperty(ref _Title, value);
}
private string _Message;
public string Message
{
get => _Message;
set => SetProperty(ref _Message, value);
}
#endregion
#region Commands
private ICommand _ConfirmCommand;
public ICommand ConfirmCommand
{
get => _ConfirmCommand;
set => SetProperty(ref _ConfirmCommand, value);
}
private void ConfirmCommandExecute()
{
RequestClose(new DialogParameters { { "confirm", true } });
}
private ICommand _AbortCommand;
public ICommand AbortCommand
{
get => _AbortCommand;
set => SetProperty(ref _AbortCommand, value);
}
private void AbortCommandExecute()
{
RequestClose(new DialogParameters { { "abort", true } });
}
#endregion
public event Action<IDialogParameters> RequestClose;
public bool CanCloseDialog()
{
return true;
}
public void OnDialogClosed()
{
}
public void OnDialogOpened(IDialogParameters parameters)
{
Title = parameters.GetValue<string>("title");
Message = parameters.GetValue<string>("message");
}
}
}

View File

@ -1,18 +0,0 @@
<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" xmlns:views="clr-namespace:Borepin.View"
x:Class="Borepin.Page.BFFHInstancesPage">
<ContentPage.Content>
<StackLayout>
<ListView ItemsSource="{Binding ServerInstance_List}">
<ListView.ItemTemplate>
<DataTemplate>
<ViewCell>
<views:BFFHInstanceEntryView />
</ViewCell>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
</StackLayout>
</ContentPage.Content>
</ContentPage>

View File

@ -9,7 +9,7 @@
<StackLayout>
<Button Text="Machines" Command="{Binding NavigateCommand}" CommandParameter="MachinesPage" />
<Button Text="Settings" Command="{Binding NavigateCommand}" CommandParameter="SettingsPage" />
<Button Text="Servers" Command="{Binding NavigateCommand}" CommandParameter="BFFHInstancesPage" />
<Button Text="Servers" Command="{Binding NavigateCommand}" CommandParameter="ServerListPage" />
</StackLayout>
</ContentPage>
</MasterDetailPage.Master>

View File

@ -0,0 +1,24 @@
<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:views="clr-namespace:Borepin.View"
x:Class="Borepin.Page.ServerListPage">
<NavigationPage.TitleView>
<Label Text="Servers" HorizontalOptions="End" Margin="0, 0, 10, 0" VerticalOptions="CenterAndExpand" FontSize="Medium" TextColor="{StaticResource FirstColor}"/>
</NavigationPage.TitleView>
<ContentPage.Content>
<StackLayout>
<ListView ItemsSource="{Binding ServerListItemViewModel_List}">
<ListView.ItemTemplate>
<DataTemplate>
<ViewCell>
<views:ServerListItemView />
</ViewCell>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
<Button Text="Connect to new Server" Command="{Binding AddInstancesCommand}"/>
<Button Text="Delete All Servers" Command="{Binding DeleteAllInstancesCommand}"/>
</StackLayout>
</ContentPage.Content>
</ContentPage>

View File

@ -10,9 +10,9 @@ using Xamarin.Forms.Xaml;
namespace Borepin.Page
{
[XamlCompilation(XamlCompilationOptions.Compile)]
public partial class BFFHInstancesPage : ContentPage
public partial class ServerListPage : ContentPage
{
public BFFHInstancesPage()
public ServerListPage()
{
InitializeComponent();
}

View File

@ -1,11 +1,9 @@
using Borepin.Service;
using Borepin.Service.ServerInstances;
using Borepin.Service.Instances;
using Prism.Mvvm;
using Prism.Navigation;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Input;
using Xamarin.Forms;
@ -15,10 +13,10 @@ namespace Borepin.PageModel
public class HostSelectPageModel : BindableBase
{
private INavigationService _NavigationService;
private IBFFHInstanceService _BFFHInstanceService;
private IInstanceService _BFFHInstanceService;
private BFFHService _BFFHService;
public HostSelectPageModel(INavigationService navigationService, BFFHService bffhService, IBFFHInstanceService bffhInstanceService)
public HostSelectPageModel(INavigationService navigationService, BFFHService bffhService, IInstanceService bffhInstanceService)
{
_NavigationService = navigationService;
_BFFHInstanceService = bffhInstanceService;

View File

@ -1,35 +0,0 @@
using Borepin.Model;
using Borepin.Service.ServerInstances;
using Prism.Mvvm;
using Prism.Navigation;
using System.Collections.ObjectModel;
using System.Threading.Tasks;
namespace Borepin.PageModel
{
public class BFFHInstancesPageModel : BindableBase
{
private INavigationService _NavigationService;
private IBFFHInstanceService _BFFHInstanceService;
public BFFHInstancesPageModel(INavigationService navigationService, IBFFHInstanceService bffhInstanceService)
{
_NavigationService = navigationService;
_BFFHInstanceService = bffhInstanceService;
LoadData();
}
private async Task LoadData()
{
_ServerInstance_List = new ObservableCollection<BFFHInstance>(await _BFFHInstanceService.GetBFFHInstances());
}
private ObservableCollection<BFFHInstance> _ServerInstance_List;
public ObservableCollection<BFFHInstance> ServerInstance_List
{
get => _ServerInstance_List;
set => SetProperty(ref _ServerInstance_List, value);
}
}
}

View File

@ -0,0 +1,92 @@
using Borepin.Service.Instances;
using Borepin.ViewModel;
using Prism.Mvvm;
using System.Collections.Generic;
using System.Threading.Tasks;
using System.Linq;
using Borepin.Model;
using System.Windows.Input;
using Prism.Commands;
using Prism.Navigation;
using Prism.Services.Dialogs;
namespace Borepin.PageModel
{
public class ServerListPageModel : BindableBase
{
private INavigationService _NavigationService;
private IDialogService _DialogService;
private IInstanceService _InstanceService;
public ServerListPageModel(INavigationService navigationService, IDialogService dialogService, IInstanceService instanceService)
{
_NavigationService = navigationService;
_DialogService = dialogService;
_InstanceService = instanceService;
DeleteAllInstancesCommand = new DelegateCommand(DeleteAllInstancesCommandExecuted);
AddInstancesCommand = new DelegateCommand(AddInstancesCommandExecuted);
LoadData();
}
private async Task<bool> LoadData()
{
List<BFFHInstance> list = await _InstanceService.GetBFFHInstances();
ServerListItemViewModel_List = list.Select(x => new ServerListItemViewModel(x)).ToList();
return await Task.FromResult(true);
}
#region Properties
private List<ServerListItemViewModel> _ServerListItemViewModel_List;
public List<ServerListItemViewModel> ServerListItemViewModel_List
{
get => _ServerListItemViewModel_List;
set => SetProperty(ref _ServerListItemViewModel_List, value);
}
#endregion
#region Commands
private ICommand _DeleteAllInstancesCommand;
public ICommand DeleteAllInstancesCommand
{
get => _DeleteAllInstancesCommand;
set => SetProperty(ref _DeleteAllInstancesCommand, value);
}
private void DeleteAllInstancesCommandExecuted()
{
var parameters = new DialogParameters
{
{ "title", "Remove all Servers" },
{ "message", "Do you really want to remove all known Servers?" }
};
_DialogService.ShowDialog("ConfirmDialog", parameters, DeleteAllInstancesConfirm);
}
private void DeleteAllInstancesConfirm(IDialogResult result)
{
if (result.Parameters.ContainsKey("confirm"))
{
_InstanceService.RemoveAllBFFHInstances();
}
}
private ICommand _AddInstancesCommand;
public ICommand AddInstancesCommand
{
get => _AddInstancesCommand;
set => SetProperty(ref _AddInstancesCommand, value);
}
private async void AddInstancesCommandExecuted()
{
INavigationResult result = await _NavigationService.NavigateAsync("HostSelectPage");
if (!result.Success)
{
System.Diagnostics.Debugger.Break();
}
}
#endregion
}
}

View File

@ -5,20 +5,20 @@ using Capnp.Rpc;
using Borepin.Service.Credentials;
using Borepin.Model;
using System.Threading.Tasks;
using Borepin.Service.ServerInstances;
using Borepin.Service.Instances;
namespace Borepin.Service
{
public class BFFHService
{
private IBFFHInstanceService _BFFHInstanceService;
private IInstanceService _BFFHInstanceService;
private CredentialsService _CredentialsService;
private Connection _Connection;
public Uri ConnectedHost { get; private set; }
public BFFHService(IBFFHInstanceService bffhInstanceService)
public BFFHService(IInstanceService bffhInstanceService)
{
_BFFHInstanceService = bffhInstanceService;
_CredentialsService = new CredentialsService();

View File

@ -2,9 +2,9 @@
using System.Collections.Generic;
using System.Threading.Tasks;
namespace Borepin.Service.ServerInstances
namespace Borepin.Service.Instances
{
public interface IBFFHInstanceService
public interface IInstanceService
{
Task<List<BFFHInstance>> GetBFFHInstances();

View File

@ -6,12 +6,12 @@ using System.Linq;
using System.Threading.Tasks;
using Xamarin.Essentials;
namespace Borepin.Service.ServerInstances
namespace Borepin.Service.Instances
{
/// <summary>
/// Save connected BFFHInstances in Xamarin.Essentials.Preferences
/// </summary>
public class BFFHInstanceService : IBFFHInstanceService
public class InstanceService : IInstanceService
{
private List<BFFHInstance> _BFFHInstance_List;

View File

@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<ContentView xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="Borepin.View.BFFHInstanceEntryView">
x:Class="Borepin.View.ServerListItemView">
<ContentView.Content>
<StackLayout>
<Label Text="{Binding Address}" />

View File

@ -10,9 +10,9 @@ using Xamarin.Forms.Xaml;
namespace Borepin.View
{
[XamlCompilation(XamlCompilationOptions.Compile)]
public partial class BFFHInstanceEntryView : ContentView
public partial class ServerListItemView : ContentView
{
public BFFHInstanceEntryView()
public ServerListItemView()
{
InitializeComponent();
}

View File

@ -3,18 +3,18 @@ using Prism.Mvvm;
namespace Borepin.ViewModel
{
public class BFFHInstanceEntryViewModel : BindableBase
public class ServerListItemViewModel : BindableBase
{
public ServerListItemViewModel(BFFHInstance server)
{
Address = server.Address.ToString();
}
private string _Address;
public string Address
{
get => _Address;
set => SetProperty(ref _Address, value);
}
public BFFHInstanceEntryViewModel(BFFHInstance bffhInstance)
{
Address = bffhInstance.Address.ToString();
}
}
}