feat: add the issue title to the list of issues of a poll

Also naive and inefficient, but if we paginate, we'll be ok.
And if not, we can probably improve this by batching the queries.
mj-v1.12
domi41 4 years ago
parent da923a00f7
commit 1ffe67aadc

@ -5,10 +5,17 @@
package models
import (
//"code.gitea.io/gitea/modules/references"
"code.gitea.io/gitea/modules/timeutil"
"strconv"
)
// ____ _ _ _ _ ____ _ _
// / ___|__ _ _ __ __| (_) __| | __ _| |_ ___| _ \ ___ ___ _ _| | |_
// | | / _` | '_ \ / _` | |/ _` |/ _` | __/ _ \ |_) / _ \/ __| | | | | __|
// | |__| (_| | | | | (_| | | (_| | (_| | || __/ _ < __/\__ \ |_| | | |_
// \____\__,_|_| |_|\__,_|_|\__,_|\__,_|\__\___|_| \_\___||___/\__,_|_|\__|
//
type PollCandidateResult struct {
Poll *Poll
CandidateID int64 // Issue Index (or internal candidate index, later on)
@ -20,6 +27,25 @@ type PollCandidateResult struct {
CreatedUnix timeutil.TimeStamp
}
func (result *PollCandidateResult) GetColorWord() (_ string) {
return result.Poll.GetGradeColorWord(result.MedianGrade)
}
func (result *PollCandidateResult) GetCandidateName() (_ string) { // FIXME
isssue, err := GetIssueByID(result.CandidateID + 1000)
if nil != err {
return "Candidate #" + strconv.FormatInt(result.CandidateID, 10)
}
return isssue.Title
}
// ____ _ _ _ _ ____ _ _
// / ___|__ _ _ __ __| (_) __| | __ _| |_ ___| _ \ ___ ___ _ _| | |_ ___
// | | / _` | '_ \ / _` | |/ _` |/ _` | __/ _ \ |_) / _ \/ __| | | | | __/ __|
// | |__| (_| | | | | (_| | | (_| | (_| | || __/ _ < __/\__ \ |_| | | |_\__ \
// \____\__,_|_| |_|\__,_|_|\__,_|\__,_|\__\___|_| \_\___||___/\__,_|_|\__|___/
//
// PollCandidateResults implements sort.Interface based on the Score field.
type PollCandidateResults []*PollCandidateResult
@ -27,6 +53,13 @@ func (a PollCandidateResults) Len() int { return len(a) }
func (a PollCandidateResults) Less(i, j int) bool { return a[i].Score < a[j].Score }
func (a PollCandidateResults) Swap(i, j int) { a[i], a[j] = a[j], a[i] }
// ____ _ _
// | _ \ ___ ___ _ _| | |_
// | |_) / _ \/ __| | | | | __|
// | _ < __/\__ \ |_| | | |_
// |_| \_\___||___/\__,_|_|\__|
//
type PollResult struct {
Poll *Poll
Tally *PollTally
@ -35,6 +68,7 @@ type PollResult struct {
}
func (result *PollResult) GetCandidate(candidateID int64) (_ *PollCandidateResult) {
// A `for` loop is pretty inefficient, index this somehow?
for _, candidate := range result.Candidates {
if candidate.CandidateID == candidateID {
return candidate
@ -42,7 +76,3 @@ func (result *PollResult) GetCandidate(candidateID int64) (_ *PollCandidateResul
}
return nil
}
func (result *PollCandidateResult) GetColorWord() (_ string) {
return result.Poll.GetGradeColorWord(result.MedianGrade)
}

@ -44,9 +44,7 @@ The candidates are sorted by decreasing poll success.
{{ $pollResult := .Poll.GetResult }}
<ul class="candidates issue list">
{{ range $key, $candidate := $pollResult.Candidates }}
<li class="item">
{{ template "repo/polls/merit_radial" $candidate.MeritProfile }}
&nbsp;
@ -56,9 +54,10 @@ The candidates are sorted by decreasing poll success.
<a href="{{ $.AppSubUrl }}/{{ $.RepoRelPath }}/issues/{{ $candidate.CandidateID }}">
Issue
#{{ $candidate.CandidateID }}
:
{{ $candidate.GetCandidateName }}
</a>
</li>
{{ end }}
</ul>

Loading…
Cancel
Save