diff --git a/app/controllers/administrateurs/procedures_controller.rb b/app/controllers/administrateurs/procedures_controller.rb index fc6692944..16743c768 100644 --- a/app/controllers/administrateurs/procedures_controller.rb +++ b/app/controllers/administrateurs/procedures_controller.rb @@ -63,6 +63,7 @@ module Administrateurs def new @procedure ||= Procedure.new(for_individual: true) + @existing_tags = get_existing_tags end SIGNIFICANT_DOSSIERS_THRESHOLD = 30 @@ -361,7 +362,8 @@ module Administrateurs { zone_ids: [] }, :lien_dpo, :opendata, - :procedure_expires_when_termine_enabled + :procedure_expires_when_termine_enabled, + :tags ] permited_params = if @procedure&.locked? params.require(:procedure).permit(*editable_params) @@ -371,6 +373,9 @@ module Administrateurs if permited_params[:auto_archive_on].present? permited_params[:auto_archive_on] = Date.parse(permited_params[:auto_archive_on]) + 1.day end + if permited_params[:tags].present? + permited_params[:tags] = JSON.parse(permited_params[:tags]) + end permited_params end @@ -385,5 +390,11 @@ module Administrateurs def cloned_from_library? params[:from_new_from_existing].present? end + + def get_existing_tags + unnest = Arel::Nodes::NamedFunction.new('UNNEST', [Procedure.arel_table[:tags]]) + query = Procedure.select(unnest.as('tags')).distinct.order('tags') + Procedure.connection.query(query.to_sql).flatten + end end end diff --git a/app/models/procedure.rb b/app/models/procedure.rb index 4576522c4..7499cc75a 100644 --- a/app/models/procedure.rb +++ b/app/models/procedure.rb @@ -41,6 +41,7 @@ # published_at :datetime # routing_criteria_name :text default("Votre ville") # routing_enabled :boolean +# tags :text default([]), is an Array # test_started_at :datetime # unpublished_at :datetime # web_hook_url :string diff --git a/app/views/administrateurs/procedures/_informations.html.haml b/app/views/administrateurs/procedures/_informations.html.haml index 072f3befc..384234b90 100644 --- a/app/views/administrateurs/procedures/_informations.html.haml +++ b/app/views/administrateurs/procedures/_informations.html.haml @@ -100,6 +100,18 @@ %p.explication Si votre démarche s’adresse indifféremment à une personne morale ou un particulier, choisissez l'option « Particuliers ». Vous pourrez ajouter un champ SIRET directement dans le formulaire. + %h3.header-subsection Ajouter des tags + %p.explication Les tags sont des mots ou des expressions que vous attribuez aux démarches pour décrire leur contenu et pour les retrouver. Les tags sont partagés avec la communauté, ce qui vous permet de voir les tags attribués aux démarches créées par les autres administrateurs. + = hidden_field_tag 'procedure[tags]', nil + = react_component("ComboMultiple", + options: @existing_tags, + selected: [], disabled: [], + label: 'Tags', + group: '.procedure-form__column--form', + name: 'tags', + describedby: 'procedure-tags', + acceptNewValues: true) + %details.procedure-form__options-details %summary.procedure-form__options-summary %h3.header-subsection Options avancées diff --git a/db/migrate/20221006074425_add_tags_to_procedures.rb b/db/migrate/20221006074425_add_tags_to_procedures.rb new file mode 100644 index 000000000..895a77a1a --- /dev/null +++ b/db/migrate/20221006074425_add_tags_to_procedures.rb @@ -0,0 +1,7 @@ +class AddTagsToProcedures < ActiveRecord::Migration[6.1] + disable_ddl_transaction! + def change + add_column :procedures, :tags, :text, array: true, default: [] + add_index :procedures, :tags, using: 'gin', algorithm: :concurrently + end +end diff --git a/db/schema.rb b/db/schema.rb index 2bda24d01..81c7e1606 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -667,6 +667,7 @@ ActiveRecord::Schema.define(version: 2022_10_20_094031) do t.text "routing_criteria_name", default: "Votre ville" t.boolean "routing_enabled" t.bigint "service_id" + t.text "tags", default: [], array: true t.datetime "test_started_at" t.datetime "unpublished_at" t.datetime "updated_at", null: false @@ -683,6 +684,7 @@ ActiveRecord::Schema.define(version: 2022_10_20_094031) do t.index ["procedure_expires_when_termine_enabled"], name: "index_procedures_on_procedure_expires_when_termine_enabled" t.index ["published_revision_id"], name: "index_procedures_on_published_revision_id" t.index ["service_id"], name: "index_procedures_on_service_id" + t.index ["tags"], name: "index_procedures_on_tags", using: :gin t.index ["zone_id"], name: "index_procedures_on_zone_id" end diff --git a/spec/controllers/administrateurs/procedures_controller_spec.rb b/spec/controllers/administrateurs/procedures_controller_spec.rb index f5a03b132..1fad0fcea 100644 --- a/spec/controllers/administrateurs/procedures_controller_spec.rb +++ b/spec/controllers/administrateurs/procedures_controller_spec.rb @@ -13,6 +13,7 @@ describe Administrateurs::ProceduresController, type: :controller do let(:lien_site_web) { 'http://mon-site.gouv.fr' } let(:zone) { create(:zone) } let(:zone_ids) { [zone.id] } + let(:tags) { "[\"planete\",\"environnement\"]" } describe '#apercu' do render_views @@ -56,7 +57,8 @@ describe Administrateurs::ProceduresController, type: :controller do duree_conservation_dossiers_dans_ds: duree_conservation_dossiers_dans_ds, monavis_embed: monavis_embed, zone_ids: zone_ids, - lien_site_web: lien_site_web + lien_site_web: lien_site_web, + tags: tags } } @@ -206,6 +208,7 @@ describe Administrateurs::ProceduresController, type: :controller do it { expect(subject.organisation).to eq(organisation) } it { expect(subject.administrateurs).to eq([admin]) } it { expect(subject.duree_conservation_dossiers_dans_ds).to eq(duree_conservation_dossiers_dans_ds) } + it { expect(subject.tags).to eq(["planete", "environnement"]) } end it { is_expected.to redirect_to(champs_admin_procedure_path(Procedure.last)) }