Add private columns to Champ and TypeDeChamp
This commit is contained in:
parent
52749713ab
commit
2e4ada98e6
4 changed files with 27 additions and 14 deletions
|
@ -12,8 +12,8 @@ class Champ < ActiveRecord::Base
|
||||||
before_save :multiple_select_to_string, if: Proc.new { type_champ == 'multiple_drop_down_list' }
|
before_save :multiple_select_to_string, if: Proc.new { type_champ == 'multiple_drop_down_list' }
|
||||||
|
|
||||||
scope :updated_since?, -> (date) { where('champs.updated_at > ?', date) }
|
scope :updated_since?, -> (date) { where('champs.updated_at > ?', date) }
|
||||||
scope :public_only, -> { where('champs.type != ?', 'ChampPrivate') }
|
scope :public_only, -> { where.not(type: 'ChampPrivate').or(where(private: [false, nil])) }
|
||||||
scope :private_only, -> { where(type: 'ChampPrivate') }
|
scope :private_only, -> { where(type: 'ChampPrivate').or(where(private: true)) }
|
||||||
|
|
||||||
def mandatory?
|
def mandatory?
|
||||||
mandatory
|
mandatory
|
||||||
|
@ -24,7 +24,7 @@ class Champ < ActiveRecord::Base
|
||||||
end
|
end
|
||||||
|
|
||||||
def private?
|
def private?
|
||||||
type == 'ChampPrivate'
|
super || type == 'ChampPrivate'
|
||||||
end
|
end
|
||||||
|
|
||||||
def same_hour? num
|
def same_hour? num
|
||||||
|
|
|
@ -25,20 +25,12 @@ class TypeDeChamp < ActiveRecord::Base
|
||||||
belongs_to :procedure
|
belongs_to :procedure
|
||||||
|
|
||||||
has_many :champ, inverse_of: :type_de_champ, dependent: :destroy do
|
has_many :champ, inverse_of: :type_de_champ, dependent: :destroy do
|
||||||
def build_params(params)
|
|
||||||
if proxy_association.owner.public?
|
|
||||||
params.merge(type: 'ChampPublic')
|
|
||||||
else
|
|
||||||
params.merge(type: 'ChampPrivate')
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
def build(params = {})
|
def build(params = {})
|
||||||
super(build_params(params))
|
super(params.merge(proxy_association.owner.params_for_champ))
|
||||||
end
|
end
|
||||||
|
|
||||||
def create(params = {})
|
def create(params = {})
|
||||||
super(build_params(params))
|
super(params.merge(proxy_association.owner.params_for_champ))
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
has_one :drop_down_list
|
has_one :drop_down_list
|
||||||
|
@ -50,6 +42,12 @@ class TypeDeChamp < ActiveRecord::Base
|
||||||
|
|
||||||
before_validation :check_mandatory
|
before_validation :check_mandatory
|
||||||
|
|
||||||
|
def params_for_champ
|
||||||
|
{
|
||||||
|
private: private?
|
||||||
|
}
|
||||||
|
end
|
||||||
|
|
||||||
def self.type_de_champs_list_fr
|
def self.type_de_champs_list_fr
|
||||||
type_champs.map { |champ| [I18n.t("activerecord.attributes.type_de_champ.type_champs.#{champ.last}"), champ.first] }
|
type_champs.map { |champ| [I18n.t("activerecord.attributes.type_de_champ.type_champs.#{champ.last}"), champ.first] }
|
||||||
end
|
end
|
||||||
|
|
|
@ -0,0 +1,11 @@
|
||||||
|
class AddPrivateToChampAndTypeDeChamp < ActiveRecord::Migration[5.2]
|
||||||
|
disable_ddl_transaction!
|
||||||
|
|
||||||
|
def change
|
||||||
|
add_column :champs, :private, :boolean, index: true
|
||||||
|
add_column :types_de_champ, :private, :boolean, index: true
|
||||||
|
|
||||||
|
add_index :champs, :private, algorithm: :concurrently
|
||||||
|
add_index :types_de_champ, :private, algorithm: :concurrently
|
||||||
|
end
|
||||||
|
end
|
|
@ -10,7 +10,7 @@
|
||||||
#
|
#
|
||||||
# It's strongly recommended that you check this file into your version control system.
|
# It's strongly recommended that you check this file into your version control system.
|
||||||
|
|
||||||
ActiveRecord::Schema.define(version: 2018_02_06_153121) do
|
ActiveRecord::Schema.define(version: 2018_02_09_133452) do
|
||||||
|
|
||||||
# These are extensions that must be enabled in order to support this database
|
# These are extensions that must be enabled in order to support this database
|
||||||
enable_extension "plpgsql"
|
enable_extension "plpgsql"
|
||||||
|
@ -138,7 +138,9 @@ ActiveRecord::Schema.define(version: 2018_02_06_153121) do
|
||||||
t.string "type"
|
t.string "type"
|
||||||
t.datetime "created_at"
|
t.datetime "created_at"
|
||||||
t.datetime "updated_at"
|
t.datetime "updated_at"
|
||||||
|
t.boolean "private"
|
||||||
t.index ["dossier_id"], name: "index_champs_on_dossier_id"
|
t.index ["dossier_id"], name: "index_champs_on_dossier_id"
|
||||||
|
t.index ["private"], name: "index_champs_on_private"
|
||||||
t.index ["type_de_champ_id"], name: "index_champs_on_type_de_champ_id"
|
t.index ["type_de_champ_id"], name: "index_champs_on_type_de_champ_id"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -425,6 +427,8 @@ ActiveRecord::Schema.define(version: 2018_02_06_153121) do
|
||||||
t.text "description"
|
t.text "description"
|
||||||
t.boolean "mandatory", default: false
|
t.boolean "mandatory", default: false
|
||||||
t.string "type"
|
t.string "type"
|
||||||
|
t.boolean "private"
|
||||||
|
t.index ["private"], name: "index_types_de_champ_on_private"
|
||||||
end
|
end
|
||||||
|
|
||||||
create_table "types_de_piece_justificative", id: :serial, force: :cascade do |t|
|
create_table "types_de_piece_justificative", id: :serial, force: :cascade do |t|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue