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
|
@statut = statut
|
||||||
@procedure = procedure
|
@procedure = procedure
|
||||||
@procedure_presentation = procedure_presentation
|
@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
|
end
|
||||||
|
|
||||||
def remove_filter
|
def remove_filter
|
||||||
|
|
|
@ -18,13 +18,9 @@ class Column
|
||||||
@displayable = displayable
|
@displayable = displayable
|
||||||
end
|
end
|
||||||
|
|
||||||
def id
|
def id = h_id.to_json
|
||||||
"#{table}/#{column}"
|
def h_id = { procedure_id: @procedure_id, column_id: "#{table}/#{column}" }
|
||||||
end
|
def ==(other) = h_id == other.h_id # using h_id instead of id to avoid inversion of keys
|
||||||
|
|
||||||
def ==(other)
|
|
||||||
other.to_json == to_json
|
|
||||||
end
|
|
||||||
|
|
||||||
def to_json
|
def to_json
|
||||||
{
|
{
|
||||||
|
|
|
@ -4,7 +4,10 @@ module ColumnsConcern
|
||||||
extend ActiveSupport::Concern
|
extend ActiveSupport::Concern
|
||||||
|
|
||||||
included do
|
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
|
def columns
|
||||||
columns = dossier_columns
|
columns = dossier_columns
|
||||||
|
|
|
@ -81,8 +81,10 @@ class ProcedurePresentation < ApplicationRecord
|
||||||
end
|
end
|
||||||
|
|
||||||
def add_filter(statut, column_id, value)
|
def add_filter(statut, column_id, value)
|
||||||
|
h_id = JSON.parse(column_id, symbolize_names: true)
|
||||||
|
|
||||||
if value.present?
|
if value.present?
|
||||||
column = procedure.find_column(id: column_id)
|
column = procedure.find_column(h_id:)
|
||||||
|
|
||||||
case column.table
|
case column.table
|
||||||
when TYPE_DE_CHAMP
|
when TYPE_DE_CHAMP
|
||||||
|
@ -103,7 +105,8 @@ class ProcedurePresentation < ApplicationRecord
|
||||||
end
|
end
|
||||||
|
|
||||||
def remove_filter(statut, column_id, value)
|
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 = filters.dup
|
||||||
|
|
||||||
updated_filters[statut] = filters[statut].reject do |filter|
|
updated_filters[statut] = filters[statut].reject do |filter|
|
||||||
|
@ -114,8 +117,8 @@ class ProcedurePresentation < ApplicationRecord
|
||||||
end
|
end
|
||||||
|
|
||||||
def update_displayed_fields(column_ids)
|
def update_displayed_fields(column_ids)
|
||||||
column_ids = Array.wrap(column_ids)
|
h_ids = Array.wrap(column_ids).map { |id| JSON.parse(id, symbolize_names: true) }
|
||||||
columns = column_ids.map { |id| procedure.find_column(id:) }
|
columns = h_ids.map { |h_id| procedure.find_column(h_id:) }
|
||||||
|
|
||||||
update!(displayed_fields: columns)
|
update!(displayed_fields: columns)
|
||||||
|
|
||||||
|
@ -125,7 +128,8 @@ class ProcedurePresentation < ApplicationRecord
|
||||||
end
|
end
|
||||||
|
|
||||||
def update_sort(column_id, order)
|
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: {
|
update!(sort: {
|
||||||
TABLE => column.table,
|
TABLE => column.table,
|
||||||
|
|
Loading…
Reference in a new issue