From ff68699b96eadcf362d19ea01c3b9c8233147872 Mon Sep 17 00:00:00 2001 From: Petko Bordjukov Date: Tue, 11 Oct 2016 05:16:31 +0300 Subject: [PATCH] Handle the edge case of newly created unranked events --- app/models/event.rb | 6 +++++ .../management/conferences/show.html.slim | 23 ++++++++++++------- .../conferences/vote_results.html.slim | 19 ++++++++++----- app/views/management/events/_event.slim | 8 +++++++ app/views/management/events/_speaker.slim | 2 +- app/views/management/events/show.html.slim | 2 +- .../personal_profiles/show.html.slim | 2 +- config/locales/bg.yml | 1 + 8 files changed, 46 insertions(+), 17 deletions(-) diff --git a/app/models/event.rb b/app/models/event.rb index afa7546..495e91c 100644 --- a/app/models/event.rb +++ b/app/models/event.rb @@ -12,6 +12,8 @@ class Event < ActiveRecord::Base belongs_to :event_type + scope :ranked, -> { where.not(ranked: nil).where.not(votes: nil) } + validates :conference, presence: true validates :title, presence: true validates :abstract, presence: true @@ -60,6 +62,10 @@ class Event < ActiveRecord::Base } end + def ranked? + conference.has_vote_results? and rank.present? and number_of_votes.present? + end + def per_cent_of_votes if conference.has_vote_results? and conference.number_of_ballots_cast > 0 Rational(number_of_votes * 100, conference.number_of_ballots_cast) diff --git a/app/views/management/conferences/show.html.slim b/app/views/management/conferences/show.html.slim index 04a26d7..a67802d 100644 --- a/app/views/management/conferences/show.html.slim +++ b/app/views/management/conferences/show.html.slim @@ -89,7 +89,7 @@ .row .col-lg-12 .submissions-chart#submissions-chart data-submissions="#{submissions_chart_data(@conference).to_json}" -- if @conference.vote_data_endpoint.present? +- if @conference.has_voting_endpoint? hr .row .col-lg-12 @@ -109,16 +109,23 @@ th tbody - 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| tr - if index == 0 - td.text-right rowspan="#{events.count}" - .large - span.label.label-info = event.rank - td.text-right rowspan="#{events.count}" - 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) + - if event.ranked? + td.text-right rowspan="#{events.count}" + .large + span.label.label-info = event.rank + td.text-right rowspan="#{events.count}" + 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 × + td.text-right rowspan="#{events.count}" + = t('.unranked') td = event.title td.actions = action_buttons(@conference, event, [:show]) - else diff --git a/app/views/management/conferences/vote_results.html.slim b/app/views/management/conferences/vote_results.html.slim index abea1c2..102b8a3 100644 --- a/app/views/management/conferences/vote_results.html.slim +++ b/app/views/management/conferences/vote_results.html.slim @@ -26,12 +26,19 @@ - events.each.with_index do |event, index| tr - if index == 0 - td.text-right rowspan="#{events.count}" - .large - span.label.label-info = event.rank - td.text-right rowspan="#{events.count}" - 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) + - if event.ranked? + td.text-right rowspan="#{events.count}" + .large + span.label.label-info = event.rank + td.text-right rowspan="#{events.count}" + 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 × + td.text-right rowspan="#{events.count}" + = t('.unranked') td = event.title td.actions = action_buttons(@conference, event, [:show]) - else diff --git a/app/views/management/events/_event.slim b/app/views/management/events/_event.slim index 2303a2e..1241239 100644 --- a/app/views/management/events/_event.slim +++ b/app/views/management/events/_event.slim @@ -14,6 +14,14 @@ dd = event.track.name dt = Event.human_attribute_name :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 = links_to_event_participants_for(event) diff --git a/app/views/management/events/_speaker.slim b/app/views/management/events/_speaker.slim index 840a4c7..62b555e 100644 --- a/app/views/management/events/_speaker.slim +++ b/app/views/management/events/_speaker.slim @@ -63,7 +63,7 @@ tr td = event.title td.text-center - - if event.conference.has_vote_results? + - if event.ranked? .large .label.label-info = event.rank td = event.conference.title diff --git a/app/views/management/events/show.html.slim b/app/views/management/events/show.html.slim index bdabb24..9ecb6b0 100644 --- a/app/views/management/events/show.html.slim +++ b/app/views/management/events/show.html.slim @@ -41,7 +41,7 @@ .panel.panel-info.panel-rank .panel-heading = t '.rank' - - if @conference.has_vote_results? + - if @event.ranked? .panel-body .row .col-xs-3 diff --git a/app/views/management/personal_profiles/show.html.slim b/app/views/management/personal_profiles/show.html.slim index 273738b..256e048 100644 --- a/app/views/management/personal_profiles/show.html.slim +++ b/app/views/management/personal_profiles/show.html.slim @@ -50,7 +50,7 @@ tr td = event.title td.text-center - - if event.conference.has_vote_results? + - if event.ranked? .large .label.label-info = event.rank td = event.conference.title diff --git a/config/locales/bg.yml b/config/locales/bg.yml index 8269395..832ae82 100644 --- a/config/locales/bg.yml +++ b/config/locales/bg.yml @@ -29,6 +29,7 @@ bg: fetch_vote_results: "Изтегли резултатите от гласуването" percent: "%" rank: "Позиция" + unranked: "Няма данни" show: full_vote_results: "Пълни резултати от гласуването" vote_data_never_updated: "Резулатите от гласуването не са изтеглени"