tech: use facet_id to sort fields
This commit is contained in:
parent
743ff8c8a9
commit
b6464c1963
10 changed files with 38 additions and 18 deletions
|
@ -1,4 +1,4 @@
|
|||
= form_tag update_sort_instructeur_procedure_path(procedure_id: @procedure.id, table: 'notifications', column: 'notifications', order: opposite_order), method: :get, data: { controller: 'autosubmit' } do
|
||||
= form_tag update_sort_instructeur_procedure_path(procedure_id: @procedure.id, facet_id: 'notifications/notifications', order: opposite_order), method: :get, data: { controller: 'autosubmit' } do
|
||||
.fr-fieldset__element.fr-m-0
|
||||
.fr-checkbox-group.fr-checkbox-group--sm
|
||||
= check_box_tag :order, opposite_order, active?
|
||||
|
|
|
@ -1,12 +1,17 @@
|
|||
class Instructeurs::ColumnTableHeaderComponent < ApplicationComponent
|
||||
attr_reader :procedure_presentation, :facet
|
||||
# maybe extract a FacetSorter class?
|
||||
#
|
||||
|
||||
def initialize(procedure_presentation:, facet:)
|
||||
@procedure_presentation = procedure_presentation
|
||||
@facet = facet
|
||||
end
|
||||
|
||||
def facet_id
|
||||
facet.id
|
||||
end
|
||||
|
||||
def sorted_by_current_facet?
|
||||
procedure_presentation.sort['table'] == facet.table &&
|
||||
procedure_presentation.sort['column'] == facet.column
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
%th{ aria_sort, scope: "col", class: facet.classname }
|
||||
= link_to update_sort_instructeur_procedure_path(@procedure_presentation.procedure, table: facet.table, column: facet.column, order: @procedure_presentation.opposite_order_for(facet.table, facet.column)) do
|
||||
= link_to update_sort_instructeur_procedure_path(@procedure_presentation.procedure, facet_id:, order: @procedure_presentation.opposite_order_for(facet.table, facet.column)) do
|
||||
- if sorted_by_current_facet?
|
||||
- if sorted_ascending?
|
||||
#{facet.label} ↑
|
||||
|
|
|
@ -141,7 +141,7 @@ module Instructeurs
|
|||
end
|
||||
|
||||
def update_sort
|
||||
procedure_presentation.update_sort(params[:table], params[:column], params[:order])
|
||||
procedure_presentation.update_sort(params[:facet_id], params[:order])
|
||||
|
||||
redirect_back(fallback_location: instructeur_procedure_url(procedure))
|
||||
end
|
||||
|
|
|
@ -15,6 +15,8 @@ module FacetsConcern
|
|||
end
|
||||
|
||||
def dossier_facets
|
||||
common = [Facet.new(table: 'self', column: 'id', classname: 'number-col'), Facet.new(table: 'notifications', column: 'notifications', label: "notifications", filterable: false)]
|
||||
|
||||
dates = ['created_at', 'updated_at', 'depose_at', 'en_construction_at', 'en_instruction_at', 'processed_at']
|
||||
.map { |column| Facet.new(table: 'self', column:, type: :date) }
|
||||
|
||||
|
@ -23,7 +25,7 @@ module FacetsConcern
|
|||
|
||||
states = [Facet.new(table: 'self', column: 'state', type: :enum, scope: 'instructeurs.dossiers.filterable_state', virtual: true)]
|
||||
|
||||
[dates, sva_svr_facets(for_filters: true), virtual_dates, states].flatten.compact
|
||||
[common, dates, sva_svr_facets(for_filters: true), virtual_dates, states].flatten.compact
|
||||
end
|
||||
|
||||
def sva_svr_facets(for_filters: false)
|
||||
|
|
|
@ -124,11 +124,13 @@ class ProcedurePresentation < ApplicationRecord
|
|||
end
|
||||
end
|
||||
|
||||
def update_sort(table, column, order)
|
||||
def update_sort(facet_id, order)
|
||||
facet = procedure.find_facet(id: facet_id)
|
||||
|
||||
update!(sort: {
|
||||
TABLE => table,
|
||||
COLUMN => column,
|
||||
ORDER => order.presence || opposite_order_for(table, column)
|
||||
TABLE => facet.table,
|
||||
COLUMN => facet.column,
|
||||
ORDER => order.presence || opposite_order_for(facet.table, facet.column)
|
||||
})
|
||||
end
|
||||
|
||||
|
|
|
@ -1,9 +0,0 @@
|
|||
%th{ @procedure_presentation.aria_sort(@procedure_presentation.sort['order'], field), scope: "col", class: field.classname }
|
||||
= link_to update_sort_instructeur_procedure_path(@procedure, table: field.table, column: field.column, order: @procedure_presentation.opposite_order_for(field.table, field.column)) do
|
||||
- if @procedure_presentation.sorted_by?(field)
|
||||
- if @procedure_presentation.sort['order'] == 'asc'
|
||||
#{field.label} ↑
|
||||
- else
|
||||
#{field.label} ↓
|
||||
- else
|
||||
#{field.label}
|
|
@ -473,7 +473,7 @@ Rails.application.routes.draw do
|
|||
end
|
||||
|
||||
patch 'update_displayed_fields'
|
||||
get 'update_sort/:table/:column' => 'procedures#update_sort', as: 'update_sort'
|
||||
get 'update_sort/:facet_id' => 'procedures#update_sort', as: 'update_sort'
|
||||
post 'add_filter'
|
||||
post 'update_filter'
|
||||
get 'remove_filter'
|
||||
|
|
|
@ -872,6 +872,24 @@ describe Instructeurs::ProceduresController, type: :controller do
|
|||
end
|
||||
end
|
||||
|
||||
describe '#update_filter' do
|
||||
let(:instructeur) { create(:instructeur) }
|
||||
let(:procedure) { create(:procedure, :for_individual) }
|
||||
def procedure_presentation = instructeur.assign_to.first.procedure_presentation_or_default_and_errors.first
|
||||
|
||||
before do
|
||||
create(:assign_to, instructeur:, groupe_instructeur: build(:groupe_instructeur, procedure:))
|
||||
|
||||
sign_in(instructeur.user)
|
||||
end
|
||||
|
||||
it 'can change order' do
|
||||
expect { get :update_sort, params: { procedure_id: procedure.id, facet_id: "individual/nom", order: 'asc' } }
|
||||
.to change { procedure_presentation.sort }
|
||||
.from({ "column" => "notifications", "order" => "desc", "table" => "notifications" })
|
||||
.to({ "column" => "nom", "order" => "asc", "table" => "individual" })
|
||||
end
|
||||
end
|
||||
describe '#add_filter' do
|
||||
let(:instructeur) { create(:instructeur) }
|
||||
let(:procedure) { create(:procedure, :for_individual) }
|
||||
|
|
|
@ -14,6 +14,8 @@ describe FacetsConcern do
|
|||
let(:tdc_private_2) { procedure.active_revision.types_de_champ_private[1] }
|
||||
let(:expected) {
|
||||
[
|
||||
{ label: 'Nº dossier', table: 'self', column: 'id', classname: 'number-col', virtual: false, type: :text, scope: '', value_column: :value, filterable: true },
|
||||
{ label: 'notifications', table: 'notifications', column: 'notifications', virtual: false, type: :text, scope: '', value_column: :value, filterable: false },
|
||||
{ label: 'Créé le', table: 'self', column: 'created_at', classname: '', virtual: false, type: :date, scope: '', value_column: :value, filterable: true },
|
||||
{ label: 'Mis à jour le', table: 'self', column: 'updated_at', classname: '', virtual: false, type: :date, scope: '', value_column: :value, filterable: true },
|
||||
{ label: 'Déposé le', table: 'self', column: 'depose_at', classname: '', virtual: false, type: :date, scope: '', value_column: :value, filterable: true },
|
||||
|
|
Loading…
Reference in a new issue