Skip to content

Commit

Permalink
wip columns
Browse files Browse the repository at this point in the history
  • Loading branch information
lisa-durand authored and E-L-T committed Dec 17, 2024
1 parent f6cf897 commit 4e92f3f
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 5 deletions.
8 changes: 8 additions & 0 deletions app/models/referentiel.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,12 @@
class Referentiel < ApplicationRecord
has_many :items, class_name: 'ReferentielItem', dependent: :destroy
has_many :types_de_champ, inverse_of: :referentiel, dependent: :nullify

def data_header_columns
items.first.data.keys
end

def option_header_column
items.first.option.keys.first
end
end
23 changes: 19 additions & 4 deletions app/models/types_de_champ/drop_down_list_type_de_champ.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,32 @@ class TypesDeChamp::DropDownListTypeDeChamp < TypesDeChamp::TypeDeChampBase

def columns(procedure:, displayable: true, prefix: nil)
if referentiel?
[
Columns::JSONPathColumn.new(
super
.concat(
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}",
type: :text,
jsonpath: "$.referentiel.data.#{header}",
displayable:
)
end
)
.concat(
[Columns::JSONPathColumn.new(
procedure_id: procedure.id,
stable_id:,
tdc_type: type_champ,
label: "#{libelle_with_prefix(prefix)} – Référentiel",
label: "#{libelle_with_prefix(prefix)} – Référentiel #{referentiel.option_header_column}",
type: :text,
jsonpath: '$.referentiel',
jsonpath: "$.referentiel.option.#{referentiel.option_header_column}",
displayable:
)
]
)
else
super
end
Expand Down
2 changes: 1 addition & 1 deletion app/models/types_de_champ/type_de_champ_base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
class TypesDeChamp::TypeDeChampBase
include ActiveModel::Validations

delegate :description, :libelle, :mandatory, :mandatory?, :stable_id, :fillable?, :public?, :type_champ, :options_for_select, :drop_down_options, :referentiel_drop_down_options, :drop_down_other?, :referentiel?, to: :@type_de_champ
delegate :description, :libelle, :mandatory, :mandatory?, :stable_id, :fillable?, :public?, :type_champ, :options_for_select, :drop_down_options, :referentiel_drop_down_options, :drop_down_other?, :referentiel?, :referentiel, to: :@type_de_champ

FILL_DURATION_SHORT = 10.seconds
FILL_DURATION_MEDIUM = 1.minute
Expand Down

0 comments on commit 4e92f3f

Please sign in to comment.