diff --git a/app/controllers/users/dossiers_controller.rb b/app/controllers/users/dossiers_controller.rb index 864b593581d..55d8a5644ee 100644 --- a/app/controllers/users/dossiers_controller.rb +++ b/app/controllers/users/dossiers_controller.rb @@ -375,6 +375,7 @@ def update @to_show, @to_hide, @to_update = champs_to_turbo_update(champs_public_attributes_params, dossier.champs.filter(&:public?)) render :update, layout: false end + format.html { redirect_to dossier_path(@dossier) } end end diff --git a/app/graphql/types/champs/referentiel_de_polynesie_champ_type.rb b/app/graphql/types/champs/referentiel_de_polynesie_champ_type.rb index bfab98e5838..332d99cdf0b 100644 --- a/app/graphql/types/champs/referentiel_de_polynesie_champ_type.rb +++ b/app/graphql/types/champs/referentiel_de_polynesie_champ_type.rb @@ -2,20 +2,7 @@ module Types::Champs class ReferentielDePolynesieChampType < Types::BaseObject implements Types::ChampType - field :selected_value, String, null: true field :table_id, ID, null: true field :search_field, String, null: true - - def selected_value - object.value - end - - def table_id - object.table_id - end - - def search_field - object.search_field - end end end diff --git a/app/lib/referentiel_de_polynesie/api.rb b/app/lib/referentiel_de_polynesie/api.rb index 89f78bc9bc0..5fdc6582572 100644 --- a/app/lib/referentiel_de_polynesie/api.rb +++ b/app/lib/referentiel_de_polynesie/api.rb @@ -3,16 +3,16 @@ class ReferentielDePolynesie::API class << self def available_tables - engine&.available_tables + engine&.available_tables || [] end def search(domain_id, term) - engine&.search(domain_id, term) + engine&.search(domain_id, term) || [] end def fetch_row(external_id) table, id = external_id.split(':') - engine.fetch_row(table, id) + engine&.fetch_row(table, id) || {} end def engine diff --git a/app/lib/referentiel_de_polynesie/baserow_api.rb b/app/lib/referentiel_de_polynesie/baserow_api.rb index 7063dd8951b..533d4b3ad15 100644 --- a/app/lib/referentiel_de_polynesie/baserow_api.rb +++ b/app/lib/referentiel_de_polynesie/baserow_api.rb @@ -6,15 +6,24 @@ class << self def search(domain_id, term) config = config(domain_id) + return [] unless config search_field = config['Champ de recherche'] params = { "filter__field_#{search_field}__contains" => term } url = rows_url(config['Table']) - response = Typhoeus.get(url, headers: database_headers(config['Token']), params: params) - pp response - if response.success? - JSON.parse(response.body, symbolize_names: true)[:results].map do - { name: _1[:"field_#{search_field}"], id: _1[:id], domain: domain_id } - end + [{ name: 'Autre', id: 0, domain: domain_id }] + begin + response = Typhoeus.get(url, headers: database_headers(config['Token']), params: params) + pp response + if response.success? + JSON.parse(response.body, symbolize_names: true)[:results].map do |result| + { name: result[:"field_#{search_field}"], id: result[:id], domain: domain_id } + end + [{ name: 'Autre', id: 0, domain: domain_id }] + else + Rails.logger.error("Baserow API error: #{response.code} - #{response.body}") + [] + end + rescue Typhoeus::Errors::TyphoeusError => e + Rails.logger.error("Baserow API error: #{e.message}") + [] end end diff --git a/app/views/shared/dossiers/messages/_form.html.haml b/app/views/shared/dossiers/messages/_form.html.haml index bd0cfe98e6e..d9e85b87d4b 100644 --- a/app/views/shared/dossiers/messages/_form.html.haml +++ b/app/views/shared/dossiers/messages/_form.html.haml @@ -1,5 +1,5 @@ = render NestedForms::FormOwnerComponent.new -= form_for(commentaire, url: form_url, html: { multipart: local_assigns.has_key?(:dossier), data: { controller: 'persisted-form', persisted_form_key_value: dom_id(local_assigns.fetch(:dossier, local_assigns.fetch(:last_commentaire, current_user))) } }) do |f| += form_for(commentaire, url: form_url, html: { multipart: local_assigns.has_key?(:dossier), data: { controller: 'persisted-form', persisted_form_key_value: dom_id(local_assigns.fetch(:dossier, local_assigns.fetch(:last_commentaire, current_user))), turbo: true } }) do |f| - placeholder = t('views.shared.dossiers.messages.form.write_message_to_administration_placeholder') - if local_assigns.has_key?(:last_commentaire) = f.hidden_field :last_commentaire, value: last_commentaire.id, name: :id diff --git a/config/secrets.yml b/config/secrets.yml index 3e8eaaef59a..2df0177e435 100644 --- a/config/secrets.yml +++ b/config/secrets.yml @@ -135,6 +135,7 @@ defaults: &defaults userpwd: <%= ENV['CERTIGNA_USERPWD'] %> baserow: url: <%= ENV['API_BASEROW_URL'] %> + token: <%= ENV['API_BASEROW_TOKEN'] %> config_table: <%= ENV['API_BASEROW_CONFIG_TABLE'] %> autocomplete: api_geo_url: <%= ENV['API_GEO_URL'] %>