add comments
This commit is contained in:
parent
450420aa81
commit
14809b35af
2 changed files with 9 additions and 0 deletions
|
@ -18,8 +18,13 @@ class Column
|
|||
@displayable = displayable
|
||||
end
|
||||
|
||||
# the id is a String to be used in forms
|
||||
def id = h_id.to_json
|
||||
|
||||
# the h_id is a Hash and hold enough information to find the column
|
||||
# in the ColumnType class, aka be able to do the h_id -> column conversion
|
||||
def h_id = { procedure_id: @procedure_id, column_id: "#{table}/#{column}" }
|
||||
|
||||
def ==(other) = h_id == other.h_id # using h_id instead of id to avoid inversion of keys
|
||||
|
||||
def to_json
|
||||
|
|
|
@ -4,6 +4,10 @@ module ColumnsConcern
|
|||
extend ActiveSupport::Concern
|
||||
|
||||
included do
|
||||
# we cannot use column.id ( == { procedure_id, column_id }.to_json)
|
||||
# as the order of the keys is not guaranteed
|
||||
# instead, we are using h_id == { procedure_id:, column_id: }
|
||||
# another way to find a column is to look for its label
|
||||
def find_column(h_id: nil, label: nil)
|
||||
return columns.find { _1.h_id == h_id } if h_id.present?
|
||||
return columns.find { _1.label == label } if label.present?
|
||||
|
|
Loading…
Reference in a new issue