368436 évolution des PortTypes - #783
Conversation
f832eb1 to
ae33114
Compare
| scope :attachable_to_server, -> { where("? = ANY(attachable_to)", :server) } | ||
| scope :attachable_to_pdu, -> { where("? = ANY(attachable_to)", :pdu) } |
There was a problem hiding this comment.
| scope :attachable_to_server, -> { where("? = ANY(attachable_to)", :server) } | |
| scope :attachable_to_pdu, -> { where("? = ANY(attachable_to)", :pdu) } | |
| scope :usable_by, -> (usable_by) { where("? = ANY(attachable_to)", usable_by) } |
| has_many :card_types, dependent: :restrict_with_error | ||
| has_many :sockets, class_name: "PowerDistributionUnit::Socket", dependent: :restrict_with_error | ||
|
|
||
| validates :attachable_to, array_inclusion: { in: %w[pdu server] } |
There was a problem hiding this comment.
Enum definition is missing, no?
There was a problem hiding this comment.
I have not found a "multiple value enum" built in for rails. It is juste an array of string isn't it ?
| def change | ||
| rename_column :port_types, :power, :is_power | ||
|
|
||
| create_enum :port_attachable_type, %w[pdu server] |
There was a problem hiding this comment.
| create_enum :port_attachable_type, %w[pdu server] | |
| create_enum :port_types_usable_by, %w[pdu server] |
| up_only do | ||
| PortTypeMigration.reset_column_information | ||
| PortTypeMigration.find_each do |port_type| | ||
| port_type.update!(is_power: port_type.name == "ALIM", attachable_to: ["server"]) |
There was a problem hiding this comment.
| port_type.update!(is_power: port_type.name == "ALIM", attachable_to: ["server"]) | |
| port_type.update!(is_power: port_type.name == "ALIM", usable_by: ["server"]) |
| rename_column :port_types, :power, :is_power | ||
|
|
||
| create_enum :port_attachable_type, %w[pdu server] | ||
| add_column :port_types, :attachable_to, :enum, enum_type: :port_attachable_type, array: true |
There was a problem hiding this comment.
| add_column :port_types, :attachable_to, :enum, enum_type: :port_attachable_type, array: true | |
| add_column :port_types, :usable_by, :enum, enum_type: :port_types_usable_by, array: true |
0c7935a to
dd80681
Compare
4bc769a to
1582efd
Compare
|
|
||
| def self.usable_by_options_for_select | ||
| PortType::USABLE_BY_VALUES.map do |value| | ||
| [I18n.t(".activerecord.attributes.port_type.usable_by/#{value}"), value] |
| blank: can't be blank, or "All domains" must be checked | ||
|
|
||
| messages: | ||
| array_inclusion: "includes unauthorized values : %{wrong_values}" |
There was a problem hiding this comment.
| array_inclusion: "includes unauthorized values : %{wrong_values}" | |
| array_inclusion: "includes unauthorized values: %{wrong_values}" |
| <% end %> | ||
|
|
||
| <% table.with_column(PortType.human_attribute_name(:usable_by)) do |port_type| %> | ||
| <%= port_type.usable_by.to_sentence %> |
There was a problem hiding this comment.
Values not translated. Maybe use decorator for this.
|
|
||
| <dl class="show-page_dl d-grid row-gap-2 mb-0"> | ||
| <dt class="pb-2"><%= PortType.human_attribute_name(:usable_by) %></dt> | ||
| <dd class="mb-0 pb-2 ps-3"><%= @port_type.usable_by.to_sentence %></dd> |
There was a problem hiding this comment.
Values not translated. Maybe use decorator for this
| usable_by/server: Server | ||
| usable_by/pdu: Pdu |
There was a problem hiding this comment.
Use same format as we usually do for enums
| usable_by/server: Serveur | ||
| usable_by/pdu: Pdu |
There was a problem hiding this comment.
Use same format as we usually do for enums
| one: Network hub cluster | ||
| other: Network hub clusters | ||
| color: Color | ||
| port_type: |
There was a problem hiding this comment.
Add missing attributes already present in fr
| def port_type_options_for_select | ||
| PortTypeDecorator.options_for_select(PortType.where(power: true)) | ||
| def port_types_options_for_select | ||
| PortTypeDecorator.options_for_select(PortType.usable_by(:pdu)) |
There was a problem hiding this comment.
should only show usable_by(:pdu) & power: true for this form.
| # get sql type to cast properly | ||
| # It returns the array's element type | ||
| element_type = columns_hash[name.to_s].sql_type | ||
|
|
||
| # encode array so it can be understood by PG | ||
| encoder = PG::TextEncoder::Array.new | ||
| encoded = encoder.encode(db_values) | ||
|
|
||
| where( | ||
| "#{name} @> ?::#{element_type}[]", | ||
| encoded, | ||
| ) |
There was a problem hiding this comment.
Does where("#{name} @> ARRAY[?]::varchar[]", db_values) works?
There was a problem hiding this comment.
It does not if I'm right.
Like the DB fields is / (can be) a PG enum, @> will not accept another type as the exact field type.
A PG enum value isn't comparable to a varchar, the array elements can also be integers ...
The values are sent as text, and PG cast them. I haven't found any encoder for that column API
ea77ce9 to
ae4ac74
Compare
No description provided.