Skip to content
Snippets Groups Projects
Commit a0dac7c9 authored by Arnaud Levy's avatar Arnaud Levy
Browse files

simpler

parent 90b44f7c
No related branches found
No related tags found
No related merge requests found
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
......@@ -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">
......
......@@ -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
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment