affichage selon l'ordre de instructeurs_procedures.position
This commit is contained in:
parent
64f39e2c78
commit
010ea0586c
3 changed files with 24 additions and 5 deletions
|
@ -25,7 +25,8 @@ module Instructeurs
|
|||
|
||||
@procedures = all_procedures.order(closed_at: :desc, unpublished_at: :desc, published_at: :desc, created_at: :desc)
|
||||
publiees_or_closes_with_dossiers_en_cours = all_procedures_for_listing.publiees.or(all_procedures.closes.where(id: procedures_dossiers_en_cours))
|
||||
@procedures_en_cours = publiees_or_closes_with_dossiers_en_cours.order(published_at: :desc).page(params[:page]).per(ITEMS_PER_PAGE)
|
||||
current_instructeur.ensure_instructeur_procedures_for(publiees_or_closes_with_dossiers_en_cours)
|
||||
@procedures_en_cours = publiees_or_closes_with_dossiers_en_cours.order_by_position_for(current_instructeur).page(params[:page]).per(ITEMS_PER_PAGE)
|
||||
closes_with_no_dossier_en_cours = all_procedures.closes.excluding(all_procedures.closes.where(id: procedures_dossiers_en_cours))
|
||||
@procedures_closes = closes_with_no_dossier_en_cours.order(created_at: :desc).page(params[:page]).per(ITEMS_PER_PAGE)
|
||||
@procedures_draft = all_procedures_for_listing.brouillons.order(created_at: :desc).page(params[:page]).per(ITEMS_PER_PAGE)
|
||||
|
|
|
@ -107,6 +107,17 @@ class Instructeur < ApplicationRecord
|
|||
end
|
||||
end
|
||||
|
||||
def ensure_instructeur_procedures_for(procedures)
|
||||
current_instructeur_procedures = instructeurs_procedures.where(procedure_id: procedures.map(&:id))
|
||||
top_position = current_instructeur_procedures.map(&:position).max || 0
|
||||
missing_instructeur_procedures = procedures.sort_by(&:published_at).map(&:id).filter_map do |procedure_id|
|
||||
if !procedure_id.in?(current_instructeur_procedures.map(&:procedure_id))
|
||||
{ instructeur_id: id, procedure_id:, position: top_position += 1 }
|
||||
end
|
||||
end
|
||||
InstructeursProcedure.insert_all(missing_instructeur_procedures) if missing_instructeur_procedures.size.positive?
|
||||
end
|
||||
|
||||
def procedure_presentation_and_errors_for_procedure_id(procedure_id)
|
||||
assign_to
|
||||
.joins(:groupe_instructeur)
|
||||
|
|
|
@ -193,6 +193,17 @@ class Procedure < ApplicationRecord
|
|||
)
|
||||
}
|
||||
|
||||
scope :for_api_v2, -> {
|
||||
includes(:draft_revision, :published_revision, administrateurs: :user)
|
||||
}
|
||||
|
||||
scope :order_by_position_for, -> (instructeur) {
|
||||
joins(:instructeurs_procedures)
|
||||
.select('procedures.*, instructeurs_procedures.position AS position')
|
||||
.where(instructeurs_procedures: { instructeur_id: instructeur.id })
|
||||
.order('position DESC')
|
||||
}
|
||||
|
||||
enum declarative_with_state: {
|
||||
en_instruction: 'en_instruction',
|
||||
accepte: 'accepte'
|
||||
|
@ -203,10 +214,6 @@ class Procedure < ApplicationRecord
|
|||
other: 'other'
|
||||
}, _prefix: true
|
||||
|
||||
scope :for_api_v2, -> {
|
||||
includes(:draft_revision, :published_revision, administrateurs: :user)
|
||||
}
|
||||
|
||||
validates :libelle, presence: true, allow_blank: false, allow_nil: false
|
||||
validates :description, presence: true, allow_blank: false, allow_nil: false
|
||||
validates :administrateurs, presence: true
|
||||
|
|
Loading…
Reference in a new issue