Add link and query examples with identity prefill
This commit is contained in:
parent
4cbb8e91f2
commit
be02dd965f
11 changed files with 116 additions and 67 deletions
|
@ -25,6 +25,6 @@ class PrefillDescriptionsController < ApplicationController
|
|||
end
|
||||
|
||||
def prefill_description_params
|
||||
params.require(:type_de_champ).permit(:selected_type_de_champ_ids)
|
||||
params.require(:procedure).permit(:selected_type_de_champ_ids, :identity_items_selected)
|
||||
end
|
||||
end
|
||||
|
|
|
@ -4,22 +4,25 @@ class PrefillDescription < SimpleDelegator
|
|||
MAX_PREFILL_LINK_LENGTH = 2000
|
||||
|
||||
attr_reader :selected_type_de_champ_ids
|
||||
attr_reader :identity_items_selected
|
||||
|
||||
def initialize(procedure)
|
||||
super(procedure)
|
||||
@selected_type_de_champ_ids = []
|
||||
@identity_items_selected = []
|
||||
end
|
||||
|
||||
def update(attributes)
|
||||
@selected_type_de_champ_ids = attributes[:selected_type_de_champ_ids]&.split(' ') || []
|
||||
@identity_items_selected = attributes[:identity_items_selected]&.split(' ') || []
|
||||
end
|
||||
|
||||
def types_de_champ
|
||||
TypesDeChamp::PrefillTypeDeChamp.wrap(active_revision.types_de_champ_public.fillable.partition(&:prefillable?).flatten, active_revision)
|
||||
end
|
||||
|
||||
def include?(type_de_champ_id)
|
||||
selected_type_de_champ_ids.include?(type_de_champ_id.to_s)
|
||||
def include?(entity)
|
||||
selected_type_de_champ_ids.include?(entity) || identity_items_selected.include?(entity)
|
||||
end
|
||||
|
||||
def link_too_long?
|
||||
|
@ -27,7 +30,7 @@ class PrefillDescription < SimpleDelegator
|
|||
end
|
||||
|
||||
def prefill_link
|
||||
@prefill_link ||= CGI.unescape(commencer_url({ path: path }.merge(prefilled_champs_as_params)))
|
||||
@prefill_link ||= CGI.unescape(commencer_url({ path: path }.merge(prefilled_champs_as_params).merge(prefilled_identity_as_params)))
|
||||
end
|
||||
|
||||
def prefill_query
|
||||
|
@ -35,7 +38,7 @@ class PrefillDescription < SimpleDelegator
|
|||
<<~TEXT
|
||||
curl --request POST '#{api_public_v1_dossiers_url(self)}' \\
|
||||
--header 'Content-Type: application/json' \\
|
||||
--data '#{prefilled_champs_as_params.to_json}'
|
||||
--data '#{prefilled_identity_as_params.merge(prefilled_champs_as_params).to_json}'
|
||||
TEXT
|
||||
end
|
||||
|
||||
|
@ -52,4 +55,8 @@ class PrefillDescription < SimpleDelegator
|
|||
def prefilled_champs_as_params
|
||||
prefilled_champs.map { |type_de_champ| ["champ_#{type_de_champ.to_typed_id_for_query}", type_de_champ.example_value] }.to_h
|
||||
end
|
||||
|
||||
def prefilled_identity_as_params
|
||||
identity_items_selected.map { |item| ["identite_#{item}", I18n.t("views.prefill_descriptions.edit.examples.#{item}")] }.to_h
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
= turbo_frame_tag "#{dom_id(prefill_description)}_url" do
|
||||
= turbo_frame_tag dom_id(prefill_description, :url) do
|
||||
- theme = prefill_description.link_too_long? ? :warning : :success
|
||||
- icon = prefill_description.link_too_long? ? "fr-icon-warning-fill" : "fr-icon-paint-fill"
|
||||
- body = prefill_description.link_too_long? ? t("views.prefill_descriptions.edit.prefill_link_too_long") : t("views.prefill_descriptions.edit.prefill_link_info")
|
||||
|
||||
- if prefill_description.prefilled_champs.any?
|
||||
- if prefill_description.prefilled_champs.any? || prefill_description.identity_items_selected.any?
|
||||
= render Dsfr::CalloutComponent.new(title: t("views.prefill_descriptions.edit.prefill_link_title"), theme: theme, icon: icon) do |c|
|
||||
- c.with_html_body do
|
||||
%p= body
|
||||
|
|
|
@ -1,7 +1,5 @@
|
|||
= turbo_frame_tag "#{dom_id(prefill_description)}_query" do
|
||||
|
||||
- if prefill_description.prefilled_champs.any?
|
||||
|
||||
= turbo_frame_tag dom_id(prefill_description, :query) do
|
||||
- if prefill_description.prefilled_champs.any? || prefill_description.identity_items_selected.any?
|
||||
= render Dsfr::CalloutComponent.new(title: t("views.prefill_descriptions.edit.prefill_query_title"), theme: :success, icon: "fr-icon-code-box-fill") do |c|
|
||||
- c.with_html_body do
|
||||
%p= t("views.prefill_descriptions.edit.prefill_query_info")
|
||||
|
|
|
@ -0,0 +1,18 @@
|
|||
= turbo_frame_tag dom_id(prefill_description, :prefillable_entities) do
|
||||
|
||||
.fr-grid-row.fr-grid-row--gutters.fr-pt-1w.fr-pb-5w
|
||||
- if prefill_description.for_individual?
|
||||
- ["prenom", "nom", "genre"].each do |identity_item|
|
||||
= render "prefillable_entity_card",
|
||||
prefill_description: prefill_description, type_de_champ: nil,
|
||||
prefillable: true, already_included: prefill_description.include?(identity_item),
|
||||
all_entities: prefill_description.identity_items_selected, new_entity: identity_item,
|
||||
title: t("views.prefill_descriptions.edit.title.#{identity_item}"), description: t("views.prefill_descriptions.edit.description.#{identity_item}"), possible_values: t("views.prefill_descriptions.edit.possible_values.#{identity_item}"), example_value: t("views.prefill_descriptions.edit.examples.#{identity_item}")
|
||||
|
||||
.fr-grid-row.fr-grid-row--gutters.fr-pt-1w.fr-pb-5w
|
||||
- prefill_description.types_de_champ.each do |type_de_champ|
|
||||
= render "prefillable_entity_card",
|
||||
prefill_description: prefill_description, type_de_champ: type_de_champ,
|
||||
prefillable: type_de_champ.prefillable?, already_included: prefill_description.include?(type_de_champ.id.to_s),
|
||||
all_entities: prefill_description.selected_type_de_champ_ids, new_entity: type_de_champ.id.to_s,
|
||||
title: type_de_champ.libelle, description: type_de_champ.description, possible_values: type_de_champ.possible_values, example_value: type_de_champ.example_value
|
|
@ -0,0 +1,42 @@
|
|||
- form_field = type_de_champ ? :selected_type_de_champ_ids : :identity_items_selected
|
||||
.fr-col-md-6.fr-col-12
|
||||
.card
|
||||
.card-title.flex.justify-between.align-center
|
||||
= title
|
||||
= form_for prefill_description, url: prefill_description_path(prefill_description.path), data: { turbo: true } do |f|
|
||||
- if already_included
|
||||
= f.hidden_field form_field, value: all_entities - [new_entity]
|
||||
= f.submit t("views.prefill_descriptions.edit.entity_remove"), class: 'fr-btn fr-btn--secondary fr-btn--md'
|
||||
- elsif prefillable
|
||||
= f.hidden_field form_field, value: all_entities + [new_entity]
|
||||
= f.submit t("views.prefill_descriptions.edit.entity_add"), id: "#{new_entity}_add_button", class: 'fr-btn fr-btn--md'
|
||||
- else
|
||||
%button.fr-btn.fr-btn--secondary{ disabled: true }
|
||||
= t("views.prefill_descriptions.edit.entity_unavailable")
|
||||
|
||||
%p
|
||||
= description
|
||||
|
||||
%table.table.vertical
|
||||
%tbody
|
||||
- if type_de_champ
|
||||
%tr
|
||||
%th
|
||||
= t("views.prefill_descriptions.edit.champ_id")
|
||||
%td
|
||||
= type_de_champ.to_typed_id_for_query
|
||||
%tr
|
||||
%th
|
||||
= t("views.prefill_descriptions.edit.champ_type")
|
||||
%td
|
||||
= t("activerecord.attributes.type_de_champ.type_champs.#{type_de_champ.type_champ}")
|
||||
%tr{ class: prefillable ? "" : "fr-text-mention--grey" }
|
||||
%th
|
||||
= t("views.prefill_descriptions.edit.possible_values.title")
|
||||
%td
|
||||
= possible_values
|
||||
%tr{ class: prefillable ? "" : "fr-text-mention--grey" }
|
||||
%th
|
||||
= t("views.prefill_descriptions.edit.examples.title")
|
||||
%td
|
||||
= example_value
|
|
@ -1,45 +0,0 @@
|
|||
= turbo_frame_tag "#{dom_id(prefill_description)}_types_de_champs" do
|
||||
.fr-grid-row.fr-grid-row--gutters.fr-py-5w
|
||||
- prefill_description.types_de_champ.each do |type_de_champ|
|
||||
- prefillable = type_de_champ.prefillable?
|
||||
|
||||
.fr-col-md-6.fr-col-12
|
||||
.card
|
||||
.card-title.flex.justify-between.align-center
|
||||
= type_de_champ.libelle
|
||||
= form_for type_de_champ, url: prefill_description_path(prefill_description.path), data: { turbo: true } do |f|
|
||||
- if prefill_description.include?(type_de_champ.id)
|
||||
= f.hidden_field :selected_type_de_champ_ids, value: (prefill_description.selected_type_de_champ_ids - [type_de_champ.id.to_s])
|
||||
= f.submit t("views.prefill_descriptions.edit.champ_remove"), class: 'fr-btn fr-btn--secondary fr-btn--md'
|
||||
- elsif prefillable && !prefill_description.include?(type_de_champ.id)
|
||||
= f.hidden_field :selected_type_de_champ_ids, value: (prefill_description.selected_type_de_champ_ids + [type_de_champ.id.to_s])
|
||||
= f.submit t("views.prefill_descriptions.edit.champ_add"), class: 'fr-btn fr-btn--md'
|
||||
- else
|
||||
%button.fr-btn.fr-btn--secondary{ disabled: true }
|
||||
= t("views.prefill_descriptions.edit.champ_unavailable")
|
||||
|
||||
%p
|
||||
= type_de_champ.description
|
||||
|
||||
%table.table.vertical
|
||||
%tbody
|
||||
%tr
|
||||
%th
|
||||
= t("views.prefill_descriptions.edit.champ_id")
|
||||
%td
|
||||
= type_de_champ.to_typed_id_for_query
|
||||
%tr
|
||||
%th
|
||||
= t("views.prefill_descriptions.edit.champ_type")
|
||||
%td
|
||||
= t("activerecord.attributes.type_de_champ.type_champs.#{type_de_champ.type_champ}")
|
||||
%tr{ class: prefillable ? "" : "fr-text-mention--grey" }
|
||||
%th
|
||||
= t("views.prefill_descriptions.edit.possible_values.title")
|
||||
%td
|
||||
= type_de_champ.possible_values
|
||||
%tr{ class: prefillable ? "" : "fr-text-mention--grey" }
|
||||
%th
|
||||
= t("views.prefill_descriptions.edit.examples.title")
|
||||
%td
|
||||
= type_de_champ.example_value
|
|
@ -14,7 +14,7 @@
|
|||
%p
|
||||
= t("views.prefill_descriptions.edit.info_html")
|
||||
|
||||
= render "types_de_champs", prefill_description: @prefill_description
|
||||
= render "prefillable_entities", prefill_description: @prefill_description
|
||||
|
||||
= render "prefill_link", prefill_description: @prefill_description
|
||||
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
= turbo_stream.replace "#{dom_id(@prefill_description)}_types_de_champs" do
|
||||
= render "types_de_champs", prefill_description: @prefill_description
|
||||
= turbo_stream.replace dom_id(@prefill_description, :prefillable_entities) do
|
||||
= render "prefillable_entities", prefill_description: @prefill_description
|
||||
|
||||
= turbo_stream.replace "#{dom_id(@prefill_description)}_url" do
|
||||
= turbo_stream.replace dom_id(@prefill_description, :url) do
|
||||
= render "prefill_link", prefill_description: @prefill_description
|
||||
|
||||
= turbo_stream.replace "#{dom_id(@prefill_description)}_query" do
|
||||
= turbo_stream.replace dom_id(@prefill_description, :query) do
|
||||
= render "prefill_query", prefill_description: @prefill_description
|
||||
|
|
|
@ -230,14 +230,25 @@ en:
|
|||
info_html: To do this, select the fields below that you want to prefill.<br> You will then find a prefill link at the bottom of this page, which you will just need to copy, adapt by replacing the default values, and share.<br> In the same way, you will find an example of a cURL request at the bottom of the page to adapt if you want to prefill the folders via API.
|
||||
champ_id: ID
|
||||
champ_type: Type
|
||||
champ_add: Add
|
||||
champ_remove: Remove
|
||||
champ_unavailable: Unavailable
|
||||
entity_add: Add
|
||||
entity_remove: Remove
|
||||
entity_unavailable: Unavailable
|
||||
title:
|
||||
prenom: First name (identity)
|
||||
nom: Last name (identity)
|
||||
genre: Gender (identity)
|
||||
description:
|
||||
prenom: The first name of the owner of the file
|
||||
nom: The last name of the owner of the file
|
||||
genre: The gender name of the owner of the file
|
||||
possible_values:
|
||||
link:
|
||||
title: All possible values
|
||||
text: See all possible values
|
||||
title: Values
|
||||
prenom: A first name
|
||||
nom: A last name
|
||||
genre: '"M." for Mister, "Mme" for Madam'
|
||||
text_html: A short text
|
||||
textarea_html: A long text
|
||||
decimal_number_html: A decimal number
|
||||
|
@ -265,6 +276,9 @@ en:
|
|||
dossier_link_html: The file ID, as integer
|
||||
examples:
|
||||
title: Example
|
||||
prenom: "Jean"
|
||||
nom: "Dupont"
|
||||
genre: "M."
|
||||
text: Short text
|
||||
textarea: Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.
|
||||
decimal_number: 49.3
|
||||
|
@ -284,6 +298,7 @@ en:
|
|||
dossier_link: 42
|
||||
rna: "W503726238"
|
||||
siret: "13002526500013"
|
||||
civilite: "M."
|
||||
prefill_link_title: Prefill link (GET)
|
||||
prefill_link_info: Use the button to copy the link, then remplace the values with your data.
|
||||
prefill_link_too_long: Warning, the prefill link is too long and may not work on all browsers.
|
||||
|
|
|
@ -226,14 +226,25 @@ fr:
|
|||
info_html: Pour cela, sélectionnez ci-dessous les champs que vous souhaitez préremplir.<br> Vous trouverez ensuite en bas de cette page un lien de préremplissage qu'il ne vous restera plus qu'à copier, à adapter en remplaçant les valeurs par défaut et à partager.<br> De la même façon, vous trouverez en bas de page un exemple de requête cURL à adapter si vous souhaitez préremplir les dossiers par API.
|
||||
champ_id: ID
|
||||
champ_type: Type
|
||||
champ_add: Ajouter
|
||||
champ_remove: Retirer
|
||||
champ_unavailable: Indisponible
|
||||
entity_add: Ajouter
|
||||
entity_remove: Retirer
|
||||
entity_unavailable: Indisponible
|
||||
title:
|
||||
prenom: Prénom (identité)
|
||||
nom: Nom (identité)
|
||||
genre: Genre (identité)
|
||||
description:
|
||||
prenom: Le prénom du ou de la propriétaire du dossier
|
||||
nom: Le nom du ou de la propriétaire du dossier
|
||||
genre: Le genre du ou de la propriétaire du dossier
|
||||
possible_values:
|
||||
link:
|
||||
title: Toutes les valeurs possibles
|
||||
text: Voir toutes les valeurs possibles
|
||||
title: Valeurs
|
||||
prenom: Un prénom
|
||||
nom: Un nom
|
||||
genre: '"M." pour Monsieur, "Mme" pour Madame'
|
||||
text_html: Un texte court
|
||||
textarea_html: Un texte long
|
||||
decimal_number_html: Un nombre décimal
|
||||
|
@ -261,6 +272,9 @@ fr:
|
|||
epci_html: Un tableau contenant le code de département et <a href="https://geo.api.gouv.fr/epcis" target="_blank" rel="noopener noreferrer">celui de l'EPCI</a>
|
||||
examples:
|
||||
title: Exemple
|
||||
prenom: "Jean"
|
||||
nom: "Dupont"
|
||||
genre: "M."
|
||||
text: Texte court
|
||||
textarea: Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.
|
||||
decimal_number: 49.3
|
||||
|
|
Loading…
Reference in a new issue