[#2750] do parsing of displayed_fields inside ProcedurePresentation

rather than in the view
This commit is contained in:
Frederic Merizen 2018-10-05 15:25:24 +02:00
parent f59984ea70
commit 40a5ff0266
3 changed files with 23 additions and 20 deletions

View file

@ -85,21 +85,8 @@ class ProcedurePresentation < ApplicationRecord
end
end
def get_value(dossier, table, column)
assert_valid_column(table, column)
case table
when 'self'
dossier.send(column)
when 'user'
dossier.user.send(column)
when 'etablissement'
dossier.etablissement&.send(column)
when 'type_de_champ'
dossier.champs.find { |c| c.type_de_champ_id == column.to_i }.value
when 'type_de_champ_private'
dossier.champs_private.find { |c| c.type_de_champ_id == column.to_i }.value
end
def displayed_field_values(dossier)
displayed_fields.map { |field| get_value(dossier, field['table'], field['column']) }
end
def sorted_ids(dossiers, gestionnaire)
@ -176,6 +163,23 @@ class ProcedurePresentation < ApplicationRecord
private
def get_value(dossier, table, column)
assert_valid_column(table, column)
case table
when 'self'
dossier.send(column)
when 'user'
dossier.user.send(column)
when 'etablissement'
dossier.etablissement&.send(column)
when 'type_de_champ'
dossier.champs.find { |c| c.type_de_champ_id == column.to_i }.value
when 'type_de_champ_private'
dossier.champs_private.find { |c| c.type_de_champ_id == column.to_i }.value
end
end
def field_hash(label, table, column)
{
'label' => label,

View file

@ -104,10 +104,9 @@
= link_to(gestionnaire_dossier_path(@procedure, dossier), class: 'cell-link') do
= dossier.id
- @procedure_presentation.displayed_fields.each do |field|
- @procedure_presentation.displayed_field_values(dossier).each do |value|
%td
= link_to(gestionnaire_dossier_path(@procedure, dossier), class: 'cell-link') do
= @procedure_presentation.get_value(dossier, field['table'], field['column'])
= link_to(value, gestionnaire_dossier_path(@procedure, dossier), class: 'cell-link')
%td.status-col
= link_to(gestionnaire_dossier_path(@procedure, dossier), class: 'cell-link') do

View file

@ -109,9 +109,9 @@ describe ProcedurePresentation do
end
describe '#get_value' do
let(:procedure_presentation) { ProcedurePresentation.create(assign_to: assign_to) }
let(:procedure_presentation) { ProcedurePresentation.create(assign_to: assign_to, displayed_fields: [{ 'table' => table, 'column' => column }]) }
subject { procedure_presentation.get_value(dossier, table, column) }
subject { procedure_presentation.displayed_field_values(dossier).first }
context 'for self table' do
let(:table) { 'self' }