diff --git a/app/controllers/admin/communication/extranets/contacts_controller.rb b/app/controllers/admin/communication/extranets/contacts_controller.rb index 3a822b27cc8e72f488ad6dda875f7a5ac6ac8718..b0c127fc5170ed558dd143a521a8b14312875c7a 100644 --- a/app/controllers/admin/communication/extranets/contacts_controller.rb +++ b/app/controllers/admin/communication/extranets/contacts_controller.rb @@ -1,24 +1,31 @@ class Admin::Communication::Extranets::ContactsController < Admin::Communication::Extranets::ApplicationController def index - respond_to do |format| - format.html { - @people = current_university.people - .for_language_id(current_university.default_language_id) - .ordered - .page(params[:persons_page]) - @organizations = current_university.organizations - .for_language_id(current_university.default_language_id) - .ordered - .page(params[:organizations_page]) - } - format.xlsx { export } - end - - + @people = current_university.people + .for_language_id(current_university.default_language_id) + .ordered + .page(params[:persons_page]) + @organizations = current_university.organizations + .for_language_id(current_university.default_language_id) + .ordered + .page(params[:organizations_page]) breadcrumb add_breadcrumb Communication::Extranet.human_attribute_name(:feature_contacts) end + def export_people + @people = @extranet.connected_people.ordered + filename = "people-#{Time.now.strftime("%Y%m%d%H%M%S")}.xlsx" + response.headers['Content-Disposition'] = "attachment; filename=#{filename}" + render "admin/university/people/index" + end + + def export_organizations + @organizations = @extranet.connected_organizations.ordered + filename = "organizations-#{Time.now.strftime("%Y%m%d%H%M%S")}.xlsx" + response.headers['Content-Disposition'] = "attachment; filename=#{filename}" + render "admin/university/organizations/index" + end + def connect load_object @extranet.connect @object @@ -46,21 +53,4 @@ class Admin::Communication::Extranets::ContactsController < Admin::Communication object_id = params[:objectId] @object = object_type.constantize.find object_id end - - def export - # params[export] can be "people" or "organizations" - export = params['export'] - case params['export'] - when 'people' - @people = @extranet.connected_people.ordered - when 'organizations' - @organizations = @extranet.connected_organizations.ordered - else - raise ActionController::RoutingError.new('Not Found') - end - - filename = "#{export}-#{Time.now.strftime("%Y%m%d%H%M%S")}.xlsx" - response.headers['Content-Disposition'] = "attachment; filename=#{filename}" - render "admin/university/#{export}/index" - end end diff --git a/app/views/admin/communication/extranets/contacts/index.html.erb b/app/views/admin/communication/extranets/contacts/index.html.erb index 1d5c9c26f4d727027b62ff8b71e19afffaa0edaf..617da5e7977866a223e2f2fe142d95b5cc451b7f 100644 --- a/app/views/admin/communication/extranets/contacts/index.html.erb +++ b/app/views/admin/communication/extranets/contacts/index.html.erb @@ -2,7 +2,7 @@ <%= render 'admin/communication/extranets/sidebar' do %> <% action = link_to t('export'), - admin_communication_extranet_contacts_path(extranet_id: @extranet.id, export: 'people', format: :xlsx), + export_people_admin_communication_extranet_contacts_path(extranet_id: @extranet.id, format: :xlsx), class: button_classes('ms-1') if can?(:show, University::Person) %> <%= osuny_panel University::Person.model_name.human(count: 2), action: action do %> <div class="table-responsive"> @@ -21,7 +21,7 @@ <%= paginate @people, theme: 'bootstrap-5', param_name: :persons_page %> <% end %> <% action = link_to t('export'), - admin_communication_extranet_contacts_path(extranet_id: @extranet.id, export: 'organizations', format: :xlsx), + export_organizations_admin_communication_extranet_contacts_path(extranet_id: @extranet.id, format: :xlsx), class: button_classes('ms-1') if can?(:show, University::Person) %> <%= osuny_panel University::Organization.model_name.human(count: 2), action: action do %> <div class="table-responsive"> diff --git a/config/routes/admin/communication.rb b/config/routes/admin/communication.rb index ef9c971ee0782a96ca3a25fbc54c56219323670f..f448c4dba79c173400f385e5270ce74463ee9344 100644 --- a/config/routes/admin/communication.rb +++ b/config/routes/admin/communication.rb @@ -81,6 +81,8 @@ namespace :communication do resources :alumni, only: :index, controller: 'extranets/alumni' resources :contacts, only: :index, controller: 'extranets/contacts' do collection do + get :export_people + get :export_organizations post :toggle post :connect post :disconnect