From a1ddcb6d34116ef974001f8a20ac837d41fa8f31 Mon Sep 17 00:00:00 2001 From: Simon Lehericey Date: Thu, 13 Jul 2017 15:38:57 +0200 Subject: [PATCH 1/5] DossierController: remove useless facade --- app/controllers/backoffice/dossiers_controller.rb | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/app/controllers/backoffice/dossiers_controller.rb b/app/controllers/backoffice/dossiers_controller.rb index 0c153122d..61d3fdc16 100644 --- a/app/controllers/backoffice/dossiers_controller.rb +++ b/app/controllers/backoffice/dossiers_controller.rb @@ -95,9 +95,7 @@ class Backoffice::DossiersController < Backoffice::DossiersListController end def receive - create_dossier_facade params[:dossier_id] - - dossier = @facade.dossier + dossier = Dossier.find(params[:dossier_id]) dossier.received! flash.notice = 'Dossier considéré comme reçu.' From 1c1a47d83a636159c14c1a52d103245ea5f0bd16 Mon Sep 17 00:00:00 2001 From: gregoirenovel Date: Mon, 17 Jul 2017 15:06:36 +0200 Subject: [PATCH 2/5] publiee_ou_archivee -> publiees_ou_archivees --- app/controllers/stats_controller.rb | 2 +- app/models/procedure.rb | 10 +++++----- app/views/root/landing.html.haml | 2 +- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/app/controllers/stats_controller.rb b/app/controllers/stats_controller.rb index 619e43121..ec79e78f5 100644 --- a/app/controllers/stats_controller.rb +++ b/app/controllers/stats_controller.rb @@ -4,7 +4,7 @@ class StatsController < ApplicationController MEAN_NUMBER_OF_CHAMPS_IN_A_FORM = 24.0 def index - procedures = Procedure.publiee_ou_archivee + procedures = Procedure.publiees_ou_archivees dossiers = Dossier.where.not(:state => :draft) @procedures_count = procedures.count diff --git a/app/models/procedure.rb b/app/models/procedure.rb index 665eddb24..1f0508c22 100644 --- a/app/models/procedure.rb +++ b/app/models/procedure.rb @@ -32,11 +32,11 @@ class Procedure < ActiveRecord::Base mount_uploader :logo, ProcedureLogoUploader default_scope { where(hidden_at: nil) } - scope :brouillons, -> { where(published_at: nil).where(archived_at: nil) } - scope :publiees, -> { where.not(published_at: nil).where(archived_at: nil) } - scope :archivees, -> { where.not(archived_at: nil) } - scope :publiee_ou_archivee, -> { where.not(published_at: nil) } - scope :by_libelle, -> { order(libelle: :asc) } + scope :brouillons, -> { where(published_at: nil).where(archived_at: nil) } + scope :publiees, -> { where.not(published_at: nil).where(archived_at: nil) } + scope :archivees, -> { where.not(archived_at: nil) } + scope :publiees_ou_archivees, -> { where.not(published_at: nil) } + scope :by_libelle, -> { order(libelle: :asc) } validates :libelle, presence: true, allow_blank: false, allow_nil: false validates :description, presence: true, allow_blank: false, allow_nil: false diff --git a/app/views/root/landing.html.haml b/app/views/root/landing.html.haml index 1d9d97d73..2801ddbdb 100644 --- a/app/views/root/landing.html.haml +++ b/app/views/root/landing.html.haml @@ -80,7 +80,7 @@ %ul.numbers %li.number .number-value - = number_with_delimiter(Procedure.publiee_ou_archivee.count, :locale => :fr) + = number_with_delimiter(Procedure.publiees_ou_archivees.count, :locale => :fr) .number-label< procédures %br<> From 20b4c7ce6fb103b2df8fbbb190cd03fbc36a0bdb Mon Sep 17 00:00:00 2001 From: gregoirenovel Date: Mon, 17 Jul 2017 15:10:05 +0200 Subject: [PATCH 3/5] [Fix #146] Use published_at for procedures in Stats Instead of created_at, which is less representative --- app/controllers/stats_controller.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/controllers/stats_controller.rb b/app/controllers/stats_controller.rb index ec79e78f5..8760d0f82 100644 --- a/app/controllers/stats_controller.rb +++ b/app/controllers/stats_controller.rb @@ -10,8 +10,8 @@ class StatsController < ApplicationController @procedures_count = procedures.count @dossiers_count = dossiers.count - @procedures_cumulative = cumulative_hash(procedures) - @procedures_in_the_last_4_months = last_four_months_hash(procedures) + @procedures_cumulative = cumulative_hash(procedures, :published_at) + @procedures_in_the_last_4_months = last_four_months_hash(procedures, :published_at) @dossiers_cumulative = cumulative_hash(dossiers, :initiated_at) @dossiers_in_the_last_4_months = last_four_months_hash(dossiers, :initiated_at) From 6f2c63c0944dafa2c3f035c6f2d357a18cf3f247 Mon Sep 17 00:00:00 2001 From: gregoirenovel Date: Mon, 17 Jul 2017 15:12:05 +0200 Subject: [PATCH 4/5] =?UTF-8?q?Remove=20default=20values=20for=20some=20st?= =?UTF-8?q?at=20methods=E2=80=99=20arguments?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/stats_controller.rb | 4 +- spec/controllers/stats_controller_spec.rb | 78 ++++++----------------- 2 files changed, 20 insertions(+), 62 deletions(-) diff --git a/app/controllers/stats_controller.rb b/app/controllers/stats_controller.rb index 8760d0f82..109163dc9 100644 --- a/app/controllers/stats_controller.rb +++ b/app/controllers/stats_controller.rb @@ -36,7 +36,7 @@ class StatsController < ApplicationController private - def last_four_months_hash(association, date_attribute = :created_at) + def last_four_months_hash(association, date_attribute) min_date = 3.months.ago.beginning_of_month.to_date if administration_signed_in? max_date = Time.now.to_date @@ -53,7 +53,7 @@ class StatsController < ApplicationController .map { |e| [I18n.l(e.first, format: "%B %Y"), e.last] } end - def cumulative_hash(association, date_attribute = :created_at) + def cumulative_hash(association, date_attribute) sum = 0 association .group("DATE_TRUNC('month', #{date_attribute.to_s})") diff --git a/spec/controllers/stats_controller_spec.rb b/spec/controllers/stats_controller_spec.rb index 4891e9ef1..f2fe3c36b 100644 --- a/spec/controllers/stats_controller_spec.rb +++ b/spec/controllers/stats_controller_spec.rb @@ -2,35 +2,13 @@ require 'spec_helper' describe StatsController, type: :controller do describe "#last_four_months_hash" do - context "without a date attribute" do - before do - FactoryGirl.create(:procedure, :created_at => 6.months.ago) - FactoryGirl.create(:procedure, :created_at => 62.days.ago) - FactoryGirl.create(:procedure, :created_at => 62.days.ago) - FactoryGirl.create(:procedure, :created_at => 31.days.ago) - - @controller = StatsController.new - - allow(@controller).to receive(:administration_signed_in?).and_return(false) - end - - let (:association) { Procedure.all } - - subject { @controller.send(:last_four_months_hash, association) } - - it { expect(subject).to eq([ - [I18n.l(62.days.ago.beginning_of_month, format: "%B %Y"), 2], - [I18n.l(31.days.ago.beginning_of_month, format: "%B %Y"), 1] - ]) - } - end - - context "with a date attribute" do + context "while a regular user is logged in" do before do FactoryGirl.create(:procedure, :created_at => 6.months.ago, :updated_at => 6.months.ago) FactoryGirl.create(:procedure, :created_at => 2.months.ago, :updated_at => 62.days.ago) FactoryGirl.create(:procedure, :created_at => 2.months.ago, :updated_at => 62.days.ago) FactoryGirl.create(:procedure, :created_at => 2.months.ago, :updated_at => 31.days.ago) + FactoryGirl.create(:procedure, :created_at => 2.months.ago, :updated_at => 1.day.ago) @controller = StatsController.new allow(@controller).to receive(:administration_signed_in?).and_return(false) @@ -49,10 +27,10 @@ describe StatsController, type: :controller do context "while a super admin is logged in" do before do - FactoryGirl.create(:procedure, :created_at => 6.months.ago) - FactoryGirl.create(:procedure, :created_at => 45.days.ago) - FactoryGirl.create(:procedure, :created_at => 1.day.ago) - FactoryGirl.create(:procedure, :created_at => 1.day.ago) + FactoryGirl.create(:procedure, :updated_at => 6.months.ago) + FactoryGirl.create(:procedure, :updated_at => 45.days.ago) + FactoryGirl.create(:procedure, :updated_at => 1.day.ago) + FactoryGirl.create(:procedure, :updated_at => 1.day.ago) @controller = StatsController.new @@ -61,7 +39,7 @@ describe StatsController, type: :controller do let (:association) { Procedure.all } - subject { @controller.send(:last_four_months_hash, association) } + subject { @controller.send(:last_four_months_hash, association, :updated_at) } it { expect(subject).to eq([ [I18n.l(45.days.ago.beginning_of_month, format: "%B %Y"), 1], @@ -72,41 +50,21 @@ describe StatsController, type: :controller do end describe '#cumulative_hash' do - context "without a date attribute" do - before do - FactoryGirl.create(:procedure, :created_at => 45.days.ago) - FactoryGirl.create(:procedure, :created_at => 15.days.ago) - FactoryGirl.create(:procedure, :created_at => 15.days.ago) - end - - let (:association) { Procedure.all } - - subject { StatsController.new.send(:cumulative_hash, association) } - - it { expect(subject).to eq({ - 45.days.ago.beginning_of_month => 1, - 15.days.ago.beginning_of_month => 3 - }) - } + before do + FactoryGirl.create(:procedure, :created_at => 45.days.ago, :updated_at => 20.days.ago) + FactoryGirl.create(:procedure, :created_at => 15.days.ago, :updated_at => 20.days.ago) + FactoryGirl.create(:procedure, :created_at => 15.days.ago, :updated_at => 10.days.ago) end - context "with a date attribute" do - before do - FactoryGirl.create(:procedure, :created_at => 45.days.ago, :updated_at => 20.days.ago) - FactoryGirl.create(:procedure, :created_at => 15.days.ago, :updated_at => 20.days.ago) - FactoryGirl.create(:procedure, :created_at => 15.days.ago, :updated_at => 10.days.ago) - end + let (:association) { Procedure.all } - let (:association) { Procedure.all } + subject { StatsController.new.send(:cumulative_hash, association, :updated_at) } - subject { StatsController.new.send(:cumulative_hash, association, :updated_at) } - - it { expect(subject).to eq({ - 20.days.ago.beginning_of_month => 2, - 10.days.ago.beginning_of_month => 3 - }) - } - end + it { expect(subject).to eq({ + 20.days.ago.beginning_of_month => 2, + 10.days.ago.beginning_of_month => 3 + }) + } end describe "#procedures_count_per_administrateur" do From c464a6faba193679446f9c3e844c9b75ecee79f4 Mon Sep 17 00:00:00 2001 From: gregoirenovel Date: Mon, 17 Jul 2017 16:36:32 +0200 Subject: [PATCH 5/5] [Fix #168] Sort published and archived procedures by publication_date --- app/controllers/admin/procedures_controller.rb | 4 ++-- app/decorators/procedure_decorator.rb | 4 ++++ app/views/admin/procedures/_list.html.haml | 13 ++++++++++--- 3 files changed, 16 insertions(+), 5 deletions(-) diff --git a/app/controllers/admin/procedures_controller.rb b/app/controllers/admin/procedures_controller.rb index 9e6dca90a..e85e6c2b4 100644 --- a/app/controllers/admin/procedures_controller.rb +++ b/app/controllers/admin/procedures_controller.rb @@ -6,7 +6,7 @@ class Admin::ProceduresController < AdminController def index @procedures = smart_listing_create :procedures, - current_administrateur.procedures.publiees.order(created_at: :desc), + current_administrateur.procedures.publiees.order(published_at: :desc), partial: "admin/procedures/list", array: true @@ -15,7 +15,7 @@ class Admin::ProceduresController < AdminController def archived @procedures = smart_listing_create :procedures, - current_administrateur.procedures.archivees.order(created_at: :desc), + current_administrateur.procedures.archivees.order(published_at: :desc), partial: "admin/procedures/list", array: true diff --git a/app/decorators/procedure_decorator.rb b/app/decorators/procedure_decorator.rb index 50f64c2ab..7ac4871db 100644 --- a/app/decorators/procedure_decorator.rb +++ b/app/decorators/procedure_decorator.rb @@ -9,6 +9,10 @@ class ProcedureDecorator < Draper::Decorator created_at.localtime.strftime('%d/%m/%Y %H:%M') end + def published_at_fr + published_at.localtime.strftime('%d/%m/%Y %H:%M') + end + def logo_img if logo.blank? h.image_url(LOGO_NAME) diff --git a/app/views/admin/procedures/_list.html.haml b/app/views/admin/procedures/_list.html.haml index d838bd2f0..c1633985c 100644 --- a/app/views/admin/procedures/_list.html.haml +++ b/app/views/admin/procedures/_list.html.haml @@ -5,7 +5,10 @@ %th#libelle= smart_listing.sortable 'Libellé', 'libelle' - if @active_class %th Lien - %th#created_at= smart_listing.sortable 'Date création', 'created_at' + - if @active_class || @archived_class + %th#published_at= smart_listing.sortable 'Date publication', 'published_at' + - else + %th#created_at= smart_listing.sortable 'Date création', 'created_at' %th Actions - @procedures.each do |procedure| @@ -16,8 +19,12 @@ = procedure.libelle - if @active_class %td.procedure-lien= link_to procedure.lien, procedure.lien, 'data-method' => :get - %td - = procedure.created_at_fr + - if @active_class || @archived_class + %td + = procedure.published_at_fr + - else + %td + = procedure.created_at_fr %td = link_to('Cloner', admin_procedure_clone_path(procedure.id), 'data-method' => :put, class: 'btn-sm btn-primary clone-btn') - unless procedure.publiee_ou_archivee?