From b48af51ee9483813e8b5f929b1acf35ca41b186c Mon Sep 17 00:00:00 2001 From: Simon Lehericey Date: Tue, 11 Jul 2017 16:09:03 +0200 Subject: [PATCH] NewDesign: procedure show only header --- .../new_design/procedures_show.scss | 75 +++++++++++++++++++ .../new_gestionnaire/procedures_controller.rb | 20 +++++ app/models/dossier.rb | 24 +++--- .../procedures/show.html.haml | 33 ++++++++ config/locales/fr.yml | 17 +++++ config/routes.rb | 8 +- .../procedures_controller_spec.rb | 67 +++++++++++++++++ 7 files changed, 231 insertions(+), 13 deletions(-) create mode 100644 app/assets/stylesheets/new_design/procedures_show.scss create mode 100644 app/views/new_gestionnaire/procedures/show.html.haml diff --git a/app/assets/stylesheets/new_design/procedures_show.scss b/app/assets/stylesheets/new_design/procedures_show.scss new file mode 100644 index 000000000..3e9772d98 --- /dev/null +++ b/app/assets/stylesheets/new_design/procedures_show.scss @@ -0,0 +1,75 @@ +@import "colors"; +@import "common"; +@import "constants"; + +#procedure-show { + .header { + background-color: $light-grey; + padding-top: $default-padding; + + .container { + display: flex; + } + + .procedure-logo { + margin-right: $default-padding; + } + + h1 { + color: $black; + font-size: 22px; + margin-bottom: 2 * $default-padding; + } + + .dossiers-categories { + li { + display: inline-block; + height: 56px; + width: 130px; + line-height: 17px; + position: relative; + text-align: center; + font-size: 14px; + + a { + color: $black; + } + + &::before, + &:last-child::after { + content: ""; + position: absolute; + height: 36px; + width: 1px; + background-color: $border-grey; + margin-right: $default-padding; + } + + &::before { + left: 0px; + } + + &:last-child::after { + right: 0px; + top: 0px; + margin-right: 0px; + } + + &.active { + border-bottom: 2px solid $blue; + + a { + color: $blue; + } + } + + .dossiers-count { + position: relative; + display: block; + font-size: 16px; + font-weight: bold; + } + } + } + } +} diff --git a/app/controllers/new_gestionnaire/procedures_controller.rb b/app/controllers/new_gestionnaire/procedures_controller.rb index 26940b425..23e943b03 100644 --- a/app/controllers/new_gestionnaire/procedures_controller.rb +++ b/app/controllers/new_gestionnaire/procedures_controller.rb @@ -15,6 +15,26 @@ module NewGestionnaire @followed_dossiers_count_per_procedure = current_gestionnaire.followed_dossiers.where(procedure: @procedures).group(:procedure_id).count end + def show + @procedure = procedure + + @a_suivre_dossiers = procedure + .dossiers + .without_followers + .en_cours + + @followed_dossiers = current_gestionnaire + .followed_dossiers + .where(procedure: @procedure) + .en_cours + + @termines_dossiers = procedure.dossiers.termine + + @all_state_dossiers = procedure.dossiers.all_state + + @archived_dossiers = procedure.dossiers.archived + end + private def procedure diff --git a/app/models/dossier.rb b/app/models/dossier.rb index eb0c573f0..d916cc51a 100644 --- a/app/models/dossier.rb +++ b/app/models/dossier.rb @@ -17,6 +17,7 @@ class Dossier < ActiveRecord::Base WAITING_FOR_USER = %w(replied) EN_CONSTRUCTION = %w(initiated updated replied) EN_INSTRUCTION = %w(received) + EN_CONSTRUCTION_OU_INSTRUCTION = EN_CONSTRUCTION + EN_INSTRUCTION A_INSTRUIRE = %w(received) TERMINE = %w(closed refused without_continuation) @@ -43,16 +44,17 @@ class Dossier < ActiveRecord::Base belongs_to :user default_scope { where(hidden_at: nil) } - scope :state_brouillon, -> { where(state: BROUILLON) } - scope :state_not_brouillon, -> { where.not(state: BROUILLON) } - scope :state_nouveaux, -> { where(state: NOUVEAUX) } - scope :state_ouvert, -> { where(state: OUVERT) } - scope :state_waiting_for_gestionnaire, -> { where(state: WAITING_FOR_GESTIONNAIRE) } - scope :state_waiting_for_user, -> { where(state: WAITING_FOR_USER) } - scope :state_en_construction, -> { where(state: EN_CONSTRUCTION) } - scope :state_en_instruction, -> { where(state: EN_INSTRUCTION) } - scope :state_a_instruire, -> { where(state: A_INSTRUIRE) } - scope :state_termine, -> { where(state: TERMINE) } + scope :state_brouillon, -> { where(state: BROUILLON) } + scope :state_not_brouillon, -> { where.not(state: BROUILLON) } + scope :state_nouveaux, -> { where(state: NOUVEAUX) } + scope :state_ouvert, -> { where(state: OUVERT) } + scope :state_waiting_for_gestionnaire, -> { where(state: WAITING_FOR_GESTIONNAIRE) } + scope :state_waiting_for_user, -> { where(state: WAITING_FOR_USER) } + scope :state_en_construction, -> { where(state: EN_CONSTRUCTION) } + scope :state_en_instruction, -> { where(state: EN_INSTRUCTION) } + scope :state_en_construction_ou_instruction, -> { where(state: EN_CONSTRUCTION_OU_INSTRUCTION) } + scope :state_a_instruire, -> { where(state: A_INSTRUIRE) } + scope :state_termine, -> { where(state: TERMINE) } scope :archived, -> { where(archived: true) } scope :not_archived, -> { where(archived: false) } @@ -67,6 +69,8 @@ class Dossier < ActiveRecord::Base scope :a_instruire, -> { not_archived.state_a_instruire.order_by_updated_at(:asc) } scope :termine, -> { not_archived.state_termine.order_by_updated_at(:asc) } scope :downloadable, -> { state_not_brouillon.order_by_updated_at(:asc) } + scope :en_cours, -> { not_archived.state_en_construction_ou_instruction.order_by_updated_at(:asc) } + scope :without_followers, -> { includes(:follows).where(follows: { id: nil }) } accepts_nested_attributes_for :individual diff --git a/app/views/new_gestionnaire/procedures/show.html.haml b/app/views/new_gestionnaire/procedures/show.html.haml new file mode 100644 index 000000000..916dd91fc --- /dev/null +++ b/app/views/new_gestionnaire/procedures/show.html.haml @@ -0,0 +1,33 @@ +#procedure-show + .header + .container + - if @procedure.logo.present? + = image_tag @procedure.logo, height: 40, class: 'procedure-logo' + + .right + %h1= @procedure.libelle + %ul.dossiers-categories + %li{ class: (@statut == 'a-suivre') ? 'active' : nil }> + = link_to(procedure_path(@procedure, statut: 'a-suivre')) do + %span.dossiers-count= @a_suivre_dossiers.count + à suivre + + %li{ class: (@statut == 'suivis') ? 'active' : nil }> + = link_to(procedure_path(@procedure, statut: 'suivis')) do + %span.dossiers-count= @followed_dossiers.count + = t('pluralize.followed', count: @followed_dossiers.count) + + %li{ class: (@statut == 'traites') ? 'active' : nil }> + = link_to(procedure_path(@procedure, statut: 'traites')) do + %span.dossiers-count= @termines_dossiers.count + = t('pluralize.processed', count: @termines_dossiers.count) + + %li{ class: (@statut == 'tous') ? 'active' : nil }> + = link_to(procedure_path(@procedure, statut: 'tous')) do + %span.dossiers-count= @all_state_dossiers.count + tous les dossiers + + %li{ class: (@statut == 'archives') ? 'active' : nil }> + = link_to(procedure_path(@procedure, statut: 'archives')) do + %span.dossiers-count= @archived_dossiers.count + = t('pluralize.archived', count: @archived_dossiers.count) diff --git a/config/locales/fr.yml b/config/locales/fr.yml index b94806305..590b7b894 100644 --- a/config/locales/fr.yml +++ b/config/locales/fr.yml @@ -285,3 +285,20 @@ fr: x_seconds: one: 1 seconde other: "%{count} secondes" + pluralize: + processed: + zero: traité + one: traité + other: traités + new: + zero: nouveau + one: nouveau + other: nouveaux + followed: + zero: suivi + one: suivi + other: suivis + archived: + zero: archivé + one: archivé + other: archivés diff --git a/config/routes.rb b/config/routes.rb index 8ce8d4502..50d309cbd 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -238,9 +238,11 @@ Rails.application.routes.draw do end scope module: 'new_gestionnaire' do - resources :procedures, only: [:index] do - resources :dossiers, only: [] do - get 'attestation' + resources :procedures, only: [:index, :show], param: :procedure_id do + member do + resources :dossiers, only: [] do + get 'attestation' + end end end end diff --git a/spec/controllers/new_gestionnaire/procedures_controller_spec.rb b/spec/controllers/new_gestionnaire/procedures_controller_spec.rb index 029da58d8..e9c64db6c 100644 --- a/spec/controllers/new_gestionnaire/procedures_controller_spec.rb +++ b/spec/controllers/new_gestionnaire/procedures_controller_spec.rb @@ -118,4 +118,71 @@ describe NewGestionnaire::ProceduresController, type: :controller do end end end + + describe "#show" do + let(:gestionnaire) { create(:gestionnaire) } + let!(:procedure) { create(:procedure, gestionnaires: [gestionnaire]) } + + context "when logged in" do + before do + sign_in(gestionnaire) + get :show, params: { procedure_id: procedure.id } + end + + it { expect(response).to have_http_status(:ok) } + it { expect(assigns(:procedure)).to eq(procedure) } + + context 'with a new draft dossier' do + let!(:draft_dossier) { create(:dossier, procedure: procedure, state: 'draft') } + + it { expect(assigns(:a_suivre_dossiers)).to be_empty } + it { expect(assigns(:followed_dossiers)).to be_empty } + it { expect(assigns(:termines_dossiers)).to be_empty } + it { expect(assigns(:all_state_dossiers)).to be_empty } + it { expect(assigns(:archived_dossiers)).to be_empty } + end + + context 'with a new dossier without follower' do + let!(:new_unfollow_dossier) { create(:dossier, procedure: procedure, state: 'received') } + + it { expect(assigns(:a_suivre_dossiers)).to match([new_unfollow_dossier]) } + it { expect(assigns(:followed_dossiers)).to be_empty } + it { expect(assigns(:termines_dossiers)).to be_empty } + it { expect(assigns(:all_state_dossiers)).to match([new_unfollow_dossier]) } + it { expect(assigns(:archived_dossiers)).to be_empty } + end + + context 'with a new dossier with a follower' do + let!(:new_followed_dossier) { create(:dossier, procedure: procedure, state: 'received') } + + before { gestionnaire.followed_dossiers << new_followed_dossier } + + it { expect(assigns(:a_suivre_dossiers)).to be_empty } + it { expect(assigns(:followed_dossiers)).to match([new_followed_dossier]) } + it { expect(assigns(:termines_dossiers)).to be_empty } + it { expect(assigns(:all_state_dossiers)).to match([new_followed_dossier]) } + it { expect(assigns(:archived_dossiers)).to be_empty } + end + + context 'with a termine dossier with a follower' do + let!(:termine_dossier) { create(:dossier, procedure: procedure, state: 'closed') } + + it { expect(assigns(:a_suivre_dossiers)).to be_empty } + it { expect(assigns(:followed_dossiers)).to be_empty } + it { expect(assigns(:termines_dossiers)).to match([termine_dossier]) } + it { expect(assigns(:all_state_dossiers)).to match([termine_dossier]) } + it { expect(assigns(:archived_dossiers)).to be_empty } + end + + context 'with an archived dossier' do + let!(:archived_dossier) { create(:dossier, procedure: procedure, state: 'received', archived: true) } + + it { expect(assigns(:a_suivre_dossiers)).to be_empty } + it { expect(assigns(:followed_dossiers)).to be_empty } + it { expect(assigns(:termines_dossiers)).to be_empty } + it { expect(assigns(:all_state_dossiers)).to be_empty } + it { expect(assigns(:archived_dossiers)).to match([archived_dossier]) } + end + end + end end