diff --git a/app/controllers/admin/communication/extranets/contacts_controller.rb b/app/controllers/admin/communication/extranets/contacts_controller.rb index d74dbda0e861fa1935b9d89dced9a2aa059aa2e7..874d4cf96c2e62b05cc411db75b45f7592be69f9 100644 --- a/app/controllers/admin/communication/extranets/contacts_controller.rb +++ b/app/controllers/admin/communication/extranets/contacts_controller.rb @@ -1,7 +1,21 @@ class Admin::Communication::Extranets::ContactsController < Admin::Communication::Extranets::ApplicationController def index - @persons = current_university.people.ordered.page params[:persons_page] - @organizations = current_university.organizations.ordered.page params[:organizations_page] + @persons = current_university.people.ordered + @organizations = current_university.organizations.ordered + respond_to do |format| + format.html { + @persons = @persons.page params[:persons_page] + @organizations = @organizations.page params[:organizations_page] + } + format.xlsx { + @export = params['export'] + filename = "#{@export}-#{Time.now.strftime("%Y%m%d%H%M%S")}.xlsx" + response.headers['Content-Disposition'] = "attachment; filename=#{filename}" + render @export + } + end + + breadcrumb add_breadcrumb Communication::Extranet.human_attribute_name(:feature_contacts) end @@ -26,4 +40,4 @@ class Admin::Communication::Extranets::ContactsController < Admin::Communication object_id = params[:objectId] @object = object_type.constantize.find object_id end -end \ No newline at end of file +end diff --git a/app/views/admin/communication/extranets/contacts/index.html.erb b/app/views/admin/communication/extranets/contacts/index.html.erb index ca91cce032e8b569206f5842e7574b60ef48c5aa..d79fc8d55e2c4504627ef2f85e43563f6d9bb0d7 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: 'persons'), + admin_communication_extranet_contacts_path(extranet_id: @extranet.id, export: 'persons', 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"> @@ -40,7 +40,10 @@ </div> <%= paginate @persons, theme: 'bootstrap-5', param_name: :persons_page %> <% end %> - <%= osuny_panel University::Organization.model_name.human(count: 2) do %> + <% action = link_to t('export'), + admin_communication_extranet_contacts_path(extranet_id: @extranet.id, export: 'organizations', 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"> <table class="<%= table_classes%>"> <tbody> diff --git a/app/views/admin/communication/extranets/contacts/persons.xlsx.axlsx b/app/views/admin/communication/extranets/contacts/persons.xlsx.axlsx new file mode 100644 index 0000000000000000000000000000000000000000..47e62236f029ce550876629ab348f5377f2c5821 --- /dev/null +++ b/app/views/admin/communication/extranets/contacts/persons.xlsx.axlsx @@ -0,0 +1,14 @@ +@users ||= users + +wb = xlsx_package.workbook +wb.add_worksheet(name: "index") do |sheet| + + headers = User::xls_header_for(current_brand) + + # for headers types are always :string (because those are labels) + sheet.add_row headers[:labels], types: Array.new(headers[:types].length) { |_| :string } + + @users.each do |user| + sheet.add_row user.xls_basic_row, types: headers[:types] + end +end