procedures: group new_from_existing list by organization

As procedures are not grouped by Service (which are unique to an
administrator) but by organization, this allows procedures with the same
organization name to be displayed together.
This commit is contained in:
Pierre de La Morinerie 2018-07-03 20:18:49 +02:00
parent 56987e5147
commit b0a9e49549
5 changed files with 34 additions and 3 deletions

View file

@ -186,8 +186,8 @@ class Admin::ProceduresController < AdminController
@grouped_procedures = Procedure
.where(id: significant_procedure_ids)
.group_by(&:administrateur)
.sort_by { |a, _| a.created_at }
.group_by(&:organisation_name)
.sort_by { |_, procedures| procedures.first.created_at }
end
def active_class

View file

@ -152,6 +152,10 @@ class Procedure < ApplicationRecord
libelle.parameterize.first(50)
end
def organisation_name
service&.nom || organisation
end
def types_de_champ_ordered
types_de_champ.order(:order_place)
end

View file

@ -12,7 +12,7 @@
%br
- @grouped_procedures.each do |_, procedures|
%b
= procedures.first.organisation
= procedures.first.organisation_name
%table{ style: 'margin-bottom: 40px;' }
- procedures.sort_by(&:id).each do |procedure|
%tr{ style: 'height: 36px;' }

View file

@ -553,6 +553,20 @@ describe Admin::ProceduresController, type: :controller do
expect(response_procedures).not_to include(large_draft_procedure)
end
end
describe 'grouping' do
let(:service_1) { create(:service, nom: 'DDT des Vosges') }
let(:service_2) { create(:service, nom: 'DDT du Loiret') }
let!(:procedure_with_service_1) { create(:procedure_with_dossiers, :published, organisation: nil, service: service_1, dossiers_count: 2) }
let!(:procedure_with_service_2) { create(:procedure_with_dossiers, :published, organisation: nil, service: service_2, dossiers_count: 2) }
let!(:procedure_without_service) { create(:procedure_with_dossiers, :published, organisation: 'DDT du Loiret', dossiers_count: 2) }
it 'groups procedures with services as well as procedures with organisations' do
expect(grouped_procedures.length).to eq 2
expect(grouped_procedures.find{ |o, p| o == 'DDT des Vosges' }.last).to contain_exactly(procedure_with_service_1)
expect(grouped_procedures.find{ |o, p| o == 'DDT du Loiret' }.last).to contain_exactly(procedure_with_service_2, procedure_without_service)
end
end
end
describe 'GET #path_list' do

View file

@ -735,6 +735,19 @@ describe Procedure do
it { expect(Champ.count).to eq(0) }
end
describe "#organisation_name" do
subject { procedure.organisation_name }
context 'when the procedure has a service (and no organization)' do
let(:procedure) { create(:procedure, :with_service, organisation: nil) }
it { is_expected.to eq procedure.service.nom }
end
context 'when the procedure has an organization (and no service)' do
let(:procedure) { create(:procedure, organisation: 'DDT des Vosges', service: nil) }
it { is_expected.to eq procedure.organisation }
end
end
describe '#juridique_required' do
it 'automatically jumps to true once cadre_juridique or deliberation have been set' do
p = create(