From 2b146a6d627c7d82e4612d40692547d13fb58f8d Mon Sep 17 00:00:00 2001 From: Simon Lehericey Date: Wed, 1 Nov 2017 20:40:33 +0100 Subject: [PATCH 1/2] Notifications: show dossiers with notification in first place --- .../new_design/dossiers_table.scss | 19 ++++++++++++++++--- .../new_gestionnaire/procedures_controller.rb | 15 ++++++++++++++- .../procedures/show.html.haml | 13 ++++++++++--- .../procedures_controller_spec.rb | 2 +- 4 files changed, 41 insertions(+), 8 deletions(-) diff --git a/app/assets/stylesheets/new_design/dossiers_table.scss b/app/assets/stylesheets/new_design/dossiers_table.scss index c0b34500d..e50d5f0c1 100644 --- a/app/assets/stylesheets/new_design/dossiers_table.scss +++ b/app/assets/stylesheets/new_design/dossiers_table.scss @@ -33,17 +33,30 @@ } .icon.folder { - margin-right: $default-spacer; position: relative; .notifications { - top: 0px; - right: -10px; + top: -3px; + right: -6px; + } + } + + .notification-col { + width: 30px; + text-align: center; + + a { + font-size: 16px; } } .number-col { width: 110px; + text-align: center; + } + + .folder-col { + text-align: center; } .status-col { diff --git a/app/controllers/new_gestionnaire/procedures_controller.rb b/app/controllers/new_gestionnaire/procedures_controller.rb index a8a1708e6..c13d70fc1 100644 --- a/app/controllers/new_gestionnaire/procedures_controller.rb +++ b/app/controllers/new_gestionnaire/procedures_controller.rb @@ -240,7 +240,16 @@ module NewGestionnaire includes = '' where = '' + sorted_ids = nil + case table + when 'notifications' + dossiers_id_with_notification = current_gestionnaire.notifications_for_procedure(procedure) + if order == 'desc' + sorted_ids = dossiers_id_with_notification + (dossiers.order('dossiers.updated_at desc').ids - dossiers_id_with_notification) + else + sorted_ids = (dossiers.order('dossiers.updated_at asc').ids - dossiers_id_with_notification) + dossiers_id_with_notification + end when 'self' order = "dossiers.#{column} #{order}" when'france_connect_information' @@ -255,7 +264,11 @@ module NewGestionnaire order = "#{table.pluralize}.#{column} #{order}" end - dossiers.includes(includes).where(where).order(Dossier.sanitize_for_order(order)).pluck(:id) + if sorted_ids.nil? + sorted_ids = dossiers.includes(includes).where(where).order(Dossier.sanitize_for_order(order)).pluck(:id) + end + + sorted_ids end def current_filters diff --git a/app/views/new_gestionnaire/procedures/show.html.haml b/app/views/new_gestionnaire/procedures/show.html.haml index c1e9dfc49..66cf44902 100644 --- a/app/views/new_gestionnaire/procedures/show.html.haml +++ b/app/views/new_gestionnaire/procedures/show.html.haml @@ -74,6 +74,11 @@ %table.table.dossiers-table.hoverable %thead %tr + - if @statut == 'suivis' || @statut == 'tous' + = render partial: "header_field", locals: { field: { "label" => "●", "table" => "notifications", "column" => "notifications" }, classname: "notification-col" } + - else + %th.notification-col + = render partial: "header_field", locals: { field: { "label" => "Nº dossier", "table" => "self", "column" => "id" }, classname: "number-col" } - @displayed_fields.each do |field| @@ -96,11 +101,13 @@ %tbody - @dossiers.each do |dossier| %tr + %td.folder-col + .icon.folder + - if current_gestionnaire.notifications_for_procedure(@procedure).include?(dossier.id) + %span.notifications{ 'aria-label': 'notifications' } + %td.number-col = link_to(dossier_path(@procedure, dossier), class: 'cell-link') do - .icon.folder - - if current_gestionnaire.notifications_for_procedure(@procedure).include?(dossier.id) - %span.notifications{ 'aria-label': 'notifications' } = dossier.id - @displayed_fields.each do |field| diff --git a/spec/controllers/new_gestionnaire/procedures_controller_spec.rb b/spec/controllers/new_gestionnaire/procedures_controller_spec.rb index bd11a7e00..a7f2f7583 100644 --- a/spec/controllers/new_gestionnaire/procedures_controller_spec.rb +++ b/spec/controllers/new_gestionnaire/procedures_controller_spec.rb @@ -295,7 +295,7 @@ describe NewGestionnaire::ProceduresController, type: :controller do let(:statut) { 'tous' } it { expect(assigns(:statut)).to eq('tous') } - it { expect(assigns(:dossiers)).to match([a_suivre__dossier, new_followed_dossier, termine_dossier].sort_by(&:updated_at)) } + it { expect(assigns(:dossiers)).to match_array([a_suivre__dossier, new_followed_dossier, termine_dossier]) } end context 'when statut is archives' do From d0cad009406d0c95968cc3cfd9034f59cb1969dd Mon Sep 17 00:00:00 2001 From: Simon Lehericey Date: Fri, 17 Nov 2017 18:23:45 +0100 Subject: [PATCH 2/2] ProcedurePresentation: change default sort value --- ...0171117165748_change_procedure_presentation_default.rb | 5 +++++ db/schema.rb | 8 ++++---- 2 files changed, 9 insertions(+), 4 deletions(-) create mode 100644 db/migrate/20171117165748_change_procedure_presentation_default.rb diff --git a/db/migrate/20171117165748_change_procedure_presentation_default.rb b/db/migrate/20171117165748_change_procedure_presentation_default.rb new file mode 100644 index 000000000..7a8d3e1fd --- /dev/null +++ b/db/migrate/20171117165748_change_procedure_presentation_default.rb @@ -0,0 +1,5 @@ +class ChangeProcedurePresentationDefault < ActiveRecord::Migration[5.0] + def change + change_column_default :procedure_presentations, :sort, from: { "table" => "self", "column" => "id", "order" => "desc" }.to_json, to: { "table" => "notifications", "column" => "notifications", "order" => "desc" }.to_json + end +end diff --git a/db/schema.rb b/db/schema.rb index 77dee82db..e69a4eae7 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,7 +10,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 20171024135653) do +ActiveRecord::Schema.define(version: 20171117165748) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -394,9 +394,9 @@ ActiveRecord::Schema.define(version: 20171024135653) do create_table "procedure_presentations", force: :cascade do |t| t.integer "assign_to_id" - t.text "displayed_fields", default: ["{\"label\":\"Demandeur\",\"table\":\"user\",\"column\":\"email\"}"], null: false, array: true - t.json "sort", default: "{\"table\":\"self\",\"column\":\"id\",\"order\":\"desc\"}", null: false - t.json "filters", default: "{\"a-suivre\":[],\"suivis\":[],\"traites\":[],\"tous\":[],\"archives\":[]}", null: false + t.text "displayed_fields", default: ["{\"label\":\"Demandeur\",\"table\":\"user\",\"column\":\"email\"}"], null: false, array: true + t.json "sort", default: "{\"table\":\"notifications\",\"column\":\"notifications\",\"order\":\"desc\"}", null: false + t.json "filters", default: "{\"a-suivre\":[],\"suivis\":[],\"traites\":[],\"tous\":[],\"archives\":[]}", null: false t.index ["assign_to_id"], name: "index_procedure_presentations_on_assign_to_id", unique: true, using: :btree end