Add historic for piece justificative
This commit is contained in:
parent
4b7e6426b3
commit
bb79aca58a
14 changed files with 99 additions and 76 deletions
|
@ -3,10 +3,14 @@ $(document).ready(modal_action);
|
|||
|
||||
function modal_action() {
|
||||
$('#PJmodal').on('show.bs.modal', function (event) {
|
||||
$("#PJmodal .modal-body .table .tr_content").hide();
|
||||
|
||||
var button = $(event.relatedTarget) // Button that triggered the modal
|
||||
var modal_title = button.data('modal_title') // Extract info from data-* attributes
|
||||
var modal_title = button.data('modal_title'); // Extract info from data-* attributes
|
||||
var modal_index = button.data('modal_index'); // Extract info from data-* attributes
|
||||
|
||||
var modal = $(this)
|
||||
modal.find('#PJmodal_title').html(modal_title)
|
||||
modal.find('#PJmodal_title').html(modal_title);
|
||||
$("#PJmodal .modal-body .table #"+modal_index).show();
|
||||
})
|
||||
}
|
9
app/assets/stylesheets/pj_modal.scss
Normal file
9
app/assets/stylesheets/pj_modal.scss
Normal file
|
@ -0,0 +1,9 @@
|
|||
#PJmodal {
|
||||
.modal-body {
|
||||
.table {
|
||||
.tr_content {
|
||||
display: none;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -55,9 +55,13 @@ class Users::DescriptionController < UsersController
|
|||
end
|
||||
end
|
||||
|
||||
@dossier.pieces_justificatives.each do |piece_justificative|
|
||||
unless params["piece_justificative_#{piece_justificative.type}"].nil?
|
||||
piece_justificative.content = params["piece_justificative_#{piece_justificative.type}"]
|
||||
@dossier.types_de_piece_justificative.each do |type_de_pieces_justificatives|
|
||||
unless params["piece_justificative_#{type_de_pieces_justificatives.id}"].nil?
|
||||
|
||||
piece_justificative = PieceJustificative.new(content: params["piece_justificative_#{type_de_pieces_justificatives.id}"],
|
||||
dossier: @dossier,
|
||||
type_de_piece_justificative: type_de_pieces_justificatives)
|
||||
|
||||
unless piece_justificative.save
|
||||
flash.now.alert = piece_justificative.errors.full_messages.join('<br />').html_safe
|
||||
return render 'show'
|
||||
|
|
|
@ -27,7 +27,6 @@ class Dossier < ActiveRecord::Base
|
|||
delegate :types_de_piece_justificative, to: :procedure
|
||||
delegate :types_de_champ, to: :procedure
|
||||
|
||||
after_save :build_default_pieces_justificatives, if: Proc.new { procedure_id_changed? }
|
||||
after_save :build_default_champs, if: Proc.new { procedure_id_changed? }
|
||||
|
||||
validates :nom_projet, presence: true, allow_blank: false, allow_nil: true
|
||||
|
@ -38,14 +37,12 @@ class Dossier < ActiveRecord::Base
|
|||
WAITING_FOR_USER = %w(replied validated)
|
||||
TERMINE = %w(closed)
|
||||
|
||||
def retrieve_piece_justificative_by_type(type)
|
||||
def retrieve_last_piece_justificative_by_type(type)
|
||||
pieces_justificatives.where(type_de_piece_justificative_id: type).last
|
||||
end
|
||||
|
||||
def build_default_pieces_justificatives
|
||||
procedure.types_de_piece_justificative.each do |type_de_piece_justificative|
|
||||
PieceJustificative.create(type_de_piece_justificative_id: type_de_piece_justificative.id, dossier_id: id)
|
||||
end
|
||||
def retrieve_all_piece_justificative_by_type(type)
|
||||
pieces_justificatives.where(type_de_piece_justificative_id: type)
|
||||
end
|
||||
|
||||
def build_default_champs
|
||||
|
|
|
@ -12,5 +12,5 @@ class DossierSerializer < ActiveModel::Serializer
|
|||
has_many :cerfa
|
||||
has_many :commentaires
|
||||
has_many :champs
|
||||
has_many :pieces_justificatives
|
||||
has_many :types_de_piece_justificative
|
||||
end
|
|
@ -2,5 +2,4 @@ class PieceJustificativeSerializer < ActiveModel::Serializer
|
|||
attributes :created_at,
|
||||
:content_url => :url
|
||||
|
||||
has_one :type_de_piece_justificative
|
||||
end
|
|
@ -2,4 +2,6 @@ class TypeDePieceJustificativeSerializer < ActiveModel::Serializer
|
|||
attributes :id,
|
||||
:libelle,
|
||||
:description
|
||||
|
||||
has_many :pieces_justificatives
|
||||
end
|
|
@ -8,7 +8,7 @@
|
|||
Historique des
|
||||
%span#PJmodal_title
|
||||
.modal-body
|
||||
%table.table#cerfa
|
||||
%table.table
|
||||
%thead
|
||||
%th
|
||||
Utilisateur
|
||||
|
@ -16,16 +16,28 @@
|
|||
Date d'envoi
|
||||
%th
|
||||
Lien
|
||||
-if @facade.procedure.cerfa_flag?
|
||||
- if @facade.dossier.cerfa_available?
|
||||
- @facade.cerfas_ordered.each do |cerfa|
|
||||
%thead.tr_content#cerfa
|
||||
-if @facade.procedure.cerfa_flag?
|
||||
- if @facade.dossier.cerfa_available?
|
||||
- @facade.cerfas_ordered.each do |cerfa|
|
||||
%tr
|
||||
%td.col-md-6.col-lg-4
|
||||
= cerfa.dossier.user.email
|
||||
%td.col-md-6.col-lg-4
|
||||
= cerfa.created_at
|
||||
%td.col-md-6.col-lg-4
|
||||
=link_to 'Récupérer', cerfa.content_url, {target: :blank}
|
||||
- @facade.dossier.types_de_piece_justificative.each do |type_de_piece_justificative|
|
||||
%tbody.tr_content{id: "type_de_pj_#{type_de_piece_justificative.id}"}
|
||||
- @facade.dossier.retrieve_all_piece_justificative_by_type(type_de_piece_justificative.id).each do |piece_justificative|
|
||||
%tr
|
||||
%td.col-md-6.col-lg-4
|
||||
= cerfa.dossier.user.email
|
||||
= piece_justificative.dossier.user.email
|
||||
%td.col-md-6.col-lg-4
|
||||
= cerfa.created_at
|
||||
= piece_justificative.created_at
|
||||
%td.col-md-6.col-lg-4
|
||||
=link_to 'Récupérer', cerfa.content_url, {target: :blank}
|
||||
=link_to 'Récupérer', piece_justificative.content_url, {target: :blank}
|
||||
|
||||
|
||||
|
||||
.modal-footer
|
||||
|
|
|
@ -18,22 +18,30 @@
|
|||
"data-toggle" => "modal",
|
||||
:type => "button",
|
||||
"data-modal_title" => 'formulaires',
|
||||
"data-modal_type" => 'cerfa'}
|
||||
"data-modal_index" => 'cerfa'}
|
||||
- else
|
||||
= 'Pièce non fournie'
|
||||
|
||||
- @facade.dossier.pieces_justificatives.each do |piece_justificative|
|
||||
%tr{ id: "piece_justificative_#{piece_justificative.type}" }
|
||||
- @facade.dossier.types_de_piece_justificative.each do |type_de_piece_justificative|
|
||||
%tr{ id: "piece_justificative_#{type_de_piece_justificative.id}" }
|
||||
%th.col-lg-6
|
||||
= piece_justificative.libelle
|
||||
= type_de_piece_justificative.libelle
|
||||
%td.col-lg-6.col-md-6
|
||||
- if piece_justificative.api_entreprise
|
||||
- if type_de_piece_justificative.api_entreprise
|
||||
%span.text-success Nous l'avons récupéré pour vous.
|
||||
- elsif !piece_justificative.empty?
|
||||
- elsif !(@pj = @facade.dossier.retrieve_last_piece_justificative_by_type(type_de_piece_justificative.id)).nil?
|
||||
- if user_signed_in?
|
||||
= 'Pièce fournie'
|
||||
- elsif gestionnaire_signed_in?
|
||||
%a{ href: "#{piece_justificative.content_url}", target: '_blank' } Consulter
|
||||
%a{ href: "#{@pj.content_url}", target: '_blank' } Consulter
|
||||
%span{style:'margin-left:12px'}
|
||||
\-
|
||||
%a.btn.glyphicon.glyphicon-time{style:'color: black; padding-top: 0',
|
||||
"data-target" => "#PJmodal",
|
||||
"data-toggle" => "modal",
|
||||
:type => "button",
|
||||
"data-modal_title" => type_de_piece_justificative.libelle,
|
||||
"data-modal_index" => "type_de_pj_#{type_de_piece_justificative.id}"}
|
||||
- else
|
||||
= 'Pièce non fournie'
|
||||
|
||||
|
|
|
@ -94,16 +94,16 @@
|
|||
application/vnd.oasis.opendocument.presentation,
|
||||
application/vnd.oasis.opendocument.spreadsheet", :max_file_size => 3.megabytes }
|
||||
|
||||
- @dossier.pieces_justificatives.each do |piece_justificative|
|
||||
- @dossier.types_de_piece_justificative.each do |type_de_piece_justificative|
|
||||
%tr
|
||||
%th.col-lg-6
|
||||
= piece_justificative.libelle
|
||||
= type_de_piece_justificative.libelle
|
||||
%td.col-lg-5
|
||||
-if piece_justificative.api_entreprise
|
||||
%span.text-success{ id: "piece_justificative_#{piece_justificative.type}" } Nous l'avons récupéré pour vous.
|
||||
-if type_de_piece_justificative.api_entreprise
|
||||
%span.text-success{ id: "piece_justificative_#{type_de_piece_justificative.id}" } Nous l'avons récupéré pour vous.
|
||||
-else
|
||||
-if piece_justificative.empty?
|
||||
= file_field_tag "piece_justificative_#{piece_justificative.type}", accept: " application/pdf,
|
||||
-if @dossier.retrieve_last_piece_justificative_by_type(type_de_piece_justificative.id).nil?
|
||||
= file_field_tag "piece_justificative_#{type_de_piece_justificative.id}", accept: " application/pdf,
|
||||
application/msword,
|
||||
application/vnd.openxmlformats-officedocument.wordprocessingml.document,
|
||||
application/vnd.ms-excel,
|
||||
|
@ -116,7 +116,7 @@
|
|||
-else
|
||||
%span.btn.btn-sm.btn-file.btn-success
|
||||
Modifier
|
||||
= file_field_tag "piece_justificative_#{piece_justificative.type}", accept: " application/pdf,
|
||||
= file_field_tag "piece_justificative_#{type_de_piece_justificative.id}", accept: " application/pdf,
|
||||
application/msword,
|
||||
application/vnd.openxmlformats-officedocument.wordprocessingml.document,
|
||||
application/vnd.ms-excel,
|
||||
|
|
|
@ -116,7 +116,7 @@ describe API::V1::DossiersController do
|
|||
let!(:dossier) { Timecop.freeze(date_creation) { create(:dossier, :with_entreprise, procedure: procedure) } }
|
||||
let(:dossier_id) { dossier.id }
|
||||
let(:body) { JSON.parse(retour.body, symbolize_names: true) }
|
||||
let(:field_list) { [:id, :nom_projet, :created_at, :updated_at, :description, :archived, :mandataire_social, :entreprise, :etablissement, :cerfa, :pieces_justificatives, :champs, :commentaires] }
|
||||
let(:field_list) { [:id, :nom_projet, :created_at, :updated_at, :description, :archived, :mandataire_social, :entreprise, :etablissement, :cerfa, :types_de_piece_justificative, :champs, :commentaires] }
|
||||
subject { body[:dossier] }
|
||||
|
||||
it 'return REST code 200', :show_in_doc do
|
||||
|
@ -161,30 +161,34 @@ describe API::V1::DossiersController do
|
|||
it { expect(subject.keys).to match_array(field_list) }
|
||||
end
|
||||
|
||||
describe 'pieces_justificatives' do
|
||||
describe 'types_de_piece_justificative' do
|
||||
before do
|
||||
create :piece_justificative, dossier: dossier, type_de_piece_justificative: dossier.procedure.types_de_piece_justificative.first
|
||||
end
|
||||
|
||||
let(:field_list) { [
|
||||
:url] }
|
||||
subject { super()[:pieces_justificatives] }
|
||||
:id,
|
||||
:libelle,
|
||||
:description] }
|
||||
subject { super()[:types_de_piece_justificative] }
|
||||
|
||||
it { expect(subject.length).to eq 2 }
|
||||
|
||||
describe 'first piece justificative' do
|
||||
describe 'first type de piece justificative' do
|
||||
subject { super().first }
|
||||
|
||||
it { expect(subject.keys.include?(:url)).to be_truthy }
|
||||
it { expect(subject[:created_at]).not_to be_nil }
|
||||
it { expect(subject.keys.include?(:type_de_piece_justificative)).to be_truthy }
|
||||
it { expect(subject.keys.include?(:id)).to be_truthy }
|
||||
it { expect(subject[:libelle]).to eq('RIB') }
|
||||
it { expect(subject[:description]).to eq('Releve identité bancaire') }
|
||||
|
||||
describe 'type de piece justificative' do
|
||||
describe 'piece justificative' do
|
||||
let(:field_list) { [
|
||||
:id,
|
||||
:libelle,
|
||||
:description] }
|
||||
subject { super()[:type_de_piece_justificative] }
|
||||
:url, :created_at] }
|
||||
subject {
|
||||
super()[:pieces_justificatives].first }
|
||||
|
||||
it { expect(subject.keys.include?(:id)).to be_truthy }
|
||||
it { expect(subject[:libelle]).to eq('RIB') }
|
||||
it { expect(subject[:description]).to eq('Releve identité bancaire') }
|
||||
it { expect(subject.keys.include?(:url)).to be_truthy }
|
||||
it { expect(subject[:created_at]).not_to be_nil }
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -220,11 +220,11 @@ describe Users::DescriptionController, type: :controller do
|
|||
end
|
||||
|
||||
context 'for piece 0' do
|
||||
subject { dossier.retrieve_piece_justificative_by_type all_pj_type[0].to_s }
|
||||
subject { dossier.retrieve_last_piece_justificative_by_type all_pj_type[0].to_s }
|
||||
it { expect(subject.content).not_to be_nil }
|
||||
end
|
||||
context 'for piece 1' do
|
||||
subject { dossier.retrieve_piece_justificative_by_type all_pj_type[1].to_s }
|
||||
subject { dossier.retrieve_last_piece_justificative_by_type all_pj_type[1].to_s }
|
||||
it { expect(subject.content).not_to be_nil }
|
||||
end
|
||||
end
|
||||
|
|
|
@ -42,7 +42,7 @@ feature 'user is on description page' do
|
|||
end
|
||||
context 'when he adds a piece_justificative and submit form' do
|
||||
before do
|
||||
file_input_id = 'piece_justificative_' + dossier.pieces_justificatives.first.type.to_s
|
||||
file_input_id = 'piece_justificative_' + dossier.types_de_piece_justificative.first.id.to_s
|
||||
attach_file(file_input_id, File.path('spec/support/files/dossierPDF.pdf'))
|
||||
click_on('Soumettre mon dossier')
|
||||
dossier.reload
|
||||
|
|
|
@ -88,24 +88,17 @@ describe Dossier do
|
|||
end
|
||||
end
|
||||
|
||||
describe '#retrieve_piece_justificative_by_type' do
|
||||
let(:all_dossier_pj_id) { dossier.procedure.types_de_piece_justificative }
|
||||
subject { dossier.retrieve_piece_justificative_by_type all_dossier_pj_id.first }
|
||||
describe '#retrieve_last_piece_justificative_by_type' do
|
||||
let(:types_de_pj_dossier) { dossier.procedure.types_de_piece_justificative }
|
||||
|
||||
subject { dossier.retrieve_last_piece_justificative_by_type types_de_pj_dossier.first }
|
||||
|
||||
before do
|
||||
dossier.build_default_pieces_justificatives
|
||||
create :piece_justificative, :rib, dossier: dossier, type_de_piece_justificative: types_de_pj_dossier.first
|
||||
end
|
||||
|
||||
it 'returns piece justificative with given type' do
|
||||
expect(subject.type).to eq(all_dossier_pj_id.first.id)
|
||||
end
|
||||
end
|
||||
|
||||
describe '#build_default_pieces_justificatives' do
|
||||
context 'when dossier is linked to a procedure' do
|
||||
let(:dossier) { create(:dossier, user: user) }
|
||||
it 'build all pieces justificatives needed' do
|
||||
expect(dossier.pieces_justificatives.count).to eq(2)
|
||||
end
|
||||
expect(subject.type).to eq(types_de_pj_dossier.first.id)
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -123,11 +116,6 @@ describe Dossier do
|
|||
subject { build(:dossier, procedure: procedure, user: user) }
|
||||
let!(:procedure) { create(:procedure) }
|
||||
context 'when is linked to a procedure' do
|
||||
it 'creates default pieces justificatives' do
|
||||
expect(subject).to receive(:build_default_pieces_justificatives)
|
||||
subject.save
|
||||
end
|
||||
|
||||
it 'creates default champs' do
|
||||
expect(subject).to receive(:build_default_champs)
|
||||
subject.save
|
||||
|
@ -135,10 +123,6 @@ describe Dossier do
|
|||
end
|
||||
context 'when is not linked to a procedure' do
|
||||
subject { create(:dossier, procedure: procedure, user: user) }
|
||||
it 'does not create default pieces justificatives' do
|
||||
expect(subject).not_to receive(:build_default_pieces_justificatives)
|
||||
subject.update_attributes(description: 'plop')
|
||||
end
|
||||
|
||||
it 'does not create default champs' do
|
||||
expect(subject).not_to receive(:build_default_champs)
|
||||
|
|
Loading…
Reference in a new issue