From a37320bae93d1faefe943ff627125c126f54cfb2 Mon Sep 17 00:00:00 2001 From: Xavier J Date: Mon, 1 Aug 2016 18:10:32 +0200 Subject: [PATCH] Add lateral panel to configure dossier list in back office --- app/assets/javascripts/pref_list_dossier.js | 33 +++ app/assets/stylesheets/backoffice.scss | 12 + app/assets/stylesheets/pref_list_menu.scss | 20 ++ .../backoffice/dossiers_controller.rb | 23 +- .../preference_list_dossier_controller.rb | 31 +++ app/decorators/dossier_decorator.rb | 4 + app/decorators/etablissement_decorator.rb | 4 + .../france_connect_information_decorator.rb | 4 + app/mailers/new_admin_mailer.rb | 2 +- app/models/dossier.rb | 1 + app/models/gestionnaire.rb | 1 + app/models/preference_list_dossier.rb | 94 +++++++ app/views/backoffice/dossiers/_list.html.haml | 31 ++- .../backoffice/dossiers/_onglets.html.haml | 24 +- .../backoffice/dossiers/_pref_list.html.haml | 43 +++ .../backoffice/dossiers/_pref_list.js.erb | 14 + app/views/backoffice/dossiers/index.html.haml | 2 + app/views/layouts/application.html.haml | 6 + config/routes.rb | 8 + ...35927_add_preference_list_dossier_table.rb | 15 ++ db/schema.rb | 13 +- ...preference_list_dossier_controller_spec.rb | 51 ++++ spec/factories/preference_list_dossier.rb | 11 + ..._page_pref_list_dossier_backoffice_spec.rb | 86 ++++++ .../backoffice/navigate_to_dossier_spec.rb | 9 + spec/models/dossier_spec.rb | 1 + spec/models/gestionnaire_spec.rb | 1 + spec/models/preference_list_dossier_spec.rb | 253 ++++++++++++++++++ .../dossiers/index_html.haml_spec.rb | 24 ++ 29 files changed, 794 insertions(+), 27 deletions(-) create mode 100644 app/assets/javascripts/pref_list_dossier.js create mode 100644 app/assets/stylesheets/pref_list_menu.scss create mode 100644 app/controllers/backoffice/preference_list_dossier_controller.rb create mode 100644 app/decorators/etablissement_decorator.rb create mode 100644 app/decorators/france_connect_information_decorator.rb create mode 100644 app/models/preference_list_dossier.rb create mode 100644 app/views/backoffice/dossiers/_pref_list.html.haml create mode 100644 app/views/backoffice/dossiers/_pref_list.js.erb create mode 100644 db/migrate/20160722135927_add_preference_list_dossier_table.rb create mode 100644 spec/controllers/backoffice/preference_list_dossier_controller_spec.rb create mode 100644 spec/factories/preference_list_dossier.rb create mode 100644 spec/features/backoffice/lateral_page_pref_list_dossier_backoffice_spec.rb create mode 100644 spec/models/preference_list_dossier_spec.rb diff --git a/app/assets/javascripts/pref_list_dossier.js b/app/assets/javascripts/pref_list_dossier.js new file mode 100644 index 000000000..70bf1a4dd --- /dev/null +++ b/app/assets/javascripts/pref_list_dossier.js @@ -0,0 +1,33 @@ +$(document).on('page:load', pref_list_dossier_actions); +$(document).ready(pref_list_dossier_actions); + +function pref_list_dossier_actions() { + pref_list_dossier_open_action(); + pref_list_dossier_close_action(); +} + +function pref_list_dossier_open_action() { + $("#pref_list_dossier_open_action").on('click', function () { + $("#pref_list_menu").css('display', 'block'); + $("#pref_list_menu").css('visibility', 'visible'); + + $("#pref_list_menu").animate({ + right: 0 + }, 250); + }); +} + +function pref_list_dossier_close_action() { + $("#pref_list_dossier_close_action").on('click', function () { + $("#pref_list_menu").animate({ + right: parseInt($("#pref_list_menu").css('width'), 10)*(-1)+'px' + },{ + duration: 250, + complete: function () { + $("#pref_list_menu").css('display', 'none'); + $("#pref_list_menu").css('visibility', 'hidden'); + } + } + ) + }); +} \ No newline at end of file diff --git a/app/assets/stylesheets/backoffice.scss b/app/assets/stylesheets/backoffice.scss index f0054f56c..b447e2a5e 100644 --- a/app/assets/stylesheets/backoffice.scss +++ b/app/assets/stylesheets/backoffice.scss @@ -6,6 +6,18 @@ } } +#backoffice_index, #backoffice_search { + margin-left: -7rem; + margin-right: -7rem; +} + +#pref_list{ + .dropdown-menu { + padding: 10px; + width: 500px; + } +} + #onglets { ul { li, li.active { diff --git a/app/assets/stylesheets/pref_list_menu.scss b/app/assets/stylesheets/pref_list_menu.scss new file mode 100644 index 000000000..0ab24a30d --- /dev/null +++ b/app/assets/stylesheets/pref_list_menu.scss @@ -0,0 +1,20 @@ +#pref_list_menu{ + z-index: 100; + display: none; + position: fixed; + visibility: hidden; + top: 10px; + right: -470px; + background-color: rgba(255, 255, 255, 0.95); + border-left: solid 1px lightgrey; + box-shadow: 0 6px 12px rgba(0, 0, 0, 0.2); + width: 470px; + height: calc(100% - 25px); + padding: 15px; + overflow: scroll; +} + +.open_pref_list { + right: 0 !important; + display: block !important; +} \ No newline at end of file diff --git a/app/controllers/backoffice/dossiers_controller.rb b/app/controllers/backoffice/dossiers_controller.rb index edf67db28..82d41b543 100644 --- a/app/controllers/backoffice/dossiers_controller.rb +++ b/app/controllers/backoffice/dossiers_controller.rb @@ -7,10 +7,7 @@ class Backoffice::DossiersController < ApplicationController def index @liste = params[:liste] || 'a_traiter' - @dossiers = smart_listing_create :dossiers, - dossiers_to_display, - partial: "backoffice/dossiers/list", - array: true + smartlisting_dossier total_dossiers_per_state end @@ -61,8 +58,26 @@ class Backoffice::DossiersController < ApplicationController redirect_to request.referer end + def reload_smartlisting + begin + @liste = URI(request.referer).query.split('=').second + rescue NoMethodError + @liste = 'a_traiter' + end + smartlisting_dossier + + render 'backoffice/dossiers/index', formats: :js + end + private + def smartlisting_dossier + @dossiers = smart_listing_create :dossiers, + dossiers_to_display, + partial: "backoffice/dossiers/list", + array: true + end + def dossiers_to_display {'a_traiter' => waiting_for_gestionnaire, 'en_attente' => waiting_for_user, diff --git a/app/controllers/backoffice/preference_list_dossier_controller.rb b/app/controllers/backoffice/preference_list_dossier_controller.rb new file mode 100644 index 000000000..034ff1fb1 --- /dev/null +++ b/app/controllers/backoffice/preference_list_dossier_controller.rb @@ -0,0 +1,31 @@ +class Backoffice::PreferenceListDossierController < ApplicationController + include SmartListing::Helper::ControllerExtensions + helper SmartListing::Helper + + before_action :authenticate_gestionnaire! + + def add + PreferenceListDossier.create( + libelle: params[:libelle], + table: params[:table], + attr: params[:attr], + attr_decorate: params[:attr_decorate], + bootstrap_lg: params[:bootstrap_lg], + order: nil, + filter: nil, + gestionnaire: current_gestionnaire + ) + + render partial: 'backoffice/dossiers/pref_list', formats: :js + end + + def reload_pref_list + render partial: 'backoffice/dossiers/pref_list' + end + + def delete + PreferenceListDossier.delete(params[:pref_id]) + + render partial: 'backoffice/dossiers/pref_list', formats: :js + end +end diff --git a/app/decorators/dossier_decorator.rb b/app/decorators/dossier_decorator.rb index a1b76c80d..109b95bf7 100644 --- a/app/decorators/dossier_decorator.rb +++ b/app/decorators/dossier_decorator.rb @@ -8,6 +8,10 @@ class DossierDecorator < Draper::Decorator 'dd/mm/YYYY' end + def first_creation + created_at.localtime.strftime('%d/%m/%Y %H:%M') + end + def last_update updated_at.localtime.strftime('%d/%m/%Y %H:%M') end diff --git a/app/decorators/etablissement_decorator.rb b/app/decorators/etablissement_decorator.rb new file mode 100644 index 000000000..23f809c79 --- /dev/null +++ b/app/decorators/etablissement_decorator.rb @@ -0,0 +1,4 @@ +class EtablissementDecorator < Draper::Decorator + delegate_all + +end diff --git a/app/decorators/france_connect_information_decorator.rb b/app/decorators/france_connect_information_decorator.rb new file mode 100644 index 000000000..206361fe8 --- /dev/null +++ b/app/decorators/france_connect_information_decorator.rb @@ -0,0 +1,4 @@ +class FranceConnectInformationDecorator < Draper::Decorator + delegate_all + +end diff --git a/app/mailers/new_admin_mailer.rb b/app/mailers/new_admin_mailer.rb index 22c0428fb..f7acb8e7e 100644 --- a/app/mailers/new_admin_mailer.rb +++ b/app/mailers/new_admin_mailer.rb @@ -4,7 +4,7 @@ class NewAdminMailer < ApplicationMailer @admin = admin @password = password - mail(from: "tech@apientreprise.fr", to: 'tech@apientreprise.fr', + mail(from: "tps@apientreprise.fr", to: 'tech@apientreprise.fr', subject: "Création d'un compte Admin TPS") end end diff --git a/app/models/dossier.rb b/app/models/dossier.rb index 4e0f13f8c..f387d28d5 100644 --- a/app/models/dossier.rb +++ b/app/models/dossier.rb @@ -27,6 +27,7 @@ class Dossier < ActiveRecord::Base delegate :siret, to: :etablissement, allow_nil: true delegate :types_de_piece_justificative, to: :procedure delegate :types_de_champ, to: :procedure + delegate :france_connect_information, to: :user after_save :build_default_champs, if: Proc.new { procedure_id_changed? } diff --git a/app/models/gestionnaire.rb b/app/models/gestionnaire.rb index 128783937..2faf97c47 100644 --- a/app/models/gestionnaire.rb +++ b/app/models/gestionnaire.rb @@ -8,6 +8,7 @@ class Gestionnaire < ActiveRecord::Base has_many :procedures, through: :assign_to has_many :dossiers, through: :procedures has_many :follows + has_many :preference_list_dossiers def dossiers_filter dossiers.where(procedure_id: procedure_filter_list) diff --git a/app/models/preference_list_dossier.rb b/app/models/preference_list_dossier.rb new file mode 100644 index 000000000..93befa9d0 --- /dev/null +++ b/app/models/preference_list_dossier.rb @@ -0,0 +1,94 @@ +class PreferenceListDossier < ActiveRecord::Base + belongs_to :gestionnaire + + def table_attr + return self.attr if table.empty? + table + '.' + attr + end + + def self.available_columns + { + dossier: columns_dossier, + procedure: columns_procedure, + entreprise: columns_entreprise, + etablissement: columns_etablissement, + user: columns_user + } + end + + private + + def self.columns_dossier + table = nil + + { + dossier_id: create_column('ID', table, 'id', 'id', 1), + created_at: create_column('Créé le', table, 'created_at', 'first_creation', 2), + updated_at: create_column('Mise à jour le', table, 'updated_at', 'last_update', 2), + state: create_column('Statut', table, 'state', 'display_state', 1) + } + end + + def self.columns_procedure + table = 'procedure' + + { + libelle: create_column('Libellé procédure', table, 'libelle', 'libelle', 4), + organisation: create_column('Organisation', table, 'organisation', 'organisation', 3), + direction: create_column('Direction', table, 'direction', 'direction', 3) + } + end + + def self.columns_entreprise + table = 'entreprise' + + { + siren: create_column('SIREN', table, 'siren', 'siren', 2), + forme_juridique: create_column('Forme juridique', table, 'forme_juridique', 'forme_juridique', 3), + nom_commercial: create_column('Nom commercial', table, 'nom_commercial', 'nom_commercial', 3), + raison_sociale: create_column('Raison sociale', table, 'raison_sociale', 'raison_sociale', 3), + siret_siege_social: create_column('SIRET siège social', table, 'siret_siege_social', 'siret_siege_social', 2), + date_creation: create_column('Date de création', table, 'date_creation', 'date_creation', 2), + } + end + + def self.columns_etablissement + table = 'etablissement' + + { + siret: create_column('SIRET', table, 'siret', 'siret', 2), + libelle: create_column('Nom établissement', table, 'libelle_naf', 'libelle_naf', 3), + code_postal: create_column('Code postal', table, 'code_postal', 'code_postal', 1) + } + end + + def self.columns_user + table = 'user' + + { + email: create_column('Email', table, 'email', 'email', 2) + } + end + + def self.columns_france_connect + table = 'france_connect_information' + + { + gender: create_column('Civilité', table, 'gender', 'gender', 1), + given_name: create_column('Prénom', table, 'given_name', 'given_name', 2), + family_name: create_column('Nom', table, 'family_name', 'family_name', 2) + } + end + + def self.create_column libelle, table, attr, attr_decorate, bootstrap_lg + { + libelle: libelle, + table: table, + attr: attr, + attr_decorate: attr_decorate, + bootstrap_lg: bootstrap_lg, + order: nil, + filter: nil + } + end +end \ No newline at end of file diff --git a/app/views/backoffice/dossiers/_list.html.haml b/app/views/backoffice/dossiers/_list.html.haml index 6307fff8c..3afa85d7a 100644 --- a/app/views/backoffice/dossiers/_list.html.haml +++ b/app/views/backoffice/dossiers/_list.html.haml @@ -1,21 +1,25 @@ - unless smart_listing.empty? %table.table %thead - %th= smart_listing.sortable 'Procédure', 'procedure.libelle' - %th= smart_listing.sortable 'Raison sociale', 'entreprise.raison_sociale' - %th= smart_listing.sortable 'État', 'state' - %th= smart_listing.sortable 'Date de mise à jour', 'updated_at' - %th.center Actions - %th.center Abonnés + - current_gestionnaire.preference_list_dossiers.order(:id).each do |preference| + %th{class: "col-md-#{preference.bootstrap_lg} col-lg-#{preference.bootstrap_lg}"}= smart_listing.sortable preference.libelle, preference.table_attr + %th.col-md-1.col-lg-1.center Actions + %th.col-md-1.col-lg-1.center Abonnés - @dossiers.each do |dossier| - - dossier = dossier.decorate %tr - %td.col-md-4.col-lg-4= dossier.procedure.libelle - %td.col-md-4.col-lg-4 - = link_to(dossier.entreprise.raison_sociale, "/backoffice/dossiers/#{dossier.id}") - %td= dossier.display_state - %td= dossier.last_update + - current_gestionnaire.preference_list_dossiers.order(:id).each_with_index do |preference, index| + %td + - if preference.table.empty? + - value = dossier.decorate.public_send(preference.attr_decorate) + - else + - value = dossier.public_send(preference.table).decorate.public_send(preference.attr_decorate) + + - if index == 0 + = link_to value, backoffice_dossier_path(id: dossier.id) + - else + = value + %td.center - if current_gestionnaire.follow?(dossier.id) = link_to('Quitter'.html_safe, backoffice_dossier_follow_path(dossier_id: dossier.id), 'data-method' => :put, class: 'btn-sm btn-danger', id: "suivre_dossier_#{dossier.id}") @@ -26,6 +30,7 @@ = smart_listing.paginate = smart_listing.pagination_per_page_links + - else %h4.center - Aucun dossier + Aucun dossier \ 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 589b12fce..29ff955e7 100644 --- a/app/views/backoffice/dossiers/_onglets.html.haml +++ b/app/views/backoffice/dossiers/_onglets.html.haml @@ -31,12 +31,20 @@ .badge.progress-bar-success =@dossiers_termine_total - %li#search{class: "#{'active' unless @dossiers_search.nil?}", style:'float:right'} - %a - = form_tag(backoffice_dossiers_search_url, method: :get) do - .input-group{style:'width: 300px'} - = text_field_tag('q', "#{@search_terms unless @search_terms.nil? }", id: 'q', placeholder: "Rechercher un dossier ...", class:'form-control') - %span.input-group-btn - %button.btn.btn-default{ id:'search_button' } - %i.fa.fa-search + %ul.nav.nav-tabs.navbar-right{style:'border-bottom: none;'} + %li#search{class: "#{'active' unless @dossiers_search.nil?}"} + %a + = form_tag(backoffice_dossiers_search_url, method: :get) do + .input-group{style:'width: 300px'} + = text_field_tag('q', "#{@search_terms unless @search_terms.nil? }", id: 'q', placeholder: "Rechercher un dossier ...", class:'form-control') + %span.input-group-btn + %button.btn.btn-default{ id:'search_button' } + %i.fa.fa-search + + - if @dossiers_search.nil? + %li#pref_list + %a.btn#pref_list_dossier_open_action{href: '#'} + %i.fa.fa-columns + + %br \ No newline at end of file diff --git a/app/views/backoffice/dossiers/_pref_list.html.haml b/app/views/backoffice/dossiers/_pref_list.html.haml new file mode 100644 index 000000000..e802bb638 --- /dev/null +++ b/app/views/backoffice/dossiers/_pref_list.html.haml @@ -0,0 +1,43 @@ +%button#pref_list_dossier_close_action.btn.btn-danger.btn-xs{style:'float:right'} + %i.fa.fa-close +%h3 Gestion de colonnes affichées + +%p{style:'margin-top: 15px; margin-bottom: 20px'} + Ce menu vous permet de choisir les différentes colonnes que vous souhaitez voir apparaitrent dans votre interface de suivi des dossiers. + +%h4.text-primary + Actuelles + +%ul + - current_gestionnaire.preference_list_dossiers.order(:id).each_with_index do |preference, index| + %li + = form_tag backoffice_preference_list_dossier_delete_path, method: :delete, remote: true do + = hidden_field_tag :pref_id, preference.id + = preference.libelle + %button.btn.btn-default.btn-xs{type: :submit, id: "delete_pref_list_#{preference[:table]}_#{preference[:attr]}"} + %i.fa.fa-minus + +%h4.text-success{style:'margin-top: 15px'} + Disponibles + +%table + - PreferenceListDossier.available_columns.each_with_index do |tables, index| + - if index%2 == 0 + %tr + + %td.col-sm-5.col-md-5.col-lg-5{style: 'vertical-align: top'} + %h5= tables.first.to_s.gsub('_', ' ').capitalize + %ul + - tables.second.each do |columns| + %li + = form_tag backoffice_preference_list_dossier_add_path, method: :post, remote: true do + = hidden_field_tag :libelle, columns.second[:libelle] + = hidden_field_tag :table, columns.second[:table] + = hidden_field_tag :attr, columns.second[:attr] + = hidden_field_tag :attr_decorate, columns.second[:attr_decorate] + = hidden_field_tag :bootstrap_lg, columns.second[:bootstrap_lg] + + = columns.second[:libelle] + %button.btn.btn-default.btn-xs{type: :submit, id: "add_pref_list_#{columns.second[:table]}_#{columns.second[:attr]}"} + %i.fa.fa-plus + diff --git a/app/views/backoffice/dossiers/_pref_list.js.erb b/app/views/backoffice/dossiers/_pref_list.js.erb new file mode 100644 index 000000000..2d421e10f --- /dev/null +++ b/app/views/backoffice/dossiers/_pref_list.js.erb @@ -0,0 +1,14 @@ +$.ajax({ + method: 'get', + url: '/backoffice/preference_list_dossier/reload_smartlisting', + async: true +}); + +$.ajax({ + methd: 'get', + url: '/backoffice/preference_list_dossier/reload_pref_list', + async: true +}).done(function (data) { + $("#pref_list_menu").html(data); + pref_list_dossier_actions(); +}); diff --git a/app/views/backoffice/dossiers/index.html.haml b/app/views/backoffice/dossiers/index.html.haml index d6095bffd..f6156379e 100644 --- a/app/views/backoffice/dossiers/index.html.haml +++ b/app/views/backoffice/dossiers/index.html.haml @@ -1,4 +1,6 @@ #backoffice_index + #pref_list_menu + = render partial: 'pref_list' = render partial: 'onglets' = smart_listing_render :dossiers diff --git a/app/views/layouts/application.html.haml b/app/views/layouts/application.html.haml index 440c59544..7fb7c8008 100644 --- a/app/views/layouts/application.html.haml +++ b/app/views/layouts/application.html.haml @@ -7,9 +7,15 @@ = stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track' => true = stylesheet_link_tag 'application_split2', media: 'all', 'data-turbolinks-track' => true + + = javascript_include_tag 'application', 'data-turbolinks-track' => true = csrf_meta_tags %body + - if Rails.env == 'test' + %script{type: 'text/javascript'} + (typeof jQuery !== 'undefined') && (jQuery.fx.off = true); + %div#wrap %div#header.navbar =render partial: "layouts/navbar" diff --git a/config/routes.rb b/config/routes.rb index cc657c43d..cb11c81c3 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -139,6 +139,14 @@ Rails.application.routes.draw do patch 'filtres/update' => 'procedure_filter#update' + namespace :preference_list_dossier do + post 'add' + delete 'delete' + + get 'reload_smartlisting' => '/backoffice/dossiers#reload_smartlisting' + get 'reload_pref_list' + end + resources :dossiers do post 'valid' => 'dossiers#valid' post 'close' => 'dossiers#close' diff --git a/db/migrate/20160722135927_add_preference_list_dossier_table.rb b/db/migrate/20160722135927_add_preference_list_dossier_table.rb new file mode 100644 index 000000000..d638ee92f --- /dev/null +++ b/db/migrate/20160722135927_add_preference_list_dossier_table.rb @@ -0,0 +1,15 @@ +class AddPreferenceListDossierTable < ActiveRecord::Migration + def change + create_table :preference_list_dossiers do |t| + t.string :libelle + t.string :table + t.string :attr + t.string :attr_decorate + t.string :bootstrap_lg + t.string :order + t.string :filter + end + + add_belongs_to :preference_list_dossiers, :gestionnaire + end +end diff --git a/db/schema.rb b/db/schema.rb index 1dacf946f..0a0f042e0 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -11,7 +11,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 20160718124741) do +ActiveRecord::Schema.define(version: 20160722135927) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -234,6 +234,17 @@ ActiveRecord::Schema.define(version: 20160718124741) do add_index "pieces_justificatives", ["type_de_piece_justificative_id"], name: "index_pieces_justificatives_on_type_de_piece_justificative_id", using: :btree + create_table "preference_list_dossiers", force: :cascade do |t| + t.string "libelle" + t.string "table" + t.string "attr" + t.string "attr_decorate" + t.string "bootstrap_lg" + t.string "order" + t.string "filter" + t.integer "gestionnaire_id" + end + create_table "procedure_paths", force: :cascade do |t| t.string "path", limit: 30 t.integer "procedure_id" diff --git a/spec/controllers/backoffice/preference_list_dossier_controller_spec.rb b/spec/controllers/backoffice/preference_list_dossier_controller_spec.rb new file mode 100644 index 000000000..ecf6c25f0 --- /dev/null +++ b/spec/controllers/backoffice/preference_list_dossier_controller_spec.rb @@ -0,0 +1,51 @@ +require 'spec_helper' + +describe Backoffice::PreferenceListDossierController, type: :controller do + let(:gestionnaire) { create :gestionnaire } + let(:libelle) { 'Plop' } + let(:table) { 'plip' } + let(:attr) { 'plap' } + let(:attr_decorate) { 'plup' } + let(:bootstrap_lg) { 'plyp' } + + before do + sign_in gestionnaire + end + + describe '#POST add' do + subject { post :add, libelle: libelle, + table: table, + attr: attr, + attr_decorate: attr_decorate, + bootstrap_lg: bootstrap_lg } + + it { expect(subject.status).to eq 200 } + it { expect { subject }.to change(PreferenceListDossier, :count).by(1) } + + describe 'attributs' do + let(:last) { PreferenceListDossier.last } + + before do + subject + end + + it { expect(last.libelle).to eq libelle } + it { expect(last.table).to eq table } + it { expect(last.attr).to eq attr } + it { expect(last.attr_decorate).to eq attr_decorate } + it { expect(last.bootstrap_lg).to eq bootstrap_lg } + it { expect(last.order).to be_nil } + it { expect(last.filter).to be_nil } + it { expect(last.gestionnaire).to eq gestionnaire } + end + end + + describe '#DELETE delete' do + let!(:pref) { create :preference_list_dossier } + + subject { delete :delete, pref_id: pref.id } + + it { expect(subject.status).to eq 200 } + it { expect { subject }.to change(PreferenceListDossier, :count).by(-1) } + end +end diff --git a/spec/factories/preference_list_dossier.rb b/spec/factories/preference_list_dossier.rb new file mode 100644 index 000000000..cda3b8c11 --- /dev/null +++ b/spec/factories/preference_list_dossier.rb @@ -0,0 +1,11 @@ +FactoryGirl.define do + factory :preference_list_dossier do + libelle 'Procedure' + table 'procedure' + attr 'libelle' + attr_decorate 'libelle' + order nil + filter nil + bootstrap_lg 1 + end +end diff --git a/spec/features/backoffice/lateral_page_pref_list_dossier_backoffice_spec.rb b/spec/features/backoffice/lateral_page_pref_list_dossier_backoffice_spec.rb new file mode 100644 index 000000000..e2fe77a4d --- /dev/null +++ b/spec/features/backoffice/lateral_page_pref_list_dossier_backoffice_spec.rb @@ -0,0 +1,86 @@ +require 'spec_helper' + +feature 'usage of pref list dossier lateral panel', js: true do + + let(:administrateur) { create(:administrateur) } + let(:gestionnaire) { create(:gestionnaire, administrateurs: [administrateur]) } + let(:procedure) { create(:procedure, administrateur: administrateur) } + + before do + create(:dossier, :with_entreprise, procedure: procedure, state: 'initiated') + create :assign_to, procedure: procedure, gestionnaire: gestionnaire + visit backoffice_path + end + + scenario 'he is redirected to /gestionnaires/sign_id' do + expect(page).to have_css('#gestionnaire_login') + end + + context 'when user enter good credentials' do + before do + page.find_by_id(:gestionnaire_email).set gestionnaire.email + page.find_by_id(:gestionnaire_password).set gestionnaire.password + page.click_on 'Se connecter' + end + + scenario 'he is redirected to /backoffice' do + expect(page).to have_css('#backoffice_index') + end + + scenario 'lateral panel is masked' do + expect(page).to have_css('#pref_list_menu', visible: false) + end + + context 'when on click on pref list button' do + before do + page.click_on 'pref_list_dossier_open_action' + end + + scenario 'lateral panel is appeared' do + expect(page).to have_css('#pref_list_menu') + end + + context 'when on click on add attribut button' do + before do + page.click_on 'add_pref_list_entreprise_siren' + end + + scenario 'preference list panel is brought up to date' do + wait_for_ajax + expect(page).to have_css('#delete_pref_list_entreprise_siren') + end + + scenario 'dossier is brought up to date' do + wait_for_ajax + expect(page).to have_selector("a.sortable[data-attr='entreprise.siren']") + end + + context 'when on click on delete attribut button' do + before do + page.click_on 'delete_pref_list_entreprise_siren' + end + + scenario 'preference list panel is brought up to date' do + wait_for_ajax + expect(page).not_to have_css('#delete_pref_list_entreprise_siren') + end + + scenario 'dossier is brought up to date' do + wait_for_ajax + expect(page).not_to have_selector("a.sortable[data-attr='entreprise.siren']") + end + + context 'when on click on close pref list button' do + before do + page.click_on 'pref_list_dossier_close_action' + end + + scenario 'lateral panel is masked' do + expect(page).to have_css('#pref_list_menu', visible: false) + end + end + end + end + end + end +end \ No newline at end of file diff --git a/spec/features/backoffice/navigate_to_dossier_spec.rb b/spec/features/backoffice/navigate_to_dossier_spec.rb index 4a3664a99..05114df6e 100644 --- a/spec/features/backoffice/navigate_to_dossier_spec.rb +++ b/spec/features/backoffice/navigate_to_dossier_spec.rb @@ -9,6 +9,13 @@ feature 'on backoffice page' do before do create :assign_to, gestionnaire: gestionnaire, procedure: procedure + + create :preference_list_dossier, + gestionnaire: gestionnaire, + table: 'entreprise', + attr: 'raison_sociale', + attr_decorate: 'raison_sociale' + visit backoffice_path end @@ -17,6 +24,8 @@ feature 'on backoffice page' do page.find_by_id(:gestionnaire_email).set gestionnaire.email page.find_by_id(:gestionnaire_password).set gestionnaire.password page.click_on 'Se connecter' + + end context 'when he click on first dossier' do before do diff --git a/spec/models/dossier_spec.rb b/spec/models/dossier_spec.rb index b26b8243e..3a789effc 100644 --- a/spec/models/dossier_spec.rb +++ b/spec/models/dossier_spec.rb @@ -33,6 +33,7 @@ describe Dossier do it { is_expected.to delegate_method(:siret).to(:etablissement) } it { is_expected.to delegate_method(:types_de_piece_justificative).to(:procedure) } it { is_expected.to delegate_method(:types_de_champ).to(:procedure) } + it { is_expected.to delegate_method(:france_connect_information).to(:user) } end describe 'methods' do diff --git a/spec/models/gestionnaire_spec.rb b/spec/models/gestionnaire_spec.rb index 17a8b55a2..e485b028f 100644 --- a/spec/models/gestionnaire_spec.rb +++ b/spec/models/gestionnaire_spec.rb @@ -32,6 +32,7 @@ describe Gestionnaire, type: :model do it { is_expected.to have_many(:procedures) } it { is_expected.to have_many(:dossiers) } it { is_expected.to have_many(:follows) } + it { is_expected.to have_many(:preference_list_dossiers) } end describe '#dossiers_filter' do diff --git a/spec/models/preference_list_dossier_spec.rb b/spec/models/preference_list_dossier_spec.rb new file mode 100644 index 000000000..e65b377fb --- /dev/null +++ b/spec/models/preference_list_dossier_spec.rb @@ -0,0 +1,253 @@ +require 'spec_helper' + +describe PreferenceListDossier do + it { is_expected.to have_db_column(:libelle) } + it { is_expected.to have_db_column(:table) } + it { is_expected.to have_db_column(:attr) } + it { is_expected.to have_db_column(:attr_decorate) } + it { is_expected.to have_db_column(:bootstrap_lg) } + it { is_expected.to have_db_column(:order) } + it { is_expected.to have_db_column(:filter) } + it { is_expected.to have_db_column(:gestionnaire_id) } + + it { is_expected.to belong_to(:gestionnaire) } + + describe '.available_columns' do + subject { PreferenceListDossier.available_columns } + + describe 'dossier' do + subject { super()[:dossier] } + + it { expect(subject.size).to eq 4 } + + describe 'dossier_id' do + subject { super()[:dossier_id] } + + it { expect(subject[:libelle]).to eq 'ID' } + it { expect(subject[:table]).to be_nil } + it { expect(subject[:attr]).to eq 'id' } + it { expect(subject[:attr_decorate]).to eq 'id' } + it { expect(subject[:bootstrap_lg]).to eq 1 } + it { expect(subject[:order]).to be_nil } + it { expect(subject[:filter]).to be_nil } + end + + describe 'created_at' do + subject { super()[:created_at] } + + it { expect(subject[:libelle]).to eq 'Créé le' } + it { expect(subject[:table]).to be_nil } + it { expect(subject[:attr]).to eq 'created_at' } + it { expect(subject[:attr_decorate]).to eq 'first_creation' } + it { expect(subject[:bootstrap_lg]).to eq 2 } + it { expect(subject[:order]).to be_nil } + it { expect(subject[:filter]).to be_nil } + end + + describe 'updated_at' do + subject { super()[:updated_at] } + + it { expect(subject[:libelle]).to eq 'Mise à jour le' } + it { expect(subject[:table]).to be_nil } + it { expect(subject[:attr]).to eq 'updated_at' } + it { expect(subject[:attr_decorate]).to eq 'last_update' } + it { expect(subject[:bootstrap_lg]).to eq 2 } + it { expect(subject[:order]).to be_nil } + it { expect(subject[:filter]).to be_nil } + end + + describe 'state' do + subject { super()[:state] } + + it { expect(subject[:libelle]).to eq 'Statut' } + it { expect(subject[:table]).to be_nil } + it { expect(subject[:attr]).to eq 'state' } + it { expect(subject[:attr_decorate]).to eq 'display_state' } + it { expect(subject[:bootstrap_lg]).to eq 1 } + it { expect(subject[:order]).to be_nil } + it { expect(subject[:filter]).to be_nil } + end + end + + describe 'procedure' do + subject { super()[:procedure] } + + it { expect(subject.size).to eq 3 } + + describe 'libelle' do + subject { super()[:libelle] } + + it { expect(subject[:libelle]).to eq 'Libellé procédure' } + it { expect(subject[:table]).to eq 'procedure' } + it { expect(subject[:attr]).to eq 'libelle' } + it { expect(subject[:attr_decorate]).to eq 'libelle' } + it { expect(subject[:bootstrap_lg]).to eq 4 } + it { expect(subject[:order]).to be_nil } + it { expect(subject[:filter]).to be_nil } + end + + describe 'organisation' do + subject { super()[:organisation] } + + it { expect(subject[:libelle]).to eq 'Organisation' } + it { expect(subject[:table]).to eq 'procedure' } + it { expect(subject[:attr]).to eq 'organisation' } + it { expect(subject[:attr_decorate]).to eq 'organisation' } + it { expect(subject[:bootstrap_lg]).to eq 3 } + it { expect(subject[:order]).to be_nil } + it { expect(subject[:filter]).to be_nil } + end + + describe 'direction' do + subject { super()[:direction] } + + it { expect(subject[:libelle]).to eq 'Direction' } + it { expect(subject[:table]).to eq 'procedure' } + it { expect(subject[:attr]).to eq 'direction' } + it { expect(subject[:attr_decorate]).to eq 'direction' } + it { expect(subject[:bootstrap_lg]).to eq 3 } + it { expect(subject[:order]).to be_nil } + it { expect(subject[:filter]).to be_nil } + end + end + + describe 'entreprise' do + subject { super()[:entreprise] } + + it { expect(subject.size).to eq 6 } + + describe 'siren' do + subject { super()[:siren] } + + it { expect(subject[:libelle]).to eq 'SIREN' } + it { expect(subject[:table]).to eq 'entreprise' } + it { expect(subject[:attr]).to eq 'siren' } + it { expect(subject[:attr_decorate]).to eq 'siren' } + it { expect(subject[:bootstrap_lg]).to eq 2 } + it { expect(subject[:order]).to be_nil } + it { expect(subject[:filter]).to be_nil } + end + + describe 'forme_juridique' do + subject { super()[:forme_juridique] } + + it { expect(subject[:libelle]).to eq 'Forme juridique' } + it { expect(subject[:table]).to eq 'entreprise' } + it { expect(subject[:attr]).to eq 'forme_juridique' } + it { expect(subject[:attr_decorate]).to eq 'forme_juridique' } + it { expect(subject[:bootstrap_lg]).to eq 3 } + it { expect(subject[:order]).to be_nil } + it { expect(subject[:filter]).to be_nil } + end + + describe 'nom_commercial' do + subject { super()[:nom_commercial] } + + it { expect(subject[:libelle]).to eq 'Nom commercial' } + it { expect(subject[:table]).to eq 'entreprise' } + it { expect(subject[:attr]).to eq 'nom_commercial' } + it { expect(subject[:attr_decorate]).to eq 'nom_commercial' } + it { expect(subject[:bootstrap_lg]).to eq 3 } + it { expect(subject[:order]).to be_nil } + it { expect(subject[:filter]).to be_nil } + end + + describe 'raison_sociale' do + subject { super()[:raison_sociale] } + + it { expect(subject[:libelle]).to eq 'Raison sociale' } + it { expect(subject[:table]).to eq 'entreprise' } + it { expect(subject[:attr]).to eq 'raison_sociale' } + it { expect(subject[:attr_decorate]).to eq 'raison_sociale' } + it { expect(subject[:bootstrap_lg]).to eq 3 } + it { expect(subject[:order]).to be_nil } + it { expect(subject[:filter]).to be_nil } + end + + describe 'siret_siege_social' do + subject { super()[:siret_siege_social] } + + it { expect(subject[:libelle]).to eq 'SIRET siège social' } + it { expect(subject[:table]).to eq 'entreprise' } + it { expect(subject[:attr]).to eq 'siret_siege_social' } + it { expect(subject[:attr_decorate]).to eq 'siret_siege_social' } + it { expect(subject[:bootstrap_lg]).to eq 2 } + it { expect(subject[:order]).to be_nil } + it { expect(subject[:filter]).to be_nil } + end + + describe 'date_creation' do + subject { super()[:date_creation] } + + it { expect(subject[:libelle]).to eq 'Date de création' } + it { expect(subject[:table]).to eq 'entreprise' } + it { expect(subject[:attr]).to eq 'date_creation' } + it { expect(subject[:attr_decorate]).to eq 'date_creation' } + it { expect(subject[:bootstrap_lg]).to eq 2 } + it { expect(subject[:order]).to be_nil } + it { expect(subject[:filter]).to be_nil } + end + + end + + describe 'etablissement' do + subject { super()[:etablissement] } + + it { expect(subject.size).to eq 3 } + + describe 'siret' do + subject { super()[:siret] } + + it { expect(subject[:libelle]).to eq 'SIRET' } + it { expect(subject[:table]).to eq 'etablissement' } + it { expect(subject[:attr]).to eq 'siret' } + it { expect(subject[:attr_decorate]).to eq 'siret' } + it { expect(subject[:bootstrap_lg]).to eq 2 } + it { expect(subject[:order]).to be_nil } + it { expect(subject[:filter]).to be_nil } + end + + describe 'libelle' do + subject { super()[:libelle] } + + it { expect(subject[:libelle]).to eq 'Nom établissement' } + it { expect(subject[:table]).to eq 'etablissement' } + it { expect(subject[:attr]).to eq 'libelle_naf' } + it { expect(subject[:attr_decorate]).to eq 'libelle_naf' } + it { expect(subject[:bootstrap_lg]).to eq 3 } + it { expect(subject[:order]).to be_nil } + it { expect(subject[:filter]).to be_nil } + end + + describe 'code_postal' do + subject { super()[:code_postal] } + + it { expect(subject[:libelle]).to eq 'Code postal' } + it { expect(subject[:table]).to eq 'etablissement' } + it { expect(subject[:attr]).to eq 'code_postal' } + it { expect(subject[:attr_decorate]).to eq 'code_postal' } + it { expect(subject[:bootstrap_lg]).to eq 1 } + it { expect(subject[:order]).to be_nil } + it { expect(subject[:filter]).to be_nil } + end + end + + describe 'user' do + subject { super()[:user] } + + it { expect(subject.size).to eq 1 } + + describe 'email' do + subject { super()[:email] } + + it { expect(subject[:libelle]).to eq 'Email' } + it { expect(subject[:table]).to eq 'user' } + it { expect(subject[:attr]).to eq 'email' } + it { expect(subject[:attr_decorate]).to eq 'email' } + it { expect(subject[:bootstrap_lg]).to eq 2 } + it { expect(subject[:order]).to be_nil } + it { expect(subject[:filter]).to be_nil } + end + end + end +end diff --git a/spec/views/backoffice/dossiers/index_html.haml_spec.rb b/spec/views/backoffice/dossiers/index_html.haml_spec.rb index a8d59f286..382caf9a6 100644 --- a/spec/views/backoffice/dossiers/index_html.haml_spec.rb +++ b/spec/views/backoffice/dossiers/index_html.haml_spec.rb @@ -15,6 +15,30 @@ describe 'backoffice/dossiers/index.html.haml', type: :view do decorate_dossier_closed.entreprise.update_column(:raison_sociale, 'plip') decorate_dossier_replied.entreprise.update_column(:raison_sociale, 'plop') + create :preference_list_dossier, + gestionnaire: gestionnaire, + table: '', + attr: 'state', + attr_decorate: 'display_state' + + create :preference_list_dossier, + gestionnaire: gestionnaire, + table: 'procedure', + attr: 'libelle', + attr_decorate: 'libelle' + + create :preference_list_dossier, + gestionnaire: gestionnaire, + table: 'entreprise', + attr: 'raison_sociale', + attr_decorate: 'raison_sociale' + + create :preference_list_dossier, + gestionnaire: gestionnaire, + table: '', + attr: 'last_update', + attr_decorate: 'last_update' + create :assign_to, gestionnaire: gestionnaire, procedure: procedure sign_in gestionnaire end