Merge pull request #8040 from colinux/manager-expand-bloc-repetable

feat(manager): améliore la liste des champs d'un dossier
This commit is contained in:
Colin Darie 2022-11-15 17:25:56 +01:00 committed by GitHub
commit ae6ae92f48
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
10 changed files with 127 additions and 23 deletions

View file

@ -1,3 +1,5 @@
@import "constants";
[data-reach-combobox-token-label] {
border: 1px solid #CCCCCC;
border-radius: 4px;
@ -35,5 +37,22 @@
}
.mt-1 {
margin-top: 1rem;
margin-top: $default-spacer !important;
}
.pl-8 {
padding-left: ($default-spacer * 8) !important;
}
.cell-group-header {
font-weight: 600;
}
.cell-disabled {
opacity: 0.6;
}
.mandatory {
color: #A10005;
font-size: 18px;
}

View file

@ -0,0 +1,45 @@
class Manager::DossierChampRowComponent < ApplicationComponent
with_collection_parameter :row
attr_reader :row
def initialize(row:)
@row = row
end
def icon
return unless row.visible?
if row.mandatory_blank?
"🔴"
else
"🟢"
end
end
def status
if !row.visible? && row.conditional?
"masqué, conditionnel"
elsif row.blank? && !row.piece_justificative_file.attached?
"vide"
else
"rempli"
end
end
def cell_class(cell: nil)
class_names(
'cell-data': true,
'cell-disabled': !row.visible?,
'pl-8': cell == :label && row.child?
)
end
def nested_rows
if row.respond_to?(:rows)
row.rows
else
[]
end
end
end

View file

@ -0,0 +1,19 @@
%tr
%td{ class: cell_class(cell: :label) }
= row.libelle
- if row.mandatory?
%span.mandatory *
%td{ class: cell_class }
= I18n.t("activerecord.attributes.type_de_champ.type_champs.#{row.type_champ}")
%td{ class: cell_class }
= icon
= status
- nested_rows.each_with_index do |group_rows, index|
%thead
%tr
%td.cell-group-header{ colspan: 3 }
= "Bloc ##{index + 1} “#{row.libelle}”"
= render Manager::DossierChampRowComponent.with_collection(group_rows)

View file

@ -8,7 +8,7 @@ class UserDashboard < Administrate::BaseDashboard
# which determines how the attribute is displayed
# on pages throughout the dashboard.
ATTRIBUTE_TYPES = {
id: Field::Number,
id: Field::Number.with_options(searchable: true),
email: Field::String,
confirmed?: Field::Boolean,
created_at: Field::DateTime,

View file

@ -6,19 +6,6 @@
%td.cell-label Type de champ
%td.cell-label Rempli
%tbody
- field.data.each do |f|
%tr
%td.cell-data
= f.libelle
- if f.mandatory?
%span.mandatory{ style: 'color: #A10005;' } *
%td.cell-data
= I18n.t("activerecord.attributes.type_de_champ.type_champs.#{f.type_champ}")
%td.cell-data
- if f.blank?
vide
- else
rempli
= render Manager::DossierChampRowComponent.with_collection(field.data)
- else
Aucun

View file

@ -2,7 +2,7 @@
%td.cell-data
= type_de_champ.libelle
- if type_de_champ.mandatory?
%span.mandatory{ style: 'color: #A10005;' } *
%span.mandatory *
%td.cell-data
= I18n.t("activerecord.attributes.type_de_champ.type_champs.#{type_de_champ.type_champ}")

View file

@ -40,4 +40,3 @@
<% end %>
</dd>
</dl>
<hr />

View file

@ -3,4 +3,4 @@
%h2.huge-title Espace Manager
%p Munissez-vous de votre téléphone sur lequel vous avez installé une application cliente 2FA (Google Authenticator, Authy, AndOTP, ...)
%br
%p= link_to "Activer l'authentification double-facteur", enable_super_admin_otp_path, method: :put, class: 'button primary'
%p= link_to "Activer l'authentification double-facteur", enable_super_admin_otp_path, method: :put, class: 'fr-btn fr-btn--lg'

View file

@ -15,7 +15,5 @@
= f.label :otp_attempt, 'Code OTP (uniquement si vous avez déjà activé 2FA)'
= f.text_field :otp_attempt
.auth-options
.text-right
= link_to "Mot de passe oublié ou réinitialisation 2FA ?", new_super_admin_password_path, class: "link"
= f.submit "Se connecter", class: "button large primary expand"
%p= link_to "Mot de passe oublié ou réinitialisation 2FA ?", new_super_admin_password_path, class: "link"
= f.submit "Se connecter", class: "fr-btn fr-btn--lg"

View file

@ -0,0 +1,37 @@
include ActionView::Helpers::SanitizeHelper
describe Manager::DossiersController, type: :controller do
let(:super_admin) { create(:super_admin) }
before do
sign_in super_admin
procedure = create(:procedure, :published, types_de_champ_public: types_de_champ)
@dossier = create(:dossier, :en_construction, :with_populated_champs, procedure:)
end
let(:types_de_champ) { [] }
render_views
describe 'GET #index' do
it "should list dossiers" do
get :index
expect(response.body).to include(@dossier.procedure.libelle)
end
end
describe "GET #show" do
let(:types_de_champ) {
[
{ libelle: "Nom", mandatory: true }
]
}
before do
get :show, params: { id: @dossier.id }
end
subject { strip_tags(response.body) }
it { expect(subject).to match(%r{Nom\s+\*\s+Texte\s+🟢\s+rempli}) }
end
end