Esempio n. 1
0
        /// <summary>
        /// Function to get a line for one of the compact mode displays,
        /// based on whether this is a parent or child node.
        /// </summary>
        /// <param name="displayMode">The display mode currently being used.</param>
        /// <returns>Returns a string representation of the current vote node.</returns>
        public string GetLine(DisplayMode displayMode)
        {
            var lines = Text.GetStringLines();

            if (lines.Count == 0)
            {
                return(string.Empty);
            }

            string results = string.Empty;

            if (HasChildren || (!HasParent && lines.Count == 1))
            {
                // Parent node, or solitary node with 1 line.
                results = VoteString.ModifyVoteLine(lines[0], marker: VoterCount.ToString());
            }
            else if (HasParent && lines.Count == 1)
            {
                // Child node with 1 line
                if (displayMode == DisplayMode.Compact)
                {
                    results = VoteString.ModifyVoteLine(lines[0], prefix: "", marker: VoterCount.ToString());
                }
                else
                {
                    results = VoteString.ModifyVoteLine(lines[0], prefix: "-", marker: VoterCount.ToString());
                }
            }
            else if (!HasChildren)
            {
                // Other nodes without children (typically child nodes).

                StringBuilder sb = new StringBuilder();

                if (HasParent && displayMode == DisplayMode.CompactNoVoters)
                {
                    sb.Append("-");
                }

                sb.Append("[");
                sb.Append(VoterCount);
                sb.Append("]");

                // Only explicitly add tasks to parent nodes
                if (!HasParent)
                {
                    string task = VoteString.GetVoteTask(lines[0]);
                    if (!string.IsNullOrEmpty(task))
                    {
                        sb.Append($"[{task}]");
                    }
                }


                sb.Append(" Plan: ");
                string firstVoter = VoteInfo.GetFirstVoter(Voters);
                sb.Append(firstVoter);

                // Only add the link if we're not showing the voters
                if (displayMode == DisplayMode.CompactNoVoters)
                {
                    string link;

                    VoteType voteType = firstVoter.IsPlanName() ? VoteType.Plan : VoteType.Vote;
                    link = VoteInfo.GetVoterUrl(firstVoter, voteType);

                    sb.Append(" — ");
                    sb.Append(link);
                }

                results = sb.ToString();
            }

            // Child nodes in compact mode will be put in spoilers.  Remove BBCode.
            if (HasParent && displayMode == DisplayMode.Compact)
            {
                results = VoteString.RemoveBBCode(results);
            }

            return(results);
        }
Esempio n. 2
0
        /// <summary>
        /// Handle general organization of outputting the tally results,
        /// grouped by task.  Use VoteNodes if displaying in a compact
        /// mode, or just use the original votes if displaying in a normal
        /// mode.
        /// Display the vote, the count, and the voters, as appropriate.
        /// </summary>
        private void ConstructNormalOutput(CancellationToken token)
        {
            token.ThrowIfCancellationRequested();

            if (VoteInfo.NormalVoterCount == 0)
            {
                return;
            }

            var allVotes           = VoteCounter.GetVotesCollection(VoteType.Vote);
            var votesGroupedByTask = VoteInfo.GroupVotesByTask(allVotes);

            bool firstTask = true;

            foreach (var taskGroup in votesGroupedByTask)
            {
                token.ThrowIfCancellationRequested();

                if (taskGroup.Any())
                {
                    if (!firstTask)
                    {
                        AddLineBreak();
                    }

                    firstTask = false;

                    AddTaskLabel(taskGroup.Key);

                    if (DisplayMode == DisplayMode.Compact || DisplayMode == DisplayMode.CompactNoVoters)
                    {
                        var nodes = VoteInfo.GetVoteNodes(taskGroup);

                        foreach (var vote in nodes)
                        {
                            if (vote.VoterCount > 0)
                            {
                                AddVote(vote);
                            }
                        }
                    }
                    else
                    {
                        foreach (var vote in taskGroup.OrderByDescending(v => VoteInfo.CountVote(v)).ThenBy(q => VoteInfo.LastVoteID(q.Value)))
                        {
                            if (AdvancedOptions.Instance.DisplayPlansWithNoVotes || VoteInfo.CountVote(vote) > 0)
                            {
                                AddVote(vote);
                                AddVoteCount(vote);
                                AddVoters(vote.Value, "Voters");
                            }
                        }
                    }
                }
            }

            AddTotalVoterCount(VoteInfo.NormalVoterCount);
        }