From 28966fdf87d8e206c35e38992650efdfd5642cf4 Mon Sep 17 00:00:00 2001 From: domi41 Date: Thu, 23 Feb 2023 09:25:14 +0100 Subject: [PATCH] style: flourish the start page of polls --- models/poll.go | 9 +++++--- models/poll_deliberator.go | 22 +++++++------------ models/poll_deliberator_test.go | 2 +- options/locale/locale_en-US.ini | 3 +++ options/locale/locale_fr-FR.ini | 3 +++ routers/web/repo/poll.go | 12 +++++++--- .../polls/{polls_index.tmpl => index.tmpl} | 4 ++-- .../repo/polls/{polls_new.tmpl => new.tmpl} | 2 +- templates/repo/polls/start.tmpl | 15 +++++++++++++ .../repo/polls/{polls_view.tmpl => view.tmpl} | 2 +- web_src/less/_repository.less | 13 +++++++++++ 11 files changed, 62 insertions(+), 25 deletions(-) rename templates/repo/polls/{polls_index.tmpl => index.tmpl} (95%) rename templates/repo/polls/{polls_new.tmpl => new.tmpl} (98%) create mode 100644 templates/repo/polls/start.tmpl rename templates/repo/polls/{polls_view.tmpl => view.tmpl} (97%) diff --git a/models/poll.go b/models/poll.go index 23da8564a..bf78f1726 100644 --- a/models/poll.go +++ b/models/poll.go @@ -1,4 +1,4 @@ -// Copyright 2020 The Gitea Authors. All rights reserved. +// Copyright 2020 The Gitea Community. All rights reserved. // Use of this source code is governed by a MIT-style // license that can be found in the LICENSE file. @@ -33,7 +33,7 @@ type Poll struct { Ref string // Do we need this? Are we even using it? WHat is it? Gradation string `xorm:"-"` - AreCandidatesIssues bool // unused + AreCandidatesIssues bool // unused -- is this even the way to go ? DeadlineUnix timeutil.TimeStamp `xorm:"INDEX"` CreatedUnix timeutil.TimeStamp `xorm:"INDEX created"` @@ -67,6 +67,7 @@ func (poll *Poll) GetGradationList() []string { func (poll *Poll) GetGradeColorWord(grade uint8) (_ string) { // Another placeholder, bypassing the dragon for now + // Note: additional work was done here in the MJ Golang module switch grade { case 0: return "red" @@ -87,6 +88,7 @@ func (poll *Poll) GetGradeColorWord(grade uint8) (_ string) { func (poll *Poll) GetGradeColorCode(grade uint8) (_ string) { // Another placeholder, bypassing the dragon for now + // Note: additional work was done here in the MJ Golang module switch grade { case 0: return "#E0361C" @@ -133,7 +135,7 @@ func (poll *Poll) GetJudgmentOnCandidate(judge *user_model.User, candidateID int func (poll *Poll) GetResult() (results *PollResult) { // The deliberator should probably be a parameter of this function, // and upstream we could fetch it from context or settings. - deliberator := &PollNaiveDeliberator{ + deliberator := &MajorityJudgmentDeliberator{ UseHighMean: false, } @@ -182,6 +184,7 @@ type CreatePollOptions struct { //Grades string } +// CreatePoll creates a new Poll from the provided options func CreatePoll(opts *CreatePollOptions) (poll *Poll, err error) { ctx, committer, err := db.TxContext() if err != nil { diff --git a/models/poll_deliberator.go b/models/poll_deliberator.go index dab69d4cd..adad41ac7 100644 --- a/models/poll_deliberator.go +++ b/models/poll_deliberator.go @@ -11,21 +11,16 @@ import ( ) type PollDeliberator interface { + // Deliberate ranks Candidates and gathers statistics into a PollResult Deliberate(poll *Poll) (result *PollResult, err error) } -// _ _ _ -// | \ | | __ _(_)_ _____ -// | \| |/ _` | \ \ / / _ \ -// | |\ | (_| | |\ V / __/ -// |_| \_|\__,_|_| \_/ \___| -// - -type PollNaiveDeliberator struct { +type MajorityJudgmentDeliberator struct { UseHighMean bool // should default to false ; strategy for even number of judgments } -func (deli *PollNaiveDeliberator) Deliberate(poll *Poll) (_ *PollResult, err error) { +// Deliberate ranks Candidates and gathers statistics into a PollResult +func (deli *MajorityJudgmentDeliberator) Deliberate(poll *Poll) (_ *PollResult, err error) { naiveTallier := &PollNaiveTallier{} pollTally, err := naiveTallier.Tally(poll) @@ -56,7 +51,6 @@ func (deli *PollNaiveDeliberator) Deliberate(poll *Poll) (_ *PollResult, err err gradesProfile := make([]uint64, 0, amountOfGrades) for i := 0; i < amountOfGrades; i++ { gradesProfile = append(gradesProfile, candidateTally.Grades[i].Amount) - //gradesProfile = append(gradesProfile, uint64(i+1)) } meritProfile := &PollCandidateMeritProfile{ @@ -65,8 +59,7 @@ func (deli *PollNaiveDeliberator) Deliberate(poll *Poll) (_ *PollResult, err err Position: 0, // see below Grades: gradesProfile, JudgmentsAmount: candidateTally.JudgmentsAmount, - //JudgmentsAmount: (6+1)*3, - CreatedUnix: creationTime, + CreatedUnix: creationTime, } candidates = append(candidates, &PollCandidateResult{ @@ -117,12 +110,14 @@ func (deli *PollNaiveDeliberator) Deliberate(poll *Poll) (_ *PollResult, err err // String scoring is not the fastest but it was within reach of a Go newbie. /* +GetScore computes the score of a Candidate This method follows the following algorithm: // Assume that each candidate has the same amount of judgments = MAX_JUDGES. // (best fill with 0=REJECT to allow posterior candidate addition, cf. ) for each Candidate + tally = CandidateTally(Candidate) // sums of judgments, per grade, basically score = "" // score is a string but could be raw bits // When we append integers to score below, @@ -147,9 +142,8 @@ for each Candidate // Use it later in a bubble sort or whatever Candidate.score = score - */ -func (deli *PollNaiveDeliberator) GetScore(pct *PollCandidateTally) (_ string) { +func (deli *MajorityJudgmentDeliberator) GetScore(pct *PollCandidateTally) (_ string) { score := "" ct := pct.Copy() // /!. Poll is not a copy (nor does it have to be) diff --git a/models/poll_deliberator_test.go b/models/poll_deliberator_test.go index 72eb83c50..75aef4ab9 100644 --- a/models/poll_deliberator_test.go +++ b/models/poll_deliberator_test.go @@ -28,7 +28,7 @@ func TestNaiveDeliberator(t *testing.T) { assert.NoError(t, err) assert.NotNil(t, poll) - pnd := &PollNaiveDeliberator{} + pnd := &MajorityJudgmentDeliberator{} // No judgments yet diff --git a/options/locale/locale_en-US.ini b/options/locale/locale_en-US.ini index 6ebd62e56..cd4d39246 100644 --- a/options/locale/locale_en-US.ini +++ b/options/locale/locale_en-US.ini @@ -1668,7 +1668,10 @@ milestones.filter_sort.most_issues = Most issues milestones.filter_sort.least_issues = Least issues polls = Polls +polls.welcome = Welcome to the Polls. +polls.welcome_desc = Polls let you hear the song of the crowd. polls.create = Create Poll +polls.create_first_poll = Create the first Poll polls.create.success = You created the poll '%s'. polls.cancel = Cancel polls.delete.success = You deleted the poll. Why would you do such a thing?! I'm hurt. diff --git a/options/locale/locale_fr-FR.ini b/options/locale/locale_fr-FR.ini index 6098b5bc9..f36c6800e 100644 --- a/options/locale/locale_fr-FR.ini +++ b/options/locale/locale_fr-FR.ini @@ -1636,7 +1636,10 @@ signing.wont_sign.approved=La fusion ne sera pas signée car la PR n'a pas appro signing.wont_sign.not_signed_in=Vous n'êtes pas authentifié polls = Scrutins +polls.welcome = Bienvenue dans les Scrutins. +polls.welcome_desc = Les scrutins révèlent le chant de la foule. polls.create = Créer un Scrutin +polls.create_first_poll = Créer un premier Scrutin polls.create.success = Vous avez créé le scrutin '%s'. polls.cancel = Annuler polls.delete.success = Vous avez supprimé le scrutin. M'enfin !? diff --git a/routers/web/repo/poll.go b/routers/web/repo/poll.go index 4d8113831..5441909a5 100644 --- a/routers/web/repo/poll.go +++ b/routers/web/repo/poll.go @@ -15,9 +15,10 @@ import ( ) const ( - tplPollsIndex base.TplName = "repo/polls/polls_index" - tplPollsView base.TplName = "repo/polls/polls_view" - tplPollsNew base.TplName = "repo/polls/polls_new" + tplPollsStart base.TplName = "repo/polls/start" + tplPollsIndex base.TplName = "repo/polls/index" + tplPollsView base.TplName = "repo/polls/view" + tplPollsNew base.TplName = "repo/polls/new" ) // IndexPolls renders an index of all the polls @@ -36,6 +37,11 @@ func IndexPolls(ctx *context.Context) { return } + if 0 == len(polls) { + ctx.HTML(200, tplPollsStart) + return + } + ctx.Data["Polls"] = polls //pager := context.NewPagination(total, setting.UI.IssuePagingNum, page, 5) diff --git a/templates/repo/polls/polls_index.tmpl b/templates/repo/polls/index.tmpl similarity index 95% rename from templates/repo/polls/polls_index.tmpl rename to templates/repo/polls/index.tmpl index dff8f8f26..ee8b73805 100644 --- a/templates/repo/polls/polls_index.tmpl +++ b/templates/repo/polls/index.tmpl @@ -4,7 +4,7 @@
-{{if or .CanWriteIssues .CanWritePulls}} +{{if .CanWritePolls}}