Optimize management events view

This commit is contained in:
Petko Bordjukov 2019-05-05 00:23:53 +03:00
parent eeb92483f3
commit 23bd2ab334
2 changed files with 36 additions and 29 deletions

View File

@ -3,7 +3,14 @@ module Management
def index def index
@conference = find_conference @conference = find_conference
@filters = filter_params || {} @filters = filter_params || {}
@events = EventSearch.new(scope: Event.where(conference: @conference).eager_load(:participants_with_personal_profiles, :proposition, :proposer, :track, :event_type).preload(:conference), filters: params[:filters]).results
@events = EventSearch
.new(scope: Event.where(conference: @conference)
.eager_load(:participants_with_personal_profiles,
:proposition, :proposer, {track: [:translations]},
{event_type: [:translations]}, :feedbacks)
.preload(:conference), filters: params[:filters]).results
# @events = @conference.events.order(:title).includes(:proposition, :proposer, :track, :event_type) # @events = @conference.events.order(:title).includes(:proposition, :proposer, :track, :event_type)
end end
@ -46,7 +53,7 @@ module Management
private private
def find_conference def find_conference
Conference.find(params[:conference_id]) Conference.eager_load({tracks: :translations}, {event_types: :translations}).find(params[:conference_id])
end end
def filter_params def filter_params

View File

@ -7,8 +7,8 @@
= Event.model_name.human(count: 2).mb_chars.titleize = Event.model_name.human(count: 2).mb_chars.titleize
small< small<
| ( | (
= t '.total', current: @events.count, total: current_conference.events.count = t '.total', current: @events.size, total: @conference.events.size
=< Event.model_name.human(count: current_conference.events.count) =< Event.model_name.human(count: @conference.events.size)
| ) | )
.row.visible-sm .row.visible-sm
.col-xs-12 .col-xs-12
@ -21,73 +21,73 @@
.panel-body .panel-body
ul.nav.nav-pills.nav-stacked ul.nav.nav-pills.nav-stacked
= content_tag :li, role: "presentation", class: @filters[:event_type_id].blank? ? 'active' : nil = content_tag :li, role: "presentation", class: @filters[:event_type_id].blank? ? 'active' : nil
= link_to management_conference_events_path(current_conference, filters: @filters.except(:event_type_id)) = link_to management_conference_events_path(@conference, filters: @filters.except(:event_type_id))
= t '.all' = t '.all'
span.badge.pull-right = current_conference.events.count span.badge.pull-right = @conference.events.size
- current_conference.event_types.each do |event_type| - @conference.event_types.each do |event_type|
= content_tag :li, role: "presentation", class: @filters[:event_type_id].to_i == event_type.id ? 'active' : nil = content_tag :li, role: "presentation", class: @filters[:event_type_id].to_i == event_type.id ? 'active' : nil
= link_to management_conference_events_path(current_conference, filters: @filters.merge({event_type_id: event_type.id})) = link_to management_conference_events_path(@conference, filters: @filters.merge({event_type_id: event_type.id}))
= event_type.name = event_type.name
span.badge.pull-right = current_conference.events.where(event_type: event_type).count span.badge.pull-right = @conference.events.where(event_type: event_type).size
.panel.panel-default .panel.panel-default
.panel-heading .panel-heading
= Event.human_attribute_name(:track) = Event.human_attribute_name(:track)
.panel-body .panel-body
ul.nav.nav-pills.nav-stacked ul.nav.nav-pills.nav-stacked
= content_tag :li, role: "presentation", class: @filters[:track_id].blank? ? 'active' : nil = content_tag :li, role: "presentation", class: @filters[:track_id].blank? ? 'active' : nil
= link_to management_conference_events_path(current_conference, filters: @filters.except(:track_id)) = link_to management_conference_events_path(@conference, filters: @filters.except(:track_id))
= t '.all' = t '.all'
span.badge.pull-right = current_conference.events.count span.badge.pull-right = @conference.events.size
- current_conference.tracks.each do |track| - @conference.tracks.each do |track|
= content_tag :li, role: "presentation", class: @filters[:track_id] == track.id.to_s ? 'active' : nil = content_tag :li, role: "presentation", class: @filters[:track_id] == track.id.to_s ? 'active' : nil
= link_to management_conference_events_path(current_conference, filters: @filters.merge({track_id: track.id})) = link_to management_conference_events_path(@conference, filters: @filters.merge({track_id: track.id}))
= track.name = track.name
span.badge.pull-right = current_conference.events.where(track: track).count span.badge.pull-right = @conference.events.where(track: track).size
.panel.panel-default .panel.panel-default
.panel-heading .panel-heading
= Event.human_attribute_name(:language) = Event.human_attribute_name(:language)
.panel-body .panel-body
ul.nav.nav-pills.nav-stacked ul.nav.nav-pills.nav-stacked
= content_tag :li, role: "presentation", class: @filters[:language].blank? ? 'active' : nil = content_tag :li, role: "presentation", class: @filters[:language].blank? ? 'active' : nil
= link_to management_conference_events_path(current_conference, filters: @filters.except(:language)) = link_to management_conference_events_path(@conference, filters: @filters.except(:language))
= t '.all' = t '.all'
span.badge.pull-right = current_conference.events.count span.badge.pull-right = @conference.events.size
- I18n.available_locales.map(&:to_s).each do |language| - I18n.available_locales.map(&:to_s).each do |language|
= content_tag :li, role: "presentation", class: @filters[:language] == language ? 'active' : nil = content_tag :li, role: "presentation", class: @filters[:language] == language ? 'active' : nil
= link_to management_conference_events_path(current_conference, filters: @filters.merge({language: language})) = link_to management_conference_events_path(@conference, filters: @filters.merge({language: language}))
= t("locales.#{language}") = t("locales.#{language}")
span.badge.pull-right = current_conference.events.where(language: language).count span.badge.pull-right = @conference.events.where(language: language).size
.panel.panel-default .panel.panel-default
.panel-heading .panel-heading
= Proposition.human_attribute_name(:status) = Proposition.human_attribute_name(:status)
.panel-body .panel-body
ul.nav.nav-pills.nav-stacked ul.nav.nav-pills.nav-stacked
= content_tag :li, role: "presentation", class: @filters[:status].blank? ? 'active' : nil = content_tag :li, role: "presentation", class: @filters[:status].blank? ? 'active' : nil
= link_to management_conference_events_path(current_conference, filters: @filters.except(:status)) = link_to management_conference_events_path(@conference, filters: @filters.except(:status))
= t '.all' = t '.all'
span.badge.pull-right = current_conference.events.count span.badge.pull-right = @conference.events.size
- Proposition.statuses.each do |status_name, status_id| - Proposition.statuses.each do |status_name, status_id|
= content_tag :li, role: "presentation", class: @filters[:status] == status_id.to_s ? 'active' : nil = content_tag :li, role: "presentation", class: @filters[:status] == status_id.to_s ? 'active' : nil
= link_to management_conference_events_path(current_conference, filters: @filters.merge({status: status_id})) = link_to management_conference_events_path(@conference, filters: @filters.merge({status: status_id}))
= t "activerecord.attributes.proposition.statuses.#{status_name}" = t "activerecord.attributes.proposition.statuses.#{status_name}"
span.badge.pull-right = current_conference.events.joins(:proposition).where(propositions: {status: status_id}).count span.badge.pull-right = @conference.events.joins(:proposition).where(propositions: {status: status_id}).size
.panel.panel-default .panel.panel-default
.panel-heading .panel-heading
= Proposition.human_attribute_name(:confirmed) = Proposition.human_attribute_name(:confirmed)
.panel-body .panel-body
ul.nav.nav-pills.nav-stacked ul.nav.nav-pills.nav-stacked
= content_tag :li, role: "presentation", class: @filters[:confirmed].blank? && @filters[:not_confirmed].blank? ? 'active' : nil = content_tag :li, role: "presentation", class: @filters[:confirmed].blank? && @filters[:not_confirmed].blank? ? 'active' : nil
= link_to management_conference_events_path(current_conference, filters: @filters.except(:confirmed, :not_confirmed)) = link_to management_conference_events_path(@conference, filters: @filters.except(:confirmed, :not_confirmed))
= t '.all' = t '.all'
span.badge.pull-right = current_conference.events.count span.badge.pull-right = @conference.events.size
= content_tag :li, role: "presentation", class: @filters[:confirmed].present? ? 'active' : nil = content_tag :li, role: "presentation", class: @filters[:confirmed].present? ? 'active' : nil
= link_to management_conference_events_path(current_conference, filters: @filters.except(:not_confirmed).merge({confirmed: true})) = link_to management_conference_events_path(@conference, filters: @filters.except(:not_confirmed).merge({confirmed: true}))
= t "activerecord.attributes.proposition.confirmation.confirmed" = t "activerecord.attributes.proposition.confirmation.confirmed"
span.badge.pull-right = current_conference.events.joins(:proposition).approved.where.not(propositions: {confirmed_at: nil}).count span.badge.pull-right = @conference.events.joins(:proposition).approved.where.not(propositions: {confirmed_at: nil}).size
= content_tag :li, role: "presentation", class: @filters[:not_confirmed].present? ? 'active' : nil = content_tag :li, role: "presentation", class: @filters[:not_confirmed].present? ? 'active' : nil
= link_to management_conference_events_path(current_conference, filters: @filters.except(:confirmed).merge({not_confirmed: true})) = link_to management_conference_events_path(@conference, filters: @filters.except(:confirmed).merge({not_confirmed: true}))
= t "activerecord.attributes.proposition.confirmation.not_confirmed" = t "activerecord.attributes.proposition.confirmation.not_confirmed"
span.badge.pull-right = current_conference.events.joins(:proposition).approved.where(propositions: {confirmed_at: nil}).count span.badge.pull-right = @conference.events.joins(:proposition).approved.where(propositions: {confirmed_at: nil}).size
.col-md-9 .col-md-9
.panel.panel-default .panel.panel-default
@ -102,5 +102,5 @@
tbody tbody
= render(partial: 'event', collection: @events) || render(partial: 'no_records') = render(partial: 'event', collection: @events) || render(partial: 'no_records')
.panel-footer.text-right .panel-footer.text-right
= link_to management_conference_events_path(current_conference, filters: @filters, format: 'csv'), class: 'btn btn-info' = link_to management_conference_events_path(@conference, filters: @filters, format: 'csv'), class: 'btn btn-info'
= icon :download, t('.export') = icon :download, t('.export')