From a3df5a546da1a790de0e95bf2e9eba4ab57fde5b Mon Sep 17 00:00:00 2001 From: Xavier J Date: Wed, 2 Dec 2015 14:05:56 +0100 Subject: [PATCH] - add test on active tab for back office - refactor code back office file list - add decorator for select active tabs --- .../backoffice/dossiers_controller.rb | 23 +++++++++++-------- app/decorators/dossiers_decorator.rb | 11 +++++++++ app/views/backoffice/dossiers/_list.html.haml | 16 +++++++++++++ .../backoffice/dossiers/_onglets.html.haml | 12 +++++----- .../backoffice/dossiers/a_traiter.html.haml | 18 +-------------- .../backoffice/dossiers/en_attente.html.haml | 18 +-------------- .../backoffice/dossiers/termine.html.haml | 18 +-------------- .../dossiers/a_traiter_html.haml_spec.rb | 7 +++++- .../dossiers/en_attente_html.haml_spec.rb | 7 +++++- .../dossiers/termine_html.haml_spec.rb | 7 +++++- 10 files changed, 68 insertions(+), 69 deletions(-) create mode 100644 app/views/backoffice/dossiers/_list.html.haml diff --git a/app/controllers/backoffice/dossiers_controller.rb b/app/controllers/backoffice/dossiers_controller.rb index 16ea989e7..d295959c8 100644 --- a/app/controllers/backoffice/dossiers_controller.rb +++ b/app/controllers/backoffice/dossiers_controller.rb @@ -6,21 +6,26 @@ class Backoffice::DossiersController < ApplicationController end def a_traiter - @dossiers_a_traiter = current_gestionnaire.dossiers.waiting_for_gestionnaire() - @dossiers_a_traiter = @dossiers_a_traiter.paginate(:page => params[:page]).decorate + @dossiers = current_gestionnaire.dossiers.waiting_for_gestionnaire + .paginate(:page => params[:page]).decorate + @page = 'a_traiter' total_dossiers_per_state end def en_attente - @dossiers_en_attente = current_gestionnaire.dossiers.waiting_for_user() - @dossiers_en_attente = @dossiers_en_attente.paginate(:page => params[:page]).decorate + @dossiers = current_gestionnaire.dossiers.waiting_for_user() + .paginate(:page => params[:page]).decorate + + @page = 'en_attente' total_dossiers_per_state end def termine - @dossiers_termine = current_gestionnaire.dossiers.termine() - @dossiers_termine = @dossiers_termine.paginate(:page => params[:page]).decorate + @dossiers = current_gestionnaire.dossiers.termine() + .paginate(:page => params[:page]).decorate + + @page = 'termine' total_dossiers_per_state end @@ -61,9 +66,9 @@ class Backoffice::DossiersController < ApplicationController private def total_dossiers_per_state - @dossiers_a_traiter_total = !@dossiers_a_traiter.nil? ? @dossiers_a_traiter.size : current_gestionnaire.dossiers.waiting_for_gestionnaire().size - @dossiers_en_attente_total = !@dossiers_en_attente.nil? ? @dossiers_en_attente.size : current_gestionnaire.dossiers.waiting_for_user().size - @dossiers_termine_total = !@dossiers_termine.nil? ? @dossiers_termine.size : current_gestionnaire.dossiers.termine().size + @dossiers_a_traiter_total = !@dossiers_a_traiter.nil? ? @dossiers_a_traiter.size : current_gestionnaire.dossiers.waiting_for_gestionnaire.size + @dossiers_en_attente_total = !@dossiers_en_attente.nil? ? @dossiers_en_attente.size : current_gestionnaire.dossiers.waiting_for_user.size + @dossiers_termine_total = !@dossiers_termine.nil? ? @dossiers_termine.size : current_gestionnaire.dossiers.termine.size end def initialize_instance_params dossier_id diff --git a/app/decorators/dossiers_decorator.rb b/app/decorators/dossiers_decorator.rb index 6e8571b6f..77c064fee 100644 --- a/app/decorators/dossiers_decorator.rb +++ b/app/decorators/dossiers_decorator.rb @@ -1,4 +1,15 @@ class DossiersDecorator < Draper::CollectionDecorator delegate :current_page, :per_page, :offset, :total_entries, :total_pages + def active_class_a_traiter page + 'active' if page == 'a_traiter' + end + + def active_class_en_attente page + 'active' if page == 'en_attente' + end + + def active_class_termine page + 'active' if page == 'termine' + end end diff --git a/app/views/backoffice/dossiers/_list.html.haml b/app/views/backoffice/dossiers/_list.html.haml new file mode 100644 index 000000000..786d6f70f --- /dev/null +++ b/app/views/backoffice/dossiers/_list.html.haml @@ -0,0 +1,16 @@ +%table.table + %thead.row + %th.col-md-4.col-lg-4 Procédure + %th.col-md-4.col-lg-4 Dossier + %th.col-md-2.col-lg-2 État + %th.col-md-2.col-lg-2 Date de mise à jour + - @dossiers.each do |dossier| + %tr + %td= dossier.procedure.libelle + %td + = link_to(dossier.nom_projet, "/backoffice/dossiers/#{dossier.id}") + %td= dossier.state_fr + %td= dossier.last_update + +.pagination + = will_paginate @dossiers, renderer: BootstrapPagination::Rails \ No newline at end of file diff --git a/app/views/backoffice/dossiers/_onglets.html.haml b/app/views/backoffice/dossiers/_onglets.html.haml index fe157a348..80a0e75d3 100644 --- a/app/views/backoffice/dossiers/_onglets.html.haml +++ b/app/views/backoffice/dossiers/_onglets.html.haml @@ -3,20 +3,20 @@ #onglets %ul.nav.nav-tabs - %li{class: "#{'active' unless @dossiers_a_traiter.nil? }"} - %a{:href => "#{url_for :backoffice_dossiers_a_traiter}"} + %li{ class: (@dossiers.active_class_a_traiter(@page) unless @dossiers.nil?) } + %a{:href => "#{url_for :backoffice_dossiers_a_traiter}" } %h5.text-danger = "À traiter " .badge.progress-bar-danger =@dossiers_a_traiter_total - %li{class: "#{'active' unless @dossiers_en_attente.nil? }"} - %a{:href => "#{url_for :backoffice_dossiers_en_attente}"} + %li{ class: (@dossiers.active_class_en_attente(@page) unless @dossiers.nil?) } + %a{:href => "#{url_for :backoffice_dossiers_en_attente}" } %h5.text-info ="En attente " .badge.progress-bar-info =@dossiers_en_attente_total - %li{class: "#{'active' unless @dossiers_termine.nil? }"} - %a{:href => "#{url_for :backoffice_dossiers_termine}"} + %li{ class: (@dossiers.active_class_termine(@page) unless @dossiers.nil?) } + %a{ :href => "#{url_for :backoffice_dossiers_termine}" } %h5.text-success = "Terminé" .badge.progress-bar-success diff --git a/app/views/backoffice/dossiers/a_traiter.html.haml b/app/views/backoffice/dossiers/a_traiter.html.haml index 1fdba6b6f..f9e3e9805 100644 --- a/app/views/backoffice/dossiers/a_traiter.html.haml +++ b/app/views/backoffice/dossiers/a_traiter.html.haml @@ -1,20 +1,4 @@ #backoffice_a_traiter = render partial: 'onglets' - -#%h3.text-danger À traiter - %table.table - %thead.row - %th.col-md-4.col-lg-4 Procédure - %th.col-md-4.col-lg-4 Dossier - %th.col-md-2.col-lg-2 État - %th.col-md-2.col-lg-2 Date de mise à jour - - @dossiers_a_traiter.each do |dossier| - %tr - %td= dossier.procedure.libelle - %td - = link_to(dossier.nom_projet, "/backoffice/dossiers/#{dossier.id}") - %td= dossier.state_fr - %td= dossier.last_update - -.pagination - = will_paginate @dossiers_a_traiter, renderer: BootstrapPagination::Rails \ No newline at end of file + = render partial: 'list' \ No newline at end of file diff --git a/app/views/backoffice/dossiers/en_attente.html.haml b/app/views/backoffice/dossiers/en_attente.html.haml index bd643a442..6c6122e5c 100644 --- a/app/views/backoffice/dossiers/en_attente.html.haml +++ b/app/views/backoffice/dossiers/en_attente.html.haml @@ -1,20 +1,4 @@ #backoffice_en_attente = render partial: 'onglets' - -#%h3.text-info En attente - %table.table - %thead - %th.col-md-4.col-lg-4 Procédure - %th.col-md-4.col-lg-4 Dossier - %th.col-md-2.col-lg-2 État - %th.col-md-2.col-lg-2 Date de mise à jour - - @dossiers_en_attente.each do |dossier| - %tr - %td= dossier.procedure.libelle - %td - = link_to(dossier.nom_projet, "/backoffice/dossiers/#{dossier.id}") - %td= dossier.state_fr - %td= dossier.last_update - -.pagination - = will_paginate @dossiers_en_attente, renderer: BootstrapPagination::Rails \ No newline at end of file + = render partial: 'list' \ No newline at end of file diff --git a/app/views/backoffice/dossiers/termine.html.haml b/app/views/backoffice/dossiers/termine.html.haml index 21e2b0202..5186821df 100644 --- a/app/views/backoffice/dossiers/termine.html.haml +++ b/app/views/backoffice/dossiers/termine.html.haml @@ -1,20 +1,4 @@ #backoffice_termine = render partial: 'onglets' - -#%h3.text-success Terminé - %table.table - %thead - %th.col-md-4.col-lg-4 Procédure - %th.col-md-4.col-lg-4 Dossier - %th.col-md-2.col-lg-2 État - %th.col-md-2.col-lg-2 Date de mise à jour - - @dossiers_termine.each do |dossier| - %tr - %td= dossier.procedure.libelle - %td - = link_to(dossier.nom_projet, "/backoffice/dossiers/#{dossier.id}") - %td= dossier.state_fr - %td= dossier.last_update - -.pagination - = will_paginate @dossiers_termine, renderer: BootstrapPagination::Rails \ No newline at end of file + = render partial: 'list' \ No newline at end of file diff --git a/spec/views/backoffice/dossiers/a_traiter_html.haml_spec.rb b/spec/views/backoffice/dossiers/a_traiter_html.haml_spec.rb index 435578b33..81cdf3041 100644 --- a/spec/views/backoffice/dossiers/a_traiter_html.haml_spec.rb +++ b/spec/views/backoffice/dossiers/a_traiter_html.haml_spec.rb @@ -8,7 +8,8 @@ describe 'backoffice/dossiers/a_traiter.html.haml', type: :view do let!(:decorate_dossier) { create(:dossier, :with_user, state: 'initiated', procedure: procedure).decorate } before do - assign(:dossiers_a_traiter, gestionnaire.dossiers.waiting_for_gestionnaire.paginate(:page => 1).decorate) + assign(:dossiers, gestionnaire.dossiers.waiting_for_gestionnaire.paginate(:page => 1).decorate) + assign(:page, 'a_traiter') render end @@ -18,4 +19,8 @@ describe 'backoffice/dossiers/a_traiter.html.haml', type: :view do it { is_expected.to have_content(decorate_dossier.nom_projet) } it { is_expected.to have_content(decorate_dossier.state_fr) } it { is_expected.to have_content(decorate_dossier.last_update) } + + describe 'active tab' do + it { is_expected.to have_selector('.active .text-danger') } + end end \ No newline at end of file diff --git a/spec/views/backoffice/dossiers/en_attente_html.haml_spec.rb b/spec/views/backoffice/dossiers/en_attente_html.haml_spec.rb index 264c60f3b..859b135b4 100644 --- a/spec/views/backoffice/dossiers/en_attente_html.haml_spec.rb +++ b/spec/views/backoffice/dossiers/en_attente_html.haml_spec.rb @@ -8,7 +8,8 @@ describe 'backoffice/dossiers/en_attente.html.haml', type: :view do let!(:decorate_dossier) { create(:dossier, :with_user, procedure: procedure, state: 'replied').decorate } before do - assign(:dossiers_en_attente, gestionnaire.dossiers.waiting_for_user.paginate(:page => 1).decorate) + assign(:dossiers, gestionnaire.dossiers.waiting_for_user.paginate(:page => 1).decorate) + assign(:page, 'en_attente') render end @@ -18,4 +19,8 @@ describe 'backoffice/dossiers/en_attente.html.haml', type: :view do it { is_expected.to have_content(decorate_dossier.nom_projet) } it { is_expected.to have_content(decorate_dossier.state_fr) } it { is_expected.to have_content(decorate_dossier.last_update) } + + describe 'active tab' do + it { is_expected.to have_selector('.active .text-info') } + end end \ No newline at end of file diff --git a/spec/views/backoffice/dossiers/termine_html.haml_spec.rb b/spec/views/backoffice/dossiers/termine_html.haml_spec.rb index 84ed3780a..5e696867b 100644 --- a/spec/views/backoffice/dossiers/termine_html.haml_spec.rb +++ b/spec/views/backoffice/dossiers/termine_html.haml_spec.rb @@ -8,7 +8,8 @@ describe 'backoffice/dossiers/termine.html.haml', type: :view do let!(:decorate_dossier) { create(:dossier, :with_user, procedure: procedure, state: 'closed').decorate } before do - assign(:dossiers_termine, gestionnaire.dossiers.termine.paginate(:page => 1).decorate) + assign(:dossiers, gestionnaire.dossiers.termine.paginate(:page => 1).decorate) + assign(:page, 'termine') render end @@ -18,4 +19,8 @@ describe 'backoffice/dossiers/termine.html.haml', type: :view do it { is_expected.to have_content(decorate_dossier.nom_projet) } it { is_expected.to have_content(decorate_dossier.state_fr) } it { is_expected.to have_content(decorate_dossier.last_update) } + + describe 'active tab' do + it { is_expected.to have_selector('.active .text-success') } + end end \ No newline at end of file