export all demarches
This commit is contained in:
parent
cea92c0488
commit
3a660349ad
3 changed files with 29 additions and 2 deletions
|
@ -1,6 +1,7 @@
|
|||
module Administrateurs
|
||||
class ProceduresController < AdministrateurController
|
||||
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 :draft_valid?, only: [:apercu]
|
||||
|
@ -334,9 +335,15 @@ module Administrateurs
|
|||
def all
|
||||
@filter = ProceduresFilter.new(current_administrateur, params)
|
||||
all_procedures = filter_procedures(@filter)
|
||||
|
||||
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
|
||||
|
||||
def administrateurs
|
||||
@filter = ProceduresFilter.new(current_administrateur, params)
|
||||
|
|
|
@ -60,4 +60,14 @@ class ProceduresFilter
|
|||
params.to_h.merge(filter => new_filter)
|
||||
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
|
||||
|
|
|
@ -95,6 +95,16 @@ describe Administrateurs::ProceduresController, type: :controller do
|
|||
|
||||
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
|
||||
subject
|
||||
expect(values_for_field(assigns(:procedures), "id")).to include(published_procedure.id)
|
||||
|
|
Loading…
Reference in a new issue