First draft autofetch data for RNA
This commit is contained in:
parent
ecd54de854
commit
0d9f02c88d
15 changed files with 64 additions and 15 deletions
|
@ -455,6 +455,13 @@
|
|||
min-height: 1px;
|
||||
}
|
||||
|
||||
.rna-info {
|
||||
margin-top: -$default-fields-spacer;
|
||||
margin-bottom: $default-fields-spacer;
|
||||
// Ensure the bottom-margin is not collapsed when the element is empty
|
||||
min-height: 1px;
|
||||
}
|
||||
|
||||
.send-wrapper {
|
||||
display: flex;
|
||||
width: 100%;
|
||||
|
|
|
@ -2,8 +2,11 @@
|
|||
id: @champ.input_id,
|
||||
aria: { describedby: @champ.describedby_id },
|
||||
placeholder: t(".placeholder"),
|
||||
data: { controller: 'turbo-input', turbo_input_url_value: champs_rna_path(@champ.id) },
|
||||
required: @champ.mandatory?,
|
||||
pattern: "W[0-9]{9}",
|
||||
title: t(".title"),
|
||||
class: "width-33-desktop",
|
||||
maxlength: 10
|
||||
.rna-info{ id: dom_id(@champ, :rna_info) }
|
||||
= render 'shared/champs/rna/association', champ: @champ
|
||||
|
|
14
app/controllers/champs/rna_controller.rb
Normal file
14
app/controllers/champs/rna_controller.rb
Normal file
|
@ -0,0 +1,14 @@
|
|||
class Champs::RNAController < ApplicationController
|
||||
before_action :authenticate_logged_user!
|
||||
|
||||
def show
|
||||
@champ = policy_scope(Champ).find(params[:champ_id])
|
||||
@rna = read_param_value(@champ.input_name, 'value')
|
||||
begin
|
||||
data = APIEntreprise::RNAAdapter.new(@rna, @champ.procedure_id).to_params
|
||||
@champ.update(data: data, value: @rna, skip_cleanup: true, skip_fetch: true)
|
||||
rescue => error
|
||||
@champ.update(data: nil, value: @rna, skip_cleanup: true, skip_fetch: true)
|
||||
end
|
||||
end
|
||||
end
|
|
@ -434,7 +434,6 @@ module Users
|
|||
if @dossier.champs.any?(&:changed_for_autosave?)
|
||||
@dossier.last_champ_updated_at = Time.zone.now
|
||||
end
|
||||
|
||||
if !@dossier.save(**validation_options)
|
||||
errors += @dossier.errors.full_messages
|
||||
elsif should_change_groupe_instructeur?
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
class APIEntreprise::AssociationJob < APIEntreprise::Job
|
||||
def perform(etablissement_id, procedure_id)
|
||||
find_etablissement(etablissement_id)
|
||||
etablissement_params = APIEntreprise::RNAAdapter.new(etablissement.siret, procedure_id).to_params
|
||||
etablissement_params = APIEntreprise::RNAAdapter.new(etablissement.siret, procedure_id, true).to_params
|
||||
etablissement.update!(etablissement_params)
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,9 +1,10 @@
|
|||
class APIEntreprise::Adapter
|
||||
UNAVAILABLE = 'Donnée indisponible'
|
||||
|
||||
def initialize(siret, procedure_id)
|
||||
def initialize(siret, procedure_id, depreciated = false)
|
||||
@siret = siret
|
||||
@procedure_id = procedure_id
|
||||
@depreciated = depreciated
|
||||
end
|
||||
|
||||
def api(procedure_id = nil)
|
||||
|
|
|
@ -25,6 +25,9 @@ class Champ < ApplicationRecord
|
|||
belongs_to :parent, class_name: 'Champ', optional: true
|
||||
has_one_attached :piece_justificative_file
|
||||
|
||||
attr_accessor :skip_cleanup
|
||||
attr_accessor :skip_fetch
|
||||
|
||||
# We declare champ specific relationships (Champs::CarteChamp, Champs::SiretChamp and Champs::RepetitionChamp)
|
||||
# here because otherwise we can't easily use includes in our queries.
|
||||
has_many :geo_areas, -> { order(:created_at) }, dependent: :destroy, inverse_of: :champ
|
||||
|
@ -76,9 +79,9 @@ class Champ < ApplicationRecord
|
|||
|
||||
before_create :set_dossier_id, if: :needs_dossier_id?
|
||||
before_validation :set_dossier_id, if: :needs_dossier_id?
|
||||
before_save :cleanup_if_empty
|
||||
before_save :cleanup_if_empty, unless: :skip_cleanup
|
||||
before_save :normalize
|
||||
after_update_commit :fetch_external_data_later
|
||||
after_update_commit :fetch_external_data_later, unless: :skip_fetch
|
||||
|
||||
def public?
|
||||
!private?
|
||||
|
|
|
@ -27,8 +27,16 @@ class Champs::RNAChamp < Champ
|
|||
|
||||
delegate :id, to: :procedure, prefix: true
|
||||
|
||||
def title
|
||||
data&.dig("association_titre")
|
||||
end
|
||||
|
||||
def identifier
|
||||
title.present? ? "#{value} (#{title})" : value
|
||||
end
|
||||
|
||||
def for_export
|
||||
data&.dig("association_titre")&.present? ? "#{value} (#{data.dig("association_titre")})" : value
|
||||
identifier
|
||||
end
|
||||
|
||||
def search_terms
|
||||
|
|
|
@ -41,6 +41,10 @@
|
|||
{
|
||||
"type": "integer"
|
||||
},
|
||||
{
|
||||
"type": "string",
|
||||
"format": "date"
|
||||
},
|
||||
{
|
||||
"type": "null"
|
||||
}
|
||||
|
|
1
app/views/champs/rna/show.turbo_stream.haml
Normal file
1
app/views/champs/rna/show.turbo_stream.haml
Normal file
|
@ -0,0 +1 @@
|
|||
= turbo_stream.update dom_id(@champ, :rna_info), partial: 'shared/champs/rna/association', locals: { champ: @champ }
|
4
app/views/shared/champs/rna/_association.html.haml
Normal file
4
app/views/shared/champs/rna/_association.html.haml
Normal file
|
@ -0,0 +1,4 @@
|
|||
- if champ.value.present? && champ.data.blank?
|
||||
%p.pt-1= t('.not_found')
|
||||
- elsif champ.value.present?
|
||||
%p.pt-1= t('.data_fetched', title: champ.title)
|
|
@ -1,8 +1,8 @@
|
|||
- if champ.blank?
|
||||
- if champ.value.blank?
|
||||
%p= t('.not_filled')
|
||||
- elsif profile == 'instructeur'
|
||||
- else
|
||||
- if champ.data.blank?
|
||||
%p= t('.fetching_data', rna: champ.value)
|
||||
%p= t('.not_found', rna: champ.value)
|
||||
- else
|
||||
%p= t('.data_fetched_title', rna: champ.value)
|
||||
%ul
|
||||
|
@ -12,5 +12,3 @@
|
|||
- ['association_date_creation', 'association_date_declaration', 'association_date_publication'].each do |scope|
|
||||
- if champ.data[scope].present?
|
||||
%li #{t("activemodel.attributes.rna_champ.data.#{scope}")} : #{l(champ.data[scope].to_date)}
|
||||
- else
|
||||
%p= champ.value
|
||||
|
|
|
@ -19,8 +19,11 @@ en:
|
|||
rna:
|
||||
show:
|
||||
not_filled: not filled
|
||||
fetching_data: "Fetching data for RNA number %{rna}."
|
||||
data_fetched_title: Data received thanks to RNA number "%{rna}"
|
||||
not_found: "RNA number %{rna} (no association found)"
|
||||
data_fetched_title: Data received from RNA number "%{rna}"
|
||||
association:
|
||||
data_fetched: "This RNA number is linked to %{title}"
|
||||
not_found: "No association found"
|
||||
dgfip:
|
||||
show:
|
||||
not_filled: not filled
|
||||
|
|
|
@ -21,8 +21,11 @@ fr:
|
|||
rna:
|
||||
show:
|
||||
not_filled: non renseigné
|
||||
fetching_data: "La récupération automatique des données pour l'association avec le numéro RNA %{rna} est en cours."
|
||||
data_fetched_title: Données complémentaires obtenues grâce au RNA "%{rna}"
|
||||
not_found: "RNA %{rna} (aucun établissement trouvé)"
|
||||
data_fetched_title: Données obtenues grâce au RNA "%{rna}"
|
||||
association:
|
||||
data_fetched: "Ce RNA correspond à %{title}"
|
||||
not_found: "Aucun établissement trouvé"
|
||||
dgfip:
|
||||
show:
|
||||
not_filled: non renseigné
|
||||
|
|
|
@ -153,6 +153,7 @@ Rails.application.routes.draw do
|
|||
|
||||
namespace :champs do
|
||||
get ':champ_id/siret', to: 'siret#show', as: :siret
|
||||
get ':champ_id/rna', to: 'rna#show', as: :rna
|
||||
get ':champ_id/dossier_link', to: 'dossier_link#show', as: :dossier_link
|
||||
post ':champ_id/repetition', to: 'repetition#add', as: :repetition
|
||||
delete ':champ_id/repetition', to: 'repetition#remove'
|
||||
|
|
Loading…
Reference in a new issue