can choose multiple zones

This commit is contained in:
Christophe Robillard 2022-08-24 15:16:58 +02:00 committed by krichtof
parent 6d90f65159
commit 94ca93e130
5 changed files with 10 additions and 20 deletions

View file

@ -351,7 +351,7 @@ module Administrateurs
:monavis_embed,
:api_entreprise_token,
:duree_conservation_dossiers_dans_ds,
:zone_id,
{ zone_ids: [] },
:lien_dpo,
:opendata,
:procedure_expires_when_termine_enabled

View file

@ -1,13 +0,0 @@
module ZoneHelper
def grouped_options_for_zone(date)
date ||= Time.zone.now
collectivite = Zone.find_by(acronym: "COLLECTIVITE")
{
"--" => [
[I18n.t('i_dont_know', scope: 'utils'), nil],
[collectivite.label, collectivite.id]
],
I18n.t('ministeres', scope: 'zones') => (Zone.available_at(date) - [collectivite]).map { |m| [m.label_at(date), m.id] }
}
end
end

View file

@ -28,5 +28,8 @@ class Zone < ApplicationRecord
def self.available_at(date)
Zone.all.filter { |zone| zone.available_at?(date) }.sort_by { |zone| zone.label_at(date) }
.map do |zone|
OpenStruct.new(id: zone.id, label: zone.label_at(date))
end
end
end

View file

@ -14,10 +14,10 @@
= f.text_area :description, rows: '6', placeholder: 'Description de la démarche, destinataires, etc. ', class: 'form-control'
- if Flipper.enabled? :zonage
= f.label :zone do
= t('zone', scope: 'activerecord.attributes.procedure')
%span.mandatory *
= f.select :zone_id, grouped_options_for_zone(@procedure.published_or_created_at)
= f.collection_check_boxes :zone_ids, Zone.available_at(@procedure.published_or_created_at), :id, :label do |b|
.editable-champ.editable-champ-checkbox
= b.check_box
= b.label
%h3.header-subsection Logo de la démarche
= render Attachment::EditComponent.new(form: f, attached_file: @procedure.logo, direct_upload: true, user_can_destroy: true)

View file

@ -114,8 +114,8 @@ describe Zone do
end
it 'returns only available zones at specific date' do
expect(Zone.available_at(start_last_government + 1.day)).to eq [culture]
expect(Zone.available_at(start_previous_government + 1.day)).to eq [culture, om]
expect(Zone.available_at(start_last_government + 1.day).map(&:label)).to eq ["Ministère de la Culture"]
expect(Zone.available_at(start_previous_government + 1.day).map(&:label)).to eq ["Ministère de la Culture", "Ministère des Outre-mer"]
end
end
end