export all demarches

This commit is contained in:
Christophe Robillard 2022-11-25 19:55:59 +01:00
parent cea92c0488
commit 3a660349ad
3 changed files with 29 additions and 2 deletions

View file

@ -1,6 +1,7 @@
module Administrateurs module Administrateurs
class ProceduresController < AdministrateurController class ProceduresController < AdministrateurController
layout 'all', only: [:all, :administrateurs] layout 'all', only: [:all, :administrateurs]
respond_to :html, :xlsx
before_action :retrieve_procedure, only: [:champs, :annotations, :modifications, :edit, :zones, :monavis, :update_monavis, :jeton, :update_jeton, :publication, :publish, :transfert, :close, :allow_expert_review, :experts_require_administrateur_invitation, :reset_draft] before_action :retrieve_procedure, only: [:champs, :annotations, :modifications, :edit, :zones, :monavis, :update_monavis, :jeton, :update_jeton, :publication, :publish, :transfert, :close, :allow_expert_review, :experts_require_administrateur_invitation, :reset_draft]
before_action :draft_valid?, only: [:apercu] before_action :draft_valid?, only: [:apercu]
@ -334,8 +335,14 @@ module Administrateurs
def all def all
@filter = ProceduresFilter.new(current_administrateur, params) @filter = ProceduresFilter.new(current_administrateur, params)
all_procedures = filter_procedures(@filter) all_procedures = filter_procedures(@filter)
all_procedures = Kaminari.paginate_array(all_procedures.to_a, offset: 0, limit: ITEMS_PER_PAGE, total_count: all_procedures.count)
@procedures = all_procedures.page(params[:page]).per(25) respond_to do |format|
format.html do
all_procedures = Kaminari.paginate_array(all_procedures.to_a, offset: 0, limit: ITEMS_PER_PAGE, total_count: all_procedures.count)
@procedures = all_procedures.page(params[:page]).per(25)
end
format.xlsx { render xlsx: SpreadsheetArchitect.to_xlsx(headers: all_procedures.to_a.first.keys, data: all_procedures.to_a.map(&:values)), filename: "demarches-#{@filter}" }
end
end end
def administrateurs def administrateurs

View file

@ -60,4 +60,14 @@ class ProceduresFilter
params.to_h.merge(filter => new_filter) params.to_h.merge(filter => new_filter)
end end
end end
def to_s
filters = []
filters << selected_zones&.map { |zone| zone.current_label.parameterize }
filters << libelle&.parameterize
filters << email
filters << "from-#{from_publication_date}" if from_publication_date
filters << statuses
filters.compact.join('-')
end
end end

View file

@ -95,6 +95,16 @@ describe Administrateurs::ProceduresController, type: :controller do
it { expect(subject.status).to eq(200) } it { expect(subject.status).to eq(200) }
context 'for export' do
subject { get :all, format: :xlsx }
it 'exports result in xlsx' do
allow(SpreadsheetArchitect).to receive(:to_xlsx)
subject
expect(SpreadsheetArchitect).to have_received(:to_xlsx)
end
end
it 'display published or closed procedures' do it 'display published or closed procedures' do
subject subject
expect(values_for_field(assigns(:procedures), "id")).to include(published_procedure.id) expect(values_for_field(assigns(:procedures), "id")).to include(published_procedure.id)