Merge branch 'develop' of github.com:sgmap/tps into develop
# Conflicts: # app/views/admin/procedures/_modal_publish.html.haml
This commit is contained in:
commit
721ea424ed
9 changed files with 71 additions and 62 deletions
|
@ -54,8 +54,6 @@ function path_validation(el) {
|
|||
}
|
||||
|
||||
function validatePath(path) {
|
||||
console.log(path);
|
||||
|
||||
var re = /^[a-z0-9_]{3,30}$/;
|
||||
return re.test(path);
|
||||
}
|
||||
|
@ -81,6 +79,7 @@ function path_type_init() {
|
|||
display: display,
|
||||
source: bloodhound,
|
||||
templates: {
|
||||
empty: 'Ce lien est disponible !',
|
||||
suggestion: Handlebars.compile("<div class='path_mine_{{mine}}'>{{label}}</div>")
|
||||
},
|
||||
limit: 5
|
||||
|
|
|
@ -87,26 +87,30 @@ class Admin::ProceduresController < AdminController
|
|||
end
|
||||
|
||||
def publish
|
||||
if ! ProcedurePathFormatValidator.new().validate_string(params[:procedure_path])
|
||||
procedure = current_administrateur.procedures.find(params[:procedure_id])
|
||||
|
||||
test_procedure = ProcedurePath.new(
|
||||
{
|
||||
path: params[:procedure_path],
|
||||
procedure: procedure,
|
||||
administrateur: procedure.administrateur
|
||||
})
|
||||
unless test_procedure.validate
|
||||
flash.alert = 'Lien de la procédure invalide'
|
||||
return redirect_to admin_procedures_path
|
||||
end
|
||||
|
||||
procedure_path = ProcedurePath.find_by_path(params[:procedure_path])
|
||||
@procedure = current_administrateur.procedures.find(params[:procedure_id])
|
||||
|
||||
if (procedure_path)
|
||||
if (procedure_path.administrateur_id == current_administrateur.id)
|
||||
procedure_path.procedure.archive
|
||||
@procedure.publish(params[:procedure_path])
|
||||
else
|
||||
@mine = false
|
||||
return render '/admin/procedures/publish', formats: 'js'
|
||||
end
|
||||
else
|
||||
@procedure.publish(params[:procedure_path])
|
||||
end
|
||||
|
||||
procedure.publish(params[:procedure_path])
|
||||
flash.notice = "Procédure publiée"
|
||||
render js: "window.location = '#{admin_procedures_path}'"
|
||||
|
||||
|
@ -116,8 +120,8 @@ class Admin::ProceduresController < AdminController
|
|||
end
|
||||
|
||||
def archive
|
||||
@procedure = current_administrateur.procedures.find(params[:procedure_id])
|
||||
@procedure.archive
|
||||
procedure = current_administrateur.procedures.find(params[:procedure_id])
|
||||
procedure.archive
|
||||
|
||||
flash.notice = "Procédure archivée"
|
||||
redirect_to admin_procedures_path
|
||||
|
@ -128,14 +132,14 @@ class Admin::ProceduresController < AdminController
|
|||
end
|
||||
|
||||
def clone
|
||||
@procedure = current_administrateur.procedures.find(params[:procedure_id])
|
||||
procedure = current_administrateur.procedures.find(params[:procedure_id])
|
||||
|
||||
new_procedure = @procedure.clone
|
||||
new_procedure = procedure.clone
|
||||
if new_procedure
|
||||
flash.notice = 'Procédure clonée'
|
||||
redirect_to edit_admin_procedure_path(id: new_procedure.id)
|
||||
else
|
||||
flash.now.alert = @procedure.errors.full_messages.join('<br />').html_safe
|
||||
flash.now.alert = procedure.errors.full_messages.join('<br />').html_safe
|
||||
render 'index'
|
||||
end
|
||||
|
||||
|
|
|
@ -28,6 +28,10 @@ class Procedure < ActiveRecord::Base
|
|||
procedure_path.path unless procedure_path.nil?
|
||||
end
|
||||
|
||||
def default_path
|
||||
libelle.downcase.gsub(/[^a-z0-9\-_]/,"_").gsub(/_*$/, '').gsub(/_+/, '_')
|
||||
end
|
||||
|
||||
def types_de_champ_ordered
|
||||
types_de_champ.order(:order_place)
|
||||
end
|
||||
|
|
|
@ -9,8 +9,4 @@ class ProcedurePathFormatValidator < ActiveModel::Validator
|
|||
record.errors[:path] << "Path invalide" unless path_regex.match(record.path)
|
||||
end
|
||||
|
||||
def validate_string(path)
|
||||
return false if path.blank?
|
||||
path_regex.match(path)
|
||||
end
|
||||
end
|
||||
|
|
|
@ -23,8 +23,8 @@
|
|||
%br
|
||||
%h4 Lien de la procédure
|
||||
%p.center
|
||||
= root_url
|
||||
= text_field_tag('procedure_path', @procedure.libelle.downcase.gsub(/[^a-z0-9\-_]/,"_").gsub(/_*$/, '').gsub(/_+/, '_'),
|
||||
="#{root_url}commencer/"
|
||||
= text_field_tag('procedure_path', @procedure.default_path,
|
||||
id: 'procedure_path',
|
||||
placeholder: 'Chemin vers la procédure',
|
||||
class:'form-control',
|
||||
|
@ -40,7 +40,7 @@
|
|||
%br
|
||||
Vous ne pouvez pas l'utiliser car il appartient à un autre administrateur.
|
||||
#path_is_invalid.text-danger.center.message
|
||||
Ce lien n'est pas valide. Seuls les caractères a-z, 0-9 et '_' sont autorisés.
|
||||
Ce lien n'est pas valide. Il doit comporter au moins 3 caractères et seuls les caractères a-z, 0-9 et '_' sont autorisés.
|
||||
.modal-footer
|
||||
= submit_tag "#{@procedure.archived?? 'Réactiver' : 'Publier'}", class: %w(btn btn btn-success),
|
||||
id: 'publish',
|
||||
|
|
|
@ -2,19 +2,19 @@
|
|||
=render partial: 'head', locals: {active: 'Informations'}
|
||||
|
||||
-if ! @facade.procedure.published?
|
||||
%a.btn.btn-success{"data-target" => "#publishModal", "data-toggle" => "modal", :type => "button", style:'float: right; margin-top: 10px'}
|
||||
%a#publish.btn.btn-success{"data-target" => "#publishModal", "data-toggle" => "modal", :type => "button", style:'float: right; margin-top: 10px'}
|
||||
%i.fa.fa-eraser
|
||||
Publier
|
||||
%br
|
||||
=render partial: '/admin/procedures/modal_publish'
|
||||
|
||||
-if @facade.procedure.archived?
|
||||
%a.btn.btn-small.btn-default.text-info{"data-target" => "#publishModal", "data-toggle" => "modal", :type => "button", style:'float: right; margin-top: 10px'}
|
||||
%a#reenable.btn.btn-small.btn-default.text-info{"data-target" => "#publishModal", "data-toggle" => "modal", :type => "button", style:'float: right; margin-top: 10px'}
|
||||
%i.fa.fa-eraser
|
||||
Réactiver
|
||||
%br
|
||||
=render partial: '/admin/procedures/modal_publish'
|
||||
-else
|
||||
-elsif @facade.procedure.published?
|
||||
= form_tag admin_procedure_archive_path(procedure_id: @facade.procedure.id, archive: !@facade.procedure.archived?), method: :put, style:'float: right; margin-top: 10px' do
|
||||
%button#archive.btn.btn-small.btn-default.text-info{type: :button}
|
||||
%i.fa.fa-eraser
|
||||
|
|
|
@ -364,7 +364,7 @@ describe Admin::ProceduresController, type: :controller do
|
|||
it { expect(flash[:notice]).to have_content 'Procédure archivée' }
|
||||
end
|
||||
|
||||
context 'when owner want reactive procedure' do
|
||||
context 'when owner want to re-enable procedure' do
|
||||
before do
|
||||
put :publish, procedure_id: procedure.id, procedure_path: 'fake_path'
|
||||
procedure.reload
|
||||
|
|
|
@ -11,24 +11,24 @@ describe ProcedurePath do
|
|||
end
|
||||
|
||||
describe 'validation' do
|
||||
context 'path' do
|
||||
describe 'path' do
|
||||
let(:admin) { create(:administrateur) }
|
||||
let(:procedure) { create(:procedure) }
|
||||
let(:procedure_path) { create(:procedure_path, administrateur: admin, procedure: procedure, path: path) }
|
||||
|
||||
context 'path is nil' do
|
||||
context 'when path is nil' do
|
||||
let(:path) { nil }
|
||||
it { expect{procedure_path}.to raise_error }
|
||||
it { expect{procedure_path}.to raise_error ActiveRecord::RecordInvalid }
|
||||
end
|
||||
context 'path is empty' do
|
||||
context 'when path is empty' do
|
||||
let(:path) { '' }
|
||||
it { expect{procedure_path}.to raise_error }
|
||||
it { expect{procedure_path}.to raise_error ActiveRecord::RecordInvalid }
|
||||
end
|
||||
context 'path is invalid' do
|
||||
context 'when path is invalid' do
|
||||
let(:path) { 'Demande de subvention' }
|
||||
it { expect{procedure_path}.to raise_error(ActiveRecord::RecordInvalid) }
|
||||
it { expect{procedure_path}.to raise_error ActiveRecord::RecordInvalid }
|
||||
end
|
||||
context 'path is invalid' do
|
||||
context 'when path is valid' do
|
||||
let(:path) { 'ma_super_procedure' }
|
||||
it { expect{procedure_path}.not_to raise_error }
|
||||
end
|
||||
|
|
|
@ -7,53 +7,59 @@ describe 'admin/procedures/show.html.haml', type: :view do
|
|||
before do
|
||||
assign(:facade, AdminProceduresShowFacades.new(procedure.decorate))
|
||||
assign(:procedure, procedure)
|
||||
render
|
||||
end
|
||||
|
||||
describe 'publish button' do
|
||||
it { expect(rendered).to have_content('Publier') }
|
||||
end
|
||||
|
||||
describe 'archive and unarchive button' do
|
||||
describe 'procedure is draft' do
|
||||
before do
|
||||
procedure.publish('fake_path')
|
||||
render
|
||||
end
|
||||
|
||||
context 'when procedure is published' do
|
||||
before do
|
||||
procedure.publish('fake_path')
|
||||
procedure.reload
|
||||
end
|
||||
it { expect(rendered).to have_content('Archiver') }
|
||||
describe 'publish button is visible' do
|
||||
it { expect(rendered).to have_css('a#publish') }
|
||||
it { expect(rendered).not_to have_css('button#archive') }
|
||||
it { expect(rendered).not_to have_css('a#reenable') }
|
||||
end
|
||||
|
||||
context 'when procedure is archived' do
|
||||
let(:archived) { true }
|
||||
it { expect(rendered).to have_content('Réactiver') }
|
||||
describe 'procedure link is not present' do
|
||||
it { expect(rendered).to have_content('Cette procédure n\'a pas encore été publiée et n\'est donc pas accessible par le public.') }
|
||||
end
|
||||
end
|
||||
|
||||
describe 'procedure link' do
|
||||
|
||||
context 'is not present when not published' do
|
||||
it { expect(rendered).to have_content('Cette procédure n\'a pas encore été publiée et n\'est donc pas accessible par le public.') }
|
||||
describe 'procedure is published' do
|
||||
before do
|
||||
procedure.publish('fake_path')
|
||||
procedure.reload
|
||||
render
|
||||
end
|
||||
|
||||
context 'is present when already published' do
|
||||
before do
|
||||
procedure.publish('fake_path')
|
||||
render
|
||||
end
|
||||
describe 'archive button is visible', js: true do
|
||||
it { expect(rendered).not_to have_css('a#publish') }
|
||||
it { expect(rendered).to have_css('button#archive') }
|
||||
it { expect(rendered).not_to have_css('a#reenable') }
|
||||
end
|
||||
|
||||
describe 'procedure link is present' do
|
||||
it { expect(rendered).to have_content(commencer_url(procedure_path: procedure.path)) }
|
||||
end
|
||||
end
|
||||
|
||||
context 'is not present when archived' do
|
||||
before do
|
||||
procedure.archive
|
||||
render
|
||||
end
|
||||
describe 'procedure is archived' do
|
||||
before do
|
||||
procedure.publish('fake_path')
|
||||
procedure.archive
|
||||
procedure.reload
|
||||
render
|
||||
end
|
||||
|
||||
describe 'Re-enable button is visible' do
|
||||
it { expect(rendered).not_to have_css('a#publish') }
|
||||
it { expect(rendered).not_to have_css('button#archive') }
|
||||
it { expect(rendered).to have_css('a#reenable') }
|
||||
end
|
||||
|
||||
describe 'procedure link is not present' do
|
||||
it { expect(rendered).to have_content('Cette procédure a été archivée et n\'est plus accessible par le public.') }
|
||||
end
|
||||
end
|
||||
|
||||
end
|
Loading…
Reference in a new issue