Skip to content

Commit

Permalink
advanced transaction listing controls
Browse files Browse the repository at this point in the history
  • Loading branch information
arkein committed May 5, 2016
1 parent 2ad0564 commit 91f1f71
Show file tree
Hide file tree
Showing 9 changed files with 180 additions and 39 deletions.
40 changes: 22 additions & 18 deletions Hearthstone Treasury/Controls/MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -28,23 +28,27 @@
</Controls:Flyout>
</Controls:FlyoutsControl>
</Controls:MetroWindow.Flyouts>
<ScrollViewer Margin="0, 0, 2, 0">
<StackPanel>
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition/>
</Grid.RowDefinitions>
<GroupBox Grid.Row="0" Header="Statistics">
<local:StatisticsControl DataContext="{Binding Statistics}"/>
<WrapPanel Orientation="Vertical">
<Controls:MetroTabControl>
<Controls:MetroTabItem Header="Transactions">
<Controls:MetroTabItem.Content>
<local:TransactionsListingControl DataContext="{Binding TransactionList}"/>
</Controls:MetroTabItem.Content>
</Controls:MetroTabItem>
<Controls:MetroTabItem Header="Reports">
<Controls:MetroTabItem.Content>
<local:ReportControl DataContext="{Binding Reports}"/>
</Controls:MetroTabItem.Content>
</Controls:MetroTabItem>
</Controls:MetroTabControl>
</WrapPanel>
</StackPanel>
</ScrollViewer>
</GroupBox>
<GroupBox Grid.Row="1">
<Controls:MetroTabControl>
<Controls:MetroTabItem Header="Transactions">
<Controls:MetroTabItem.Content>
<local:TransactionsListingControl DataContext="{Binding TransactionList}"/>
</Controls:MetroTabItem.Content>
</Controls:MetroTabItem>
<Controls:MetroTabItem Header="Reports">
<Controls:MetroTabItem.Content>
<local:ReportControl DataContext="{Binding Reports}"/>
</Controls:MetroTabItem.Content>
</Controls:MetroTabItem>
</Controls:MetroTabControl>
</GroupBox>
</Grid>
</Controls:MetroWindow>
8 changes: 4 additions & 4 deletions Hearthstone Treasury/Controls/ReportControl.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
xmlns:local="clr-namespace:Hearthstone_Treasury.Controls"
mc:Ignorable="d"
d:DesignHeight="300" d:DesignWidth="300">
<WrapPanel>
<local:DistributionChart DataContext="{Binding IncomeDistributionChart}" ></local:DistributionChart>
<local:DistributionChart DataContext="{Binding OutcomeDistributionChart}" ></local:DistributionChart>
</WrapPanel>
<WrapPanel>
<local:DistributionChart DataContext="{Binding IncomeDistributionChart}" ></local:DistributionChart>
<local:DistributionChart DataContext="{Binding OutcomeDistributionChart}" ></local:DistributionChart>
</WrapPanel>
</UserControl>
33 changes: 33 additions & 0 deletions Hearthstone Treasury/Controls/TransactionTemplateControl.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<UserControl x:Class="Hearthstone_Treasury.Controls.TransactionTemplateControl"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:Hearthstone_Treasury.Controls"
xmlns:sys="clr-namespace:System;assembly=mscorlib"
xmlns:Models="clr-namespace:Hearthstone_Treasury.ViewModels"
mc:Ignorable="d">
<UserControl.Resources>
<ObjectDataProvider x:Key="categoryEnum" MethodName="GetValues" ObjectType="{x:Type sys:Enum}">
<ObjectDataProvider.MethodParameters>
<x:Type Type="Models:CategoryEnum"/>
</ObjectDataProvider.MethodParameters>
</ObjectDataProvider>
</UserControl.Resources>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="Auto"/>
</Grid.ColumnDefinitions>
<ComboBox Grid.Column="0" SelectedValuePath="{Binding Category}" ItemsSource="{Binding Source={StaticResource categoryEnum}}" Margin="2,0,2,0"/>
<Label Grid.Column="1" Content="Change"/>
<TextBox Grid.Column="2" Text="{Binding Difference}" Margin="2,0,2,0" />
<Label Grid.Column="3" Content="Comment"/>
<TextBox Grid.Column="4" Text="{Binding Comment}" Margin="2,0,2,0"/>
<Button Grid.Column="5" Margin="2" Content="Add" Command="{Binding CreateTransaction}"/>
</Grid>
</UserControl>
28 changes: 28 additions & 0 deletions Hearthstone Treasury/Controls/TransactionTemplateControl.xaml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace Hearthstone_Treasury.Controls
{
/// <summary>
/// Interaction logic for TransactionTemplateControl.xaml
/// </summary>
public partial class TransactionTemplateControl : UserControl
{
public TransactionTemplateControl()
{
InitializeComponent();
}
}
}
57 changes: 42 additions & 15 deletions Hearthstone Treasury/Controls/TransactionsListingControl.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,48 @@
xmlns:local="clr-namespace:Hearthstone_Treasury.Controls"
xmlns:sys="clr-namespace:System;assembly=mscorlib"
xmlns:Models="clr-namespace:Hearthstone_Treasury.ViewModels"
xmlns:scm="clr-namespace:System.ComponentModel;assembly=WindowsBase"
mc:Ignorable="d"
d:DesignHeight="300" d:DesignWidth="300">
<DataGrid ItemsSource="{Binding Transactions}" AutoGenerateColumns="False" CanUserReorderColumns="False">
<DataGrid.Resources>
<ObjectDataProvider x:Key="categoryEnum" MethodName="GetValues" ObjectType="{x:Type sys:Enum}">
<ObjectDataProvider.MethodParameters>
<x:Type Type="Models:CategoryEnum"/>
</ObjectDataProvider.MethodParameters>
</ObjectDataProvider>
</DataGrid.Resources>
<DataGrid.Columns>
<DataGridTextColumn Binding="{Binding Moment}" Header="When" SortDirection="Ascending"/>
<DataGridComboBoxColumn Header="Category" SelectedItemBinding="{Binding Category}" ItemsSource="{Binding Source={StaticResource categoryEnum}}"/>
<DataGridTextColumn Binding="{Binding Difference}" Header="Difference"/>
<DataGridTextColumn Binding="{Binding Comment}" Header="Comments" />
</DataGrid.Columns>
</DataGrid>
<UserControl.Resources>
<ObjectDataProvider x:Key="categoryEnum" MethodName="GetValues" ObjectType="{x:Type sys:Enum}">
<ObjectDataProvider.MethodParameters>
<x:Type Type="Models:CategoryEnum"/>
</ObjectDataProvider.MethodParameters>
</ObjectDataProvider>
<CollectionViewSource x:Key="TransactionsViewSource" Source="{Binding Transactions}">
<CollectionViewSource.SortDescriptions>
<scm:SortDescription PropertyName="Moment" Direction="Descending"/>
</CollectionViewSource.SortDescriptions>
</CollectionViewSource>
</UserControl.Resources>
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition/>
</Grid.RowDefinitions>
<GroupBox Header="New entry">
<local:TransactionTemplateControl Grid.Row="0" DataContext="{Binding TransactionTemplate}"/>
</GroupBox>
<DataGrid Grid.Row="1" ItemsSource="{Binding Source={StaticResource TransactionsViewSource}}" AutoGenerateColumns="False" CanUserReorderColumns="False" ClipToBounds="True"
VerticalScrollBarVisibility="Auto" HorizontalAlignment="Stretch">
<DataGrid.Columns>
<DataGridTemplateColumn Header="Date" SortDirection="Descending" SortMemberPath="Moment">
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<TextBlock Text="{Binding Moment,StringFormat={}{0:d}}" ToolTip="{Binding Moment,StringFormat={}{0:t}}" TextAlignment="Center"/>
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
<DataGridTemplateColumn.CellEditingTemplate>
<DataTemplate>
<DatePicker SelectedDate="{Binding Moment}" HorizontalContentAlignment="Center"/>
</DataTemplate>
</DataGridTemplateColumn.CellEditingTemplate>
</DataGridTemplateColumn>
<DataGridComboBoxColumn Header="Category" SelectedItemBinding="{Binding Category}" ItemsSource="{Binding Source={StaticResource categoryEnum}}"/>
<DataGridTextColumn Binding="{Binding Difference}" Header="Difference"/>
<DataGridTextColumn Binding="{Binding Comment}" Header="Comments" />
</DataGrid.Columns>
</DataGrid>
</Grid>
</UserControl>
8 changes: 8 additions & 0 deletions Hearthstone Treasury/Hearthstone Treasury.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -117,10 +117,14 @@
<Compile Include="Controls\TransactionsListingControl.xaml.cs">
<DependentUpon>TransactionsListingControl.xaml</DependentUpon>
</Compile>
<Compile Include="Controls\TransactionTemplateControl.xaml.cs">
<DependentUpon>TransactionTemplateControl.xaml</DependentUpon>
</Compile>
<Compile Include="Controls\TreasuryMenuItem.xaml.cs">
<DependentUpon>TreasuryMenuItem.xaml</DependentUpon>
</Compile>
<Compile Include="HearthstoneTreasuryPlugin.cs" />
<Compile Include="ViewModels\NewTransactionViewModel.cs" />
<Compile Include="ViewModels\StatisticsViewModel.cs" />
<Compile Include="ViewModels\TransactionListViewModel.cs" />
<Compile Include="ViewModels\PluginSettingsViewModel.cs" />
Expand Down Expand Up @@ -160,6 +164,10 @@
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="Controls\TransactionTemplateControl.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="Controls\TreasuryMenuItem.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
Expand Down
24 changes: 24 additions & 0 deletions Hearthstone Treasury/ViewModels/NewTransactionViewModel.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
using ReactiveUI;
using ReactiveUI.Fody.Helpers;

namespace Hearthstone_Treasury.ViewModels
{
public class NewTransactionViewModel : ReactiveObject
{
public NewTransactionViewModel()
{
CreateTransaction = ReactiveCommand.Create();
}

public ReactiveCommand<object> CreateTransaction { get; private set; }

[Reactive]
public int Difference { get; set; }

[Reactive]
public CategoryEnum Category { get; set; }

[Reactive]
public string Comment { get; set; }
}
}
4 changes: 2 additions & 2 deletions Hearthstone Treasury/ViewModels/PluginSettingsViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ public static PluginSettingsViewModel LoadSettings(string filePath)
{
settings = new PluginSettingsViewModel()
{
CollectionWindowWidth = 395,
CollectionWindowHeight = 560,
CollectionWindowWidth = 487,
CollectionWindowHeight = 666,
InitialBalance = 0
};
}
Expand Down
17 changes: 17 additions & 0 deletions Hearthstone Treasury/ViewModels/TransactionListViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using System.Linq;
using System.Reactive;
using System.Reactive.Linq;
using System.Windows;

namespace Hearthstone_Treasury.ViewModels
{
Expand All @@ -15,6 +16,19 @@ public TransactionListViewModel(ReactiveList<TransactionViewModel> transactionsL
TransactionsChanged.Select(_ => CalculateReportingDays()).ToProperty(this, x => x.ReportingDays, out reportingDays, CalculateReportingDays());
TransactionsChanged.Select(_ => Transactions.Where(x => x.Difference > 0).Sum(x => x.Difference)).ToProperty(this, x => x.GoldIn, out goldIn, Transactions.Where(x => x.Difference > 0).Sum(x => x.Difference));
TransactionsChanged.Select(_ => Transactions.Where(x => x.Difference < 0).Sum(x => x.Difference)).ToProperty(this, x => x.GoldOut, out goldOut, Transactions.Where(x => x.Difference < 0).Sum(x => x.Difference));

TransactionTemplate = new NewTransactionViewModel();
TransactionTemplate.CreateTransaction.Subscribe(t => AddTransactionFromTemplate());
}

private void AddTransactionFromTemplate()
{
Transactions.Add(new TransactionViewModel()
{
Category = TransactionTemplate.Category,
Difference = TransactionTemplate.Difference,
Comment = TransactionTemplate.Comment,
});
}

private double CalculateReportingDays()
Expand All @@ -31,6 +45,9 @@ private double CalculateReportingDays()
return days;
}

[Reactive]
public NewTransactionViewModel TransactionTemplate { get; set; }

[Reactive]
public ReactiveList<TransactionViewModel> Transactions { get; private set; }

Expand Down

0 comments on commit 91f1f71

Please sign in to comment.