Skip to content

Commit

Permalink
Merge pull request #34 from evoto-tech/feature/homepage
Browse files Browse the repository at this point in the history
Feature/homepage
  • Loading branch information
MetalMichael authored Apr 14, 2017
2 parents 479b3a1 + f27ce58 commit d8aabc4
Show file tree
Hide file tree
Showing 4 changed files with 84 additions and 30 deletions.
2 changes: 2 additions & 0 deletions EvotoClient/Skins/MainSkin.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
Source="pack://application:,,,/MaterialDesignThemes.Wpf;component/Themes/MaterialDesignTheme.Defaults.xaml" />
<ResourceDictionary
Source="pack://application:,,,/MaterialDesignThemes.Wpf;component/Themes/MaterialDesignTheme.ProgressBar.xaml" />
<ResourceDictionary
Source="pack://application:,,,/MaterialDesignThemes.Wpf;component/Themes/MaterialDesignTheme.CheckBox.xaml" />
<ResourceDictionary
Source="pack://application:,,,/MaterialDesignColors;component/Themes/Recommended/Accent/MaterialDesignColor.Lime.xaml" />
</ResourceDictionary.MergedDictionaries>
Expand Down
17 changes: 15 additions & 2 deletions EvotoClient/ViewModel/BlockchainViewModel.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Models;
using System;
using Models;

namespace EvotoClient.ViewModel
{
Expand All @@ -18,7 +19,19 @@ public BlockchainViewModel(BlockchainDetails model)
public string ChainString => _model.ChainString;

public string EndDate
=> "Ends: " + _model.ExpiryDate.ToShortTimeString() + " " + _model.ExpiryDate.ToShortDateString();
{
get
{
var time = _model.ExpiryDate.ToShortTimeString();
var date = _model.ExpiryDate.ToShortDateString();
var verb = (IsCurrent) ? "Ends" : "Ended";
return $"{verb}: {time} {date}";
}
}

public DateTime ExpiryDate => _model.ExpiryDate;

public bool IsCurrent => _model.ExpiryDate > DateTime.UtcNow;

public BlockchainDetails GetModel()
{
Expand Down
48 changes: 35 additions & 13 deletions EvotoClient/ViewModel/HomeViewModel.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System.Diagnostics;
using System.ComponentModel;
using System.Linq;
using System.Threading.Tasks;
using System.Windows.Data;
using Api.Clients;
using GalaSoft.MvvmLight.Command;
using Microsoft.Practices.ServiceLocation;
Expand Down Expand Up @@ -28,7 +29,10 @@ public HomeViewModel()
ProceedCommand = new RelayCommand(DoProceed, CanProceed);
RefreshCommand = new RelayCommand(async () => await GetVotes(), CanRefresh);

Votes = new ObservableRangeCollection<BlockchainViewModel>();
VoteCollection = new ObservableRangeCollection<BlockchainViewModel>();
VoteSource = CollectionViewSource.GetDefaultView(VoteCollection);
VoteSource.Filter = VoteFilter;
VoteSource.SortDescriptions.Add(new SortDescription("ExpiryDate", ListSortDirection.Ascending));
}

#region Commands
Expand Down Expand Up @@ -67,11 +71,24 @@ public bool NoVotes
}
}

private bool _showAllVotes;

public bool ShowAllVotes
{
get { return _showAllVotes; }
set
{
Set(ref _showAllVotes, value);
VoteSource.Refresh();
}
}

public bool NoVotesMessageVisible => !Loading && NoVotes;

public bool VotesVisible => !Loading && !NoVotes;

public ObservableRangeCollection<BlockchainViewModel> Votes { get; }
public ObservableRangeCollection<BlockchainViewModel> VoteCollection { get; }
public ICollectionView VoteSource { get; }

private BlockchainViewModel _selectedVote;

Expand Down Expand Up @@ -99,14 +116,15 @@ private void DoProceed()
// Contact the Registrar to see if we have voted on this vote yet
Task.Run(async () =>
{
var voted = await _voteClient.HasVoted(SelectedVote.ChainString);

Ui(() =>
var showResults = true;
if (SelectedVote.IsCurrent)
{
Loading = false;
});
showResults = await _voteClient.HasVoted(SelectedVote.ChainString);
}

if (!voted)
Ui(() => { Loading = false; });

if (!showResults)
{
MainVm.ChangeView(EvotoView.Vote);
var voteView = GetVm<VoteViewModel>();
Expand All @@ -119,8 +137,6 @@ private void DoProceed()
resultsVm.SelectVote(SelectedVote.GetModel());
}
});


}

private bool CanProceed()
Expand All @@ -145,8 +161,9 @@ private async Task GetVotes()
Loading = false;
if (votes.Any())
{
Votes.Clear();
Votes.AddRange(voteVms);
VoteCollection.Clear();
VoteCollection.AddRange(voteVms);
VoteSource.Refresh();
NoVotes = false;
}
else
Expand All @@ -156,6 +173,11 @@ private async Task GetVotes()
});
}

private bool VoteFilter(object item)
{
return ShowAllVotes || ((BlockchainViewModel) item).IsCurrent;
}

#endregion
}
}
47 changes: 32 additions & 15 deletions EvotoClient/Views/HomeView.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,58 +16,75 @@

<Grid Margin="0 10 0 0">
<Grid.ColumnDefinitions>
<ColumnDefinition />
<ColumnDefinition Width="6*" />
<ColumnDefinition Width="4*" />
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="9*" MaxHeight="30" />
<RowDefinition Height="71*" />
<RowDefinition Height="10*" />
<RowDefinition Height="10*" />
</Grid.RowDefinitions>
<TextBlock Style="{DynamicResource MaterialDesignTitleTextBlock}" Padding="16 0" >Available Votes</TextBlock>
<TextBlock Style="{DynamicResource MaterialDesignTitleTextBlock}"
Padding="16 0">
Available Votes
</TextBlock>

<CheckBox
Style="{DynamicResource MaterialDesignCheckBox}"
Grid.Row="0" Grid.Column="1"
HorizontalAlignment="Right"
VerticalAlignment="Center"
FlowDirection="RightToLeft"
Margin="0 0 10 0"
IsChecked="{Binding ShowAllVotes}">
<TextBlock FlowDirection="LeftToRight">Show All Votes?</TextBlock>
</CheckBox>

<ProgressBar Style="{StaticResource MaterialDesignCircularProgressBar}"
Grid.Row="1" Grid.Column="0"
Grid.Row="1" Grid.Column="0" Grid.ColumnSpan="2"
IsIndeterminate="True"
Visibility="{Binding Loading, Converter={StaticResource BoolToVisibilityHiddenConverter}}"
VerticalAlignment="Center" HorizontalAlignment="Center"
Margin="5 5 5 5" />

<TextBlock
Visibility="{Binding NoVotesMessageVisible, Converter={StaticResource BoolToVisibilityHiddenConverter}}"
Grid.Row="1"
Grid.Row="1" Grid.ColumnSpan="2" Grid.Column="0"
FontSize="16" TextWrapping="Wrap"
VerticalAlignment="Center" HorizontalAlignment="Center"
TextAlignment="Center"
Text="Sorry, there are no votes available at this time" />

<ListBox
Grid.Row="1"
ItemsSource="{Binding Votes}"
BorderBrush="Transparent"
<ListBox
Grid.Row="1" Grid.Column="0" Grid.ColumnSpan="2"
ItemsSource="{Binding VoteSource}"
BorderBrush="Transparent"
HorizontalContentAlignment="Stretch"
SelectedItem="{Binding SelectedVote}"
Visibility="{Binding VotesVisible, Converter={StaticResource BoolToVisibilityHiddenConverter}}">
<ListBox.ItemTemplate>
<DataTemplate>
<Grid Margin="4">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="7*"/>
<ColumnDefinition Width="3*"/>
<ColumnDefinition Width="7*" />
<ColumnDefinition Width="3*" />
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="1*" />
<RowDefinition Height="1*" />
</Grid.RowDefinitions>
<TextBlock Padding="16 0 0 0" Grid.Row="0" Grid.Column="0" FontWeight="Bold" Text="{Binding Name}" />
<TextBlock Padding="16 0 0 0" Grid.Row="1" Grid.Column="0" Text="{Binding Info}" />
<TextBlock Grid.Row="0" Grid.RowSpan="2" Grid.Column="1" Text="{Binding EndDate}" />
<TextBlock Padding="16 0 0 0" Grid.Row="0" Grid.Column="0" FontWeight="Bold"
Text="{Binding Name}" />
<TextBlock Padding="16 0 0 0" Grid.Row="1" Grid.Column="0" Grid.ColumnSpan="2"
Text="{Binding Info}" TextWrapping="Wrap" />
<TextBlock Grid.Row="0" Grid.Column="1" Text="{Binding EndDate}" />
</Grid>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>

<Button Grid.Row="2" Command="{Binding ProceedCommand}">Proceed</Button>
<Button Grid.Row="3" Command="{Binding RefreshCommand}">Refresh</Button>
<Button Grid.Row="2" Grid.Column="0" Grid.ColumnSpan="2" Command="{Binding ProceedCommand}">Proceed</Button>
<Button Grid.Row="3" Grid.Column="0" Grid.ColumnSpan="2" Command="{Binding RefreshCommand}">Refresh</Button>
</Grid>
</UserControl>

0 comments on commit d8aabc4

Please sign in to comment.