diff --git a/EvotoClient/Skins/MainSkin.xaml b/EvotoClient/Skins/MainSkin.xaml
index c4bab37..5b57d05 100644
--- a/EvotoClient/Skins/MainSkin.xaml
+++ b/EvotoClient/Skins/MainSkin.xaml
@@ -7,6 +7,8 @@
Source="pack://application:,,,/MaterialDesignThemes.Wpf;component/Themes/MaterialDesignTheme.Defaults.xaml" />
+
diff --git a/EvotoClient/ViewModel/BlockchainViewModel.cs b/EvotoClient/ViewModel/BlockchainViewModel.cs
index 59b266f..796be16 100644
--- a/EvotoClient/ViewModel/BlockchainViewModel.cs
+++ b/EvotoClient/ViewModel/BlockchainViewModel.cs
@@ -1,4 +1,5 @@
-using Models;
+using System;
+using Models;
namespace EvotoClient.ViewModel
{
@@ -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()
{
diff --git a/EvotoClient/ViewModel/HomeViewModel.cs b/EvotoClient/ViewModel/HomeViewModel.cs
index ec24aba..bbc7914 100644
--- a/EvotoClient/ViewModel/HomeViewModel.cs
+++ b/EvotoClient/ViewModel/HomeViewModel.cs
@@ -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;
@@ -28,7 +29,10 @@ public HomeViewModel()
ProceedCommand = new RelayCommand(DoProceed, CanProceed);
RefreshCommand = new RelayCommand(async () => await GetVotes(), CanRefresh);
- Votes = new ObservableRangeCollection();
+ VoteCollection = new ObservableRangeCollection();
+ VoteSource = CollectionViewSource.GetDefaultView(VoteCollection);
+ VoteSource.Filter = VoteFilter;
+ VoteSource.SortDescriptions.Add(new SortDescription("ExpiryDate", ListSortDirection.Ascending));
}
#region Commands
@@ -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 Votes { get; }
+ public ObservableRangeCollection VoteCollection { get; }
+ public ICollectionView VoteSource { get; }
private BlockchainViewModel _selectedVote;
@@ -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();
@@ -119,8 +137,6 @@ private void DoProceed()
resultsVm.SelectVote(SelectedVote.GetModel());
}
});
-
-
}
private bool CanProceed()
@@ -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
@@ -156,6 +173,11 @@ private async Task GetVotes()
});
}
+ private bool VoteFilter(object item)
+ {
+ return ShowAllVotes || ((BlockchainViewModel) item).IsCurrent;
+ }
+
#endregion
}
}
\ No newline at end of file
diff --git a/EvotoClient/Views/HomeView.xaml b/EvotoClient/Views/HomeView.xaml
index 232b9ee..eea9d17 100644
--- a/EvotoClient/Views/HomeView.xaml
+++ b/EvotoClient/Views/HomeView.xaml
@@ -16,7 +16,8 @@
-
+
+
@@ -24,10 +25,24 @@
- Available Votes
+
+ Available Votes
+
+
+
+ Show All Votes?
+
-
@@ -52,22 +67,24 @@
-
-
+
+
-
-
-
+
+
+
-
-
+
+
\ No newline at end of file