Add repetitions to api
This commit is contained in:
parent
127a4d2ffb
commit
b266915892
7 changed files with 51 additions and 10 deletions
|
@ -5,10 +5,11 @@ class Champ < ApplicationRecord
|
|||
has_many :commentaires
|
||||
has_one_attached :piece_justificative_file
|
||||
|
||||
# We declare champ specific relationships (Champs::CarteChamp and Champs::SiretChamp)
|
||||
# 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, dependent: :destroy
|
||||
belongs_to :etablissement, dependent: :destroy
|
||||
has_many :champs, -> { ordered }, foreign_key: :parent_id, inverse_of: :parent, dependent: :destroy
|
||||
|
||||
delegate :libelle, :type_champ, :order_place, :mandatory?, :description, :drop_down_list, :exclude_from_export?, :exclude_from_view?, :repetition?, to: :type_de_champ
|
||||
|
||||
|
|
|
@ -1,6 +1,4 @@
|
|||
class Champs::RepetitionChamp < Champ
|
||||
has_many :champs, -> { ordered }, foreign_key: :parent_id, inverse_of: :parent, dependent: :destroy
|
||||
|
||||
accepts_nested_attributes_for :champs, allow_destroy: true
|
||||
|
||||
def rows
|
||||
|
@ -21,11 +19,21 @@ class Champs::RepetitionChamp < Champ
|
|||
# The user cannot enter any information here so it doesn’t make much sense to search
|
||||
end
|
||||
|
||||
def rows_for_export
|
||||
rows.each.with_index(1).map do |champs, index|
|
||||
Champs::RepetitionChamp::Row.new(index: index, dossier_id: dossier_id.to_s, champs: champs)
|
||||
end
|
||||
end
|
||||
|
||||
class Row < Hashie::Dash
|
||||
property :index
|
||||
property :dossier_id
|
||||
property :champs
|
||||
|
||||
def read_attribute_for_serialization(attribute)
|
||||
self[attribute]
|
||||
end
|
||||
|
||||
def spreadsheet_columns
|
||||
[
|
||||
['Dossier ID', :dossier_id],
|
||||
|
|
|
@ -137,12 +137,18 @@ class Dossier < ApplicationRecord
|
|||
champs: [
|
||||
:geo_areas,
|
||||
:etablissement,
|
||||
piece_justificative_file_attachment: :blob
|
||||
piece_justificative_file_attachment: :blob,
|
||||
champs: [
|
||||
piece_justificative_file_attachment: :blob
|
||||
]
|
||||
],
|
||||
champs_private: [
|
||||
:geo_areas,
|
||||
:etablissement,
|
||||
piece_justificative_file_attachment: :blob
|
||||
piece_justificative_file_attachment: :blob,
|
||||
champs: [
|
||||
piece_justificative_file_attachment: :blob
|
||||
]
|
||||
],
|
||||
justificatif_motivation_attachment: :blob,
|
||||
attestation: [],
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue