2015-11-16 16:16:08 +01:00
|
|
|
class Admin::ProceduresController < AdminController
|
2016-01-07 15:29:29 +01:00
|
|
|
include SmartListing::Helper::ControllerExtensions
|
|
|
|
helper SmartListing::Helper
|
2015-10-26 15:54:20 +01:00
|
|
|
|
2015-12-24 15:57:03 +01:00
|
|
|
before_action :retrieve_procedure, only: [:show, :edit]
|
2015-12-21 12:02:53 +01:00
|
|
|
|
2015-10-26 15:54:20 +01:00
|
|
|
def index
|
2018-01-30 14:43:56 +01:00
|
|
|
# FIXME: remove when
|
|
|
|
# https://github.com/Sology/smart_listing/issues/134
|
|
|
|
# is fixed
|
|
|
|
permit_smart_listing_params
|
|
|
|
# END OF FIXME
|
|
|
|
|
2016-01-07 15:29:29 +01:00
|
|
|
@procedures = smart_listing_create :procedures,
|
2017-07-17 16:36:32 +02:00
|
|
|
current_administrateur.procedures.publiees.order(published_at: :desc),
|
2017-06-12 13:49:51 +02:00
|
|
|
partial: "admin/procedures/list",
|
|
|
|
array: true
|
2016-01-07 15:29:29 +01:00
|
|
|
|
2015-12-24 15:22:07 +01:00
|
|
|
active_class
|
2015-10-26 15:54:20 +01:00
|
|
|
end
|
|
|
|
|
2015-11-27 16:23:02 +01:00
|
|
|
def archived
|
2018-01-30 14:43:56 +01:00
|
|
|
# FIXME: remove when
|
|
|
|
# https://github.com/Sology/smart_listing/issues/134
|
|
|
|
# is fixed
|
|
|
|
permit_smart_listing_params
|
|
|
|
# END OF FIXME
|
|
|
|
|
2016-01-07 15:29:29 +01:00
|
|
|
@procedures = smart_listing_create :procedures,
|
2017-07-17 16:36:32 +02:00
|
|
|
current_administrateur.procedures.archivees.order(published_at: :desc),
|
2017-06-12 13:49:51 +02:00
|
|
|
partial: "admin/procedures/list",
|
|
|
|
array: true
|
2016-01-07 15:29:29 +01:00
|
|
|
|
2015-12-24 15:22:07 +01:00
|
|
|
archived_class
|
2016-01-07 15:29:29 +01:00
|
|
|
|
|
|
|
render 'index'
|
2015-11-27 16:23:02 +01:00
|
|
|
end
|
|
|
|
|
2016-06-09 17:49:38 +02:00
|
|
|
def draft
|
2018-01-30 14:43:56 +01:00
|
|
|
# FIXME: remove when
|
|
|
|
# https://github.com/Sology/smart_listing/issues/134
|
|
|
|
# is fixed
|
|
|
|
permit_smart_listing_params
|
|
|
|
# END OF FIXME
|
|
|
|
|
2016-06-09 17:49:38 +02:00
|
|
|
@procedures = smart_listing_create :procedures,
|
2017-07-11 15:16:06 +02:00
|
|
|
current_administrateur.procedures.brouillons.order(created_at: :desc),
|
2017-06-12 13:49:51 +02:00
|
|
|
partial: "admin/procedures/list",
|
|
|
|
array: true
|
2016-06-09 17:49:38 +02:00
|
|
|
|
|
|
|
draft_class
|
|
|
|
|
|
|
|
render 'index'
|
|
|
|
end
|
|
|
|
|
2015-10-26 15:54:20 +01:00
|
|
|
def show
|
2015-12-24 15:57:03 +01:00
|
|
|
@facade = AdminProceduresShowFacades.new @procedure.decorate
|
2015-12-04 16:17:35 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
def edit
|
2015-10-26 15:54:20 +01:00
|
|
|
end
|
|
|
|
|
2017-06-28 18:18:51 +02:00
|
|
|
def hide
|
2017-07-20 14:44:54 +02:00
|
|
|
procedure = current_administrateur.procedures.find(params[:id])
|
2017-06-28 18:18:51 +02:00
|
|
|
procedure.hide!
|
2018-01-18 17:45:33 +01:00
|
|
|
# procedure should no longer be reachable so we delete its procedure_path
|
|
|
|
# that way it is also available for another procedure
|
|
|
|
# however, sometimes the path has already been deleted (ex: stolen by another procedure),
|
|
|
|
# so we're not certain the procedure has a procedure_path anymore
|
|
|
|
procedure.procedure_path.try(:destroy)
|
2017-06-28 18:18:51 +02:00
|
|
|
|
2018-02-28 17:37:44 +01:00
|
|
|
flash.notice = "Procédure supprimée, en cas d'erreur contactez nous : contact@demarches-simplifiees.fr"
|
2017-06-28 18:18:51 +02:00
|
|
|
redirect_to admin_procedures_draft_path
|
|
|
|
end
|
|
|
|
|
2017-12-21 17:59:56 +01:00
|
|
|
def destroy
|
|
|
|
procedure = current_administrateur.procedures.find(params[:id])
|
|
|
|
|
|
|
|
return render json: {}, status: 401 if procedure.publiee_ou_archivee?
|
|
|
|
|
|
|
|
procedure.destroy
|
|
|
|
|
|
|
|
flash.notice = 'Procédure supprimée'
|
|
|
|
redirect_to admin_procedures_draft_path
|
|
|
|
end
|
|
|
|
|
2015-10-26 15:54:20 +01:00
|
|
|
def new
|
|
|
|
@procedure ||= Procedure.new
|
2015-12-08 10:11:58 +01:00
|
|
|
@procedure.module_api_carto ||= ModuleAPICarto.new
|
2015-10-26 15:54:20 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
def create
|
2017-02-14 18:13:19 +01:00
|
|
|
@procedure = Procedure.new(procedure_params)
|
2015-12-08 10:11:58 +01:00
|
|
|
@procedure.module_api_carto = ModuleAPICarto.new(create_module_api_carto_params) if @procedure.valid?
|
2015-10-26 15:54:20 +01:00
|
|
|
|
2018-01-11 19:04:39 +01:00
|
|
|
if !@procedure.save
|
2017-07-13 09:46:13 +02:00
|
|
|
flash.now.alert = @procedure.errors.full_messages
|
2015-10-26 15:54:20 +01:00
|
|
|
return render 'new'
|
|
|
|
end
|
|
|
|
|
|
|
|
flash.notice = 'Procédure enregistrée'
|
2015-11-26 18:41:41 +01:00
|
|
|
redirect_to admin_procedure_types_de_champ_path(procedure_id: @procedure.id)
|
2015-10-26 15:54:20 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
def update
|
2015-11-27 10:39:05 +01:00
|
|
|
@procedure = current_administrateur.procedures.find(params[:id])
|
2015-10-26 15:54:20 +01:00
|
|
|
|
2018-01-11 19:04:39 +01:00
|
|
|
if !@procedure.update_attributes(procedure_params)
|
2017-07-13 09:46:13 +02:00
|
|
|
flash.now.alert = @procedure.errors.full_messages
|
2015-12-04 16:17:35 +01:00
|
|
|
return render 'edit'
|
2015-10-26 15:54:20 +01:00
|
|
|
end
|
2015-12-10 17:13:39 +01:00
|
|
|
|
2017-02-15 15:21:34 +01:00
|
|
|
flash.notice = 'Procédure modifiée'
|
2016-06-06 18:25:51 +02:00
|
|
|
redirect_to edit_admin_procedure_path(id: @procedure.id)
|
2015-10-26 15:54:20 +01:00
|
|
|
end
|
|
|
|
|
2016-06-09 17:49:38 +02:00
|
|
|
def publish
|
2016-06-30 10:24:01 +02:00
|
|
|
procedure = current_administrateur.procedures.find(params[:procedure_id])
|
|
|
|
|
2016-07-12 15:20:10 +02:00
|
|
|
new_procedure_path = ProcedurePath.new(
|
2018-01-15 18:48:14 +01:00
|
|
|
{
|
|
|
|
path: params[:procedure_path],
|
|
|
|
procedure: procedure,
|
|
|
|
administrateur: procedure.administrateur
|
2018-01-15 19:29:44 +01:00
|
|
|
}
|
|
|
|
)
|
2018-01-15 18:48:14 +01:00
|
|
|
|
2016-07-12 15:20:10 +02:00
|
|
|
if new_procedure_path.validate
|
|
|
|
new_procedure_path.delete
|
|
|
|
else
|
2016-06-24 16:41:44 +02:00
|
|
|
flash.alert = 'Lien de la procédure invalide'
|
|
|
|
return redirect_to admin_procedures_path
|
|
|
|
end
|
|
|
|
|
|
|
|
procedure_path = ProcedurePath.find_by_path(params[:procedure_path])
|
2016-07-12 15:20:10 +02:00
|
|
|
if procedure_path
|
|
|
|
if procedure_path.administrateur_id == current_administrateur.id
|
2016-06-24 16:41:44 +02:00
|
|
|
procedure_path.procedure.archive
|
2016-12-21 11:00:05 +01:00
|
|
|
procedure_path.delete
|
2016-06-24 16:41:44 +02:00
|
|
|
else
|
2016-06-30 12:33:43 +02:00
|
|
|
@mine = false
|
|
|
|
return render '/admin/procedures/publish', formats: 'js'
|
2016-06-24 16:41:44 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-07-12 15:20:10 +02:00
|
|
|
procedure.publish!(params[:procedure_path])
|
|
|
|
|
2016-06-24 16:41:44 +02:00
|
|
|
flash.notice = "Procédure publiée"
|
2016-06-30 12:33:43 +02:00
|
|
|
render js: "window.location = '#{admin_procedures_path}'"
|
2016-06-24 16:41:44 +02:00
|
|
|
|
|
|
|
rescue ActiveRecord::RecordNotFound
|
2017-07-13 10:16:55 +02:00
|
|
|
flash.alert = 'Procédure inexistante'
|
2016-06-24 16:41:44 +02:00
|
|
|
redirect_to admin_procedures_path
|
2016-06-09 17:49:38 +02:00
|
|
|
end
|
2015-11-26 18:41:41 +01:00
|
|
|
|
2016-07-22 11:34:34 +02:00
|
|
|
def transfer
|
2017-06-26 16:06:53 +02:00
|
|
|
admin = Administrateur.find_by_email(params[:email_admin].downcase)
|
2016-07-22 12:25:23 +02:00
|
|
|
|
2017-06-22 16:45:52 +02:00
|
|
|
if admin.nil?
|
|
|
|
render '/admin/procedures/transfer', formats: 'js', status: 404
|
|
|
|
else
|
|
|
|
procedure = current_administrateur.procedures.find(params[:procedure_id])
|
2018-01-08 14:44:15 +01:00
|
|
|
clone_procedure = procedure.clone(admin)
|
2016-07-22 12:25:23 +02:00
|
|
|
|
2017-06-22 16:45:52 +02:00
|
|
|
clone_procedure.save
|
2016-07-22 11:34:34 +02:00
|
|
|
|
2017-06-22 16:45:52 +02:00
|
|
|
flash.now.notice = "La procédure a correctement été clonée vers le nouvel administrateur."
|
2016-07-22 11:34:34 +02:00
|
|
|
|
2017-06-22 16:45:52 +02:00
|
|
|
render '/admin/procedures/transfer', formats: 'js', status: 200
|
|
|
|
end
|
2016-07-22 11:34:34 +02:00
|
|
|
end
|
|
|
|
|
2016-06-09 17:49:38 +02:00
|
|
|
def archive
|
2016-06-30 10:24:01 +02:00
|
|
|
procedure = current_administrateur.procedures.find(params[:procedure_id])
|
|
|
|
procedure.archive
|
2016-06-24 16:41:44 +02:00
|
|
|
|
|
|
|
flash.notice = "Procédure archivée"
|
|
|
|
redirect_to admin_procedures_path
|
|
|
|
|
|
|
|
rescue ActiveRecord::RecordNotFound
|
2017-07-13 10:16:55 +02:00
|
|
|
flash.alert = 'Procédure inexistante'
|
2016-06-24 16:41:44 +02:00
|
|
|
redirect_to admin_procedures_path
|
2015-11-26 18:41:41 +01:00
|
|
|
end
|
|
|
|
|
2016-06-15 11:34:05 +02:00
|
|
|
def clone
|
2018-01-08 14:44:28 +01:00
|
|
|
procedure = Procedure.find(params[:procedure_id])
|
2018-01-08 14:44:15 +01:00
|
|
|
new_procedure = procedure.clone(current_administrateur)
|
2018-01-08 15:42:38 +01:00
|
|
|
|
|
|
|
if new_procedure.save
|
2016-06-15 11:34:05 +02:00
|
|
|
flash.notice = 'Procédure clonée'
|
|
|
|
redirect_to edit_admin_procedure_path(id: new_procedure.id)
|
|
|
|
else
|
2018-01-08 15:43:41 +01:00
|
|
|
if params[:from_new_from_existing].present?
|
|
|
|
flash.alert = new_procedure.errors.full_messages
|
|
|
|
redirect_to new_from_existing_admin_procedures_path
|
|
|
|
else
|
|
|
|
flash.now.alert = new_procedure.errors.full_messages
|
|
|
|
render 'index'
|
|
|
|
end
|
2016-06-15 11:34:05 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
rescue ActiveRecord::RecordNotFound
|
2017-07-13 10:16:55 +02:00
|
|
|
flash.alert = 'Procédure inexistante'
|
2016-06-15 11:34:05 +02:00
|
|
|
redirect_to admin_procedures_path
|
|
|
|
end
|
|
|
|
|
2018-01-04 18:36:45 +01:00
|
|
|
def new_from_existing
|
|
|
|
procedures_with_more_than_30_dossiers_ids = Procedure
|
|
|
|
.publiees_ou_archivees
|
|
|
|
.joins(:dossiers)
|
|
|
|
.group("procedures.id")
|
|
|
|
.having("count(dossiers.id) > ?", 30)
|
|
|
|
.pluck('procedures.id')
|
|
|
|
|
|
|
|
@grouped_procedures = Procedure
|
|
|
|
.where(id: procedures_with_more_than_30_dossiers_ids)
|
|
|
|
.group_by(&:administrateur)
|
|
|
|
.sort_by { |a, _| a.created_at }
|
|
|
|
end
|
|
|
|
|
2015-12-24 15:22:07 +01:00
|
|
|
def active_class
|
2016-01-19 17:19:38 +01:00
|
|
|
@active_class = 'active'
|
2015-12-24 15:22:07 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
def archived_class
|
2016-01-19 17:19:38 +01:00
|
|
|
@archived_class = 'active'
|
2015-12-24 15:22:07 +01:00
|
|
|
end
|
|
|
|
|
2016-06-09 17:49:38 +02:00
|
|
|
def draft_class
|
|
|
|
@draft_class = 'active'
|
|
|
|
end
|
|
|
|
|
2016-06-24 16:41:44 +02:00
|
|
|
def path_list
|
2018-01-15 19:22:02 +01:00
|
|
|
json_path_list = ProcedurePath
|
|
|
|
.joins(', procedures')
|
|
|
|
.where("procedures.id = procedure_paths.procedure_id")
|
|
|
|
.where("procedures.archived_at" => nil)
|
|
|
|
.where("path LIKE ?", "%#{params[:request]}%")
|
|
|
|
.pluck(:path, :administrateur_id)
|
|
|
|
.map do |value|
|
|
|
|
{
|
|
|
|
label: value.first,
|
|
|
|
mine: value.second == current_administrateur.id
|
|
|
|
}
|
|
|
|
end.to_json
|
|
|
|
|
|
|
|
render json: json_path_list
|
2016-06-24 16:41:44 +02:00
|
|
|
end
|
|
|
|
|
2015-10-26 15:54:20 +01:00
|
|
|
private
|
|
|
|
|
2017-02-14 18:13:19 +01:00
|
|
|
def procedure_params
|
2017-03-14 10:45:59 +01:00
|
|
|
editable_params = [:libelle, :description, :organisation, :direction, :lien_site_web, :lien_notice, :euro_flag, :logo, :auto_archive_on]
|
2017-02-15 14:13:02 +01:00
|
|
|
if @procedure.try(:locked?)
|
2017-03-14 10:45:59 +01:00
|
|
|
params.require(:procedure).permit(*editable_params)
|
2017-02-15 14:13:02 +01:00
|
|
|
else
|
2018-02-06 16:58:04 +01:00
|
|
|
params.require(:procedure).permit(*editable_params, :lien_demarche, :cerfa_flag, :for_individual, :individual_with_siret, :ask_birthday, module_api_carto_attributes: [:id, :use_api_carto, :quartiers_prioritaires, :cadastre]).merge(administrateur_id: current_administrateur.id)
|
2017-02-15 14:13:02 +01:00
|
|
|
end
|
2015-12-08 10:11:58 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
def create_module_api_carto_params
|
|
|
|
params.require(:procedure).require(:module_api_carto_attributes).permit(:id, :use_api_carto, :quartiers_prioritaires, :cadastre)
|
2015-10-26 15:54:20 +01:00
|
|
|
end
|
|
|
|
end
|