Merge branch 'staging'

This commit is contained in:
Xavier J 2016-08-22 17:17:30 +02:00
commit fef5ee140a
104 changed files with 2127 additions and 269 deletions

View file

@ -26,13 +26,19 @@ function on_change_type_de_champ_select (){
$("select.form-control.type_champ").on('change', function(e){ $("select.form-control.type_champ").on('change', function(e){
parent = $(this).parent().parent() parent = $(this).parent().parent();
parent.removeClass('header_section');
parent.children(".drop_down_list").removeClass('show_inline');
switch(this.value){
case 'header_section':
parent.addClass('header_section');
break;
case 'drop_down_list':
parent.children(".drop_down_list").addClass('show_inline');
break;
if (this.value === 'header_section') {
parent.addClass('header_section')
}
else {
parent.removeClass('header_section')
} }
}) })
} }

View file

@ -44,5 +44,3 @@ function scroll_to() {
}); });
} }

View file

@ -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');
}
}
)
});
}

View file

@ -14,5 +14,14 @@
.form-group.mandatory { .form-group.mandatory {
display: none; display: none;
} }
}
#liste_champ{
.show_inline {
display: inline-block !important;
}
.form-group.drop_down_list{
display: none;
}
} }

View file

@ -184,7 +184,7 @@ div.pagination {
.alert.alert-success.move_up, .alert.alert-success.move_up,
.alert.alert-danger.siret{ .alert.alert-danger.siret{
position: absolute; position: fixed;
top: 0px; top: 0px;
left: 0; left: 0;
height: 52px; height: 52px;

View file

@ -6,6 +6,18 @@
} }
} }
#backoffice_index, #backoffice_search {
margin-left: -7rem;
margin-right: -7rem;
}
#pref_list{
.dropdown-menu {
padding: 10px;
width: 500px;
}
}
#onglets { #onglets {
ul { ul {
li, li.active { li, li.active {

View file

@ -57,6 +57,12 @@
} }
} }
.type_champ-drop_down_list {
@extend .col-md-4;
@extend .col-lg-4;
}
.type_champ-civilite { .type_champ-civilite {
@extend .col-md-3; @extend .col-md-3;
@extend .col-lg-3; @extend .col-lg-3;

View file

@ -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;
}

View file

@ -4,29 +4,27 @@ class Admin::TypesDeChampController < AdminController
def destroy def destroy
@procedure.types_de_champ.destroy(params[:id]) @procedure.types_de_champ.destroy(params[:id])
create_facade
render 'show', format: :js render 'show', format: :js
rescue ActiveRecord::RecordNotFound rescue ActiveRecord::RecordNotFound
render json: { message: 'Champ not found' }, status: 404 render json: {message: 'Champ not found'}, status: 404
end end
def show def show
create_facade
end end
def update def update
@procedure.update_attributes(update_params) @procedure.update_attributes(TypesDeChampService.create_update_procedure_params params)
create_facade
flash.now.notice = 'Modifications sauvegardées' flash.now.notice = 'Modifications sauvegardées'
render 'show', format: :js render 'show', format: :js
end end
def update_params
params
.require(:procedure)
.permit(types_de_champ_attributes: [:libelle, :description, :order_place, :type_champ, :id, :mandatory])
end
def move_up def move_up
index = params[:index].to_i - 1 index = params[:index].to_i - 1
if @procedure.switch_types_de_champ index if @procedure.switch_types_de_champ index
create_facade
render 'show', format: :js render 'show', format: :js
else else
render json: {}, status: 400 render json: {}, status: 400
@ -35,9 +33,16 @@ class Admin::TypesDeChampController < AdminController
def move_down def move_down
if @procedure.switch_types_de_champ params[:index].to_i if @procedure.switch_types_de_champ params[:index].to_i
create_facade
render 'show', format: :js render 'show', format: :js
else else
render json: {}, status: 400 render json: {}, status: 400
end end
end end
private
def create_facade
@types_de_champ_facade = AdminTypesDeChampFacades.new false, @procedure
end
end end

View file

@ -0,0 +1,49 @@
class Admin::TypesDeChampPrivateController < AdminController
before_action :retrieve_procedure
before_action :procedure_locked?
def destroy
@procedure.types_de_champ_private.destroy(params[:id])
create_facade
render 'admin/types_de_champ/show', format: :js
rescue ActiveRecord::RecordNotFound
render json: {message: 'Champ not found'}, status: 404
end
def show
create_facade
render 'admin/types_de_champ/show'
end
def update
@procedure.update_attributes(TypesDeChampService.create_update_procedure_params params, true)
create_facade
flash.now.notice = 'Modifications sauvegardées'
render 'admin/types_de_champ/show', format: :js
end
def move_up
index = params[:index].to_i - 1
if @procedure.switch_types_de_champ_private index
create_facade
render 'admin/types_de_champ/show', format: :js
else
render json: {}, status: 400
end
end
def move_down
if @procedure.switch_types_de_champ_private params[:index].to_i
create_facade
render 'admin/types_de_champ/show', format: :js
else
render json: {}, status: 400
end
end
private
def create_facade
@types_de_champ_facade = AdminTypesDeChampFacades.new true, @procedure
end
end

View file

@ -7,16 +7,14 @@ class Backoffice::DossiersController < ApplicationController
def index def index
@liste = params[:liste] || 'a_traiter' @liste = params[:liste] || 'a_traiter'
@dossiers = smart_listing_create :dossiers, smartlisting_dossier
dossiers_to_display,
partial: "backoffice/dossiers/list",
array: true
total_dossiers_per_state total_dossiers_per_state
end end
def show def show
create_dossier_facade params[:id] create_dossier_facade params[:id]
@champs = @facade.champs_private unless @facade.nil?
end end
def search def search
@ -61,8 +59,26 @@ class Backoffice::DossiersController < ApplicationController
redirect_to request.referer redirect_to request.referer
end 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 private
def smartlisting_dossier
@dossiers = smart_listing_create :dossiers,
dossiers_to_display,
partial: "backoffice/dossiers/list",
array: true
end
def dossiers_to_display def dossiers_to_display
{'a_traiter' => waiting_for_gestionnaire, {'a_traiter' => waiting_for_gestionnaire,
'en_attente' => waiting_for_user, 'en_attente' => waiting_for_user,

View file

@ -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

View file

@ -0,0 +1,19 @@
class Backoffice::PrivateFormulairesController < ApplicationController
before_action :authenticate_gestionnaire!
def update
dossier = current_gestionnaire.dossiers.find(params[:dossier_id])
unless params[:champs].nil?
champs_service_errors = ChampsService.save_formulaire dossier.champs_private, params
if champs_service_errors.empty?
flash[:notice] = "Formulaire enregistré"
else
flash[:alert] = (champs_service_errors.inject('') { |acc, error| acc+= error[:message]+'<br>' }).html_safe
end
end
render 'backoffice/dossiers/formulaire_private', formats: :js
end
end

View file

@ -43,23 +43,11 @@ class Users::DescriptionController < UsersController
end end
unless params[:champs].nil? unless params[:champs].nil?
@dossier.champs.each do |champ| champs_service_errors = ChampsService.save_formulaire @dossier.champs, params
champ.value = params[:champs]["'#{champ.id}'"]
if champ.type_champ == 'datetime' unless champs_service_errors.empty?
champ.value = params[:champs]["'#{champ.id}'"]+ flash.now.alert = (champs_service_errors.inject('') {|acc, error| acc+= error[:message]+'<br>' }).html_safe
' ' + return render 'show'
params[:time_hour]["'#{champ.id}'"] +
':' +
params[:time_minute]["'#{champ.id}'"]
end
if champ.mandatory? && (champ.value.nil? || champ.value.blank?)
flash.now.alert = "Le champ #{champ.libelle} doit être rempli."
return render 'show'
end
champ.save
end end
end end

View file

@ -19,11 +19,9 @@ class Users::RecapitulatifController < UsersController
def submit def submit
create_dossier_facade create_dossier_facade
@facade.dossier.next_step! 'user', 'submit' @facade.dossier.submit!
flash.notice = 'Dossier déposé avec succès.' flash.notice = 'Dossier déposé avec succès.'
NotificationMailer.dossier_submitted(@facade.dossier).deliver_now!
render 'show' render 'show'
end end

View file

@ -8,6 +8,10 @@ class DossierDecorator < Draper::Decorator
'dd/mm/YYYY' 'dd/mm/YYYY'
end end
def first_creation
created_at.localtime.strftime('%d/%m/%Y %H:%M')
end
def last_update def last_update
updated_at.localtime.strftime('%d/%m/%Y %H:%M') updated_at.localtime.strftime('%d/%m/%Y %H:%M')
end end

View file

@ -0,0 +1,4 @@
class EtablissementDecorator < Draper::Decorator
delegate_all
end

View file

@ -0,0 +1,4 @@
class FranceConnectInformationDecorator < Draper::Decorator
delegate_all
end

View file

@ -1,12 +1,13 @@
class TypeDeChampDecorator < Draper::Decorator class TypeDeChampDecorator < Draper::Decorator
delegate_all delegate_all
def button_up params def button_up params
h.link_to '', params[:url], class: up_classes, id: "btn_up_#{params[:index]}", remote: true, method: :post if display_up_button?(params[:index]) h.link_to '', params[:url], class: up_classes, id: "btn_up_#{params[:index]}", remote: true, method: :post if display_up_button?(params[:index], params[:private])
end end
def button_down params def button_down params
h.link_to '', params[:url], class: down_classes, id: "btn_down_#{params[:index]}", remote: true, method: :post if display_down_button?(params[:index]) h.link_to '', params[:url], class: down_classes, id: "btn_down_#{params[:index]}", remote: true, method: :post if display_down_button?(params[:index], params[:private])
end end
private private
@ -23,15 +24,19 @@ class TypeDeChampDecorator < Draper::Decorator
%w(btn btn-default form-control fa) %w(btn btn-default form-control fa)
end end
def display_up_button?(index) def display_up_button?(index, private)
!(index == 0 || count_type_de_champ < 2) !(index == 0 || count_type_de_champ(private) < 2)
end end
def display_down_button?(index) def display_down_button?(index, private)
(index + 1) < count_type_de_champ (index + 1) < count_type_de_champ(private)
end end
def count_type_de_champ def count_type_de_champ private
@count_type_de_champ ||= procedure.types_de_champ.count if private
@count_type_de_champ ||= procedure.types_de_champ_private.count
else
@count_type_de_champ ||= procedure.types_de_champ.count
end
end end
end end

View file

@ -0,0 +1,3 @@
class TypeDeChampPrivateDecorator < TypeDeChampDecorator
end

View file

@ -0,0 +1,48 @@
class AdminTypesDeChampFacades
include Rails.application.routes.url_helpers
def initialize private, procedure
@private = private
@procedure = procedure
end
def private
@private
end
def active
@private ? 'Champs privés' : 'Champs'
end
def url
@private ? admin_procedure_types_de_champ_private_path(@procedure) : admin_procedure_types_de_champ_path(@procedure)
end
def types_de_champ
@private ? @procedure.types_de_champ_private_ordered.decorate : @procedure.types_de_champ_ordered.decorate
end
def new_type_de_champ
@private ? TypeDeChampPrivate.new.decorate : TypeDeChampPublic.new.decorate
end
def fields_for_var
@private ? :types_de_champ_private : :types_de_champ
end
def move_up_url ff
@private ? move_up_admin_procedure_types_de_champ_private_path(@procedure, ff.index) : move_up_admin_procedure_types_de_champ_path(@procedure, ff.index)
end
def move_down_url ff
@private ? move_down_admin_procedure_types_de_champ_private_path(@procedure, ff.index) : move_down_admin_procedure_types_de_champ_path(@procedure, ff.index)
end
def delete_url ff
@private ? admin_procedure_type_de_champ_private_path(@procedure, ff.object.id) : admin_procedure_type_de_champ_path(@procedure, ff.object.id)
end
def add_button_id
@private ? :add_type_de_champ_private : :add_type_de_champ
end
end

View file

@ -46,6 +46,10 @@ class DossierFacades
@dossier.invites @dossier.invites
end end
def champs_private
@dossier.ordered_champs_private
end
def commentaires_files def commentaires_files
PieceJustificative.where(dossier_id: @dossier.id, type_de_piece_justificative_id: nil) PieceJustificative.where(dossier_id: @dossier.id, type_de_piece_justificative_id: nil)
end end

View file

@ -4,7 +4,7 @@ class NewAdminMailer < ApplicationMailer
@admin = admin @admin = admin
@password = password @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") subject: "Création d'un compte Admin TPS")
end end
end end

View file

@ -2,7 +2,7 @@ class Champ < ActiveRecord::Base
belongs_to :dossier belongs_to :dossier
belongs_to :type_de_champ belongs_to :type_de_champ
delegate :libelle, :type_champ, :order_place, :mandatory, :description, to: :type_de_champ delegate :libelle, :type_champ, :order_place, :mandatory, :description, :drop_down_list, to: :type_de_champ
def mandatory? def mandatory?
mandatory mandatory

View file

@ -0,0 +1,3 @@
class ChampPrivate < Champ
end

View file

@ -0,0 +1,3 @@
class ChampPublic < Champ
end

View file

@ -13,7 +13,8 @@ class Dossier < ActiveRecord::Base
has_many :cerfa, dependent: :destroy has_many :cerfa, dependent: :destroy
has_many :pieces_justificatives, dependent: :destroy has_many :pieces_justificatives, dependent: :destroy
has_many :champs, dependent: :destroy has_many :champs, class_name: 'ChampPublic', dependent: :destroy
has_many :champs_private, class_name: 'ChampPrivate', dependent: :destroy
has_many :quartier_prioritaires, dependent: :destroy has_many :quartier_prioritaires, dependent: :destroy
has_many :cadastres, dependent: :destroy has_many :cadastres, dependent: :destroy
has_many :commentaires, dependent: :destroy has_many :commentaires, dependent: :destroy
@ -27,6 +28,7 @@ class Dossier < ActiveRecord::Base
delegate :siret, to: :etablissement, allow_nil: true delegate :siret, to: :etablissement, allow_nil: true
delegate :types_de_piece_justificative, to: :procedure delegate :types_de_piece_justificative, to: :procedure
delegate :types_de_champ, 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? } after_save :build_default_champs, if: Proc.new { procedure_id_changed? }
@ -46,7 +48,11 @@ class Dossier < ActiveRecord::Base
def build_default_champs def build_default_champs
procedure.types_de_champ.each do |type_de_champ| procedure.types_de_champ.each do |type_de_champ|
Champ.create(type_de_champ_id: type_de_champ.id, dossier_id: id) ChampPublic.create(type_de_champ_id: type_de_champ.id, dossier_id: id)
end
procedure.types_de_champ_private.each do |type_de_champ|
ChampPrivate.create(type_de_champ_id: type_de_champ.id, dossier_id: id)
end end
end end
@ -54,6 +60,10 @@ class Dossier < ActiveRecord::Base
champs.joins(', types_de_champ').where("champs.type_de_champ_id = types_de_champ.id AND types_de_champ.procedure_id = #{procedure.id}").order('order_place') champs.joins(', types_de_champ').where("champs.type_de_champ_id = types_de_champ.id AND types_de_champ.procedure_id = #{procedure.id}").order('order_place')
end end
def ordered_champs_private
champs_private.joins(', types_de_champ').where("champs.type_de_champ_id = types_de_champ.id AND types_de_champ.procedure_id = #{procedure.id}").order('order_place')
end
def ordered_commentaires def ordered_commentaires
commentaires.order(created_at: :desc) commentaires.order(created_at: :desc)
end end
@ -206,4 +216,11 @@ class Dossier < ActiveRecord::Base
def total_commentaire def total_commentaire
self.commentaires.size self.commentaires.size
end end
def submit!
self.deposit_datetime= DateTime.now
next_step! 'user', 'submit'
NotificationMailer.dossier_submitted(self).deliver_now!
end
end end

View file

@ -0,0 +1,7 @@
class DropDownList < ActiveRecord::Base
belongs_to :type_de_champ
def options
value.split(/[\r\n]|[\r]|[\n]|[\n\r]/).reject(&:empty?)
end
end

View file

@ -2,4 +2,6 @@ class Entreprise < ActiveRecord::Base
belongs_to :dossier belongs_to :dossier
has_one :etablissement, dependent: :destroy has_one :etablissement, dependent: :destroy
has_one :rna_information, dependent: :destroy has_one :rna_information, dependent: :destroy
validates_presence_of :siren
end end

View file

@ -8,6 +8,9 @@ class Gestionnaire < ActiveRecord::Base
has_many :procedures, through: :assign_to has_many :procedures, through: :assign_to
has_many :dossiers, through: :procedures has_many :dossiers, through: :procedures
has_many :follows has_many :follows
has_many :preference_list_dossiers
after_create :build_default_preferences_list_dossier
def dossiers_filter def dossiers_filter
dossiers.where(procedure_id: procedure_filter_list) dossiers.where(procedure_id: procedure_filter_list)
@ -37,4 +40,48 @@ class Gestionnaire < ActiveRecord::Base
Follow.where(gestionnaire_id: id, dossier_id: dossier_id).any? Follow.where(gestionnaire_id: id, dossier_id: dossier_id).any?
end end
def build_default_preferences_list_dossier
PreferenceListDossier.available_columns.each do |table|
table.second.each do |column|
if valid_couple_table_attr? table.first, column.first
PreferenceListDossier.create(
libelle: column.second[:libelle],
table: column.second[:table],
attr: column.second[:attr],
attr_decorate: column.second[:attr_decorate],
bootstrap_lg: column.second[:bootstrap_lg],
order: nil,
filter: nil,
gestionnaire: self
)
end
end
end
end
private
def valid_couple_table_attr? table, column
couples = [{
table: :dossier,
column: :dossier_id
}, {
table: :procedure,
column: :libelle
}, {
table: :etablissement,
column: :siret
}, {
table: :entreprise,
column: :raison_sociale
}, {
table: :dossier,
column: :state
}]
couples.include?({table: table, column: column})
end
end end

View file

@ -0,0 +1,94 @@
class PreferenceListDossier < ActiveRecord::Base
belongs_to :gestionnaire
def table_attr
return self.attr if table.nil? || 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

View file

@ -1,6 +1,7 @@
class Procedure < ActiveRecord::Base class Procedure < ActiveRecord::Base
has_many :types_de_piece_justificative, dependent: :destroy has_many :types_de_piece_justificative, dependent: :destroy
has_many :types_de_champ, dependent: :destroy has_many :types_de_champ, class_name: 'TypeDeChampPublic', dependent: :destroy
has_many :types_de_champ_private, dependent: :destroy
has_many :dossiers has_many :dossiers
has_one :procedure_path, dependent: :destroy has_one :procedure_path, dependent: :destroy
@ -17,6 +18,7 @@ class Procedure < ActiveRecord::Base
accepts_nested_attributes_for :types_de_champ,:reject_if => proc { |attributes| attributes['libelle'].blank? }, :allow_destroy => true accepts_nested_attributes_for :types_de_champ,:reject_if => proc { |attributes| attributes['libelle'].blank? }, :allow_destroy => true
accepts_nested_attributes_for :types_de_piece_justificative, :reject_if => proc { |attributes| attributes['libelle'].blank? }, :allow_destroy => true accepts_nested_attributes_for :types_de_piece_justificative, :reject_if => proc { |attributes| attributes['libelle'].blank? }, :allow_destroy => true
accepts_nested_attributes_for :module_api_carto accepts_nested_attributes_for :module_api_carto
accepts_nested_attributes_for :types_de_champ_private
mount_uploader :logo, ProcedureLogoUploader mount_uploader :logo, ProcedureLogoUploader
@ -35,6 +37,10 @@ class Procedure < ActiveRecord::Base
types_de_champ.order(:order_place) types_de_champ.order(:order_place)
end end
def types_de_champ_private_ordered
types_de_champ_private.order(:order_place)
end
def types_de_piece_justificative_ordered def types_de_piece_justificative_ordered
types_de_piece_justificative.order(:order_place) types_de_piece_justificative.order(:order_place)
end end
@ -51,6 +57,10 @@ class Procedure < ActiveRecord::Base
switch_list_order(types_de_champ_ordered, index_of_first_element) switch_list_order(types_de_champ_ordered, index_of_first_element)
end end
def switch_types_de_champ_private index_of_first_element
switch_list_order(types_de_champ_private_ordered, index_of_first_element)
end
def switch_types_de_piece_justificative index_of_first_element def switch_types_de_piece_justificative index_of_first_element
switch_list_order(types_de_piece_justificative_ordered, index_of_first_element) switch_list_order(types_de_piece_justificative_ordered, index_of_first_element)
end end

View file

@ -11,12 +11,17 @@ class TypeDeChamp < ActiveRecord::Base
phone: 'phone', phone: 'phone',
address: 'address', address: 'address',
yes_no: 'yes_no', yes_no: 'yes_no',
drop_down_list: 'drop_down_list',
header_section: 'header_section' header_section: 'header_section'
} }
belongs_to :procedure belongs_to :procedure
has_many :champ, dependent: :destroy has_many :champ, dependent: :destroy
has_one :drop_down_list
accepts_nested_attributes_for :drop_down_list
validates :libelle, presence: true, allow_blank: false, allow_nil: false validates :libelle, presence: true, allow_blank: false, allow_nil: false
validates :type_champ, presence: true, allow_blank: false, allow_nil: false validates :type_champ, presence: true, allow_blank: false, allow_nil: false

View file

@ -0,0 +1,3 @@
class TypeDeChampPrivate < TypeDeChamp
end

View file

@ -0,0 +1,3 @@
class TypeDeChampPublic < TypeDeChamp
end

View file

@ -0,0 +1,5 @@
class ChampPrivateSerializer < ActiveModel::Serializer
attributes :value
has_one :type_de_champ
end

View file

@ -0,0 +1,5 @@
class ChampPublicSerializer < ActiveModel::Serializer
attributes :value
has_one :type_de_champ
end

View file

@ -1,5 +0,0 @@
class ChampSerializer < ActiveModel::Serializer
attributes :value
has_one :type_de_champ
end

View file

@ -12,6 +12,7 @@ class DossierSerializer < ActiveModel::Serializer
has_many :cerfa has_many :cerfa
has_many :commentaires has_many :commentaires
has_many :champs has_many :champs
has_many :champs_private
has_many :pieces_justificatives has_many :pieces_justificatives
has_many :types_de_piece_justificative has_many :types_de_piece_justificative
end end

View file

@ -12,6 +12,7 @@ class ProcedureSerializer < ActiveModel::Serializer
has_one :geographic_information, serializer: ModuleApiCartoSerializer has_one :geographic_information, serializer: ModuleApiCartoSerializer
has_many :types_de_champ, serializer: TypeDeChampSerializer has_many :types_de_champ, serializer: TypeDeChampSerializer
has_many :types_de_piece_justificative, serializer: TypeDePieceJustificativeSerializer has_many :types_de_champ_private, serializer: TypeDeChampSerializer
has_many :types_de_piece_justificative, serializer: TypeDePieceJustificativeSerializer
end end

View file

@ -0,0 +1,25 @@
class ChampsService
def self.save_formulaire champs, params
errors = Array.new
champs.each do |champ|
champ.value = params[:champs]["'#{champ.id}'"]
if champ.type_champ == 'datetime'
champ.value = params[:champs]["'#{champ.id}'"]+
' ' +
params[:time_hour]["'#{champ.id}'"] +
':' +
params[:time_minute]["'#{champ.id}'"]
end
if champ.mandatory? && (champ.value.nil? || champ.value.blank?)
errors.push({message: "Le champ #{champ.libelle} doit être rempli."})
end
champ.save
end
errors
end
end

View file

@ -9,6 +9,10 @@ class DossierService
def dossier_informations! def dossier_informations!
@entreprise_adapter = SIADE::EntrepriseAdapter.new(DossierService.siren @siret) @entreprise_adapter = SIADE::EntrepriseAdapter.new(DossierService.siren @siret)
if @entreprise_adapter.to_params.nil?
raise RestClient::ResourceNotFound
end
@dossier.create_entreprise(@entreprise_adapter.to_params) @dossier.create_entreprise(@entreprise_adapter.to_params)
@etablissement_adapter = SIADE::EtablissementAdapter.new(@siret) @etablissement_adapter = SIADE::EtablissementAdapter.new(@siret)

View file

@ -0,0 +1,18 @@
class TypesDeChampService
def self.create_update_procedure_params(params, private=false)
attributes = (private ? 'types_de_champ_private_attributes' : 'types_de_champ_attributes')
parameters = params
.require(:procedure)
.permit("#{attributes}" => [:libelle, :description, :order_place, :type_champ, :id, :mandatory, :type,
drop_down_list_attributes: [:value, :id]])
parameters[attributes].each do |param|
if param.second[:libelle].empty?
parameters[attributes].delete(param.first.to_s)
end
end
parameters
end
end

View file

@ -16,5 +16,9 @@
= link_to_unless(@procedure.locked?, 'Pièces justificatives', admin_procedure_pieces_justificatives_path(@procedure)) do = link_to_unless(@procedure.locked?, 'Pièces justificatives', admin_procedure_pieces_justificatives_path(@procedure)) do
= link_to('Pièces justificatives', '#') = link_to('Pièces justificatives', '#')
%li{ class: ('disabled' if @procedure.locked?) || ('active' if active == 'Champs privés') }
= link_to_unless(@procedure.locked?, 'Champs privés', admin_procedure_types_de_champ_private_path(@procedure)) do
= link_to('Champs privés', '#')
%li{ class: ('active' if active == 'Prévisualisation'), style: 'float:right' } %li{ class: ('active' if active == 'Prévisualisation'), style: 'float:right' }
= link_to('Prévisualisation', admin_procedure_previsualisation_path(@procedure), {style: 'font-style: italic;'}) = link_to('Prévisualisation', admin_procedure_previsualisation_path(@procedure), {style: 'font-style: italic;'})

View file

@ -1,4 +1,4 @@
= f.fields_for :types_de_champ, types_de_champ, remote: true do |ff| = f.fields_for @types_de_champ_facade.fields_for_var, types_de_champ, remote: true do |ff|
.form-inline{class:"#{ff.object.object.type_champ == 'header_section' ? 'header_section' : ''}"} .form-inline{class:"#{ff.object.object.type_champ == 'header_section' ? 'header_section' : ''}"}
.form-group.libelle .form-group.libelle
%h4 Libellé %h4 Libellé
@ -10,28 +10,35 @@
.form-group.description .form-group.description
%h4 Description %h4 Description
= ff.text_area :description, class: 'form-control description', placeholder: 'Description' = ff.text_area :description, class: 'form-control description', placeholder: 'Description', rows: 2
.form-group.mandatory .form-group.drop_down_list{class:"#{ff.object.object.type_champ == 'drop_down_list' ? 'show_inline' : ''}",style:'margin-right: 5px'}
%h4 Obligatoire ? %h4 Liste déroulante
.center = ff.fields_for :drop_down_list_attributes, ff.object.object.drop_down_list do |fff|
= ff.check_box :mandatory, placeholder: 'Obligatoire ?' = fff.text_area :value, class: 'form-control drop_down_list', placeholder: "Ecrire une valeur par ligne.\nEcrire --valeur-- pour un séparateur.", rows: 3, cols: 30
= fff.hidden_field :id
- unless ff.object.object.class == TypeDeChampPrivate
.form-group.mandatory
%h4 Obligatoire ?
.center
= ff.check_box :mandatory, placeholder: 'Obligatoire ?'
.form-group .form-group
= ff.hidden_field :order_place, value: ff.index = ff.hidden_field :order_place, value: ff.index
= ff.hidden_field :type
= ff.hidden_field :id = ff.hidden_field :id
- unless ff.object.id.nil? - unless ff.object.id.nil?
.form-group .form-group
%br &nbsp; %br &nbsp;
= ff.object.button_up(index: ff.index, url: move_up_admin_procedure_types_de_champ_path(@procedure, ff.index)) = ff.object.button_up(index: ff.index, url: @types_de_champ_facade.move_up_url(ff), private: @types_de_champ_facade.private)
= ff.object.button_down(index: ff.index, url: move_down_admin_procedure_types_de_champ_path(@procedure, ff.index)) = ff.object.button_down(index: ff.index, url: @types_de_champ_facade.move_down_url(ff), private: @types_de_champ_facade.private)
.form-group .form-group
%br &nbsp; %br &nbsp;
- if ff.object.id.nil? - if ff.object.id.nil?
= f.submit "Ajouter le champ", class: 'btn btn-success', id: :add_type_de_champ = f.submit "Ajouter le champ", class: 'btn btn-success', id: @types_de_champ_facade.add_button_id
- else - else
= link_to("", admin_procedure_type_de_champ_path(@procedure, ff.object.id), method: :delete, remote: true, id: "delete_type_de_champ_#{ff.object.id}", class: %w(form-control btn btn-danger fa fa-trash-o) ) = link_to("", @types_de_champ_facade.delete_url(ff), method: :delete, remote: true, id: "delete_type_de_champ_#{ff.object.id}", class: %w(form-control btn btn-danger fa fa-trash-o) )

View file

@ -1,6 +1,6 @@
= form_for [:admin, @procedure], url: admin_procedure_types_de_champ_path(@procedure) , remote: true do |f| = form_for [:admin, @procedure], url: @types_de_champ_facade.url , remote: true do |f|
= render partial: 'fields', locals: { types_de_champ: @procedure.types_de_champ_ordered.decorate, f: f } = render partial: 'admin/types_de_champ/fields', locals: { types_de_champ: @types_de_champ_facade.types_de_champ, f: f }
= f.submit "Enregistrer", class: 'btn btn-success', id: :save = f.submit "Enregistrer", class: 'btn btn-success', id: :save
%hr %hr
#new_type_de_champ #new_type_de_champ
= render partial: 'fields', locals: { types_de_champ: TypeDeChamp.new.decorate, f: f } = render partial: 'admin/types_de_champ/fields', locals: { types_de_champ: @types_de_champ_facade.new_type_de_champ, f: f }

View file

@ -1,4 +1,4 @@
=render partial: 'admin/procedures/head', locals: {active: 'Champs'} =render partial: 'admin/procedures/head', locals: {active: @types_de_champ_facade.active}
#liste_champ #liste_champ
= render partial: 'form' = render partial: 'admin/types_de_champ/form'

View file

@ -1,5 +1,5 @@
<% flash.each do |type, message| %> <% flash.each do |type, message| %>
$("#flash_message").html("<div class=\"alert alert-success move_up\" style=\"display: block:\"> <%= message.html_safe %></div>").children().fadeOut(5000) $("#flash_message").html("<div class=\"alert alert-success move_up\" style=\"display: block:\"> <%= message.html_safe %></div>").children().fadeOut(5000)
<% end %> <% end %>
$('#liste_champ').html("<%= escape_javascript(render partial: 'form', locals: { procedure: @procedure, types_de_champ: @types_de_champ } ) %>"); $('#liste_champ').html("<%= escape_javascript(render partial: 'admin/types_de_champ/form', locals: { procedure: @procedure, types_de_champ: @types_de_champ } ) %>");
on_change_type_de_champ_select (); on_change_type_de_champ_select ();

View file

@ -1,21 +1,25 @@
- unless smart_listing.empty? - unless smart_listing.empty?
%table.table %table.table
%thead %thead
%th= smart_listing.sortable 'Procédure', 'procedure.libelle' - current_gestionnaire.preference_list_dossiers.order(:id).each do |preference|
%th= smart_listing.sortable 'Raison sociale', 'entreprise.raison_sociale' %th{class: "col-md-#{preference.bootstrap_lg} col-lg-#{preference.bootstrap_lg}"}= smart_listing.sortable preference.libelle, preference.table_attr
%th= smart_listing.sortable 'État', 'state' %th.col-md-1.col-lg-1.center Actions
%th= smart_listing.sortable 'Date de mise à jour', 'updated_at' %th.col-md-1.col-lg-1.center Abonnés
%th.center Actions
%th.center Abonnés
- @dossiers.each do |dossier| - @dossiers.each do |dossier|
- dossier = dossier.decorate
%tr %tr
%td.col-md-4.col-lg-4= dossier.procedure.libelle - current_gestionnaire.preference_list_dossiers.order(:id).each_with_index do |preference, index|
%td.col-md-4.col-lg-4 %td
= link_to(dossier.entreprise.raison_sociale, "/backoffice/dossiers/#{dossier.id}") - if preference.table.nil? || preference.table.empty?
%td= dossier.display_state - value = dossier.decorate.public_send(preference.attr_decorate)
%td= dossier.last_update - 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 %td.center
- if current_gestionnaire.follow?(dossier.id) - 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}") = 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.paginate
= smart_listing.pagination_per_page_links = smart_listing.pagination_per_page_links
- else - else
%h4.center %h4.center
Aucun dossier Aucun dossier

View file

@ -31,12 +31,20 @@
.badge.progress-bar-success .badge.progress-bar-success
=@dossiers_termine_total =@dossiers_termine_total
%li#search{class: "#{'active' unless @dossiers_search.nil?}", style:'float:right'} %ul.nav.nav-tabs.navbar-right{style:'border-bottom: none;'}
%a %li#search{class: "#{'active' unless @dossiers_search.nil?}"}
= form_tag(backoffice_dossiers_search_url, method: :get) do %a
.input-group{style:'width: 300px'} = form_tag(backoffice_dossiers_search_url, method: :get) do
= text_field_tag('q', "#{@search_terms unless @search_terms.nil? }", id: 'q', placeholder: "Rechercher un dossier ...", class:'form-control') .input-group{style:'width: 300px'}
%span.input-group-btn = text_field_tag('q', "#{@search_terms unless @search_terms.nil? }", id: 'q', placeholder: "Rechercher un dossier ...", class:'form-control')
%button.btn.btn-default{ id:'search_button' } %span.input-group-btn
%i.fa.fa-search %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 %br

View file

@ -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

View file

@ -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();
});

View file

@ -0,0 +1,4 @@
<% flash.each do |type, message| %>
$("#flash_message").html("<div class=\"alert alert-success move_up\" style=\"display: block:\"> <%= message.html_safe %></div>").children().fadeOut(5000)
<% end %>
<% flash.clear %>

View file

@ -1,4 +1,6 @@
#backoffice_index #backoffice_index
#pref_list_menu
= render partial: 'pref_list'
= render partial: 'onglets' = render partial: 'onglets'
= smart_listing_render :dossiers = smart_listing_render :dossiers

View file

@ -14,31 +14,5 @@
%br %br
%div %div
%ul{class: "nav nav-tabs", role: "tablist"} = render partial: 'dossiers/tab_objects_dossier'
%li{role: "presentation", class: "active"}
%a{href: "#commentaires", 'aria-controls' => "commentaires", role: "tab", 'data-toggle' => "tab"}
Commentaires
%li{role: "presentation"}
%a{href: "#commentaires_files", 'aria-controls' => "commentaires_files", role: "tab", 'data-toggle' => "tab"}
Fichiers
%li{role: "presentation"}
%a{href: "#invites", 'aria-controls' => "invites", role: "tab", 'data-toggle' => "tab"}
Invités
%li{role: "presentation"}
%a{href: "#followers", 'aria-controls' => "followers", role: "tab", 'data-toggle' => "tab"}
Abonnés
%div{class: "tab-content"}
%div{role: "tabpanel", class: "tab-pane fade in active", id:"commentaires"}
%h3 Flux de commentaires
%br
= render partial: '/users/recapitulatif/commentaires_flux'
%div{role: "tabpanel", class: "tab-pane fade", id:"commentaires_files"}
= render partial: '/dossiers/commentaires_files'
%div{role: "tabpanel", class: "tab-pane fade", id:"invites"}
= render partial: '/dossiers/invites'
%div{role: "tabpanel", class: "tab-pane fade", id:"followers"}
= render partial: 'followers'
%br
%br %br

View file

@ -0,0 +1,43 @@
%ul{class: "nav nav-tabs", role: "tablist"}
%li{role: "presentation", class: "active"}
%a{href: "#commentaires", 'aria-controls' => "commentaires", role: "tab", 'data-toggle' => "tab"}
Commentaires
%li{role: "presentation"}
%a{href: "#commentaires_files", 'aria-controls' => "commentaires_files", role: "tab", 'data-toggle' => "tab"}
Fichiers
- if gestionnaire_signed_in?
%li{role: "presentation"}
%a{href: "#invites", 'aria-controls' => "invites", role: "tab", 'data-toggle' => "tab"}
Invités
%li{role: "presentation"}
%a{href: "#followers", 'aria-controls' => "followers", role: "tab", 'data-toggle' => "tab"}
Abonnés
%li{role: "presentation"}
%a{href: "#champs_private", 'aria-controls' => "champs_private", role: "tab", 'data-toggle' => "tab"}
Formulaire
%div{class: "tab-content"}
%div{role: "tabpanel", class: "tab-pane fade in active", id:"commentaires"}
%h3 Flux de commentaires
%br
= render partial: '/users/recapitulatif/commentaires_flux'
%div{role: "tabpanel", class: "tab-pane fade", id:"commentaires_files"}
= render partial: '/dossiers/commentaires_files'
- if gestionnaire_signed_in?
%div{role: "tabpanel", class: "tab-pane fade", id:"invites"}
= render partial: '/dossiers/invites'
%div{role: "tabpanel", class: "tab-pane fade", id:"followers"}
= render partial: 'followers'
%div{role: "tabpanel", class: "tab-pane fade", id:"champs_private"}
%h3 Formulaire privé
- if @champs.nil? || @champs.empty?
%br
%h4.text-primary
Pas de formulaire privé pour ce dossier
- else
= form_for @facade.dossier, url: {controller: 'backoffice/private_formulaires', action: :update, dossier_id: @facade.dossier.id}, remote: true do
= render partial: '/users/description/champs'
%br
= submit_tag :Enregistrer, {class: 'btn btn-success', style: 'float: right'}

View file

@ -7,9 +7,15 @@
= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track' => true = stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track' => true
= stylesheet_link_tag 'application_split2', 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 = javascript_include_tag 'application', 'data-turbolinks-track' => true
= csrf_meta_tags = csrf_meta_tags
%body %body
- if Rails.env == 'test'
%script{type: 'text/javascript'}
(typeof jQuery !== 'undefined') && (jQuery.fx.off = true);
%div#wrap %div#wrap
%div#header.navbar %div#header.navbar
=render partial: "layouts/navbar" =render partial: "layouts/navbar"

View file

@ -30,6 +30,9 @@
- elsif champ.type_champ == 'yes_no' - elsif champ.type_champ == 'yes_no'
=render partial: 'users/description/champs/yes_no', locals: {champ: champ} =render partial: 'users/description/champs/yes_no', locals: {champ: champ}
- elsif champ.type_champ == 'drop_down_list'
=render partial: 'users/description/champs/drop_down_list', locals: {champ: champ}
-else -else
%input.form-control{name:"champs['#{champ.id}']", %input.form-control{name:"champs['#{champ.id}']",
placeholder: champ.libelle, placeholder: champ.libelle,

View file

@ -0,0 +1,13 @@
%select{ name:"champs['#{champ.id}']",
id: "champs_#{champ.id}" }
- champ.drop_down_list.options.each do |option|
- if (option=~ /^--.*--$/).nil?
- if champ.value == option
%option{selected:''}
= option
- else
%option
= option
-else
%option{disabled:''}
= option

View file

@ -24,5 +24,6 @@
= render partial: '/dossiers/infos_dossier' = render partial: '/dossiers/infos_dossier'
%br %div
= render partial: '/users/recapitulatif/commentaires_flux' %br
= render partial: 'dossiers/tab_objects_dossier'

View file

@ -13,6 +13,7 @@ ActiveSupport::Inflector.inflections(:en) do |inflect|
inflect.irregular 'piece_justificative', 'pieces_justificatives' inflect.irregular 'piece_justificative', 'pieces_justificatives'
inflect.irregular 'type_de_piece_justificative', 'types_de_piece_justificative' inflect.irregular 'type_de_piece_justificative', 'types_de_piece_justificative'
inflect.irregular 'type_de_champ', 'types_de_champ' inflect.irregular 'type_de_champ', 'types_de_champ'
inflect.irregular 'type_de_champ_private', 'types_de_champ_private'
inflect.irregular 'assign_to', 'assign_tos' inflect.irregular 'assign_to', 'assign_tos'
end end

View file

@ -93,10 +93,20 @@ Rails.application.routes.draw do
get 'profile' => 'profile#show', as: :profile get 'profile' => 'profile#show', as: :profile
resources :procedures do resources :procedures do
resources :types_de_champ, only: [:destroy]
resource :types_de_champ, only: [:show, :update] do resource :types_de_champ, only: [:show, :update] do
post '/:index/move_up' => 'types_de_champ#move_up', as: :move_up post '/:index/move_up' => 'types_de_champ#move_up', as: :move_up
post '/:index/move_down' => 'types_de_champ#move_down', as: :move_down post '/:index/move_down' => 'types_de_champ#move_down', as: :move_down
end end
resources :types_de_champ_private, only: [:destroy]
resource :types_de_champ_private, only: [:show, :update] do
post '/:index/move_up' => 'types_de_champ_private#move_up', as: :move_up
post '/:index/move_down' => 'types_de_champ_private#move_down', as: :move_down
end
resource :pieces_justificatives, only: [:show, :update]
resources :pieces_justificatives, only: :destroy
resource :pieces_justificatives, only: [:show, :update] do resource :pieces_justificatives, only: [:show, :update] do
post '/:index/move_up' => 'pieces_justificatives#move_up', as: :move_up post '/:index/move_up' => 'pieces_justificatives#move_up', as: :move_up
post '/:index/move_down' => 'pieces_justificatives#move_down', as: :move_down post '/:index/move_down' => 'pieces_justificatives#move_down', as: :move_down
@ -111,9 +121,6 @@ Rails.application.routes.draw do
resource :previsualisation, only: [:show] resource :previsualisation, only: [:show]
resources :types_de_champ, only: [:destroy]
resource :pieces_justificatives, only: [:show, :update]
resources :pieces_justificatives, only: :destroy
end end
namespace :accompagnateurs do namespace :accompagnateurs do
@ -138,6 +145,15 @@ Rails.application.routes.draw do
get 'filtres' => 'procedure_filter#index' get 'filtres' => 'procedure_filter#index'
patch 'filtres/update' => 'procedure_filter#update' patch 'filtres/update' => 'procedure_filter#update'
resource :private_formulaire
namespace :preference_list_dossier do
post 'add'
delete 'delete'
get 'reload_smartlisting' => '/backoffice/dossiers#reload_smartlisting'
get 'reload_pref_list'
end
resources :dossiers do resources :dossiers do
post 'valid' => 'dossiers#valid' post 'valid' => 'dossiers#valid'

View file

@ -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

View file

@ -0,0 +1,133 @@
class BuildDefaultPreferenceListDossier < ActiveRecord::Migration
class Gestionnaire < ActiveRecord::Base
def build_default_preferences_list_dossier
PreferenceListDossier.available_columns.each do |table|
table.second.each do |column|
if valid_couple_table_attr? table.first, column.first
PreferenceListDossier.create(
libelle: column.second[:libelle],
table: column.second[:table],
attr: column.second[:attr],
attr_decorate: column.second[:attr_decorate],
bootstrap_lg: column.second[:bootstrap_lg],
order: nil,
filter: nil,
gestionnaire_id: self.id
)
end
end
end
end
def valid_couple_table_attr? table, column
couples = [{
table: :dossier,
column: :dossier_id
}, {
table: :procedure,
column: :libelle
}, {
table: :etablissement,
column: :siret
}, {
table: :entreprise,
column: :raison_sociale
}, {
table: :dossier,
column: :state
}]
couples.include?({table: table, column: column})
end
end
class PreferenceListDossier < ActiveRecord::Base
def self.available_columns
{
dossier: columns_dossier,
procedure: columns_procedure,
entreprise: columns_entreprise,
etablissement: columns_etablissement,
user: columns_user
}
end
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.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
def up
Gestionnaire.all.each do |gestionnaire|
gestionnaire.build_default_preferences_list_dossier
end
end
def down
Gestionnaire.all.each do |gestionnaire|
PreferenceListDossier.where(gestionnaire_id: gestionnaire.id).delete_all
end
end
end

View file

@ -0,0 +1,5 @@
class AddPublicAttrOnTypeDeChamp < ActiveRecord::Migration
def change
add_column :types_de_champ, :private, :boolean, default: false
end
end

View file

@ -0,0 +1,5 @@
class AddTypeAttrOnTypeDeChamp < ActiveRecord::Migration
def change
add_column :types_de_champ, :type, :string
end
end

View file

@ -0,0 +1,17 @@
class FixDefaultTypeOnTypeDeChampTable < ActiveRecord::Migration
class TypeDeChamp < ActiveRecord::Base
end
def up
TypeDeChamp.where("private = false").update_all("type = 'TypeDeChampPublic'")
TypeDeChamp.where("private = true").update_all("type = 'TypeDeChampPrivate'")
remove_column :types_de_champ, :private
end
def down
add_column :types_de_champ, :private, :boolean, default: true
TypeDeChamp.where("type = 'TypeDeChampPublic'").update_all("private = false")
TypeDeChamp.where("type = 'TypeDeChampPrivate'").update_all("private = true")
end
end

View file

@ -0,0 +1,25 @@
class AddTypeAttrInChampTable < ActiveRecord::Migration
class TypeDeChamp < ActiveRecord::Base
has_many :champs
end
class Champ < ActiveRecord::Base
belongs_to :type_de_champ
end
def up
add_column :champs, :type, :string
Champ.all.each do |champ|
type = 'ChampPublic' if champ.type_de_champ.class == TypeDeChampPublic
type = 'ChampPrivate' if champ.type_de_champ.class == TypeDeChampPrivate
champ.update_attribute(:type, type)
end
end
def down
remove_column :champs, :type
end
end

View file

@ -0,0 +1,5 @@
class AddDepositAttrInDossierTable < ActiveRecord::Migration
def change
add_column :dossiers, :deposit_datetime, :datetime
end
end

View file

@ -0,0 +1,8 @@
class CreateDropDownListTable < ActiveRecord::Migration
def change
create_table :drop_down_lists do |t|
t.string :value
t.belongs_to :type_de_champ
end
end
end

View file

@ -11,7 +11,7 @@
# #
# It's strongly recommended that you check this file into your version control system. # It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema.define(version: 20160718124741) do ActiveRecord::Schema.define(version: 20160809083606) do
# These are extensions that must be enabled in order to support this database # These are extensions that must be enabled in order to support this database
enable_extension "plpgsql" enable_extension "plpgsql"
@ -99,6 +99,7 @@ ActiveRecord::Schema.define(version: 20160718124741) do
t.string "value" t.string "value"
t.integer "type_de_champ_id" t.integer "type_de_champ_id"
t.integer "dossier_id" t.integer "dossier_id"
t.string "type"
end end
create_table "commentaires", force: :cascade do |t| create_table "commentaires", force: :cascade do |t|
@ -123,11 +124,17 @@ ActiveRecord::Schema.define(version: 20160718124741) do
t.text "json_latlngs" t.text "json_latlngs"
t.boolean "archived", default: false t.boolean "archived", default: false
t.boolean "mandataire_social", default: false t.boolean "mandataire_social", default: false
t.datetime "deposit_datetime"
end end
add_index "dossiers", ["procedure_id"], name: "index_dossiers_on_procedure_id", using: :btree add_index "dossiers", ["procedure_id"], name: "index_dossiers_on_procedure_id", using: :btree
add_index "dossiers", ["user_id"], name: "index_dossiers_on_user_id", using: :btree add_index "dossiers", ["user_id"], name: "index_dossiers_on_user_id", using: :btree
create_table "drop_down_lists", force: :cascade do |t|
t.string "value"
t.integer "type_de_champ_id"
end
create_table "entreprises", force: :cascade do |t| create_table "entreprises", force: :cascade do |t|
t.string "siren" t.string "siren"
t.integer "capital_social" t.integer "capital_social"
@ -234,6 +241,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 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| create_table "procedure_paths", force: :cascade do |t|
t.string "path", limit: 30 t.string "path", limit: 30
t.integer "procedure_id" t.integer "procedure_id"
@ -285,6 +303,7 @@ ActiveRecord::Schema.define(version: 20160718124741) do
t.integer "procedure_id" t.integer "procedure_id"
t.text "description" t.text "description"
t.boolean "mandatory", default: false t.boolean "mandatory", default: false
t.string "type"
end end
create_table "types_de_piece_justificative", force: :cascade do |t| create_table "types_de_piece_justificative", force: :cascade do |t|

View file

@ -41,24 +41,34 @@ describe Admin::TypesDeChampController, type: :controller do
let(:mandatory) { 'on' } let(:mandatory) { 'on' }
let(:procedure_params) do let(:procedure_params) do
{ types_de_champ_attributes: {types_de_champ_attributes:
{ '0' => {'0' =>
{ {
libelle: libelle, libelle: libelle,
type_champ: type_champ, type_champ: type_champ,
description: description, description: description,
order_place: order_place, order_place: order_place,
id: types_de_champ_id, id: types_de_champ_id,
mandatory: mandatory mandatory: mandatory
} },
} '1' =>
{
libelle: '',
type_champ: 'text',
description: '',
order_place: '1',
id: '',
mandatory: false,
type: 'TypeDeChampPublic'
}
}
} }
end end
let(:request) { put :update, format: :js, procedure_id: procedure.id, procedure: procedure_params } let(:request) { put :update, format: :js, procedure_id: procedure.id, procedure: procedure_params }
context 'when procedure is found' do context 'when procedure is found' do
it { expect{ request }.to change(TypeDeChamp, :count).by(1) } it { expect { request }.to change(TypeDeChamp, :count).by(1) }
describe 'created type de champ' do describe 'created type de champ' do
before do before do
@ -121,7 +131,7 @@ describe Admin::TypesDeChampController, type: :controller do
end end
end end
context 'when procedure and type de champs are not linked' do context 'when procedure and type de champs are not linked' do
let(:type_de_champ) { create(:type_de_champ) } let(:type_de_champ) { create(:type_de_champ_public) }
let(:type_de_champ_id) { type_de_champ.id } let(:type_de_champ_id) { type_de_champ.id }
it { expect(subject.status).to eq(404) } it { expect(subject.status).to eq(404) }
end end
@ -136,20 +146,20 @@ describe Admin::TypesDeChampController, type: :controller do
end end
context 'when procedure have only one type de champ' do context 'when procedure have only one type de champ' do
let(:index) { 1 } let(:index) { 1 }
let!(:type_de_champ) { create(:type_de_champ, procedure: procedure) } let!(:type_de_champ) { create(:type_de_champ_public, procedure: procedure) }
it { expect(subject.status).to eq(400) } it { expect(subject.status).to eq(400) }
end end
context 'when procedure have tow type de champs' do context 'when procedure have tow type de champs' do
context 'when index == 0' do context 'when index == 0' do
let(:index) { 0 } let(:index) { 0 }
let!(:type_de_champ_1) { create(:type_de_champ, procedure: procedure) } let!(:type_de_champ_1) { create(:type_de_champ_public, procedure: procedure) }
let!(:type_de_champ_2) { create(:type_de_champ, procedure: procedure) } let!(:type_de_champ_2) { create(:type_de_champ_public, procedure: procedure) }
it { expect(subject.status).to eq(400) } it { expect(subject.status).to eq(400) }
end end
context 'when index > 0' do context 'when index > 0' do
let(:index) { 1 } let(:index) { 1 }
let!(:type_de_champ_0) { create(:type_de_champ, procedure: procedure, order_place: 0) } let!(:type_de_champ_0) { create(:type_de_champ_public, procedure: procedure, order_place: 0) }
let!(:type_de_champ_1) { create(:type_de_champ, procedure: procedure, order_place: 1) } let!(:type_de_champ_1) { create(:type_de_champ_public, procedure: procedure, order_place: 1) }
it { expect(subject.status).to eq(200) } it { expect(subject.status).to eq(200) }
it { expect(subject).to render_template('show') } it { expect(subject).to render_template('show') }
@ -174,12 +184,12 @@ describe Admin::TypesDeChampController, type: :controller do
it { expect(subject.status).to eq(400) } it { expect(subject.status).to eq(400) }
end end
context 'when procedure have only one type de champ' do context 'when procedure have only one type de champ' do
let!(:type_de_champ_0) { create(:type_de_champ, procedure: procedure) } let!(:type_de_champ_0) { create(:type_de_champ_public, procedure: procedure) }
it { expect(subject.status).to eq(400) } it { expect(subject.status).to eq(400) }
end end
context 'when procedure have 2 type de champ' do context 'when procedure have 2 type de champ' do
let!(:type_de_champ_0) { create(:type_de_champ, procedure: procedure, order_place: 0) } let!(:type_de_champ_0) { create(:type_de_champ_public, procedure: procedure, order_place: 0) }
let!(:type_de_champ_1) { create(:type_de_champ, procedure: procedure, order_place: 1) } let!(:type_de_champ_1) { create(:type_de_champ_public, procedure: procedure, order_place: 1) }
context 'when index represent last type_de_champ' do context 'when index represent last type_de_champ' do
let(:index) { 1 } let(:index) { 1 }
it { expect(subject.status).to eq(400) } it { expect(subject.status).to eq(400) }

View file

@ -0,0 +1,212 @@
require 'spec_helper'
describe Admin::TypesDeChampPrivateController, type: :controller do
let(:admin) { create(:administrateur) }
let(:procedure) { create(:procedure, administrateur: admin) }
before do
sign_in admin
end
describe 'GET #show' do
let(:published) { false }
let(:procedure) { create(:procedure, administrateur: admin, published: published) }
let(:procedure_id) { procedure.id }
subject { get :show, procedure_id: procedure_id }
context 'when procedure is not found' do
let(:procedure_id) { 9_999_999 }
it { expect(subject.status).to eq(404) }
end
context 'when procedure is published' do
let(:published) { true }
it { is_expected.to redirect_to admin_procedure_path id: procedure_id }
end
context 'when procedure does not belong to admin' do
let(:admin_2) { create(:administrateur) }
let(:procedure) { create(:procedure, administrateur: admin_2) }
it { expect(subject.status).to eq(404) }
end
end
describe '#update' do
let(:libelle) { 'mon libelle' }
let(:type_champ) { 'text' }
let(:description) { 'titi' }
let(:order_place) { '' }
let(:types_de_champ_id) { '' }
let(:mandatory) { 'on' }
let(:procedure_params) do
{ types_de_champ_private_attributes:
{ '0' =>
{
libelle: libelle,
type_champ: type_champ,
description: description,
order_place: order_place,
id: types_de_champ_id,
mandatory: mandatory,
type: 'TypeDeChampPrivate'
},
'1' =>
{
libelle: '',
type_champ: 'text',
description: '',
order_place: '1',
id: '',
mandatory: false,
type: 'TypeDeChampPrivate'
}
}
}
end
let(:request) { put :update, format: :js, procedure_id: procedure.id, procedure: procedure_params }
context 'when procedure is found' do
it { expect{ request }.to change(TypeDeChamp, :count).by(1) }
describe 'created type de champ' do
before do
request
procedure.reload
end
subject { procedure.types_de_champ_private.first }
it { expect(subject.libelle).to eq('mon libelle') }
it { expect(subject.type_champ).to eq('text') }
it { expect(subject.description).to eq('titi') }
it { expect(subject.mandatory).to be_truthy }
end
context 'when type_de_champ already exist' do
let(:procedure) { create(:procedure, :with_type_de_champ_private, administrateur: admin) }
let(:type_de_champ) { procedure.types_de_champ_private.first }
let(:types_de_champ_id) { type_de_champ.id }
let(:libelle) { 'toto' }
let(:type_champ) { 'text' }
let(:description) { 'citrouille' }
let(:order_place) { '0' }
let(:mandatory) { 'on' }
before do
request
procedure.reload
end
subject { procedure.types_de_champ_private.first }
it { expect(subject.libelle).to eq('toto') }
it { expect(subject.type_champ).to eq('text') }
it { expect(subject.description).to eq('citrouille') }
it { expect(subject.order_place).to eq(0) }
it { expect(subject.order_place).to be_truthy }
end
end
context 'when procedure is not found' do
subject { put :update, format: :js, procedure_id: 9_999_999, procedure: procedure_params }
it 'creates type de champ' do
expect(subject.status).to eq(404)
end
end
end
describe '#destroy' do
before do
delete :destroy, procedure_id: procedure.id, id: type_de_champ_id, format: :js
end
context 'when type de champs does not exist' do
let(:type_de_champ_id) { 99999999 }
it { expect(subject.status).to eq(404) }
end
context 'when types_de_champ exists' do
let(:procedure) { create(:procedure, :with_type_de_champ_private, administrateur: admin) }
let(:type_de_champ_id) { procedure.types_de_champ_private.first.id }
it { expect(subject.status).to eq(200) }
it 'destroy type de champ' do
procedure.reload
expect(procedure.types_de_champ.count).to eq(0)
end
end
context 'when procedure and type de champs are not linked' do
let(:type_de_champ) { create(:type_de_champ_public) }
let(:type_de_champ_id) { type_de_champ.id }
it { expect(subject.status).to eq(404) }
end
end
describe 'POST #move_up' do
subject { post :move_up, procedure_id: procedure.id, index: index, format: :js }
context 'when procedure have no type de champ' do
let(:index) { 0 }
it { expect(subject.status).to eq(400) }
end
context 'when procedure have only one type de champ' do
let(:index) { 1 }
let!(:type_de_champ) { create(:type_de_champ_private, procedure: procedure) }
it { expect(subject.status).to eq(400) }
end
context 'when procedure have tow type de champs' do
context 'when index == 0' do
let(:index) { 0 }
let!(:type_de_champ_1) { create(:type_de_champ_private, procedure: procedure) }
let!(:type_de_champ_2) { create(:type_de_champ_private, procedure: procedure) }
it { expect(subject.status).to eq(400) }
end
context 'when index > 0' do
let(:index) { 1 }
let!(:type_de_champ_0) { create(:type_de_champ_private, procedure: procedure, order_place: 0) }
let!(:type_de_champ_1) { create(:type_de_champ_private, procedure: procedure, order_place: 1) }
it { expect(subject.status).to eq(200) }
it { expect(subject).to render_template('show') }
it 'changes order places' do
post :move_up, procedure_id: procedure.id, index: index, format: :js
type_de_champ_0.reload
type_de_champ_1.reload
expect(type_de_champ_0.order_place).to eq(1)
expect(type_de_champ_1.order_place).to eq(0)
end
end
end
end
describe 'POST #move_down' do
let(:request) { post :move_down, procedure_id: procedure.id, index: index, format: :js }
let(:index) { 0 }
subject { request }
context 'when procedure have no type de champ' do
it { expect(subject.status).to eq(400) }
end
context 'when procedure have only one type de champ' do
let!(:type_de_champ_0) { create(:type_de_champ_private, procedure: procedure) }
it { expect(subject.status).to eq(400) }
end
context 'when procedure have 2 type de champ' do
let!(:type_de_champ_0) { create(:type_de_champ_private, procedure: procedure, order_place: 0) }
let!(:type_de_champ_1) { create(:type_de_champ_private, procedure: procedure, order_place: 1) }
context 'when index represent last type_de_champ' do
let(:index) { 1 }
it { expect(subject.status).to eq(400) }
end
context 'when index does not represent last type_de_champ' do
let(:index) { 0 }
it { expect(subject.status).to eq(200) }
it { expect(subject).to render_template('show') }
it 'changes order place' do
request
type_de_champ_0.reload
type_de_champ_1.reload
expect(type_de_champ_0.order_place).to eq(1)
expect(type_de_champ_1.order_place).to eq(0)
end
end
end
end
end

View file

@ -2,7 +2,7 @@ require 'spec_helper'
describe API::V1::DossiersController do describe API::V1::DossiersController do
let(:admin) { create(:administrateur) } let(:admin) { create(:administrateur) }
let(:procedure) { create(:procedure, :with_two_type_de_piece_justificative, :with_type_de_champ, administrateur: admin, cerfa_flag: true) } let(:procedure) { create(:procedure, :with_two_type_de_piece_justificative, :with_type_de_champ, :with_type_de_champ_private, administrateur: admin, cerfa_flag: true) }
let(:wrong_procedure) { create(:procedure) } let(:wrong_procedure) { create(:procedure) }
it { expect(described_class).to be < APIController } it { expect(described_class).to be < APIController }
@ -115,7 +115,7 @@ describe API::V1::DossiersController do
let!(:dossier) { Timecop.freeze(date_creation) { create(:dossier, :with_entreprise, procedure: procedure) } } let!(:dossier) { Timecop.freeze(date_creation) { create(:dossier, :with_entreprise, procedure: procedure) } }
let(:dossier_id) { dossier.id } let(:dossier_id) { dossier.id }
let(:body) { JSON.parse(retour.body, symbolize_names: true) } let(:body) { JSON.parse(retour.body, symbolize_names: true) }
let(:field_list) { [:id, :created_at, :updated_at, :archived, :mandataire_social, :total_commentaire, :entreprise, :etablissement, :cerfa, :types_de_piece_justificative, :pieces_justificatives, :champs, :commentaires, :state] } let(:field_list) { [:id, :created_at, :updated_at, :archived, :mandataire_social, :total_commentaire, :entreprise, :etablissement, :cerfa, :types_de_piece_justificative, :pieces_justificatives, :champs, :champs_private, :commentaires, :state] }
subject { body[:dossier] } subject { body[:dossier] }
it 'return REST code 200', :show_in_doc do it 'return REST code 200', :show_in_doc do
@ -230,7 +230,38 @@ describe API::V1::DossiersController do
it { expect(subject[:libelle]).to eq('Description') } it { expect(subject[:libelle]).to eq('Description') }
it { expect(subject[:description]).to eq('description de votre projet') } it { expect(subject[:description]).to eq('description de votre projet') }
it { expect(subject.keys.include?(:order_place)).to be_truthy } it { expect(subject.keys.include?(:order_place)).to be_truthy }
it { expect(subject[:type]).to eq('text') } it { expect(subject[:type_champ]).to eq('text') }
end
end
end
describe 'champs_private' do
let(:field_list) { [
:url] }
subject { super()[:champs_private] }
it { expect(subject.length).to eq 1 }
describe 'first champs' do
subject { super().first }
it { expect(subject.keys.include?(:value)).to be_truthy }
it { expect(subject.keys.include?(:type_de_champ)).to be_truthy }
describe 'type de champ' do
let(:field_list) { [
:id,
:libelle,
:description,
:order_place,
:type] }
subject { super()[:type_de_champ] }
it { expect(subject.keys.include?(:id)).to be_truthy }
it { expect(subject[:libelle]).to eq('Description') }
it { expect(subject[:description]).to eq('description de votre projet') }
it { expect(subject.keys.include?(:order_place)).to be_truthy }
it { expect(subject[:type_champ]).to eq('text') }
end end
end end
end end

View file

@ -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

View file

@ -0,0 +1,28 @@
require 'spec_helper'
describe Backoffice::PrivateFormulairesController, type: :controller do
let(:gestionnaire) { create :gestionnaire }
let(:dossier) { create :dossier }
let(:dossier_champs_first) { 'plop' }
before do
create :assign_to, procedure_id: dossier.procedure.id, gestionnaire_id: gestionnaire.id
sign_in gestionnaire
end
describe '#PATCH update' do
subject { patch :update, dossier_id: dossier.id,
champs: {
"'#{dossier.champs_private.first.id}'" => dossier_champs_first
} }
before do
subject
end
it { expect(response.status).to eq 200 }
it { expect(Dossier.find(dossier.id).champs_private.first.value).to eq dossier_champs_first }
it { expect(flash[:notice]).to be_present }
end
end

View file

@ -1,7 +1,7 @@
require 'spec_helper' require 'spec_helper'
describe Users::RecapitulatifController, type: :controller do describe Users::RecapitulatifController, type: :controller do
let(:dossier) { create(:dossier, state:'initiated') } let(:dossier) { create(:dossier, state: 'initiated') }
let(:bad_dossier_id) { Dossier.count + 100000 } let(:bad_dossier_id) { Dossier.count + 100000 }
before do before do
@ -55,16 +55,22 @@ describe Users::RecapitulatifController, type: :controller do
describe 'POST #submit' do describe 'POST #submit' do
context 'when an user depose his dossier' do context 'when an user depose his dossier' do
let(:deposit_datetime) { Time.local(2016, 8, 1, 10, 5, 0) }
before do before do
dossier.validated! dossier.validated!
post :submit, dossier_id: dossier.id Timecop.freeze(deposit_datetime) { post :submit, dossier_id: dossier.id }
dossier.reload
end end
it 'dossier change his state for submitted' do it 'dossier change his state for submitted' do
dossier.reload
expect(dossier.state).to eq('submitted') expect(dossier.state).to eq('submitted')
end end
it 'dossier deposit datetime is filled' do
expect(dossier.deposit_datetime).to eq deposit_datetime
end
it 'a message informe user what his dossier is initiated' do it 'a message informe user what his dossier is initiated' do
expect(flash[:notice]).to include('Dossier déposé avec succès.') expect(flash[:notice]).to include('Dossier déposé avec succès.')
end end

View file

@ -5,9 +5,9 @@ describe TypeDeChampDecorator do
let(:procedure) { create(:procedure) } let(:procedure) { create(:procedure) }
let(:url) { 'http://localhost' } let(:url) { 'http://localhost' }
let(:params) { { url: url, index: index } } let(:params) { { url: url, index: index } }
let!(:type_de_champ_0) { create(:type_de_champ, procedure: procedure, order_place: 0) } let!(:type_de_champ_0) { create(:type_de_champ_public, procedure: procedure, order_place: 0) }
let!(:type_de_champ_1) { create(:type_de_champ, procedure: procedure, order_place: 1) } let!(:type_de_champ_1) { create(:type_de_champ_public, procedure: procedure, order_place: 1) }
let!(:type_de_champ_2) { create(:type_de_champ, procedure: procedure, order_place: 2) } let!(:type_de_champ_2) { create(:type_de_champ_public, procedure: procedure, order_place: 2) }
describe '#button_up' do describe '#button_up' do

View file

@ -5,7 +5,7 @@ FactoryGirl.define do
before(:create) do |dossier, _evaluator| before(:create) do |dossier, _evaluator|
unless dossier.procedure unless dossier.procedure
procedure = create(:procedure, :with_two_type_de_piece_justificative, :with_type_de_champ) procedure = create(:procedure, :with_two_type_de_piece_justificative, :with_type_de_champ, :with_type_de_champ_private)
dossier.procedure = procedure dossier.procedure = procedure
end end
end end

View file

@ -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

View file

@ -24,15 +24,23 @@ FactoryGirl.define do
trait :with_type_de_champ do trait :with_type_de_champ do
after(:build) do |procedure, _evaluator| after(:build) do |procedure, _evaluator|
type_de_champ = create(:type_de_champ) type_de_champ = create(:type_de_champ_public)
procedure.types_de_champ << type_de_champ procedure.types_de_champ << type_de_champ
end end
end end
trait :with_type_de_champ_private do
after(:build) do |procedure, _evaluator|
type_de_champ = create(:type_de_champ_private)
procedure.types_de_champ_private << type_de_champ
end
end
trait :with_type_de_champ_mandatory do trait :with_type_de_champ_mandatory do
after(:build) do |procedure, _evaluator| after(:build) do |procedure, _evaluator|
type_de_champ = create(:type_de_champ, mandatory: true) type_de_champ = create(:type_de_champ_public, mandatory: true)
procedure.types_de_champ << type_de_champ procedure.types_de_champ << type_de_champ
end end
@ -40,7 +48,7 @@ FactoryGirl.define do
trait :with_datetime do trait :with_datetime do
after(:build) do |procedure, _evaluator| after(:build) do |procedure, _evaluator|
type_de_champ = create(:type_de_champ, mandatory: true, type_champ: :datetime) type_de_champ = create(:type_de_champ_public, mandatory: true, type_champ: :datetime)
procedure.types_de_champ << type_de_champ procedure.types_de_champ << type_de_champ
end end

View file

@ -0,0 +1,9 @@
FactoryGirl.define do
factory :type_de_champ_private do
libelle 'Description'
description 'description de votre projet'
type_champ 'text'
order_place 1
mandatory false
end
end

View file

@ -1,5 +1,5 @@
FactoryGirl.define do FactoryGirl.define do
factory :type_de_champ do factory :type_de_champ_public do
libelle 'Description' libelle 'Description'
description 'description de votre projet' description 'description de votre projet'
type_champ 'text' type_champ 'text'

View file

@ -0,0 +1,29 @@
require 'spec_helper'
feature 'move down button type de champs', js: true do
let(:administrateur) { create(:administrateur) }
before do
login_as administrateur, scope: :administrateur
end
let(:procedure) { create(:procedure, administrateur: administrateur) }
let!(:type_de_champ_0) { create(:type_de_champ_private, procedure: procedure, order_place: 0) }
let!(:type_de_champ_1) { create(:type_de_champ_private, procedure: procedure, order_place: 1) }
let!(:type_de_champ_2) { create(:type_de_champ_private, procedure: procedure, order_place: 2) }
let!(:type_de_champ_3) { create(:type_de_champ_private, procedure: procedure, order_place: 3) }
context 'when clicking on move down for type de champ 1' do
before do
visit admin_procedure_types_de_champ_private_path procedure.id
page.find_by_id('btn_down_1').click
wait_for_ajax
type_de_champ_1.reload
type_de_champ_2.reload
end
scenario 'it switches type_de_champ 1 and 2 place ' do
expect(type_de_champ_1.order_place).to eq(2)
expect(type_de_champ_2.order_place).to eq(1)
end
end
end

View file

@ -8,10 +8,10 @@ feature 'move down button type de champs', js: true do
end end
let(:procedure) { create(:procedure, administrateur: administrateur) } let(:procedure) { create(:procedure, administrateur: administrateur) }
let!(:type_de_champ_0) { create(:type_de_champ, procedure: procedure, order_place: 0) } let!(:type_de_champ_0) { create(:type_de_champ_public, procedure: procedure, order_place: 0) }
let!(:type_de_champ_1) { create(:type_de_champ, procedure: procedure, order_place: 1) } let!(:type_de_champ_1) { create(:type_de_champ_public, procedure: procedure, order_place: 1) }
let!(:type_de_champ_2) { create(:type_de_champ, procedure: procedure, order_place: 2) } let!(:type_de_champ_2) { create(:type_de_champ_public, procedure: procedure, order_place: 2) }
let!(:type_de_champ_3) { create(:type_de_champ, procedure: procedure, order_place: 3) } let!(:type_de_champ_3) { create(:type_de_champ_public, procedure: procedure, order_place: 3) }
context 'when clicking on move down for type de champ 1' do context 'when clicking on move down for type de champ 1' do
before do before do

View file

@ -0,0 +1,29 @@
require 'spec_helper'
feature 'move up button type de champs', js: true do
let(:administrateur) { create(:administrateur) }
before do
login_as administrateur, scope: :administrateur
end
let(:procedure) { create(:procedure, administrateur: administrateur) }
let!(:type_de_champ_0) { create(:type_de_champ_private, procedure: procedure, order_place: 0) }
let!(:type_de_champ_1) { create(:type_de_champ_private, procedure: procedure, order_place: 1) }
let!(:type_de_champ_2) { create(:type_de_champ_private, procedure: procedure, order_place: 2) }
let!(:type_de_champ_3) { create(:type_de_champ_private, procedure: procedure, order_place: 3) }
context 'when clicking on move down for type de champ 1' do
before do
visit admin_procedure_types_de_champ_private_path procedure.id
page.find_by_id('btn_up_1').click
wait_for_ajax
type_de_champ_0.reload
type_de_champ_1.reload
end
scenario 'it switches type_de_champ 1 and 2 place ' do
expect(type_de_champ_0.order_place).to eq(1)
expect(type_de_champ_1.order_place).to eq(0)
end
end
end

View file

@ -8,10 +8,10 @@ feature 'move up button type de champs', js: true do
end end
let(:procedure) { create(:procedure, administrateur: administrateur) } let(:procedure) { create(:procedure, administrateur: administrateur) }
let!(:type_de_champ_0) { create(:type_de_champ, procedure: procedure, order_place: 0) } let!(:type_de_champ_0) { create(:type_de_champ_public, procedure: procedure, order_place: 0) }
let!(:type_de_champ_1) { create(:type_de_champ, procedure: procedure, order_place: 1) } let!(:type_de_champ_1) { create(:type_de_champ_public, procedure: procedure, order_place: 1) }
let!(:type_de_champ_2) { create(:type_de_champ, procedure: procedure, order_place: 2) } let!(:type_de_champ_2) { create(:type_de_champ_public, procedure: procedure, order_place: 2) }
let!(:type_de_champ_3) { create(:type_de_champ, procedure: procedure, order_place: 3) } let!(:type_de_champ_3) { create(:type_de_champ_public, procedure: procedure, order_place: 3) }
context 'when clicking on move down for type de champ 1' do context 'when clicking on move down for type de champ 1' do
before do before do

View file

@ -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

View file

@ -9,6 +9,7 @@ feature 'on backoffice page' do
before do before do
create :assign_to, gestionnaire: gestionnaire, procedure: procedure create :assign_to, gestionnaire: gestionnaire, procedure: procedure
visit backoffice_path visit backoffice_path
end end
@ -20,7 +21,7 @@ feature 'on backoffice page' do
end end
context 'when he click on first dossier' do context 'when he click on first dossier' do
before do before do
page.click_on dossier.entreprise.raison_sociale page.click_on dossier.id
end end
scenario 'it redirect to dossier page' do scenario 'it redirect to dossier page' do
expect(page).to have_css('#backoffice_dossier_show') expect(page).to have_css('#backoffice_dossier_show')

View file

@ -0,0 +1,7 @@
require 'spec_helper'
describe ChampPrivate do
require 'models/champ_shared_example.rb'
it_should_behave_like "champ_spec"
end

View file

@ -0,0 +1,7 @@
require 'spec_helper'
describe ChampPublic do
require 'models/champ_shared_example.rb'
it_should_behave_like "champ_spec"
end

View file

@ -0,0 +1,38 @@
shared_examples 'champ_spec' do
describe 'database columns' do
it { is_expected.to have_db_column(:value) }
end
describe 'associations' do
it { is_expected.to belong_to(:dossier) }
it { is_expected.to belong_to(:type_de_champ) }
end
describe 'delegation' do
it { is_expected.to delegate_method(:libelle).to(:type_de_champ) }
it { is_expected.to delegate_method(:type_champ).to(:type_de_champ) }
it { is_expected.to delegate_method(:order_place).to(:type_de_champ) }
end
describe 'data_provide' do
let(:champ) { create :champ }
subject { champ.data_provide }
context 'when type_champ is datetime' do
before do
champ.type_de_champ = create :type_de_champ_public, type_champ: 'datetime'
end
it { is_expected.to eq 'datepicker' }
end
context 'when type_champ is address' do
before do
champ.type_de_champ = create :type_de_champ_public, type_champ: 'address'
end
it { is_expected.to eq 'typeahead' }
end
end
end

View file

@ -1,40 +1,7 @@
require 'spec_helper' require 'spec_helper'
describe Champ do describe Champ do
describe 'database columns' do require 'models/champ_shared_example.rb'
it { is_expected.to have_db_column(:value) }
end
describe 'associations' do it_should_behave_like "champ_spec"
it { is_expected.to belong_to(:dossier) }
it { is_expected.to belong_to(:type_de_champ) }
end
describe 'delegation' do
it { is_expected.to delegate_method(:libelle).to(:type_de_champ) }
it { is_expected.to delegate_method(:type_champ).to(:type_de_champ) }
it { is_expected.to delegate_method(:order_place).to(:type_de_champ) }
end
describe 'data_provide' do
let(:champ) { create :champ }
subject { champ.data_provide }
context 'when type_champ is datetime' do
before do
champ.type_de_champ = create :type_de_champ, type_champ: 'datetime'
end
it { is_expected.to eq 'datepicker' }
end
context 'when type_champ is address' do
before do
champ.type_de_champ = create :type_de_champ, type_champ: 'address'
end
it { is_expected.to eq 'typeahead' }
end
end
end end

View file

@ -33,6 +33,7 @@ describe Dossier do
it { is_expected.to delegate_method(:siret).to(:etablissement) } 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_piece_justificative).to(:procedure) }
it { is_expected.to delegate_method(:types_de_champ).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 end
describe 'methods' do describe 'methods' do
@ -91,12 +92,16 @@ describe Dossier do
end end
describe '#build_default_champs' do describe '#build_default_champs' do
context 'when dossier is linked to a procedure' do context 'when dossier is linked to a procedure with type_de_champ_public and private' do
let(:dossier) { create(:dossier, user: user) } let(:dossier) { create(:dossier, user: user) }
it 'build all champs needed' do it 'build all champs needed' do
expect(dossier.champs.count).to eq(1) expect(dossier.champs.count).to eq(1)
end end
it 'build all champs_private needed' do
expect(dossier.champs_private.count).to eq(1)
end
end end
end end
@ -590,12 +595,12 @@ describe Dossier do
let(:dossier_2) { Dossier.new(id: 0, procedure: procedure_2) } let(:dossier_2) { Dossier.new(id: 0, procedure: procedure_2) }
before do before do
create :type_de_champ, libelle: 'type_1_1', order_place: 1, procedure: dossier_1.procedure create :type_de_champ_public, libelle: 'type_1_1', order_place: 1, procedure: dossier_1.procedure
create :type_de_champ, libelle: 'type_1_2', order_place: 2, procedure: dossier_1.procedure create :type_de_champ_public, libelle: 'type_1_2', order_place: 2, procedure: dossier_1.procedure
create :type_de_champ, libelle: 'type_2_1', order_place: 1, procedure: dossier_2.procedure create :type_de_champ_public, libelle: 'type_2_1', order_place: 1, procedure: dossier_2.procedure
create :type_de_champ, libelle: 'type_2_2', order_place: 2, procedure: dossier_2.procedure create :type_de_champ_public, libelle: 'type_2_2', order_place: 2, procedure: dossier_2.procedure
create :type_de_champ, libelle: 'type_2_3', order_place: 3, procedure: dossier_2.procedure create :type_de_champ_public, libelle: 'type_2_3', order_place: 3, procedure: dossier_2.procedure
dossier_1.build_default_champs dossier_1.build_default_champs
dossier_2.build_default_champs dossier_2.build_default_champs
@ -603,7 +608,7 @@ describe Dossier do
subject { dossier.ordered_champs } subject { dossier.ordered_champs }
it { expect(Champ.where(dossier_id: 0).size).to eq 5 } it { expect(ChampPublic.where(dossier_id: 0).size).to eq 5 }
describe 'for dossier 1' do describe 'for dossier 1' do
let(:dossier) { dossier_1 } let(:dossier) { dossier_1 }
@ -625,6 +630,48 @@ describe Dossier do
end end
describe '#ordered_champs_private' do
let!(:procedure_1) { create :procedure }
let!(:procedure_2) { create :procedure }
let(:dossier_1) { Dossier.new(id: 0, procedure: procedure_1) }
let(:dossier_2) { Dossier.new(id: 0, procedure: procedure_2) }
before do
create :type_de_champ_private, libelle: 'type_1_1', order_place: 1, procedure: dossier_1.procedure
create :type_de_champ_private, libelle: 'type_1_2', order_place: 2, procedure: dossier_1.procedure
create :type_de_champ_private, libelle: 'type_2_1', order_place: 1, procedure: dossier_2.procedure
create :type_de_champ_private, libelle: 'type_2_2', order_place: 2, procedure: dossier_2.procedure
create :type_de_champ_private, libelle: 'type_2_3', order_place: 3, procedure: dossier_2.procedure
dossier_1.build_default_champs
dossier_2.build_default_champs
end
subject { dossier.ordered_champs_private }
it { expect(ChampPrivate.where(dossier_id: 0).size).to eq 5 }
describe 'for dossier 1' do
let(:dossier) { dossier_1 }
it { expect(subject.size).to eq 2 }
it { expect(subject.first.type_de_champ.libelle).to eq 'type_1_1' }
it { expect(subject.last.type_de_champ.libelle).to eq 'type_1_2' }
end
describe 'for dossier 2' do
let(:dossier) { dossier_2 }
it { expect(subject.size).to eq 3 }
it { expect(subject.first.type_de_champ.libelle).to eq 'type_2_1' }
it { expect(subject.second.type_de_champ.libelle).to eq 'type_2_2' }
it { expect(subject.last.type_de_champ.libelle).to eq 'type_2_3' }
end
end
describe '#total_follow' do describe '#total_follow' do
let(:dossier) { create(:dossier, :with_entreprise, user: user) } let(:dossier) { create(:dossier, :with_entreprise, user: user) }
let(:dossier2) { create(:dossier, :with_entreprise, user: user) } let(:dossier2) { create(:dossier, :with_entreprise, user: user) }

View file

@ -32,6 +32,7 @@ describe Gestionnaire, type: :model do
it { is_expected.to have_many(:procedures) } it { is_expected.to have_many(:procedures) }
it { is_expected.to have_many(:dossiers) } it { is_expected.to have_many(:dossiers) }
it { is_expected.to have_many(:follows) } it { is_expected.to have_many(:follows) }
it { is_expected.to have_many(:preference_list_dossiers) }
end end
describe '#dossiers_filter' do describe '#dossiers_filter' do
@ -155,4 +156,39 @@ describe Gestionnaire, type: :model do
it { expect(Follow.all.size).to eq 1 } it { expect(Follow.all.size).to eq 1 }
it { expect(subject.first).to eq dossier } it { expect(subject.first).to eq dossier }
end end
describe '#build_default_preferences_list_dossier' do
subject { gestionnaire.preference_list_dossiers }
context 'when gestionnaire is created' do
it 'build default 5 pref list dossier object' do
expect(subject.size).to eq 5
end
it 'build dossier_id column' do
expect(subject.first.table).to be_nil
expect(subject.first.attr).to eq 'id'
end
it 'build dossier state column' do
expect(subject[1].table).to be_nil
expect(subject[1].attr).to eq 'state'
end
it 'build procedure libelle column' do
expect(subject[2].table).to eq 'procedure'
expect(subject[2].attr).to eq 'libelle'
end
it 'build entreprise raison_sociale column' do
expect(subject[3].table).to eq 'entreprise'
expect(subject[3].attr).to eq 'raison_sociale'
end
it 'build entreprise raison_sociale column' do
expect(subject.last.table).to eq 'etablissement'
expect(subject.last.attr).to eq 'siret'
end
end
end
end end

View file

@ -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

View file

@ -44,8 +44,8 @@ describe Procedure do
describe '#types_de_champ_ordered' do describe '#types_de_champ_ordered' do
let(:procedure) { create(:procedure) } let(:procedure) { create(:procedure) }
let!(:type_de_champ_0) { create(:type_de_champ, procedure: procedure, order_place: 1) } let!(:type_de_champ_0) { create(:type_de_champ_public, procedure: procedure, order_place: 1) }
let!(:type_de_champ_1) { create(:type_de_champ, procedure: procedure, order_place: 0) } let!(:type_de_champ_1) { create(:type_de_champ_public, procedure: procedure, order_place: 0) }
subject { procedure.types_de_champ_ordered } subject { procedure.types_de_champ_ordered }
it { expect(subject.first).to eq(type_de_champ_1) } it { expect(subject.first).to eq(type_de_champ_1) }
it { expect(subject.last).to eq(type_de_champ_0) } it { expect(subject.last).to eq(type_de_champ_0) }
@ -60,8 +60,8 @@ describe Procedure do
it { expect(subject).to eq(false) } it { expect(subject).to eq(false) }
end end
context 'when procedure have 2 types de champ' do context 'when procedure have 2 types de champ' do
let!(:type_de_champ_0) { create(:type_de_champ, procedure: procedure, order_place: 0) } let!(:type_de_champ_0) { create(:type_de_champ_public, procedure: procedure, order_place: 0) }
let!(:type_de_champ_1) { create(:type_de_champ, procedure: procedure, order_place: 1) } let!(:type_de_champ_1) { create(:type_de_champ_public, procedure: procedure, order_place: 1) }
context 'when index is not the last element' do context 'when index is not the last element' do
it { expect(subject).to eq(true) } it { expect(subject).to eq(true) }
it 'switch order place' do it 'switch order place' do
@ -128,8 +128,8 @@ describe Procedure do
let(:archived) { false } let(:archived) { false }
let(:published) { false } let(:published) { false }
let(:procedure) { create(:procedure, archived: archived, published: published) } let(:procedure) { create(:procedure, archived: archived, published: published) }
let!(:type_de_champ_0) { create(:type_de_champ, procedure: procedure, order_place: 0) } let!(:type_de_champ_0) { create(:type_de_champ_public, procedure: procedure, order_place: 0) }
let!(:type_de_champ_1) { create(:type_de_champ, procedure: procedure, order_place: 1) } let!(:type_de_champ_1) { create(:type_de_champ_public, procedure: procedure, order_place: 1) }
let!(:piece_justificative_0) { create(:type_de_piece_justificative, procedure: procedure, order_place: 0) } let!(:piece_justificative_0) { create(:type_de_piece_justificative, procedure: procedure, order_place: 0) }
let!(:piece_justificative_1) { create(:type_de_piece_justificative, procedure: procedure, order_place: 1) } let!(:piece_justificative_1) { create(:type_de_piece_justificative, procedure: procedure, order_place: 1) }
subject { procedure.clone } subject { procedure.clone }

View file

@ -0,0 +1,7 @@
require 'spec_helper'
describe TypeDeChampPrivate do
require 'models/type_de_champ_shared_example'
it_should_behave_like "type_de_champ_spec"
end

View file

@ -0,0 +1,7 @@
require 'spec_helper'
describe TypeDeChampPublic do
require 'models/type_de_champ_shared_example'
it_should_behave_like "type_de_champ_spec"
end

View file

@ -0,0 +1,44 @@
shared_examples 'type_de_champ_spec' do
describe 'database columns' do
it { is_expected.to have_db_column(:libelle) }
it { is_expected.to have_db_column(:type_champ) }
it { is_expected.to have_db_column(:order_place) }
it { is_expected.to have_db_column(:description) }
end
describe 'associations' do
it { is_expected.to belong_to(:procedure) }
it { is_expected.to have_many(:champ) }
end
describe 'validation' do
context 'libelle' do
it { is_expected.not_to allow_value(nil).for(:libelle) }
it { is_expected.not_to allow_value('').for(:libelle) }
it { is_expected.to allow_value('Montant projet').for(:libelle) }
end
context 'type' do
it { is_expected.not_to allow_value(nil).for(:type_champ) }
it { is_expected.not_to allow_value('').for(:type_champ) }
it { is_expected.to allow_value('text').for(:type_champ) }
it { is_expected.to allow_value('textarea').for(:type_champ) }
it { is_expected.to allow_value('datetime').for(:type_champ) }
it { is_expected.to allow_value('number').for(:type_champ) }
it { is_expected.to allow_value('checkbox').for(:type_champ) }
end
context 'order_place' do
# it { is_expected.not_to allow_value(nil).for(:order_place) }
# it { is_expected.not_to allow_value('').for(:order_place) }
it { is_expected.to allow_value(1).for(:order_place) }
end
context 'description' do
it { is_expected.to allow_value(nil).for(:description) }
it { is_expected.to allow_value('').for(:description) }
it { is_expected.to allow_value('blabla').for(:description) }
end
end
end

Some files were not shown because too many files have changed in this diff Show more