aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRobert2017-11-06 19:06:57 +0100
committerRobert2017-11-08 17:26:26 +0100
commit376964863bd19a8e78af8747c4db77cb9caef763 (patch)
tree733b50a80e9838ed1d1734b1f6dd399c23418a09
parent8c126ac88f031100e0f7001f1c2b0a3bdc95980d (diff)
downloadchouette-core-376964863bd19a8e78af8747c4db77cb9caef763.tar.bz2
Refs: #4823@8h; Specing out the view
- check_sets#show view speced and implemented down to the filter - control_set#show some assertions added to existing spec - bugfix in control_sets/_filter, filter not added to page if **only** direct controls associated Missing: - specing filtering (only its presence is speced so far) - specing and implementing the grouped view od the associated checks (direct and indirect)
-rw-r--r--app/controllers/compliance_check_sets_controller.rb30
-rw-r--r--app/decorators/compliance_check_decorator.rb8
-rw-r--r--app/helpers/compliance_check_sets_helper.rb5
-rw-r--r--app/views/compliance_check_sets/show.html.slim11
-rw-r--r--app/views/compliance_checks/_filters.html.slim39
-rw-r--r--app/views/compliance_control_sets/show.html.slim2
-rw-r--r--app/views/compliance_controls/_filters.html.slim1
-rw-r--r--config/locales/compliance_check_sets.en.yml11
-rw-r--r--config/locales/compliance_check_sets.fr.yml11
-rw-r--r--config/locales/compliance_checks.en.yml3
-rw-r--r--config/locales/compliance_checks.fr.yml3
-rw-r--r--spec/features/compliance_ckeck_sets_spec.rb44
-rw-r--r--spec/features/compliance_control_sets_spec.rb16
-rw-r--r--spec/support/breadcrumb_features.rb15
14 files changed, 182 insertions, 17 deletions
diff --git a/app/controllers/compliance_check_sets_controller.rb b/app/controllers/compliance_check_sets_controller.rb
index 95dcfbf05..ea87200e6 100644
--- a/app/controllers/compliance_check_sets_controller.rb
+++ b/app/controllers/compliance_check_sets_controller.rb
@@ -18,4 +18,34 @@ class ComplianceCheckSetsController < InheritedResources::Base
}
end
end
+
+ def show
+ show!(&method(:implement_show))
+ end
+
+
+ private
+
+ # Action Implementation
+ # ---------------------
+ def implement_show format
+ format.html(&method(:implement_html_show))
+ end
+
+ def implement_html_show _mime_response
+ @q_checks_form = @compliance_check_set.compliance_checks.ransack(params[:q])
+ @compliance_check_set = @compliance_check_set.decorate
+ @compliance_checks =
+ decorate_compliance_checks( @q_checks_form.result)
+ .group_by(&:compliance_check_block)
+ @direct_compliance_checks = @compliance_checks.delete nil
+ end
+
+ # Decoration
+ # ----------
+ def decorate_compliance_checks(compliance_checks)
+ ModelDecorator.decorate(
+ compliance_checks,
+ with: ComplianceCheckDecorator)
+ end
end
diff --git a/app/decorators/compliance_check_decorator.rb b/app/decorators/compliance_check_decorator.rb
new file mode 100644
index 000000000..09984aa2e
--- /dev/null
+++ b/app/decorators/compliance_check_decorator.rb
@@ -0,0 +1,8 @@
+class ComplianceCheckDecorator < Draper::Decorator
+ delegate_all
+
+ def action_links
+ links = []
+ end
+
+end
diff --git a/app/helpers/compliance_check_sets_helper.rb b/app/helpers/compliance_check_sets_helper.rb
new file mode 100644
index 000000000..c9e0bc5d8
--- /dev/null
+++ b/app/helpers/compliance_check_sets_helper.rb
@@ -0,0 +1,5 @@
+module ComplianceCheckSetsHelper
+ def compliance_check_set_path(compliance_check_set)
+ workbench_compliance_check_set_path(compliance_check_set.workbench, compliance_check_set)
+ end
+end
diff --git a/app/views/compliance_check_sets/show.html.slim b/app/views/compliance_check_sets/show.html.slim
index eefa5363f..924622922 100644
--- a/app/views/compliance_check_sets/show.html.slim
+++ b/app/views/compliance_check_sets/show.html.slim
@@ -1,12 +1,17 @@
- breadcrumb :compliance_check_set, @workbench, @compliance_check_set
/ PageHeader
= pageheader 'jeux-de-donnees',
- @compliance_check_set.referential.name
+ t('compliance_check_sets.show.title', name: @compliance_check_set.name),
+ 'Lorem ipsum dolor sit amet'
/ PageContent
.page_content
.container-fluid
.row
.col-lg-6.col-md-6.col-sm-12.col-xs-12
= definition_list t('metadatas'),
- ComplianceCheckSet.human_attribute_name(:id) => @compliance_check_set.referential.id,
- ComplianceCheckSet.human_attribute_name(:name) => @compliance_check_set.referential.name
+ ComplianceCheckSet.human_attribute_name(:name) => @compliance_check_set.name
+
+ - if params[:q].present? || @compliance_checks.any? || @direct_compliance_checks
+ .row
+ .col-lg-12
+ = render '/compliance_checks/filters'
diff --git a/app/views/compliance_checks/_filters.html.slim b/app/views/compliance_checks/_filters.html.slim
new file mode 100644
index 000000000..7b688fb7d
--- /dev/null
+++ b/app/views/compliance_checks/_filters.html.slim
@@ -0,0 +1,39 @@
+/ Compliance Check Filter
+= search_form_for @q_checks_form,
+ url: compliance_check_set_path(@compliance_check_set),
+ builder: SimpleForm::FormBuilder,
+ class: 'form form-filter' do |f|
+
+ .ffg-row
+ .input-group.search_bar
+ = f.search_field :name_cont,
+ class: 'form-control',
+ placeholder: t('compliance_checks.filters.name')
+ span.input-group-btn
+ button.btn.btn-default type='submit'
+ span.fa.fa-search
+
+ .ffg-row
+ .form-group.togglable#compliance_check_block-filter
+ .form-group.togglable#subclass-filter
+ = f.label t('compliance_checks.filters.subclass'), required: false, class: 'control-label'
+ = f.input :origin_code_cont_any,
+ collection: subclass_selection_list,
+ as: :check_boxes,
+ label: false,
+ label_method: lambda {|w| ("<span>#{w.first}</span>").html_safe},
+ required: false,
+ wrapper_html: {class: 'checkbox_list'}
+ .form-group.togglable#severity-filter
+ = f.label t('compliance_checks.filters.criticity'), required: false, class: 'control-label'
+ = f.input :criticity_eq_any,
+ collection: ComplianceControl.criticities,
+ as: :check_boxes,
+ label: false,
+ label_method: lambda {|w| ("<span>#{w}</span>").html_safe},
+ required: false,
+ wrapper_html: {class: 'checkbox_list'}
+
+ .actions
+ = link_to t('actions.erase'), @compliance_check_set, class: 'btn btn-link'
+ = f.submit t('actions.filter'), class: 'btn btn-default', id: 'compliance_check_set_compliance_checks_filter_btn'
diff --git a/app/views/compliance_control_sets/show.html.slim b/app/views/compliance_control_sets/show.html.slim
index d086c07c8..6fb6d2f8d 100644
--- a/app/views/compliance_control_sets/show.html.slim
+++ b/app/views/compliance_control_sets/show.html.slim
@@ -25,7 +25,7 @@
= definition_list t('metadatas'),
ComplianceControlSet.human_attribute_name(:name) => @compliance_control_set.name,
I18n.t('activerecord.attributes.compliance_control_set.owner_jdc') => @compliance_control_set.organisation.name
- - if params[:q].present? or @compliance_controls.any?
+ - if params[:q].present? || @compliance_controls.any? || @direct_compliance_controls
.row
.col-lg-12
= render '/compliance_controls/filters'
diff --git a/app/views/compliance_controls/_filters.html.slim b/app/views/compliance_controls/_filters.html.slim
index c729190a0..0cee8097b 100644
--- a/app/views/compliance_controls/_filters.html.slim
+++ b/app/views/compliance_controls/_filters.html.slim
@@ -1,3 +1,4 @@
+/ Compliance Control Filter
= search_form_for @q_controls_form,
url: compliance_control_set_path(@compliance_control_set),
builder: SimpleForm::FormBuilder,
diff --git a/config/locales/compliance_check_sets.en.yml b/config/locales/compliance_check_sets.en.yml
index 89c142a49..41a1fa5bf 100644
--- a/config/locales/compliance_check_sets.en.yml
+++ b/config/locales/compliance_check_sets.en.yml
@@ -1,9 +1,5 @@
en:
compliance_check_sets:
- index:
- title: Control reports
- new: Creating a Control Report
- edit: Update a Control Report
actions:
new: Add a control report
edit: Edit a control report
@@ -12,7 +8,13 @@ en:
filters:
name: Specify a control report name...
error_period_filter: End date must be greater than or equal to begin date
+ index:
+ title: Control reports
+ new: Creating a Control Report
+ edit: Update a Control Report
search_no_results: No control reports match your search
+ show:
+ title: Control report %{name}
activerecord:
attributes:
compliance_check_set:
@@ -21,3 +23,4 @@ en:
associated_object: Associated object
assigned_to: Assigned to
compliance_control_set: Compliance control set
+ name: Name
diff --git a/config/locales/compliance_check_sets.fr.yml b/config/locales/compliance_check_sets.fr.yml
index 8c21f33fd..3ad3d9fc1 100644
--- a/config/locales/compliance_check_sets.fr.yml
+++ b/config/locales/compliance_check_sets.fr.yml
@@ -1,9 +1,5 @@
fr:
compliance_check_sets:
- index:
- title: Rapports de contrôle
- new: Création d'un rapport de contrôle
- edit: Édition d'un rapport de contrôle
actions:
new: Ajouter
edit: Editer
@@ -12,7 +8,13 @@ fr:
filters:
name: Indiquez un nom d'un objet associé...
error_period_filter: La date de fin doit être supérieure ou égale à la date de début0
+ index:
+ title: Rapports de contrôle
+ new: Création d'un rapport de contrôle
+ edit: Édition d'un rapport de contrôle
search_no_results: Aucun rapport de contrôle ne correspond à votre recherche
+ show:
+ title: Rapport de contrôle %{name}
activerecord:
attributes:
compliance_check_set:
@@ -21,3 +23,4 @@ fr:
associated_object: Objet associé
assigned_to: Affectation
compliance_control_set: jeu de contrôle
+ name: Nom
diff --git a/config/locales/compliance_checks.en.yml b/config/locales/compliance_checks.en.yml
index 7f3e317be..8be7b3d0f 100644
--- a/config/locales/compliance_checks.en.yml
+++ b/config/locales/compliance_checks.en.yml
@@ -1,2 +1,5 @@
en:
compliance_checks:
+ filters:
+ subclass: Object
+ criticity: Severity
diff --git a/config/locales/compliance_checks.fr.yml b/config/locales/compliance_checks.fr.yml
index 421574cbd..e483efcc5 100644
--- a/config/locales/compliance_checks.fr.yml
+++ b/config/locales/compliance_checks.fr.yml
@@ -1,3 +1,6 @@
fr:
compliance_checks:
+ filters:
+ subclass: Objét
+ criticity: Criticité
diff --git a/spec/features/compliance_ckeck_sets_spec.rb b/spec/features/compliance_ckeck_sets_spec.rb
index a4a6b2fda..defeb10b4 100644
--- a/spec/features/compliance_ckeck_sets_spec.rb
+++ b/spec/features/compliance_ckeck_sets_spec.rb
@@ -1,14 +1,52 @@
RSpec.describe "ComplianceCheckSets", type: :feature do
+ include ComplianceCheckSetsHelper
+
login_user
# We setup a control_set with two blocks and one direct control (meaning that it is not attached to a block)
# Then we add one control to the first block and two controls to the second block
- let( :compliance_check_set ){ create :compliance_check_set }
+ let( :compliance_check_set ){ create :compliance_check_set, name: random_string }
+ let!(:direct_checks){ make_check(nil, times: 2) + make_check(nil, severity: :error) }
context 'show' do
- it 'can visit the page' do
- visit(workbench_compliance_check_set_path(compliance_check_set.workbench, compliance_check_set))
+ before do
+ visit(compliance_check_set_path(compliance_check_set))
+ end
+
+ it 'we can see the expected content' do
+ # Breadcrumbs
+ expect_breadcrumb_links "Accueil", "Gestion de l'offre", " Rapports de contrôle"
+
+ # Headline
+ expect( page ).to have_content("Rapport de contrôle #{compliance_check_set.name}")
+
+ # Information Definition List
+ expect( page.first('.dl-term') ).to have_content("Nom")
+ expect( page.first('.dl-def') ).to have_content(compliance_check_set.name)
+
+ # Filters
+ within( 'form.form-filter' ) do
+ expect( page ).to have_content("Objét")
+ expect( page ).to have_content("Criticité")
+ end
+
+
+ # Checks
+ end
+ end
+
+ def make_check ccblock=nil, times: 1, severity: :error
+ times.times.map do
+ make_one_check ccblock, severity
end
end
+
+ def make_one_check ccblock, severity
+ create( :compliance_check,
+ code: random_string,
+ compliance_check_block: ccblock,
+ compliance_check_set: compliance_check_set,
+ criticity: severity)
+ end
end
diff --git a/spec/features/compliance_control_sets_spec.rb b/spec/features/compliance_control_sets_spec.rb
index 500d4ce6f..bcb989cdc 100644
--- a/spec/features/compliance_control_sets_spec.rb
+++ b/spec/features/compliance_control_sets_spec.rb
@@ -25,7 +25,18 @@ RSpec.describe "ComplianceControlSets", type: :feature do
visit compliance_control_set_path( control_set )
end
- it 'we can see the controls inside their blocks' do
+ it 'we can see the expected content' do
+ # Breadcrumb
+ expect_breadcrumb_links "Accueil", "Liste des jeux de contrôles"
+
+ # Headline
+ expect( page ).to have_content("Consulter le jeu de contrôles #{control_set.name}")
+
+ # Information Definition List
+ expect( page.first('.dl-term') ).to have_content("Nom")
+ expect( page.first('.dl-def') ).to have_content(control_set.name)
+
+ # Children
controls.each do | control |
expect( page ).to have_content(control.code)
end
@@ -76,7 +87,8 @@ RSpec.describe "ComplianceControlSets", type: :feature do
create( :generic_attribute_control_min_max,
code: random_string,
compliance_control_block: ccblock,
- compliance_control_set: control_set)
+ compliance_control_set: control_set,
+ criticity: severity)
end
end
diff --git a/spec/support/breadcrumb_features.rb b/spec/support/breadcrumb_features.rb
new file mode 100644
index 000000000..36bfce19c
--- /dev/null
+++ b/spec/support/breadcrumb_features.rb
@@ -0,0 +1,15 @@
+module BreadcrumbFeatures
+ def expect_breadcrumb_links *link_names
+ within('.breadcrumbs') do
+ all('a').zip( link_names ).each do | link_element, link_content |
+ within(link_element) do | |
+ expect(page).to have_content(link_content)
+ end
+ end
+ end
+ end
+end
+
+RSpec.configure do | conf |
+ conf.include BreadcrumbFeatures, type: :feature
+end