StarSim

StarSim.git
git clone git://git.lenczewski.org/StarSim.git
Log | Files | Refs | README | LICENSE

commit 72a4004486081ac7b358e368ba57e67b314893c7
parent ca68e34acfefe3dca49adc9f34317d6c74ea307c
Author: Mikolaj Lenczewski <33129490+EnderRifter@users.noreply.github.com>
Date:   Fri, 16 Aug 2019 17:21:59 +0200

Polished up Overview view and view model

Diffstat:
MStarSim/StarSimGui/ViewModels/OverviewViewModel.cs | 47++++++++++++++++++++++++++++++++++++++++++-----
MStarSim/StarSimGui/Views/Overview.xaml | 38++++++++++++++++++++++++++++++++------
2 files changed, 74 insertions(+), 11 deletions(-)

diff --git a/StarSim/StarSimGui/ViewModels/OverviewViewModel.cs b/StarSim/StarSimGui/ViewModels/OverviewViewModel.cs @@ -1,5 +1,6 @@ using System.Linq; using DynamicData.Binding; +using Microsoft.EntityFrameworkCore; using ReactiveUI; using StarSimLib.Contexts; using StarSimLib.Models; @@ -24,14 +25,19 @@ namespace StarSimGui.ViewModels /// <summary> /// The backing field for the <see cref="PublishedSystems"/> property. /// </summary> - private IObservableCollection<PublishedSystem> publishedSystems; + private IObservableCollection<PublishedSystem> publishedSystemsObservable; + + /// <summary> + /// The backing field for the <see cref="SelectedPublishedSystem"/> property. + /// </summary> + private PublishedSystem selectedPublishedSystem; /// <summary> /// Initialises a new instance of the <see cref="OverviewViewModel"/> class. /// </summary> public OverviewViewModel() { - publishedSystems = new ObservableCollectionExtended<PublishedSystem>(); + publishedSystemsObservable = new ObservableCollectionExtended<PublishedSystem>(); } /// <summary> @@ -41,6 +47,8 @@ namespace StarSimGui.ViewModels public OverviewViewModel(in SimulatorContext context) : this() { dbContext = context; + + PublishedSystems.Load(dbContext.PublishedSystems.Include(system => system.System)); } /// <summary> @@ -56,26 +64,53 @@ namespace StarSimGui.ViewModels { currentUser = value; this.RaisePropertyChanged(); + this.RaisePropertyChanged(nameof(IsSelectedPublishedSystemNull)); } } /// <summary> - /// The <see cref="PublishedSystem"/> instance that the current user has published. + /// Whether the currently selected published system is null. + /// </summary> + public bool IsSelectedPublishedSystemNull + { + get { return SelectedPublishedSystem == null; } + } + + /// <summary> + /// The published systems held in the database. /// </summary> public IObservableCollection<PublishedSystem> PublishedSystems { get { - return publishedSystems; + return publishedSystemsObservable; } set { - publishedSystems = value; + publishedSystemsObservable = value; this.RaisePropertyChanged(); } } /// <summary> + /// The currently selected published system from the <see cref="PublishedSystems"/> collection. + /// </summary> + public PublishedSystem SelectedPublishedSystem + { + get + { + return selectedPublishedSystem; + } + set + { + selectedPublishedSystem = value; + this.RaisePropertyChanged(); + + this.RaisePropertyChanged(nameof(IsSelectedPublishedSystemNull)); + } + } + + /// <summary> /// Handles the <see cref="UserLoginViewModel.LoggedIn"/> event. /// </summary> /// <param name="newUser">The user which logged in.</param> @@ -87,6 +122,8 @@ namespace StarSimGui.ViewModels dbContext.PublishedSystems.Where(system => system.Publisher.Id == CurrentUser.Id); PublishedSystems.Load(usersPublishedSystems); + + SelectedPublishedSystem = null; } /// <summary> diff --git a/StarSim/StarSimGui/Views/Overview.xaml b/StarSim/StarSimGui/Views/Overview.xaml @@ -2,6 +2,7 @@ xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:vm="clr-namespace:StarSimGui.ViewModels;assembly=StarSimGui" xmlns:v="clr-namespace:StarSimGui.Views;assembly=StarSimGui" + xmlns:ssl="clr-namespace:StarSimLib.Models;assembly=StarSimLib" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" mc:Ignorable="d" @@ -12,9 +13,17 @@ <vm:OverviewViewModel /> </Design.DataContext> + <UserControl.DataTemplates> + <DataTemplate DataType="{x:Type ssl:PublishedSystem}"> + <StackPanel Orientation="Horizontal"> + <TextBlock VerticalAlignment="Center" Text="{Binding System.Name}"></TextBlock> + </StackPanel> + </DataTemplate> + </UserControl.DataTemplates> + <Border BorderBrush="Gray" BorderThickness="2" CornerRadius="2" Margin="2"> - <Grid ColumnDefinitions="*,*,*,*" RowDefinitions="*,*,*,*"> - <Border BorderBrush="Beige" BorderThickness="2" Grid.Column="0" Grid.ColumnSpan="1" Grid.Row="0" Grid.RowSpan="4"> + <Grid ColumnDefinitions="*,*,*,*,*" RowDefinitions="*,*,*,*"> + <Border BorderBrush="Gray" BorderThickness="2" CornerRadius="2" Margin="2" Grid.Column="0" Grid.ColumnSpan="1" Grid.Row="0" Grid.RowSpan="4"> <Grid ColumnDefinitions="*,*" RowDefinitions="*,*,*,*"> <TextBlock Grid.Column="0" Grid.Row="0">Username:</TextBlock> <TextBlock Grid.Column="1" Grid.Row="0" Text="{Binding CurrentUser.Username}" /> @@ -26,11 +35,28 @@ <TextBlock Grid.Column="1" Grid.Row="3" Text="{Binding CurrentUser.Id}" /> </Grid> </Border> - <Border BorderBrush="Beige" BorderThickness="2" Grid.Column="1" Grid.ColumnSpan="3" Grid.Row="0" Grid.RowSpan="3"> - <TextBlock>Hello World</TextBlock> + <Border BorderBrush="Gray" BorderThickness="2" CornerRadius="2" Margin="2" Grid.Column="1" Grid.ColumnSpan="2" Grid.Row="0" Grid.RowSpan="3"> + <StackPanel> + <TextBlock>Published Systems:</TextBlock> + <ListBox Items="{Binding PublishedSystems}" SelectedItem="{Binding SelectedPublishedSystem, Mode=OneWayToSource}"> + </ListBox> + </StackPanel> + </Border> + <Border BorderBrush="Gray" BorderThickness="2" CornerRadius="2" Margin="2" Grid.Column="3" Grid.ColumnSpan="2" Grid.Row="0" Grid.RowSpan="3"> + <StackPanel> + <TextBlock>Selected Published System's Child Bodies:</TextBlock> + <ListBox Items="{Binding SelectedPublishedSystem.System.BodyToSystemJoins}" IsVisible="{Binding !IsSelectedPublishedSystemNull}"> + </ListBox> + </StackPanel> </Border> - <Border BorderBrush="Beige" BorderThickness="2" Grid.Column="1" Grid.ColumnSpan="3" Grid.Row="3" Grid.RowSpan="1"> - <TextBlock>Hello World</TextBlock> + <Border BorderBrush="Gray" BorderThickness="2" CornerRadius="2" Margin="2" Grid.Column="1" Grid.ColumnSpan="4" Grid.Row="3" Grid.RowSpan="1"> + <StackPanel DataContext="{Binding SelectedPublishedSystem}" IsVisible="{Binding !$parent.DataContext.IsSelectedPublishedSystemNull}"> + <TextBlock>Selected Published System Details:</TextBlock> + <StackPanel Orientation="Horizontal"> + <TextBlock Text="Publish Date: "></TextBlock> + <TextBlock Text="{Binding PublishDate}"></TextBlock> + </StackPanel> + </StackPanel> </Border> </Grid> </Border>