Fix Views List

This commit is contained in:
TheJoKlLa 2022-05-22 23:39:52 +02:00
parent 224891cadb
commit c39b5bce3d
10 changed files with 203 additions and 130 deletions

View File

@ -1,4 +1,5 @@
using System; using FabAccessAPI.Schema;
using System;
using System.Globalization; using System.Globalization;
using Xamarin.Forms; using Xamarin.Forms;
@ -8,9 +9,9 @@ namespace Borepin.Converter
{ {
public object Convert(object value, Type targetType, object parameter, CultureInfo culture) public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{ {
switch((FabAccessAPI.Schema.Machine.MachineState)value) switch((Machine.MachineState)value)
{ {
case (FabAccessAPI.Schema.Machine.MachineState.free): case Machine.MachineState.free:
return (Color)Application.Current.Resources["FirstColor"]; return (Color)Application.Current.Resources["FirstColor"];
default: default:
return (Color)Application.Current.Resources["SixthColor"]; return (Color)Application.Current.Resources["SixthColor"];

View File

@ -1,4 +1,5 @@
using System; using FabAccessAPI.Schema;
using System;
using System.Globalization; using System.Globalization;
using Xamarin.Forms; using Xamarin.Forms;
@ -8,19 +9,19 @@ namespace Borepin.Converter
{ {
public object Convert(object value, Type targetType, object parameter, CultureInfo culture) public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{ {
switch((FabAccessAPI.Schema.Machine.MachineState)value) switch((Machine.MachineState)value)
{ {
case (FabAccessAPI.Schema.Machine.MachineState.free): case Machine.MachineState.free:
return "Free"; return "Free";
case (FabAccessAPI.Schema.Machine.MachineState.inUse): case Machine.MachineState.inUse:
return "In Use"; return "In Use";
case (FabAccessAPI.Schema.Machine.MachineState.toCheck): case Machine.MachineState.toCheck:
return "To Check"; return "To Check";
case (FabAccessAPI.Schema.Machine.MachineState.reserved): case Machine.MachineState.reserved:
return "Reserved"; return "Reserved";
case (FabAccessAPI.Schema.Machine.MachineState.blocked): case Machine.MachineState.blocked:
return "Blocked"; return "Blocked";
case (FabAccessAPI.Schema.Machine.MachineState.disabled): case Machine.MachineState.disabled:
return "Disabled"; return "Disabled";
default: default:
return "Unknown"; return "Unknown";

View File

@ -0,0 +1,54 @@
using FabAccessAPI;
using Prism.Mvvm;
namespace Borepin.Model
{
public class ConnectionDataVisualize : BindableBase
{
#region Private Fields
public readonly ConnectionData _ConnectionData;
#endregion
#region Constructors
public ConnectionDataVisualize(ConnectionData connectionData)
{
_ConnectionData = connectionData;
LoadData();
}
#endregion
#region Methods
public async void LoadData()
{
Host = _ConnectionData.Host.Host;
Port = _ConnectionData.Host.Port;
Username = _ConnectionData.Username;
}
#endregion
#region Fields
private string _Host;
public string Host
{
get => _Host;
set => SetProperty(ref _Host, value);
}
private int _Port;
public int Port
{
get => _Port;
set => SetProperty(ref _Port, value);
}
private string _Username;
public string Username
{
get => _Username;
set => SetProperty(ref _Username, value);
}
#endregion
}
}

View File

@ -12,20 +12,14 @@ using System;
using NaturalSort.Extension; using NaturalSort.Extension;
using System.Linq; using System.Linq;
using Borepin.Service; using Borepin.Service;
using Xamarin.Forms;
namespace Borepin.PageModel namespace Borepin.PageModel
{ {
public class MachineListPageModel : ConnectionModelBase public class MachineListPageModel : ConnectionModelBase
{ {
#region Private Fields
private Machine _NextMachine;
#endregion
#region Constructors #region Constructors
public MachineListPageModel(INavigationService navigationService, IPageDialogService pageDialogService, IAPIService apiService) : base(navigationService, pageDialogService, apiService) public MachineListPageModel(INavigationService navigationService, IPageDialogService pageDialogService, IAPIService apiService) : base(navigationService, pageDialogService, apiService)
{ {
SelectInstanceCommand = new DelegateCommand<object>(SelectInstanceCommandExecute);
ScanCodeCommand = new DelegateCommand(async () => await ScanCodeCommandExecute().ConfigureAwait(false)); ScanCodeCommand = new DelegateCommand(async () => await ScanCodeCommandExecute().ConfigureAwait(false));
RefreshCommand = new DelegateCommand(async ()=> await RefreshCommandExecute().ConfigureAwait(true)); RefreshCommand = new DelegateCommand(async ()=> await RefreshCommandExecute().ConfigureAwait(true));
} }
@ -44,21 +38,24 @@ namespace Borepin.PageModel
{ {
if(!((InUseInterface_Proxy)machine.Inuse).IsNull) if(!((InUseInterface_Proxy)machine.Inuse).IsNull)
{ {
MachineListItemViewModel new_viewmodel = new MachineListItemViewModel(machine) MachineListItemViewModel new_viewmodel = new MachineListItemViewModel(_NavigationService, _PageDialogService)
{ {
IsUserAssigned = true, IsInUseByMe = true,
}; };
await new_viewmodel.LoadInstance(machine).ConfigureAwait(false);
viewmodel_list_user_assigned.Add(new_viewmodel); viewmodel_list_user_assigned.Add(new_viewmodel);
} }
else else
{ {
viewmodel_list_not_user_assigned.Add(new MachineListItemViewModel(machine)); MachineListItemViewModel new_viewmodel = new MachineListItemViewModel(_NavigationService, _PageDialogService);
await new_viewmodel.LoadInstance(machine).ConfigureAwait(false);
viewmodel_list_not_user_assigned.Add(new_viewmodel);
} }
} }
List<MachineListItemViewModel> viewmodel_list_sorted = new List<MachineListItemViewModel>(); List<MachineListItemViewModel> viewmodel_list_sorted = new List<MachineListItemViewModel>();
viewmodel_list_sorted.AddRange(viewmodel_list_user_assigned.OrderBy(x => x.Name, StringComparison.OrdinalIgnoreCase.WithNaturalSort())); viewmodel_list_sorted.AddRange(viewmodel_list_user_assigned.OrderBy(x => x.Machine.Name, StringComparison.OrdinalIgnoreCase.WithNaturalSort()));
viewmodel_list_sorted.AddRange(viewmodel_list_not_user_assigned.OrderBy(x => x.Name, StringComparison.OrdinalIgnoreCase.WithNaturalSort())); viewmodel_list_sorted.AddRange(viewmodel_list_not_user_assigned.OrderBy(x => x.Machine.Name, StringComparison.OrdinalIgnoreCase.WithNaturalSort()));
MachineListItemViewModel_List = viewmodel_list_sorted; MachineListItemViewModel_List = viewmodel_list_sorted;
} }
#endregion #endregion
@ -96,31 +93,6 @@ namespace Borepin.PageModel
IsRefreshing = false; IsRefreshing = false;
} }
private ICommand _SelectInstanceCommand;
public ICommand SelectInstanceCommand
{
get => _SelectInstanceCommand;
set => SetProperty(ref _SelectInstanceCommand, value);
}
public void SelectInstanceCommandExecute(object obj)
{
MachineListItemViewModel viewmodel = obj as MachineListItemViewModel;
NavigationParameters parameters = new NavigationParameters
{
{ "instance", viewmodel.Instance.Id },
};
Device.BeginInvokeOnMainThread(async () =>
{
INavigationResult result = await _NavigationService.NavigateAsync($"MachinePage", parameters).ConfigureAwait(false);
if (result.Exception != null)
{
Log.Fatal(result.Exception, "Navigating failed");
}
});
}
private ICommand _ScanCodeCommand; private ICommand _ScanCodeCommand;
public ICommand ScanCodeCommand public ICommand ScanCodeCommand
{ {
@ -156,38 +128,8 @@ namespace Borepin.PageModel
return; return;
} }
_NextMachine = machine;
IsBusy = false; IsBusy = false;
} }
#endregion #endregion
#region IPageLifecycleAware
public void OnAppearing()
{
if(_NextMachine != null)
{
NavigationParameters parameters = new NavigationParameters
{
{ "id", _NextMachine.Id},
};
_NextMachine = null;
Device.BeginInvokeOnMainThread(async () =>
{
INavigationResult result = await _NavigationService.NavigateAsync("MachinePage", parameters).ConfigureAwait(false);
if (result.Exception != null)
{
Log.Fatal(result.Exception, "Navigating failed");
}
});
}
}
public void OnDisappearing()
{
}
#endregion
} }
} }

View File

@ -37,7 +37,8 @@ namespace Borepin.PageModel
IList<ConnectionData> list = await _LoginStorageService.GetList().ConfigureAwait(false); IList<ConnectionData> list = await _LoginStorageService.GetList().ConfigureAwait(false);
if (_API.IsConnected) if (_API.IsConnected)
{ {
ActiveConnection = new ServerListItemViewModel(_API.ConnectionData); ActiveConnection = new ServerListItemViewModel(_NavigationService, _PageDialogService);
await ActiveConnection.LoadInstance(_API.ConnectionData).ConfigureAwait(false);
list.Remove(_API.ConnectionData); list.Remove(_API.ConnectionData);
@ -48,7 +49,13 @@ namespace Borepin.PageModel
HasActiveConnection = false; HasActiveConnection = false;
} }
ServerListItemViewModel_List = list.Select(x => new ServerListItemViewModel(x)).ToList(); ServerListItemViewModel_List = new List<ServerListItemViewModel>();
foreach (ConnectionData connectionData in list)
{
ServerListItemViewModel serverListItemViewModel = new ServerListItemViewModel(_NavigationService, _PageDialogService);
await serverListItemViewModel.LoadInstance(connectionData).ConfigureAwait(false);
ServerListItemViewModel_List.Add(serverListItemViewModel);
}
IsBusy = false; IsBusy = false;
} }

View File

@ -23,12 +23,12 @@
<RowDefinition Height="*"/> <RowDefinition Height="*"/>
<RowDefinition Height="1"/> <RowDefinition Height="1"/>
</Grid.RowDefinitions> </Grid.RowDefinitions>
<Label Grid.Row="0" Grid.Column="1" Text="{Binding Name}" Style="{StaticResource LabelStyle_Primary}"/> <Label Grid.Row="0" Grid.Column="1" Text="{Binding Machine.Name}" Style="{StaticResource LabelStyle_Primary}"/>
<StackLayout Grid.Row="0" Grid.Column="2" Orientation="Horizontal" HorizontalOptions="End"> <StackLayout Grid.Row="0" Grid.Column="2" Orientation="Horizontal" HorizontalOptions="End">
<Label Text="{Binding State, Converter={StaticResource MachineStateStringConverter}}" TextColor="{Binding State, Converter={StaticResource MachineStateColorConverter}}" Style="{StaticResource LabelStyle_Second}"/> <Label Text="{Binding Machine.State, Converter={StaticResource MachineStateStringConverter}}" TextColor="{Binding Machine.State, Converter={StaticResource MachineStateColorConverter}}" Style="{StaticResource LabelStyle_Second}"/>
<Label Text="by Me" IsVisible="{Binding IsUserAssigned}" Style="{StaticResource LabelStyle_Second}"/> <Label Text="by Me" IsVisible="{Binding IsInUseByMe}" Style="{StaticResource LabelStyle_Second}"/>
</StackLayout> </StackLayout>
<Button Grid.Row="0" Grid.Column="3" Margin="0, 3, 0, 3" Text="➔" Command="{Binding Source={RelativeSource AncestorType={x:Type pagemodel:MachineListPageModel}}, Path=SelectInstanceCommand}" CommandParameter="{Binding .}" Style="{StaticResource Style_Button_Primary}"/> <Button Grid.Row="0" Grid.Column="3" Margin="0, 3, 0, 3" Text="➔" Command="{Binding SelectInstanceCommand}" Style="{StaticResource Style_Button_Primary}"/>
<BoxView Grid.Row="1" Grid.ColumnSpan="5" BackgroundColor="{StaticResource FifthColor}"/> <BoxView Grid.Row="1" Grid.ColumnSpan="5" BackgroundColor="{StaticResource FifthColor}"/>
</Grid> </Grid>
</ContentView.Content> </ContentView.Content>

View File

@ -16,9 +16,9 @@
<RowDefinition Height="*"/> <RowDefinition Height="*"/>
<RowDefinition Height="1"/> <RowDefinition Height="1"/>
</Grid.RowDefinitions> </Grid.RowDefinitions>
<Label Grid.Row="0" Grid.Column="1" Text="{Binding Address, StringFormat='{0}'}" Style="{StaticResource LabelStyle_Primary}" VerticalOptions="Center"/> <Label Grid.Row="0" Grid.Column="1" Text="{Binding ConnectionData.Host, StringFormat='{0}'}" Style="{StaticResource LabelStyle_Primary}" VerticalOptions="Center"/>
<Label Grid.Row="0" Grid.Column="2" Text="{Binding Username}" Style="{StaticResource LabelStyle_Second}" HorizontalTextAlignment="End" VerticalOptions="Center"/> <Label Grid.Row="0" Grid.Column="2" Text="{Binding ConnectionData.Username}" Style="{StaticResource LabelStyle_Second}" HorizontalTextAlignment="End" VerticalOptions="Center"/>
<Button Grid.Row="0" Grid.Column="3" Margin="0, 3, 0, 3" Text="➔" Command="{Binding Source={RelativeSource AncestorType={x:Type pagemodel:ServerListPageModel}}, Path=SelectInstanceCommand}" CommandParameter="{Binding .}" Style="{StaticResource Style_Button_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}"/> <BoxView Grid.Row="1" Grid.ColumnSpan="5" BackgroundColor="{StaticResource FifthColor}"/>
</Grid> </Grid>
</ContentView.Content> </ContentView.Content>

View File

@ -1,44 +1,77 @@
using Prism.Mvvm; using FabAccessAPI.Schema;
using FabAccessAPI.Schema; using System.Threading.Tasks;
using System.Windows.Input;
using Borepin.Base;
using Prism.Navigation;
using Prism.Services;
using Prism.Commands;
using Xamarin.Forms;
using Borepin.Model;
namespace Borepin.ViewModel namespace Borepin.ViewModel
{ {
public class MachineListItemViewModel : BindableBase public class MachineListItemViewModel : PageModelBase
{ {
public MachineListItemViewModel(Machine instance) #region Constructors
public MachineListItemViewModel(INavigationService navigationService, IPageDialogService pageDialogService) : base(navigationService, pageDialogService)
{ {
_Instance = instance; SelectInstanceCommand = new DelegateCommand(SelectInstanceCommandExecute);
}
#endregion
Name = instance.Name; #region LoadData
State = instance.State; public override Task LoadInstance(object instance)
{
if(instance is Machine)
{
Machine = new MachineVisualize(instance as Machine);
Machine.LoadData();
} }
private Machine _Instance; return Task.CompletedTask;
public Machine Instance }
#endregion
#region Commands
private ICommand _SelectInstanceCommand;
public ICommand SelectInstanceCommand
{ {
get => _Instance; get => _SelectInstanceCommand;
set => SetProperty(ref _Instance, value); set => SetProperty(ref _SelectInstanceCommand, value);
}
public void SelectInstanceCommandExecute()
{
NavigationParameters parameters = new NavigationParameters
{
{ "instance", Machine._Machine.Id },
};
Device.BeginInvokeOnMainThread(async () =>
{
INavigationResult result = await _NavigationService.NavigateAsync("/MainPage/NavigationPage/MachineListPage/MachinePage", parameters).ConfigureAwait(false);
if (result.Exception != null)
{
Log.Fatal(result.Exception, "Navigating failed");
}
});
} }
private string _Name; #endregion
public string Name
#region Fields
private MachineVisualize _Machine;
public MachineVisualize Machine
{ {
get => _Name; get => _Machine;
set => SetProperty(ref _Name, value); set => SetProperty(ref _Machine, value);
} }
private Machine.MachineState _State; private bool _IsInUseByMe = false;
public Machine.MachineState State public bool IsInUseByMe
{ {
get => _State; get => _IsInUseByMe;
set => SetProperty(ref _State, value); set => SetProperty(ref _IsInUseByMe, value);
}
private bool _IsUserAssigned = false;
public bool IsUserAssigned
{
get => _IsUserAssigned;
set => SetProperty(ref _IsUserAssigned, value);
} }
#endregion
} }
} }

View File

@ -1,35 +1,69 @@
using Borepin.Model; using Borepin.Base;
using Borepin.Model;
using FabAccessAPI; using FabAccessAPI;
using Prism.Mvvm; using Prism.Commands;
using Prism.Navigation;
using Prism.Services;
using System.Threading.Tasks;
using System.Windows.Input;
using Xamarin.Forms;
namespace Borepin.ViewModel namespace Borepin.ViewModel
{ {
public class ServerListItemViewModel : BindableBase public class ServerListItemViewModel : PageModelBase
{ {
#region Constructors #region Constructors
public ServerListItemViewModel(ConnectionData instance) public ServerListItemViewModel(INavigationService navigationService, IPageDialogService pageDialogService) : base(navigationService, pageDialogService)
{ {
Instance = instance; SelectInstanceCommand = new DelegateCommand(SelectInstanceCommandExecute);
Address = instance.Host.Host; }
Username = instance.Username; #endregion
#region LoadData
public override Task LoadInstance(object instance)
{
if(instance is ConnectionData)
{
ConnectionData = new ConnectionDataVisualize(instance as ConnectionData);
ConnectionData.LoadData();
}
return Task.CompletedTask;
} }
#endregion #endregion
#region Fields #region Fields
public readonly ConnectionData Instance; public readonly ConnectionData Instance;
private string _Address; private ConnectionDataVisualize _ConnectionData;
public string Address public ConnectionDataVisualize ConnectionData
{ {
get => _Address; get => _ConnectionData;
set => SetProperty(ref _Address, value); set => SetProperty(ref _ConnectionData, value);
} }
#endregion
private string _Username; #region Commands
public string Username private ICommand _SelectInstanceCommand;
public ICommand SelectInstanceCommand
{ {
get => _Username; get => _SelectInstanceCommand;
set => SetProperty(ref _Username, value); set => SetProperty(ref _SelectInstanceCommand, value);
}
public void SelectInstanceCommandExecute()
{
NavigationParameters parameters = new NavigationParameters
{
{ "instance", ConnectionData._ConnectionData },
};
Device.BeginInvokeOnMainThread(async () =>
{
INavigationResult result = await _NavigationService.NavigateAsync("/MainPage/NavigationPage/ServerListPage/ServerPage", parameters).ConfigureAwait(false);
if (result.Exception != null)
{
Log.Fatal(result.Exception, "Navigating failed");
}
});
} }
#endregion #endregion
} }

View File

@ -9,6 +9,7 @@ namespace FabAccessAPI
public Mechanism Mechanism; public Mechanism Mechanism;
public string Username; public string Username;
public Dictionary<string, object> Properties; public Dictionary<string, object> Properties;
public bool IsDefault;
public DateTime LastTime; public DateTime LastTime;
public override bool Equals(object? obj) public override bool Equals(object? obj)