Skip to content

Commit

Permalink
wip make column work with referentiel headers
Browse files Browse the repository at this point in the history
  • Loading branch information
E-L-T committed Dec 17, 2024
1 parent e00e9d8 commit b12ac7c
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 18 deletions.
7 changes: 6 additions & 1 deletion app/controllers/administrateurs/types_de_champ_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,12 @@ def import_referentiel

ActiveRecord::Base.transaction do
# Create referentiel
referentiel = type_de_champ.create_referentiel!(name: referentiel_file.original_filename)
headers = ACSV::CSV.new_for_ruby3(file.encode("UTF-8", base_encoding[:encoding], invalid: :replace, replace: ""), headers: true)
.map { |row| row.to_h }
.first
.keys

referentiel = type_de_champ.create_referentiel!(name: referentiel_file.original_filename, headers:)

csv_to_code = ACSV::CSV.new_for_ruby3(file.encode("UTF-8", base_encoding[:encoding], invalid: :replace, replace: ""), headers: true, header_converters: [:downcase, :symbol])
.map { |row| row.to_h }
Expand Down
34 changes: 17 additions & 17 deletions app/models/types_de_champ/drop_down_list_type_de_champ.rb
Original file line number Diff line number Diff line change
@@ -1,31 +1,31 @@
# frozen_string_literal: true

class TypesDeChamp::DropDownListTypeDeChamp < TypesDeChamp::TypeDeChampBase

def columns(procedure:, displayable: true, prefix: nil)
if referentiel?
referentiel.data_header_columns.map do |header|
Columns::JSONPathColumn.new(
procedure_id: procedure.id,
stable_id:,
tdc_type: type_champ,
label: "#{libelle_with_prefix(prefix)} – Référentiel #{header.humanize}",
type: :text,
jsonpath: "$.referentiel.data.#{header}",
displayable:
)
end
.concat(
[Columns::JSONPathColumn.new(
referentiel.headers.map do |header|
Columns::JSONPathColumn.new(
procedure_id: procedure.id,
stable_id:,
tdc_type: type_champ,
label: "#{libelle_with_prefix(prefix)} – Référentiel #{referentiel.option_header_column.humanize}",
label: "#{libelle_with_prefix(prefix)} – Référentiel #{header}",
type: :text,
jsonpath: "$.referentiel.option.#{referentiel.option_header_column}",
jsonpath: "$.referentiel.data.#{header.parameterize.underscore}",
displayable:
)
]
end
.concat(
[
Columns::JSONPathColumn.new(
procedure_id: procedure.id,
stable_id:,
tdc_type: type_champ,
label: "#{libelle_with_prefix(prefix)} – Référentiel #{referentiel.option_header_column.humanize}",
type: :text,
jsonpath: "$.referentiel.option.#{referentiel.option_header_column}",
displayable:
)
]
)
else
super
Expand Down

0 comments on commit b12ac7c

Please sign in to comment.