Added simple userpage

This commit is contained in:
TheJoKlLa 2022-05-24 23:27:33 +02:00
parent ce272f9f7f
commit 5c9cec5aa2
16 changed files with 397 additions and 23 deletions

View File

@ -50,6 +50,12 @@
<Compile Update="Page\AddServerProcess\SelectServerPage.xaml.cs"> <Compile Update="Page\AddServerProcess\SelectServerPage.xaml.cs">
<DependentUpon>SelectServerPage.xaml</DependentUpon> <DependentUpon>SelectServerPage.xaml</DependentUpon>
</Compile> </Compile>
<Compile Update="Page\UserPage.xaml.cs">
<DependentUpon>UserPage.xaml</DependentUpon>
</Compile>
<Compile Update="Page\UserListPage.xaml.cs">
<DependentUpon>UserListPage.xaml</DependentUpon>
</Compile>
<Compile Update="Page\MachineListPage.xaml.cs"> <Compile Update="Page\MachineListPage.xaml.cs">
<DependentUpon>MachineListPage.xaml</DependentUpon> <DependentUpon>MachineListPage.xaml</DependentUpon>
</Compile> </Compile>
@ -81,6 +87,9 @@
<Compile Update="View\MachineListItemView.xaml.cs"> <Compile Update="View\MachineListItemView.xaml.cs">
<DependentUpon>MachineListItemView.xaml</DependentUpon> <DependentUpon>MachineListItemView.xaml</DependentUpon>
</Compile> </Compile>
<Compile Update="View\UserListItemView.xaml.cs">
<DependentUpon>UserListItemView.xaml</DependentUpon>
</Compile>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<EmbeddedResource Update="Dialog\ConfirmDialog.xaml"> <EmbeddedResource Update="Dialog\ConfirmDialog.xaml">

View File

@ -8,6 +8,7 @@
<StackLayout> <StackLayout>
<StackLayout Margin="0,50,0,0" VerticalOptions="FillAndExpand"> <StackLayout Margin="0,50,0,0" VerticalOptions="FillAndExpand">
<Button Text="Machines" Command="{Binding NavigateCommand}" CommandParameter="MachineListPage" VerticalOptions="Start" BackgroundColor="{StaticResource SecondColor}" TextColor="{StaticResource FirstColor}"/> <Button Text="Machines" Command="{Binding NavigateCommand}" CommandParameter="MachineListPage" VerticalOptions="Start" BackgroundColor="{StaticResource SecondColor}" TextColor="{StaticResource FirstColor}"/>
<Button Text="Users" IsVisible="{Binding CanManageUsers}" Command="{Binding NavigateCommand}" CommandParameter="UserListPage" VerticalOptions="Start" BackgroundColor="{StaticResource SecondColor}" TextColor="{StaticResource FirstColor}"/>
<Button Text="Servers" Command="{Binding NavigateCommand}" CommandParameter="ServerListPage" VerticalOptions="Start" BackgroundColor="{StaticResource SecondColor}" TextColor="{StaticResource FirstColor}"/> <Button Text="Servers" Command="{Binding NavigateCommand}" CommandParameter="ServerListPage" VerticalOptions="Start" BackgroundColor="{StaticResource SecondColor}" TextColor="{StaticResource FirstColor}"/>
</StackLayout> </StackLayout>
<StackLayout Margin="0,0,0,10"> <StackLayout Margin="0,0,0,10">

View File

@ -0,0 +1,40 @@
<?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.UserListPage"
xmlns:converters="clr-namespace:Borepin.Converter"
Title="Machines">
<NavigationPage.TitleView>
<Button Text="Refresh" HorizontalOptions="End" BackgroundColor="{StaticResource SecondColor}" TextColor="{StaticResource FirstColor}" Command="{Binding RefreshCommand}"/>
</NavigationPage.TitleView>
<ContentPage.Resources>
<ResourceDictionary>
<converters:InvertBoolConverter x:Key="InvertBoolConverter"/>
<converters:ListNotEmptyConverter x:Key="ListNotEmptyConverter"/>
</ResourceDictionary>
</ContentPage.Resources>
<ContentPage.Content>
<StackLayout Padding="20">
<StackLayout IsVisible="{Binding IsBusy}">
<ActivityIndicator IsRunning="{Binding IsBusy}"></ActivityIndicator>
</StackLayout>
<StackLayout IsVisible="{Binding IsBusy, Converter={StaticResource InvertBoolConverter}}">
<StackLayout IsVisible="{Binding IsConnected}">
<ListView ItemsSource="{Binding UserListItemViewModel_List}" SelectionMode="None" SeparatorColor="Transparent">
<ListView.ItemTemplate>
<DataTemplate>
<ViewCell>
<views:UserListItemView />
</ViewCell>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
</StackLayout>
<StackLayout IsVisible="{Binding IsConnected, Converter={StaticResource InvertBoolConverter}}">
<Label Text="Please connect to Server" ></Label>
</StackLayout>
</StackLayout>
</StackLayout>
</ContentPage.Content>
</ContentPage>

View File

@ -0,0 +1,15 @@

using Xamarin.Forms;
using Xamarin.Forms.Xaml;
namespace Borepin.Page
{
[XamlCompilation(XamlCompilationOptions.Compile)]
public partial class UserListPage : ContentPage
{
public UserListPage()
{
InitializeComponent();
}
}
}

View File

@ -0,0 +1,28 @@
<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="Borepin.Page.UserPage"
xmlns:converters="clr-namespace:Borepin.Converter"
Title="Machine">
<ContentPage.Resources>
<ResourceDictionary>
<converters:MachineStateColorConverter x:Key="MachineStateColorConverter"/>
<converters:MachineStateStringConverter x:Key="MachineStateStringConverter"/>
<converters:IsNotNullBoolConverter x:Key="IsNotNullBoolConverter"/>
<converters:InvertBoolConverter x:Key="InvertBoolConverter"/>
</ResourceDictionary>
</ContentPage.Resources>
<ContentPage.Content>
<StackLayout Padding="20">
<StackLayout IsVisible="{Binding IsBusy}">
<ActivityIndicator IsRunning="{Binding IsBusy}"></ActivityIndicator>
</StackLayout>
<StackLayout IsVisible="{Binding IsBusy, Converter={StaticResource InvertBoolConverter}}">
<StackLayout IsVisible="{Binding IsConnected}">
<Label Text="{Binding UserItem.Username}" Style="{StaticResource LabelStyle_Title}"/>
</StackLayout>
<Label Text="Please connect to Server" IsVisible="{Binding IsConnected, Converter={StaticResource InvertBoolConverter}}"></Label>
</StackLayout>
</StackLayout>
</ContentPage.Content>
</ContentPage>

View File

@ -0,0 +1,15 @@

using Xamarin.Forms;
using Xamarin.Forms.Xaml;
namespace Borepin.Page
{
[XamlCompilation(XamlCompilationOptions.Compile)]
public partial class UserPage : ContentPage
{
public UserPage()
{
InitializeComponent();
}
}
}

View File

@ -7,11 +7,11 @@ using Prism.Navigation;
using Borepin.Base; using Borepin.Base;
using FabAccessAPI.Schema; using FabAccessAPI.Schema;
using Prism.Services; using Prism.Services;
using static FabAccessAPI.Schema.Machine;
using System; using System;
using NaturalSort.Extension; using NaturalSort.Extension;
using System.Linq; using System.Linq;
using Borepin.Service; using Borepin.Service;
using static FabAccessAPI.Schema.Machine;
namespace Borepin.PageModel namespace Borepin.PageModel
{ {

View File

@ -1,20 +1,23 @@
using System.Windows.Input; using System.Threading.Tasks;
using System.Windows.Input;
using Borepin.Base; using Borepin.Base;
using Borepin.Service;
using Borepin.Service.Versioning; using Borepin.Service.Versioning;
using FabAccessAPI.Schema;
using Prism.Navigation; using Prism.Navigation;
using Prism.Services; using Prism.Services;
using Xamarin.Forms; using Xamarin.Forms;
namespace Borepin.PageModel namespace Borepin.PageModel
{ {
public class MainPageModel : PageModelBase public class MainPageModel : ConnectionModelBase
{ {
#region Private Members #region Private Members
private readonly IVersioningService _VersioningService; private readonly IVersioningService _VersioningService;
#endregion #endregion
#region Constructors #region Constructors
public MainPageModel(INavigationService navigationService, IPageDialogService pageDialogService, IVersioningService versioningService) : base(navigationService, pageDialogService) public MainPageModel(INavigationService navigationService, IPageDialogService pageDialogService, IAPIService apiService, IVersioningService versioningService) : base(navigationService, pageDialogService, apiService)
{ {
_VersioningService = versioningService; _VersioningService = versioningService;
CurrentVersion = _VersioningService.CurrentVersion; CurrentVersion = _VersioningService.CurrentVersion;
@ -24,6 +27,16 @@ namespace Borepin.PageModel
} }
#endregion #endregion
#region LoadData
public override Task LoadAPIData()
{
UserSystem.ManageInterface_Proxy manageInterface = (UserSystem.ManageInterface_Proxy)_API.Session.UserSystem.Manage;
CanManageUsers = !manageInterface.IsNull;
return Task.CompletedTask;
}
#endregion
#region Fields #region Fields
private string _CurrentVersion; private string _CurrentVersion;
public string CurrentVersion public string CurrentVersion
@ -38,6 +51,13 @@ namespace Borepin.PageModel
get => _CurrentBuild; get => _CurrentBuild;
set => SetProperty(ref _CurrentBuild, value); set => SetProperty(ref _CurrentBuild, value);
} }
private bool _CanManageUsers;
public bool CanManageUsers
{
get => _CanManageUsers;
set => SetProperty(ref _CanManageUsers, value);
}
#endregion #endregion
#region Commands #region Commands

View File

@ -0,0 +1,78 @@
using Borepin.ViewModel;
using System.Collections.Generic;
using System.Threading.Tasks;
using System.Windows.Input;
using Prism.Commands;
using Prism.Navigation;
using Borepin.Base;
using FabAccessAPI.Schema;
using Prism.Services;
using System;
using NaturalSort.Extension;
using System.Linq;
using Borepin.Service;
namespace Borepin.PageModel
{
public class UserListPageModel : ConnectionModelBase
{
#region Constructors
public UserListPageModel(INavigationService navigationService, IPageDialogService pageDialogService, IAPIService apiService) : base(navigationService, pageDialogService, apiService)
{
RefreshCommand = new DelegateCommand(async ()=> await RefreshCommandExecute().ConfigureAwait(true));
}
#endregion
#region Data
public override async Task LoadAPIData()
{
IReadOnlyList<User> user_list = await _API.Session.UserSystem.Manage.GetUserList().ConfigureAwait(false);
List<UserListItemViewModel> viewmodel_list= new List<UserListItemViewModel>();
foreach (User user in user_list)
{
UserListItemViewModel new_viewmodel = new UserListItemViewModel(_NavigationService, _PageDialogService);
await new_viewmodel.LoadInstance(user).ConfigureAwait(false);
viewmodel_list.Add(new_viewmodel);
}
user_list.OrderBy(x => x.Username, StringComparison.OrdinalIgnoreCase.WithNaturalSort());
UserListItemViewModel_List = viewmodel_list;
}
#endregion
#region Fields
private IList<UserListItemViewModel> _UserListItemViewModel_List;
public IList<UserListItemViewModel> UserListItemViewModel_List
{
get => _UserListItemViewModel_List;
set => SetProperty(ref _UserListItemViewModel_List, value);
}
private bool _IsRefreshing;
public bool IsRefreshing
{
get => _IsRefreshing;
set => SetProperty(ref _IsRefreshing, value);
}
#endregion
#region Commands
private ICommand _RefreshCommand;
public ICommand RefreshCommand
{
get => _RefreshCommand;
set => SetProperty(ref _RefreshCommand, value);
}
public async Task RefreshCommandExecute()
{
if(_API.IsConnected)
{
await LoadAPIData().ConfigureAwait(true);
}
IsRefreshing = false;
}
#endregion
}
}

View File

@ -0,0 +1,66 @@
using Borepin.Base;
using Prism.Commands;
using Prism.Navigation;
using System.Threading.Tasks;
using System.Windows.Input;
using FabAccessAPI.Schema;
using Borepin.Model;
using Prism.Services;
using Borepin.Service;
using Borepin.Base.Exceptions;
using Capnp.Rpc;
using System;
namespace Borepin.PageModel
{
public class UserPageModel : ConnectionModelBase
{
#region Private Fields
private string _ID;
private User _User;
#endregion
#region Contructors
public UserPageModel(INavigationService navigationService, IPageDialogService pageDialogService, IAPIService apiService) : base(navigationService, pageDialogService, apiService)
{
}
#endregion
#region Data
public override Task LoadInstance(object instance)
{
if(instance is string)
{
_ID = instance as string;
}
else
{
throw new InstanceIncorrectException();
}
return Task.CompletedTask;
}
public override async Task LoadAPIData()
{
_User = (await _API.Session.UserSystem.Search.GetUserByName(_ID).ConfigureAwait(false)).Just;
UserItem = new UserVisualize(_User);
UserItem.LoadData();
}
#endregion
#region Fields
private UserVisualize _UserItem;
public UserVisualize UserItem
{
get => _UserItem;
set => SetProperty(ref _UserItem, value);
}
#endregion
#region Commands
#endregion
}
}

View File

@ -2,7 +2,6 @@
<ContentView xmlns="http://xamarin.com/schemas/2014/forms" <ContentView xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="Borepin.View.MachineListItemView" x:Class="Borepin.View.MachineListItemView"
xmlns:pagemodel="clr-namespace:Borepin.PageModel"
xmlns:converters="clr-namespace:Borepin.Converter"> xmlns:converters="clr-namespace:Borepin.Converter">
<ContentView.Resources> <ContentView.Resources>
<ResourceDictionary> <ResourceDictionary>

View File

@ -1,8 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<ContentView xmlns="http://xamarin.com/schemas/2014/forms" <ContentView xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="Borepin.View.ServerListItemView" x:Class="Borepin.View.ServerListItemView">
xmlns:pagemodel="clr-namespace:Borepin.PageModel">
<ContentView.Content> <ContentView.Content>
<Grid RowSpacing="0"> <Grid RowSpacing="0">
<Grid.ColumnDefinitions> <Grid.ColumnDefinitions>

View File

@ -0,0 +1,23 @@
<?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.UserListItemView">
<ContentView.Content>
<Grid RowSpacing="0">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="5" />
<ColumnDefinition Width="3*" />
<ColumnDefinition Width="2*" />
<ColumnDefinition Width="1*" />
<ColumnDefinition Width="1" />
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="*"/>
<RowDefinition Height="1"/>
</Grid.RowDefinitions>
<Label Grid.Row="0" Grid.Column="1" Text="{Binding User.Username, StringFormat='{0}'}" Style="{StaticResource LabelStyle_Primary}" VerticalOptions="Center"/>
<Button Grid.Row="0" Grid.Column="3" Margin="0, 3, 0, 3" Text="➔" Command="{Binding SelectInstanceCommand}" Style="{StaticResource Style_Button_Primary}" VerticalOptions="Center"/>
<BoxView Grid.Row="1" Grid.ColumnSpan="5" BackgroundColor="{StaticResource FifthColor}"/>
</Grid>
</ContentView.Content>
</ContentView>

View File

@ -0,0 +1,15 @@

using Xamarin.Forms;
using Xamarin.Forms.Xaml;
namespace Borepin.View
{
[XamlCompilation(XamlCompilationOptions.Compile)]
public partial class UserListItemView : ContentView
{
public UserListItemView()
{
InitializeComponent();
}
}
}

View File

@ -0,0 +1,71 @@
using Borepin.Base;
using Borepin.Model;
using FabAccessAPI;
using FabAccessAPI.Schema;
using Prism.Commands;
using Prism.Navigation;
using Prism.Services;
using System.Threading.Tasks;
using System.Windows.Input;
using Xamarin.Forms;
namespace Borepin.ViewModel
{
public class UserListItemViewModel : PageModelBase
{
#region Constructors
public UserListItemViewModel(INavigationService navigationService, IPageDialogService pageDialogService) : base(navigationService, pageDialogService)
{
SelectInstanceCommand = new DelegateCommand(SelectInstanceCommandExecute);
}
#endregion
#region LoadData
public override Task LoadInstance(object instance)
{
if(instance is User)
{
User = new UserVisualize(instance as User);
User.LoadData();
}
return Task.CompletedTask;
}
#endregion
#region Fields
public readonly User Instance;
private UserVisualize _User;
public UserVisualize User
{
get => _User;
set => SetProperty(ref _User, value);
}
#endregion
#region Commands
private ICommand _SelectInstanceCommand;
public ICommand SelectInstanceCommand
{
get => _SelectInstanceCommand;
set => SetProperty(ref _SelectInstanceCommand, value);
}
public void SelectInstanceCommandExecute()
{
NavigationParameters parameters = new NavigationParameters
{
{ "instance", User.Username },
};
Device.BeginInvokeOnMainThread(async () =>
{
INavigationResult result = await _NavigationService.NavigateAsync("/MainPage/NavigationPage/UserListPage/UserPage", parameters).ConfigureAwait(false);
if (result.Exception != null)
{
Log.Fatal(result.Exception, "Navigating failed");
}
});
}
#endregion
}
}

View File

@ -707,24 +707,19 @@ namespace FabAccessAPI_Test
// Assert.AreEqual(expectInterface, result); // Assert.AreEqual(expectInterface, result);
//} //}
//[TestCase("Admin1", true)] [TestCase("Admin1", true)]
//[TestCase("ManagerA1", false)] [TestCase("ManagerA1", false)]
//[TestCase("MakerA1", false)] [TestCase("MakerA1", false)]
//[TestCase("GuestA1", false)] [TestCase("GuestA1", false)]
//[Order(3)] [Order(3)]
//public async Task ManageInterface(string username, bool expectInterface) public async Task ManageInterface(string username, bool expectInterface)
//{ {
// Connection connection = await API_TestEnv_Test.Connect(username); API api = new API();
// Session session = connection.Session; ConnectionData connectionData = TestEnv.CreateConnetionData(username);
await api.Connect(connectionData);
// UserSystem.IInfoInterface infoInterface = await session.UserSystem.Info().ConfigureAwait(false);
// bool result = !((UserSystem.InfoInterface_Proxy)infoInterface.Info).IsNull; }
// API_TestEnv_Test.Disconnect(connection);
// Assert.AreEqual(expectInterface, result);
//}
[TestCase("Admin1")] [TestCase("Admin1")]
[TestCase("ManagerA1")] [TestCase("ManagerA1")]