From 2f66625f184b7a823bf5a5721647c989e4e1b8b3 Mon Sep 17 00:00:00 2001 From: simon lehericey Date: Tue, 19 Feb 2019 12:38:33 +0100 Subject: [PATCH] Manager: improve dossier view --- app/dashboards/dossier_dashboard.rb | 4 ++-- app/fields/champ_collection_field.rb | 7 ++++++ app/models/champ.rb | 16 ++++++------- .../champ_collection_field/_show.html.haml | 24 +++++++++++++++++++ .../_show.html.haml | 9 +++++++ 5 files changed, 50 insertions(+), 10 deletions(-) create mode 100644 app/fields/champ_collection_field.rb create mode 100644 app/views/fields/champ_collection_field/_show.html.haml diff --git a/app/dashboards/dossier_dashboard.rb b/app/dashboards/dossier_dashboard.rb index 456b3f3a4..698106704 100644 --- a/app/dashboards/dossier_dashboard.rb +++ b/app/dashboards/dossier_dashboard.rb @@ -16,7 +16,7 @@ class DossierDashboard < Administrate::BaseDashboard created_at: Field::DateTime, updated_at: Field::DateTime, hidden_at: Field::DateTime, - types_de_champ: TypesDeChampCollectionField + champs: ChampCollectionField }.freeze # COLLECTION_ATTRIBUTES @@ -38,7 +38,7 @@ class DossierDashboard < Administrate::BaseDashboard :state, :procedure, :user, - :types_de_champ, + :champs, :created_at, :updated_at, :hidden_at diff --git a/app/fields/champ_collection_field.rb b/app/fields/champ_collection_field.rb new file mode 100644 index 000000000..ed6dbe634 --- /dev/null +++ b/app/fields/champ_collection_field.rb @@ -0,0 +1,7 @@ +require "administrate/field/base" + +class ChampCollectionField < Administrate::Field::Base + def to_s + data + end +end diff --git a/app/models/champ.rb b/app/models/champ.rb index e0d7b35f1..c88e0fe3f 100644 --- a/app/models/champ.rb +++ b/app/models/champ.rb @@ -23,15 +23,15 @@ class Champ < ApplicationRecord end def mandatory_and_blank? - if mandatory? - case type_de_champ.type_champ - when TypeDeChamp.type_champs.fetch(:carte) - value.blank? || value == '[]' - else - value.blank? - end + mandatory? && blank? + end + + def blank? + case type_de_champ.type_champ + when TypeDeChamp.type_champs.fetch(:carte) + value.blank? || value == '[]' else - false + value.blank? end end diff --git a/app/views/fields/champ_collection_field/_show.html.haml b/app/views/fields/champ_collection_field/_show.html.haml new file mode 100644 index 000000000..f5528c9e9 --- /dev/null +++ b/app/views/fields/champ_collection_field/_show.html.haml @@ -0,0 +1,24 @@ +- if field.data.any? + %table.collection-data{ "aria-labelledby": "page-title" } + %thead + %tr + %td.cell-label Libelle + %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 +- else + Aucun diff --git a/app/views/fields/types_de_champ_collection_field/_show.html.haml b/app/views/fields/types_de_champ_collection_field/_show.html.haml index c54bb1c64..86b298e54 100644 --- a/app/views/fields/types_de_champ_collection_field/_show.html.haml +++ b/app/views/fields/types_de_champ_collection_field/_show.html.haml @@ -4,12 +4,21 @@ %tr %td.cell-label Libelle %td.cell-label Type de champ + %td.cell-label Rempli %tbody - field.data.order(:order_place).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 - else Aucun