From 4870eff959938322c31be1344f19bde82dd7955f Mon Sep 17 00:00:00 2001 From: Petko Bordjukov Date: Tue, 11 Oct 2016 02:33:39 +0300 Subject: [PATCH] Add rank display in EventsController#show --- .../stylesheets/management/_dashboard.scss | 4 ++ app/models/conference.rb | 10 +++- .../management/conferences/show.html.slim | 8 +-- .../conferences/vote_results.html.slim | 8 +-- app/views/management/events/show.html.slim | 58 ++++++++++++++----- config/locales/bg.yml | 1 + 6 files changed, 63 insertions(+), 26 deletions(-) diff --git a/app/assets/stylesheets/management/_dashboard.scss b/app/assets/stylesheets/management/_dashboard.scss index 3433f8a..6557ad5 100644 --- a/app/assets/stylesheets/management/_dashboard.scss +++ b/app/assets/stylesheets/management/_dashboard.scss @@ -5,3 +5,7 @@ .large { font-size: 2rem; } + +.panel-rank { + margin-top: 18px; +} diff --git a/app/models/conference.rb b/app/models/conference.rb index 6e17ba9..666bd2e 100644 --- a/app/models/conference.rb +++ b/app/models/conference.rb @@ -44,6 +44,10 @@ class Conference < ActiveRecord::Base vote_data_updated_at.present? end + def has_voting_endpoint? + vote_data_endpoint.present? + end + private def planned_cfp_end_date_is_before_start_date @@ -82,13 +86,13 @@ class Conference < ActiveRecord::Base private - def conn - @conn ||= Faraday.new(url: conference.vote_data_endpoint + '/summary.json', + def connection + @connection ||= Faraday.new(url: conference.vote_data_endpoint + '/summary.json', headers: {'Content-Type' => 'application/json'}) end def remote_summary_data - @remote_summary_data ||= JSON.parse(conn.get do |request| + @remote_summary_data ||= JSON.parse(connection.get do |request| request.body = {summary: {talk_ids: Conference.last.events.pluck(:id)}}.to_json end.body) end diff --git a/app/views/management/conferences/show.html.slim b/app/views/management/conferences/show.html.slim index 5c0aca4..14cb163 100644 --- a/app/views/management/conferences/show.html.slim +++ b/app/views/management/conferences/show.html.slim @@ -92,11 +92,11 @@ h2 => t '.voting_results' small - - if @conference.vote_data_updated_at.present? + - if @conference.has_vote_results? = t '.vote_data_updated_at', updated_at: l(@conference.vote_data_updated_at, format: :long) .panel.panel-default table.table.table-striped.table-hover.record-table - - if @conference.vote_data_updated_at.present? + - if @conference.has_vote_results? thead tr th.text-right = t('.rank') @@ -104,7 +104,7 @@ th = Event.model_name.human.mb_chars.capitalize th tbody - - if @conference.vote_data_updated_at.present? + - if @conference.has_vote_results? - current_conference.events.order(rank: :asc).group_by(&:rank).to_a[0..9].each do |rank, events| - events.each.with_index do |event, index| tr @@ -125,7 +125,7 @@ p =< link_to update_vote_data_management_conference_path, method: :patch, class: ['btn', 'btn-primary'] do = icon :refresh, t('.fetch_vote_results') - - if @conference.vote_data_updated_at.present? + - if @conference.has_vote_results? .panel-footer.text-right .btn-group = link_to vote_results_management_conference_path, class: ['btn', 'btn-info'] do diff --git a/app/views/management/conferences/vote_results.html.slim b/app/views/management/conferences/vote_results.html.slim index a69824e..abea1c2 100644 --- a/app/views/management/conferences/vote_results.html.slim +++ b/app/views/management/conferences/vote_results.html.slim @@ -5,7 +5,7 @@ .col-lg-12 h1.page-header = t '.vote_results' - - if @conference.vote_data_updated_at.present? + - if @conference.has_vote_results? small< = t '.vote_data_updated_at', updated_at: l(@conference.vote_data_updated_at, format: :long) - if @conference.vote_data_endpoint.present? @@ -13,7 +13,7 @@ .col-lg-12 .panel.panel-default table.table.table-striped.table-hover.record-table - - if @conference.vote_data_updated_at.present? + - if @conference.has_vote_results? thead tr th.text-right = t('.rank') @@ -21,7 +21,7 @@ th = Event.model_name.human.mb_chars.capitalize th tbody - - if @conference.vote_data_updated_at.present? + - if @conference.has_vote_results? - current_conference.events.order(rank: :asc).group_by(&:rank).each do |rank, events| - events.each.with_index do |event, index| tr @@ -42,7 +42,7 @@ p =< link_to update_vote_data_management_conference_path, method: :patch, class: ['btn', 'btn-primary'] do = icon :refresh, t('.fetch_vote_results') - - if @conference.vote_data_updated_at.present? + - if @conference.has_vote_results? .panel-footer.text-right .btn-group = link_to management_conference_path, class: ['btn', 'btn-info'] do diff --git a/app/views/management/events/show.html.slim b/app/views/management/events/show.html.slim index ab19df0..bdabb24 100644 --- a/app/views/management/events/show.html.slim +++ b/app/views/management/events/show.html.slim @@ -7,24 +7,27 @@ = @event.title small< = @event.subtitle +.row + .col-md-9 h4 = t 'events.metadata', type: @event.event_type.name, language: t("locales.#{@event.language}").mb_chars.downcase, length: @event.length - .pull-right.heading-actions - .dropdown> - button class="btn btn-sm dropdown-toggle btn-#{proposition_status_class(@event.status)}" type="button" data-toggle="dropdown" title="#{t "status.#{@event.status}"}" - = icon(proposition_status_glyph(@event.status)) - span.caret< - ul.dropdown-menu - - Proposition.statuses.each do |(status, _)| - - next if status == @event.status - li - = link_to [:management, @conference, @event.proposition, proposition: {status: status}], method: :patch do - = proposition_status_icon(status) - =< t "status.#{status}" - div.btn-group.btn-group-sm - = action_buttons(@conference, @event, [:index, :edit]) + .col-md-3.text-right + .heading-actions + .dropdown> + button class="btn btn-sm dropdown-toggle btn-#{proposition_status_class(@event.status)}" type="button" data-toggle="dropdown" title="#{t "status.#{@event.status}"}" + = icon(proposition_status_glyph(@event.status)) + span.caret< + ul.dropdown-menu + - Proposition.statuses.each do |(status, _)| + - next if status == @event.status + li + = link_to [:management, @conference, @event.proposition, proposition: {status: status}], method: :patch do + = proposition_status_icon(status) + =< t "status.#{status}" + div.btn-group.btn-group-sm + = action_buttons(@conference, @event, [:index, :edit]) .row - .col-xs-12 + = content_tag :div, class: @conference.has_vote_results? || @conference.has_voting_endpoint? ? 'col-md-9' : 'col-xs-12' h3 = Event.human_attribute_name :abstract p = simple_format @event.abstract @@ -33,6 +36,31 @@ - if @event.notes.present? h3 = Event.human_attribute_name :notes p = simple_format @event.notes + - if @conference.has_vote_results? or @conference.has_voting_endpoint? + .col-md-3 + .panel.panel-info.panel-rank + .panel-heading + = t '.rank' + - if @conference.has_vote_results? + .panel-body + .row + .col-xs-3 + .huge + .label.label-info + = @event.rank + .col-xs-9.text-right + .huge + = number_to_percentage(@event.per_cent_of_votes, strip_insignificant_zeros: true, precision: 2) + = t('management.conferences.vote_results.vote_ratio', votes: @event.number_of_votes, total_votes: @conference.number_of_ballots_cast) + - else + .panel-body.text-center + = t 'management.conferences.vote_results.vote_data_never_updated' + + = link_to update_vote_data_management_conference_path(@conference), method: :patch do + .panel-footer.text-primary.text-right + = icon :refresh, t('management.conferences.vote_results.fetch_vote_results') + +.row .col-xs-12 h3 = Event.human_attribute_name :participants = render partial: 'speaker', collection: @event.participants diff --git a/config/locales/bg.yml b/config/locales/bg.yml index 2c7ce0d..912a75e 100644 --- a/config/locales/bg.yml +++ b/config/locales/bg.yml @@ -50,6 +50,7 @@ bg: previous_event_propositions: 'Предишни предложения за събития' contacts: "Информация за контакт" show: + rank: "Класиране" review: "Преглед на %{event_type} „%{event_title}“" index: all: "Всички"