Skip to content

Commit

Permalink
When merging ranked votes of different ranks, instead of merging the …
Browse files Browse the repository at this point in the history
…votes,

the text of the 'from' vote is changed to be the text of the destination vote.
Track vote list before and after the merge, to allow re-adding the newly
changed vote to the display list.
  • Loading branch information
Kinematics committed Sep 4, 2015
1 parent e1f4cf6 commit c139c79
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
11 changes: 11 additions & 0 deletions NetTally/MergeVotesWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -225,9 +225,20 @@ private void merge_Click(object sender, RoutedEventArgs e)

try
{
var votesPrior = VoteCounter.GetVotesCollection(CurrentVoteType).Keys.ToList();

if (VoteCounter.Merge(fromVote, toVote, CurrentVoteType))
{
var votesAfter = VoteCounter.GetVotesCollection(CurrentVoteType).Keys.ToList();
var votesDiff = votesAfter.Except(votesPrior);

VoteCollection.Remove(fromVote);
if (votesDiff.Count() == 1)
{
VoteCollection.Add(votesDiff.First());
}


VoterView1.Refresh();
VoterView2.Refresh();
}
Expand Down
16 changes: 16 additions & 0 deletions TallyCore/VoteCounter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,22 @@ public bool Merge(string fromVote, string toVote, VoteType voteType)
if (!votesSet.TryGetValue(toVote, out toVoters))
throw new ArgumentException(nameof(toVote) + " does not exist.");

if (voteType == VoteType.Rank)
{
string markFrom = VoteString.GetVoteMarker(fromVote);
string markTo = VoteString.GetVoteMarker(toVote);

// If ranked votes are being merged, but of different ranks, the "to" vote will simply be a text change
if (markFrom != markTo)
{
string toContent = VoteString.GetVoteContent(toVote);
string revisedFrom = VoteString.ModifyVoteLine(fromVote, content: toContent);
Rename(fromVote, revisedFrom, voteType);
return true;
}
}


toVoters.UnionWith(fromVoters);

votesSet.Remove(fromVote);
Expand Down

0 comments on commit c139c79

Please sign in to comment.