[#2750] Move fields_for_select to ProcedurePresentation
This commit is contained in:
parent
b6b4a76906
commit
efcac5192a
6 changed files with 35 additions and 34 deletions
|
@ -28,7 +28,9 @@ module NewGestionnaire
|
|||
|
||||
@current_filters = current_filters
|
||||
@available_fields_to_filters = available_fields_to_filters
|
||||
@displayed_fields = procedure_presentation.displayed_fields
|
||||
# Technically, procedure_presentation already sets the attribute.
|
||||
# Setting it here to make clear that it is used by the view
|
||||
@procedure_presentation = procedure_presentation
|
||||
@displayed_fields_values = displayed_fields_values
|
||||
|
||||
@a_suivre_dossiers = procedure
|
||||
|
@ -225,13 +227,13 @@ module NewGestionnaire
|
|||
"#{field['table']}/#{field['column']}"
|
||||
end
|
||||
|
||||
procedure.fields_for_select.reject do |field|
|
||||
procedure_presentation.fields_for_select.reject do |field|
|
||||
current_filters_fields_ids.include?(field[1])
|
||||
end
|
||||
end
|
||||
|
||||
def eager_load_displayed_fields
|
||||
@displayed_fields
|
||||
procedure_presentation.displayed_fields
|
||||
.reject { |field| field['table'] == 'self' }
|
||||
.group_by do |field|
|
||||
if ['type_de_champ', 'type_de_champ_private'].include?(field['table'])
|
||||
|
|
|
@ -300,12 +300,6 @@ class Procedure < ApplicationRecord
|
|||
DossierFieldService.new.fields(self)
|
||||
end
|
||||
|
||||
def fields_for_select
|
||||
fields.map do |field|
|
||||
[field['label'], "#{field['table']}/#{field['column']}"]
|
||||
end
|
||||
end
|
||||
|
||||
def self.default_sort
|
||||
{
|
||||
'table' => 'self',
|
||||
|
|
|
@ -42,6 +42,12 @@ class ProcedurePresentation < ApplicationRecord
|
|||
end
|
||||
end
|
||||
|
||||
def fields_for_select
|
||||
procedure.fields.map do |field|
|
||||
[field['label'], "#{field['table']}/#{field['column']}"]
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def dossier_field_service
|
||||
|
|
|
@ -73,7 +73,7 @@
|
|||
|
||||
= render partial: "header_field", locals: { field: { "label" => "Nº dossier", "table" => "self", "column" => "id" }, classname: "number-col" }
|
||||
|
||||
- @displayed_fields.each do |field|
|
||||
- @procedure_presentation.displayed_fields.each do |field|
|
||||
= render partial: "header_field", locals: { field: field, classname: "" }
|
||||
|
||||
= render partial: "header_field", locals: { field: { "label" => "Statut", "table" => "self", "column" => "state" }, classname: "status-col" }
|
||||
|
@ -85,7 +85,7 @@
|
|||
.dropdown-content.fade-in-down
|
||||
= form_tag update_displayed_fields_gestionnaire_procedure_path(@procedure), method: :patch, class: 'dropdown-form columns-form' do
|
||||
= select_tag :values,
|
||||
options_for_select(@procedure.fields_for_select,
|
||||
options_for_select(@procedure_presentation.fields_for_select,
|
||||
selected: @displayed_fields_values),
|
||||
multiple: true,
|
||||
class: 'select2-limited'
|
||||
|
@ -105,7 +105,7 @@
|
|||
= link_to(gestionnaire_dossier_path(@procedure, dossier), class: 'cell-link') do
|
||||
= dossier.id
|
||||
|
||||
- @displayed_fields.each do |field|
|
||||
- @procedure_presentation.displayed_fields.each do |field|
|
||||
%td
|
||||
= link_to(gestionnaire_dossier_path(@procedure, dossier), class: 'cell-link') do
|
||||
= dossier_field_service.get_value(dossier, field['table'], field['column'])
|
||||
|
|
|
@ -46,4 +46,25 @@ describe ProcedurePresentation do
|
|||
it { expect(build(:procedure_presentation, filters: { "suivis" => [{ "table" => "user", "column" => "reset_password_token", "order" => "asc" }] })).to be_invalid }
|
||||
end
|
||||
end
|
||||
|
||||
describe "#fields_for_select" do
|
||||
subject { create(:procedure_presentation) }
|
||||
|
||||
before do
|
||||
allow(subject.procedure).to receive(:fields).and_return([
|
||||
{
|
||||
"label" => "label1",
|
||||
"table" => "table1",
|
||||
"column" => "column1"
|
||||
},
|
||||
{
|
||||
"label" => "label2",
|
||||
"table" => "table2",
|
||||
"column" => "column2"
|
||||
}
|
||||
])
|
||||
end
|
||||
|
||||
it { expect(subject.fields_for_select).to eq([["label1", "table1/column1"], ["label2", "table2/column2"]]) }
|
||||
end
|
||||
end
|
||||
|
|
|
@ -664,28 +664,6 @@ describe Procedure do
|
|||
|
||||
it { expect(subject.fields).to eq(expected) }
|
||||
end
|
||||
|
||||
describe "#fields_for_select" do
|
||||
subject { create(:procedure) }
|
||||
|
||||
before do
|
||||
allow(subject).to receive(:fields).and_return([
|
||||
{
|
||||
"label" => "label1",
|
||||
"table" => "table1",
|
||||
"column" => "column1"
|
||||
},
|
||||
{
|
||||
"label" => "label2",
|
||||
"table" => "table2",
|
||||
"column" => "column2"
|
||||
}
|
||||
])
|
||||
end
|
||||
|
||||
it { expect(subject.fields_for_select).to eq([["label1", "table1/column1"], ["label2", "table2/column2"]]) }
|
||||
end
|
||||
|
||||
describe ".default_sort" do
|
||||
it { expect(Procedure.default_sort).to eq({ "table" => "self", "column" => "id", "order" => "desc" }) }
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue