[#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
|
@current_filters = current_filters
|
||||||
@available_fields_to_filters = available_fields_to_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
|
@displayed_fields_values = displayed_fields_values
|
||||||
|
|
||||||
@a_suivre_dossiers = procedure
|
@a_suivre_dossiers = procedure
|
||||||
|
@ -225,13 +227,13 @@ module NewGestionnaire
|
||||||
"#{field['table']}/#{field['column']}"
|
"#{field['table']}/#{field['column']}"
|
||||||
end
|
end
|
||||||
|
|
||||||
procedure.fields_for_select.reject do |field|
|
procedure_presentation.fields_for_select.reject do |field|
|
||||||
current_filters_fields_ids.include?(field[1])
|
current_filters_fields_ids.include?(field[1])
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def eager_load_displayed_fields
|
def eager_load_displayed_fields
|
||||||
@displayed_fields
|
procedure_presentation.displayed_fields
|
||||||
.reject { |field| field['table'] == 'self' }
|
.reject { |field| field['table'] == 'self' }
|
||||||
.group_by do |field|
|
.group_by do |field|
|
||||||
if ['type_de_champ', 'type_de_champ_private'].include?(field['table'])
|
if ['type_de_champ', 'type_de_champ_private'].include?(field['table'])
|
||||||
|
|
|
@ -300,12 +300,6 @@ class Procedure < ApplicationRecord
|
||||||
DossierFieldService.new.fields(self)
|
DossierFieldService.new.fields(self)
|
||||||
end
|
end
|
||||||
|
|
||||||
def fields_for_select
|
|
||||||
fields.map do |field|
|
|
||||||
[field['label'], "#{field['table']}/#{field['column']}"]
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
def self.default_sort
|
def self.default_sort
|
||||||
{
|
{
|
||||||
'table' => 'self',
|
'table' => 'self',
|
||||||
|
|
|
@ -42,6 +42,12 @@ class ProcedurePresentation < ApplicationRecord
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def fields_for_select
|
||||||
|
procedure.fields.map do |field|
|
||||||
|
[field['label'], "#{field['table']}/#{field['column']}"]
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
def dossier_field_service
|
def dossier_field_service
|
||||||
|
|
|
@ -73,7 +73,7 @@
|
||||||
|
|
||||||
= render partial: "header_field", locals: { field: { "label" => "Nº dossier", "table" => "self", "column" => "id" }, classname: "number-col" }
|
= 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: field, classname: "" }
|
||||||
|
|
||||||
= render partial: "header_field", locals: { field: { "label" => "Statut", "table" => "self", "column" => "state" }, classname: "status-col" }
|
= render partial: "header_field", locals: { field: { "label" => "Statut", "table" => "self", "column" => "state" }, classname: "status-col" }
|
||||||
|
@ -85,7 +85,7 @@
|
||||||
.dropdown-content.fade-in-down
|
.dropdown-content.fade-in-down
|
||||||
= form_tag update_displayed_fields_gestionnaire_procedure_path(@procedure), method: :patch, class: 'dropdown-form columns-form' do
|
= form_tag update_displayed_fields_gestionnaire_procedure_path(@procedure), method: :patch, class: 'dropdown-form columns-form' do
|
||||||
= select_tag :values,
|
= select_tag :values,
|
||||||
options_for_select(@procedure.fields_for_select,
|
options_for_select(@procedure_presentation.fields_for_select,
|
||||||
selected: @displayed_fields_values),
|
selected: @displayed_fields_values),
|
||||||
multiple: true,
|
multiple: true,
|
||||||
class: 'select2-limited'
|
class: 'select2-limited'
|
||||||
|
@ -105,7 +105,7 @@
|
||||||
= link_to(gestionnaire_dossier_path(@procedure, dossier), class: 'cell-link') do
|
= link_to(gestionnaire_dossier_path(@procedure, dossier), class: 'cell-link') do
|
||||||
= dossier.id
|
= dossier.id
|
||||||
|
|
||||||
- @displayed_fields.each do |field|
|
- @procedure_presentation.displayed_fields.each do |field|
|
||||||
%td
|
%td
|
||||||
= link_to(gestionnaire_dossier_path(@procedure, dossier), class: 'cell-link') do
|
= link_to(gestionnaire_dossier_path(@procedure, dossier), class: 'cell-link') do
|
||||||
= dossier_field_service.get_value(dossier, field['table'], field['column'])
|
= 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 }
|
it { expect(build(:procedure_presentation, filters: { "suivis" => [{ "table" => "user", "column" => "reset_password_token", "order" => "asc" }] })).to be_invalid }
|
||||||
end
|
end
|
||||||
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
|
end
|
||||||
|
|
|
@ -664,28 +664,6 @@ describe Procedure do
|
||||||
|
|
||||||
it { expect(subject.fields).to eq(expected) }
|
it { expect(subject.fields).to eq(expected) }
|
||||||
end
|
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
|
describe ".default_sort" do
|
||||||
it { expect(Procedure.default_sort).to eq({ "table" => "self", "column" => "id", "order" => "desc" }) }
|
it { expect(Procedure.default_sort).to eq({ "table" => "self", "column" => "id", "order" => "desc" }) }
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue