Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ETQ Administrateur, je voudrais que les dossiers non terminés soient toujours sur la dernière révision #11045

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions app/components/dossiers/champs_rows_show_component.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ def number_with_html_delimiter(num)
end

def blank_key(champ)
key = ".blank_optional"
key += "_attachment" if champ.type_de_champ.piece_justificative_or_titre_identite?
key = champ.mandatory? ? ".blank" : ".blank_optional"
key += "_attachment" if champ.piece_justificative_or_titre_identite?

key
end
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
---
en:
blank_optional: "empty (optional)"
blank_optional_attachment: "document not supplied (optional)"
blank: 'empty'
blank_attachment: 'document not supplied'
blank_optional: 'empty (optional)'
blank_optional_attachment: 'document not supplied (optional)'
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
---
fr:
blank_optional: "non saisi (facultatif)"
blank_optional_attachment: "pièce justificative non saisie (facultative)"
blank: 'non saisi'
blank_attachment: 'pièce justificative non saisie'
blank_optional: 'non saisi (facultatif)'
blank_optional_attachment: 'pièce justificative non saisie (facultative)'
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
= render ViewableChamp::SectionComponent.new(dossier: champ.dossier, types_de_champ:, row_id:, demande_seen_at: seen_at, profile:)

- else
= render Dossiers::RowShowComponent.new(label: champ.libelle, seen_at:, profile:, content_class: champ.type_champ, updated_at: updated_at_after_deposer(champ)) do |c|
= render Dossiers::RowShowComponent.new(label: champ.libelle, seen_at:, profile:, content_class: champ.type_champ, updated_at: updated_at_after_deposer(champ), errors: champ.errors) do |c|
- if champ.blank?
- c.with_blank do
= t(blank_key(champ))
Expand Down
12 changes: 12 additions & 0 deletions app/components/dossiers/row_show_component.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,20 @@
.champ-content.fr-text-mention--grey{ class: content_class }
- if usager?
%p.champ-blank= blank
- if errors.present?
.fr-messages-group
%p.fr-message.fr-message--error
= "« #{label} » "
- errors.each do |error_message|
= error_message

- else

.champ-content{ class: content_class }
= value
- if errors.present?
.fr-messages-group
%p.fr-message.fr-message--error
= "« #{label} » "
- errors.each do |error_message|
= error_message
4 changes: 3 additions & 1 deletion app/components/dossiers/row_show_component.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,18 @@ class Dossiers::RowShowComponent < ApplicationComponent
attr_reader :updated_at
attr_reader :seen_at
attr_reader :content_class
attr_reader :errors

renders_one :value
renders_one :blank

def initialize(label:, profile: nil, updated_at: nil, seen_at: nil, content_class: nil)
def initialize(label:, profile: nil, updated_at: nil, seen_at: nil, content_class: nil, errors: nil)
@label = label
@profile = profile
@updated_at = updated_at
@seen_at = seen_at
@content_class = content_class
@errors = errors&.full_messages
end

def badge_updated_class
Expand Down
8 changes: 0 additions & 8 deletions app/components/procedure/revision_changes_component.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ def initialize(new_revision:, previous_revision:)

@tdc_changes = previous_revision.compare_types_de_champ(new_revision)
@public_move_changes, @private_move_changes = @tdc_changes.filter { _1.op == :move }.partition { !_1.private? }
@delete_champ_warning = !total_dossiers.zero? && !@tdc_changes.all?(&:can_rebase?)

@ineligibilite_rules_changes = previous_revision.compare_ineligibilite_rules(new_revision)
end
Expand All @@ -18,11 +17,4 @@ def initialize(new_revision:, previous_revision:)
def used_by_routing_rules?(type_de_champ)
@procedure.used_by_routing_rules?(type_de_champ)
end

def total_dossiers
@total_dossiers ||= @previous_revision.dossiers
.visible_by_administration
.state_en_construction_ou_instruction
.size
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,9 @@
= t('.public.add_mandatory', label: change.label)
- else
= t(".#{prefix}.add", label: change.label)
- if !total_dossiers.zero? && !change.can_rebase?
.fr-alert.fr-alert--warning.fr-mt-1v
%p= t('.breaking_change', count: total_dossiers)
- when :remove
- list.with_item do
= t(".#{prefix}.remove", label: change.label)
- if @delete_champ_warning
.fr-alert.fr-alert--warning.fr-mt-1v
%p= t('.delete_champ_html', count: total_dossiers)
- when :update
- case change.attribute
- when :libelle
Expand All @@ -28,9 +22,6 @@
- when :type_champ
- list.with_item do
= t(".#{prefix}.update_type_champ", label: change.label, to: t("activerecord.attributes.type_de_champ.type_champs.#{change.to}"))
- if !total_dossiers.zero? && !change.can_rebase?
.fr-alert.fr-alert--warning.fr-mt-1v
%p= t('.breaking_change', count: total_dossiers)
- when :description
- list.with_item do
- if change.to.blank?
Expand All @@ -47,15 +38,9 @@
- if change.from == false
- list.with_item do
= t(".public.enable_mandatory", label: change.label)
- if !total_dossiers.zero? && !change.can_rebase?
.fr-alert.fr-alert--warning.fr-mt-1v
%p= t('.breaking_change', count: total_dossiers)
- else
- list.with_item do
= t(".public.disable_mandatory", label: change.label)
- if !total_dossiers.zero? && !change.can_rebase?
.fr-alert.fr-alert--warning.fr-mt-1v
%p= t('.breaking_change', count: total_dossiers)
- when :piece_justificative_template
- list.with_item do
= t(".#{prefix}.update_piece_justificative_template", label: change.label)
Expand All @@ -74,25 +59,16 @@
- if removed.present?
- list.with_item do
= t('.remove_option', items: removed.map{ |term| "« #{term.strip} »" }.join(", "))
- if !total_dossiers.zero? && !change.can_rebase?
.fr-alert.fr-alert--warning.fr-mt-1v
%p= t('.breaking_change', count: total_dossiers)
- if (removed.present? || added.present? ) && used_by_routing_rules?(change.type_de_champ)
.fr-alert.fr-alert--warning.fr-mt-1v
= t(".#{prefix}.update_drop_down_options_alert", label: change.label)
- when :drop_down_other
- if change.from == false
- list.with_item do
= t(".#{prefix}.enable_drop_down_other", label: change.label)
- if !total_dossiers.zero? && !change.can_rebase?
.fr-alert.fr-alert--warning.fr-mt-1v
%p= t('.breaking_change', count: total_dossiers)
- else
- list.with_item do
= t(".#{prefix}.disable_drop_down_other", label: change.label)
- if !total_dossiers.zero? && !change.can_rebase?
.fr-alert.fr-alert--warning.fr-mt-1v
%p= t('.breaking_change', count: total_dossiers)
- when :carte_layers
- added = change.to.sort - change.from.sort
- removed = change.from.sort - change.to.sort
Expand Down Expand Up @@ -122,21 +98,12 @@
- if change.from.nil?
- list.with_item do
= t(".#{prefix}.add_condition", label: change.label, to: change.to)
- if !total_dossiers.zero? && !change.can_rebase?
.fr-alert.fr-alert--warning.fr-mt-1v
%p= t('.breaking_change', count: total_dossiers)
- elsif change.to.nil?
- list.with_item do
= t(".#{prefix}.remove_condition", label: change.label)
- if !total_dossiers.zero? && !change.can_rebase?
.fr-alert.fr-alert--warning.fr-mt-1v
%p= t('.breaking_change', count: total_dossiers)
- else
- list.with_item do
= t(".#{prefix}.update_condition", label: change.label, to: change.to)
- if !total_dossiers.zero? && !change.can_rebase?
.fr-alert.fr-alert--warning.fr-mt-1v
%p= t('.breaking_change', count: total_dossiers)
- when :character_limit
- if change.to.blank?
- list.with_item do
Expand Down
7 changes: 5 additions & 2 deletions app/controllers/instructeurs/dossiers_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,10 @@ def show
@acls = PiecesJustificativesService.new(user_profile: current_instructeur, export_template: nil).acl_for_dossier_export(dossier.procedure)
render(template: 'dossiers/show', formats: [:pdf])
end
format.all
format.all do
dossier.validate(:champs_public_value)
dossier.check_mandatory_and_visible_champs
end
end
end

Expand Down Expand Up @@ -308,7 +311,7 @@ def update_annotations

respond_to do |format|
format.turbo_stream do
@to_show, @to_hide, @to_update = champs_to_turbo_update(champs_private_attributes_params, dossier.champs.filter(&:private?))
@to_show, @to_hide, @to_update = champs_to_turbo_update(champs_private_attributes_params, dossier.project_champs_private_all)
end
end
end
Expand Down
4 changes: 2 additions & 2 deletions app/controllers/users/dossiers_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,7 @@ def submit_en_construction
end

format.turbo_stream do
@to_show, @to_hide, @to_update = champs_to_turbo_update(champs_public_attributes_params, dossier.champs.filter(&:public?))
@to_show, @to_hide, @to_update = champs_to_turbo_update(champs_public_attributes_params, dossier.project_champs_public_all)
render :update, layout: false
end
end
Expand All @@ -312,7 +312,7 @@ def update

respond_to do |format|
format.turbo_stream do
@to_show, @to_hide, @to_update = champs_to_turbo_update(champs_public_attributes_params, dossier.champs.filter(&:public?))
@to_show, @to_hide, @to_update = champs_to_turbo_update(champs_public_attributes_params, dossier.project_champs_public_all)
render :update, layout: false
end
end
Expand Down
6 changes: 5 additions & 1 deletion app/models/champ.rb
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,11 @@ def public?
end

def child?
row_id.present?
row_id.present? && !repetition?
end

def row?
row_id.present? && repetition?
end

# used for the `required` html attribute
Expand Down
4 changes: 0 additions & 4 deletions app/models/champs/drop_down_list_champ.rb
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,6 @@ def value_other
other? ? value : ""
end

def in?(options)
options.include?(value)
end

private

def value_is_in_options
Expand Down
4 changes: 0 additions & 4 deletions app/models/champs/linked_drop_down_list_champ.rb
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,6 @@ def has_secondary_options_for_primary?
primary_value.present? && secondary_options[primary_value]&.any?(&:present?)
end

def in?(options)
options.include?(primary_value) || options.include?(secondary_value)
end

private

def pack_value(primary, secondary)
Expand Down
4 changes: 0 additions & 4 deletions app/models/champs/multiple_drop_down_list_champ.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,6 @@ def single_checkbox?
render_as_checkboxes?
end

def in?(options)
(selected_options - options).size != selected_options.size
end

def focusable_input_id
render_as_checkboxes? ? checkbox_id(drop_down_options.first) : input_id
end
Expand Down
8 changes: 8 additions & 0 deletions app/models/champs/repetition_champ.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,14 @@ def focusable_input_id
rows.last&.first&.focusable_input_id
end

def discarded?
discarded_at.present?
end

def discard!
touch(:discarded_at)
end

def search_terms
# The user cannot enter any information here so it doesn’t make much sense to search
end
Expand Down
11 changes: 9 additions & 2 deletions app/models/concerns/champs_validate_concern.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ def valid_champ_value?
def validate_champ_value?
case validation_context
when :champs_public_value
public? && in_dossier_revision? && visible?
public? && in_dossier_revision? && !row? && !in_discarded_row? && visible?
when :champs_private_value
private? && in_dossier_revision? && visible?
private? && in_dossier_revision? && !row? && !in_discarded_row? && visible?
else
false
end
Expand All @@ -31,5 +31,12 @@ def validate_champ_value_or_prefill?
def in_dossier_revision?
dossier.revision.types_de_champ.any? { _1.stable_id == stable_id }
end

def in_discarded_row?
if child?
parent_type_de_champ = dossier.revision.parent_of(type_de_champ)
!row_id.in?(dossier.repetition_row_ids(parent_type_de_champ))
end
end
end
end
Loading
Loading