Add rank display in EventsController#show

This commit is contained in:
Petko Bordjukov 2016-10-11 02:33:39 +03:00
parent 28071e1d7a
commit 4870eff959
6 changed files with 63 additions and 26 deletions

View File

@ -5,3 +5,7 @@
.large { .large {
font-size: 2rem; font-size: 2rem;
} }
.panel-rank {
margin-top: 18px;
}

View File

@ -44,6 +44,10 @@ class Conference < ActiveRecord::Base
vote_data_updated_at.present? vote_data_updated_at.present?
end end
def has_voting_endpoint?
vote_data_endpoint.present?
end
private private
def planned_cfp_end_date_is_before_start_date def planned_cfp_end_date_is_before_start_date
@ -82,13 +86,13 @@ class Conference < ActiveRecord::Base
private private
def conn def connection
@conn ||= Faraday.new(url: conference.vote_data_endpoint + '/summary.json', @connection ||= Faraday.new(url: conference.vote_data_endpoint + '/summary.json',
headers: {'Content-Type' => 'application/json'}) headers: {'Content-Type' => 'application/json'})
end end
def remote_summary_data 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 request.body = {summary: {talk_ids: Conference.last.events.pluck(:id)}}.to_json
end.body) end.body)
end end

View File

@ -92,11 +92,11 @@
h2 h2
=> t '.voting_results' => t '.voting_results'
small 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) = t '.vote_data_updated_at', updated_at: l(@conference.vote_data_updated_at, format: :long)
.panel.panel-default .panel.panel-default
table.table.table-striped.table-hover.record-table table.table.table-striped.table-hover.record-table
- if @conference.vote_data_updated_at.present? - if @conference.has_vote_results?
thead thead
tr tr
th.text-right = t('.rank') th.text-right = t('.rank')
@ -104,7 +104,7 @@
th = Event.model_name.human.mb_chars.capitalize th = Event.model_name.human.mb_chars.capitalize
th th
tbody 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| - current_conference.events.order(rank: :asc).group_by(&:rank).to_a[0..9].each do |rank, events|
- events.each.with_index do |event, index| - events.each.with_index do |event, index|
tr tr
@ -125,7 +125,7 @@
p p
=< link_to update_vote_data_management_conference_path, method: :patch, class: ['btn', 'btn-primary'] do =< link_to update_vote_data_management_conference_path, method: :patch, class: ['btn', 'btn-primary'] do
= icon :refresh, t('.fetch_vote_results') = icon :refresh, t('.fetch_vote_results')
- if @conference.vote_data_updated_at.present? - if @conference.has_vote_results?
.panel-footer.text-right .panel-footer.text-right
.btn-group .btn-group
= link_to vote_results_management_conference_path, class: ['btn', 'btn-info'] do = link_to vote_results_management_conference_path, class: ['btn', 'btn-info'] do

View File

@ -5,7 +5,7 @@
.col-lg-12 .col-lg-12
h1.page-header h1.page-header
= t '.vote_results' = t '.vote_results'
- if @conference.vote_data_updated_at.present? - if @conference.has_vote_results?
small< small<
= t '.vote_data_updated_at', updated_at: l(@conference.vote_data_updated_at, format: :long) = t '.vote_data_updated_at', updated_at: l(@conference.vote_data_updated_at, format: :long)
- if @conference.vote_data_endpoint.present? - if @conference.vote_data_endpoint.present?
@ -13,7 +13,7 @@
.col-lg-12 .col-lg-12
.panel.panel-default .panel.panel-default
table.table.table-striped.table-hover.record-table table.table.table-striped.table-hover.record-table
- if @conference.vote_data_updated_at.present? - if @conference.has_vote_results?
thead thead
tr tr
th.text-right = t('.rank') th.text-right = t('.rank')
@ -21,7 +21,7 @@
th = Event.model_name.human.mb_chars.capitalize th = Event.model_name.human.mb_chars.capitalize
th th
tbody 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| - current_conference.events.order(rank: :asc).group_by(&:rank).each do |rank, events|
- events.each.with_index do |event, index| - events.each.with_index do |event, index|
tr tr
@ -42,7 +42,7 @@
p p
=< link_to update_vote_data_management_conference_path, method: :patch, class: ['btn', 'btn-primary'] do =< link_to update_vote_data_management_conference_path, method: :patch, class: ['btn', 'btn-primary'] do
= icon :refresh, t('.fetch_vote_results') = icon :refresh, t('.fetch_vote_results')
- if @conference.vote_data_updated_at.present? - if @conference.has_vote_results?
.panel-footer.text-right .panel-footer.text-right
.btn-group .btn-group
= link_to management_conference_path, class: ['btn', 'btn-info'] do = link_to management_conference_path, class: ['btn', 'btn-info'] do

View File

@ -7,24 +7,27 @@
= @event.title = @event.title
small< small<
= @event.subtitle = @event.subtitle
.row
.col-md-9
h4 h4
= t 'events.metadata', type: @event.event_type.name, language: t("locales.#{@event.language}").mb_chars.downcase, length: @event.length = t 'events.metadata', type: @event.event_type.name, language: t("locales.#{@event.language}").mb_chars.downcase, length: @event.length
.pull-right.heading-actions .col-md-3.text-right
.dropdown> .heading-actions
button class="btn btn-sm dropdown-toggle btn-#{proposition_status_class(@event.status)}" type="button" data-toggle="dropdown" title="#{t "status.#{@event.status}"}" .dropdown>
= icon(proposition_status_glyph(@event.status)) button class="btn btn-sm dropdown-toggle btn-#{proposition_status_class(@event.status)}" type="button" data-toggle="dropdown" title="#{t "status.#{@event.status}"}"
span.caret< = icon(proposition_status_glyph(@event.status))
ul.dropdown-menu span.caret<
- Proposition.statuses.each do |(status, _)| ul.dropdown-menu
- next if status == @event.status - Proposition.statuses.each do |(status, _)|
li - next if status == @event.status
= link_to [:management, @conference, @event.proposition, proposition: {status: status}], method: :patch do li
= proposition_status_icon(status) = link_to [:management, @conference, @event.proposition, proposition: {status: status}], method: :patch do
=< t "status.#{status}" = proposition_status_icon(status)
div.btn-group.btn-group-sm =< t "status.#{status}"
= action_buttons(@conference, @event, [:index, :edit]) div.btn-group.btn-group-sm
= action_buttons(@conference, @event, [:index, :edit])
.row .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 h3 = Event.human_attribute_name :abstract
p = simple_format @event.abstract p = simple_format @event.abstract
@ -33,6 +36,31 @@
- if @event.notes.present? - if @event.notes.present?
h3 = Event.human_attribute_name :notes h3 = Event.human_attribute_name :notes
p = simple_format @event.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 .col-xs-12
h3 = Event.human_attribute_name :participants h3 = Event.human_attribute_name :participants
= render partial: 'speaker', collection: @event.participants = render partial: 'speaker', collection: @event.participants

View File

@ -50,6 +50,7 @@ bg:
previous_event_propositions: 'Предишни предложения за събития' previous_event_propositions: 'Предишни предложения за събития'
contacts: "Информация за контакт" contacts: "Информация за контакт"
show: show:
rank: "Класиране"
review: "Преглед на %{event_type} „%{event_title}“" review: "Преглед на %{event_type} „%{event_title}“"
index: index:
all: "Всички" all: "Всички"