colonne.id = { procedure_id:, column_id: }.to_json
because: - id should be a string as other id - id need procedure_id to allow ColumnType.deserialize(id) -> Column as the columns are built by a procedure
This commit is contained in:
parent
a8b41e90cc
commit
e3697bd976
4 changed files with 17 additions and 14 deletions
|
@ -158,7 +158,7 @@ module Instructeurs
|
|||
@statut = statut
|
||||
@procedure = procedure
|
||||
@procedure_presentation = procedure_presentation
|
||||
@column = procedure.find_column(id: params[:column])
|
||||
@column = procedure.find_column(h_id: JSON.parse(params[:column], symbolize_names: true))
|
||||
end
|
||||
|
||||
def remove_filter
|
||||
|
|
|
@ -18,13 +18,9 @@ class Column
|
|||
@displayable = displayable
|
||||
end
|
||||
|
||||
def id
|
||||
"#{table}/#{column}"
|
||||
end
|
||||
|
||||
def ==(other)
|
||||
other.to_json == to_json
|
||||
end
|
||||
def id = h_id.to_json
|
||||
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,7 +4,10 @@ module ColumnsConcern
|
|||
extend ActiveSupport::Concern
|
||||
|
||||
included do
|
||||
def find_column(id:) = columns.find { |f| f.id == id }
|
||||
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?
|
||||
end
|
||||
|
||||
def columns
|
||||
columns = dossier_columns
|
||||
|
|
|
@ -81,8 +81,10 @@ class ProcedurePresentation < ApplicationRecord
|
|||
end
|
||||
|
||||
def add_filter(statut, column_id, value)
|
||||
h_id = JSON.parse(column_id, symbolize_names: true)
|
||||
|
||||
if value.present?
|
||||
column = procedure.find_column(id: column_id)
|
||||
column = procedure.find_column(h_id:)
|
||||
|
||||
case column.table
|
||||
when TYPE_DE_CHAMP
|
||||
|
@ -103,7 +105,8 @@ class ProcedurePresentation < ApplicationRecord
|
|||
end
|
||||
|
||||
def remove_filter(statut, column_id, value)
|
||||
column = procedure.find_column(id: column_id)
|
||||
h_id = JSON.parse(column_id, symbolize_names: true)
|
||||
column = procedure.find_column(h_id:)
|
||||
updated_filters = filters.dup
|
||||
|
||||
updated_filters[statut] = filters[statut].reject do |filter|
|
||||
|
@ -114,8 +117,8 @@ class ProcedurePresentation < ApplicationRecord
|
|||
end
|
||||
|
||||
def update_displayed_fields(column_ids)
|
||||
column_ids = Array.wrap(column_ids)
|
||||
columns = column_ids.map { |id| procedure.find_column(id:) }
|
||||
h_ids = Array.wrap(column_ids).map { |id| JSON.parse(id, symbolize_names: true) }
|
||||
columns = h_ids.map { |h_id| procedure.find_column(h_id:) }
|
||||
|
||||
update!(displayed_fields: columns)
|
||||
|
||||
|
@ -125,7 +128,8 @@ class ProcedurePresentation < ApplicationRecord
|
|||
end
|
||||
|
||||
def update_sort(column_id, order)
|
||||
column = procedure.find_column(id: column_id)
|
||||
h_id = JSON.parse(column_id, symbolize_names: true)
|
||||
column = procedure.find_column(h_id:)
|
||||
|
||||
update!(sort: {
|
||||
TABLE => column.table,
|
||||
|
|
Loading…
Reference in a new issue