style: flourish the start page of polls

Dominique Merle 1 year ago
parent 5d53343d6c
commit 28966fdf87

@ -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 {

@ -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. <paper>)
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)

@ -28,7 +28,7 @@ func TestNaiveDeliberator(t *testing.T) {
assert.NoError(t, err)
assert.NotNil(t, poll)
pnd := &PollNaiveDeliberator{}
pnd := &MajorityJudgmentDeliberator{}
// No judgments yet

@ -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.

@ -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 !?

@ -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)

@ -4,7 +4,7 @@
<div class="ui container">
<div class="navbar">
{{/* {{template "repo/poll/navbar" .}}*/}}
{{if and (or .CanWriteIssues .CanWritePulls) (not .Repository.IsArchived)}}
{{if and (or .CanWritePolls) (not .Repository.IsArchived)}}
<div class="ui right">
<a class="ui green button" href="{{$.Link}}/new">{{.locale.Tr "repo.polls.new"}}</a>
</div>
@ -50,7 +50,7 @@
</div>
</div>
{{if or .CanWriteIssues .CanWritePulls}}
{{if .CanWritePolls}}
<div class="ui small basic delete modal">
<div class="ui icon header">
<i class="trash icon"></i>

@ -1,5 +1,5 @@
{{template "base/head" .}}
<div class="repository new poll">
<div class="repository polls new">
{{template "repo/header" .}}
<div class="ui container">
<h2 class="ui dividing header">

@ -0,0 +1,15 @@
{{template "base/head" .}}
<div class="page-content repository polls start">
{{template "repo/header" .}}
<div class="ui container">
<div class="ui center segment">
{{svg "octicon-law" 32}}
<h2>{{.locale.Tr "repo.polls.welcome"}}</h2>
<p>{{.locale.Tr "repo.polls.welcome_desc"}}</p>
{{if and .CanWritePolls (not .Repository.IsMirror)}}
<a class="ui green button" href="{{$.Link}}/new">{{.locale.Tr "repo.polls.create_first_poll"}}</a>
{{end}}
</div>
</div>
</div>
{{template "base/footer" .}}

@ -7,7 +7,7 @@ The candidates are sorted by decreasing poll success.
*/}}
<div class="repository polls">
<div class="repository polls view">
{{ template "repo/header" . }}
<div class="ui container">
<div class="navbar">

@ -2112,6 +2112,19 @@
}
}
&.polls {
&.start {
.ui.segment {
padding-top: 70px;
padding-bottom: 100px;
.svg {
height: 48px;
}
}
}
}
&.settings {
&.collaboration {
.collaborator.list {

Loading…
Cancel
Save