Handle the edge case of newly created unranked events

This commit is contained in:
Petko Bordjukov 2016-10-11 05:16:31 +03:00
parent abe3366e5e
commit ff68699b96
8 changed files with 46 additions and 17 deletions

View File

@ -12,6 +12,8 @@ class Event < ActiveRecord::Base
belongs_to :event_type belongs_to :event_type
scope :ranked, -> { where.not(ranked: nil).where.not(votes: nil) }
validates :conference, presence: true validates :conference, presence: true
validates :title, presence: true validates :title, presence: true
validates :abstract, presence: true validates :abstract, presence: true
@ -60,6 +62,10 @@ class Event < ActiveRecord::Base
} }
end end
def ranked?
conference.has_vote_results? and rank.present? and number_of_votes.present?
end
def per_cent_of_votes def per_cent_of_votes
if conference.has_vote_results? and conference.number_of_ballots_cast > 0 if conference.has_vote_results? and conference.number_of_ballots_cast > 0
Rational(number_of_votes * 100, conference.number_of_ballots_cast) Rational(number_of_votes * 100, conference.number_of_ballots_cast)

View File

@ -89,7 +89,7 @@
.row .row
.col-lg-12 .col-lg-12
.submissions-chart#submissions-chart data-submissions="#{submissions_chart_data(@conference).to_json}" .submissions-chart#submissions-chart data-submissions="#{submissions_chart_data(@conference).to_json}"
- if @conference.vote_data_endpoint.present? - if @conference.has_voting_endpoint?
hr hr
.row .row
.col-lg-12 .col-lg-12
@ -109,16 +109,23 @@
th th
tbody tbody
- if @conference.has_vote_results? - if @conference.has_vote_results?
- current_conference.events.order(rank: :asc).group_by(&:rank).to_a[0..9].each do |rank, events| - current_conference.events.order(rank: :asc).group_by(&:rank).select { |rank, _| rank.nil? or rank <= 10 }.each do |rank, events|
- events.each.with_index do |event, index| - events.each.with_index do |event, index|
tr tr
- if index == 0 - if index == 0
td.text-right rowspan="#{events.count}" - if event.ranked?
.large td.text-right rowspan="#{events.count}"
span.label.label-info = event.rank .large
td.text-right rowspan="#{events.count}" span.label.label-info = event.rank
span title="#{t('.vote_ratio', votes: event.number_of_votes, total_votes: @conference.number_of_ballots_cast)}" td.text-right rowspan="#{events.count}"
= number_to_percentage(event.per_cent_of_votes, strip_insignificant_zeros: true, precision: 2) span title="#{t('.vote_ratio', votes: event.number_of_votes, total_votes: @conference.number_of_ballots_cast)}"
= number_to_percentage(event.per_cent_of_votes, strip_insignificant_zeros: true, precision: 2)
- else
td.text-right rowspan="#{events.count}"
.large
span.label.label-danger &times;
td.text-right rowspan="#{events.count}"
= t('.unranked')
td = event.title td = event.title
td.actions = action_buttons(@conference, event, [:show]) td.actions = action_buttons(@conference, event, [:show])
- else - else

View File

@ -26,12 +26,19 @@
- events.each.with_index do |event, index| - events.each.with_index do |event, index|
tr tr
- if index == 0 - if index == 0
td.text-right rowspan="#{events.count}" - if event.ranked?
.large td.text-right rowspan="#{events.count}"
span.label.label-info = event.rank .large
td.text-right rowspan="#{events.count}" span.label.label-info = event.rank
span title="#{t('.vote_ratio', votes: event.number_of_votes, total_votes: @conference.number_of_ballots_cast)}" td.text-right rowspan="#{events.count}"
= number_to_percentage(event.per_cent_of_votes, strip_insignificant_zeros: true, precision: 2) span title="#{t('.vote_ratio', votes: event.number_of_votes, total_votes: @conference.number_of_ballots_cast)}"
= number_to_percentage(event.per_cent_of_votes, strip_insignificant_zeros: true, precision: 2)
- else
td.text-right rowspan="#{events.count}"
.large
span.label.label-danger &times;
td.text-right rowspan="#{events.count}"
= t('.unranked')
td = event.title td = event.title
td.actions = action_buttons(@conference, event, [:show]) td.actions = action_buttons(@conference, event, [:show])
- else - else

View File

@ -14,6 +14,14 @@
dd = event.track.name dd = event.track.name
dt = Event.human_attribute_name :language dt = Event.human_attribute_name :language
dd = t("locales.#{event.language}") dd = t("locales.#{event.language}")
- if event.ranked?
dt = Event.human_attribute_name :rank
dd title="#{t('management.conferences.vote_results.vote_ratio', votes: event.number_of_votes, total_votes: @conference.number_of_ballots_cast)}"
.label.label-info
= event.rank
=< number_to_percentage(event.per_cent_of_votes, strip_insignificant_zeros: true, precision: 2)
td.visible-md.visible-lg.visible-xl td.visible-md.visible-lg.visible-xl
= links_to_event_participants_for(event) = links_to_event_participants_for(event)

View File

@ -63,7 +63,7 @@
tr tr
td = event.title td = event.title
td.text-center td.text-center
- if event.conference.has_vote_results? - if event.ranked?
.large .large
.label.label-info = event.rank .label.label-info = event.rank
td = event.conference.title td = event.conference.title

View File

@ -41,7 +41,7 @@
.panel.panel-info.panel-rank .panel.panel-info.panel-rank
.panel-heading .panel-heading
= t '.rank' = t '.rank'
- if @conference.has_vote_results? - if @event.ranked?
.panel-body .panel-body
.row .row
.col-xs-3 .col-xs-3

View File

@ -50,7 +50,7 @@
tr tr
td = event.title td = event.title
td.text-center td.text-center
- if event.conference.has_vote_results? - if event.ranked?
.large .large
.label.label-info = event.rank .label.label-info = event.rank
td = event.conference.title td = event.conference.title

View File

@ -29,6 +29,7 @@ bg:
fetch_vote_results: "Изтегли резултатите от гласуването" fetch_vote_results: "Изтегли резултатите от гласуването"
percent: "%" percent: "%"
rank: "Позиция" rank: "Позиция"
unranked: "Няма данни"
show: show:
full_vote_results: "Пълни резултати от гласуването" full_vote_results: "Пълни резултати от гласуването"
vote_data_never_updated: "Резулатите от гласуването не са изтеглени" vote_data_never_updated: "Резулатите от гласуването не са изтеглени"