Refactor types_de_champ views to use service instead of facade

This commit is contained in:
Paul Chavard 2018-11-06 14:53:07 +01:00
parent 1c87eda6e1
commit a7de2e68ed
9 changed files with 40 additions and 37 deletions

View file

@ -5,30 +5,30 @@ class Admin::TypesDeChampController < AdminController
def destroy
@procedure.types_de_champ.destroy(params[:id])
create_facade
setup_type_de_champ_service
render 'show', format: :js
rescue ActiveRecord::RecordNotFound
render json: { message: 'Champ not found' }, status: 404
end
def show
create_facade
setup_type_de_champ_service
end
def update
if @procedure.update(TypesDeChampService.create_update_procedure_params params)
setup_type_de_champ_service
if @procedure.update(@type_de_champ_service.create_update_procedure_params(params))
flash.now.notice = 'Modifications sauvegardées'
else
flash.now.alert = @procedure.errors.full_messages.join(', ')
end
create_facade
render 'show', format: :js
end
def move_up
index = params[:index].to_i - 1
if @procedure.switch_types_de_champ index
create_facade
if @procedure.switch_types_de_champ(index)
setup_type_de_champ_service
render 'show', format: :js
else
render json: {}, status: 400
@ -36,8 +36,8 @@ class Admin::TypesDeChampController < AdminController
end
def move_down
if @procedure.switch_types_de_champ params[:index].to_i
create_facade
if @procedure.switch_types_de_champ(params[:index].to_i)
setup_type_de_champ_service
render 'show', format: :js
else
render json: {}, status: 400
@ -46,7 +46,7 @@ class Admin::TypesDeChampController < AdminController
private
def create_facade
@types_de_champ_facade = AdminTypesDeChampFacades.new false, @procedure
def setup_type_de_champ_service
@type_de_champ_service = TypesDeChampService.new(@procedure)
end
end

View file

@ -5,28 +5,31 @@ class Admin::TypesDeChampPrivateController < AdminController
def destroy
@procedure.types_de_champ_private.destroy(params[:id])
create_facade
setup_type_de_champ_service
render 'admin/types_de_champ/show', format: :js
rescue ActiveRecord::RecordNotFound
render json: { message: 'Champ not found' }, status: 404
end
def show
create_facade
setup_type_de_champ_service
render 'admin/types_de_champ/show'
end
def update
@procedure.update(TypesDeChampService.create_update_procedure_params params, true)
create_facade
flash.now.notice = 'Modifications sauvegardées'
setup_type_de_champ_service
if @procedure.update(@type_de_champ_service.create_update_procedure_params(params))
flash.now.notice = 'Modifications sauvegardées'
else
flash.now.alert = @procedure.errors.full_messages.join(', ')
end
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
if @procedure.switch_types_de_champ_private(index)
setup_type_de_champ_service
render 'admin/types_de_champ/show', format: :js
else
render json: {}, status: 400
@ -34,8 +37,8 @@ class Admin::TypesDeChampPrivateController < AdminController
end
def move_down
if @procedure.switch_types_de_champ_private params[:index].to_i
create_facade
if @procedure.switch_types_de_champ_private(params[:index].to_i)
setup_type_de_champ_service
render 'admin/types_de_champ/show', format: :js
else
render json: {}, status: 400
@ -44,7 +47,7 @@ class Admin::TypesDeChampPrivateController < AdminController
private
def create_facade
@types_de_champ_facade = AdminTypesDeChampFacades.new true, @procedure
def setup_type_de_champ_service
@type_de_champ_service = TypesDeChampService.new(@procedure, true)
end
end

View file

@ -1,4 +1,4 @@
= f.fields_for @types_de_champ_facade.fields_for_var, types_de_champ, remote: true do |ff|
= f.fields_for type_de_champ_service.fields_for_var, types_de_champ, remote: true do |ff|
- type_champ = ff.object.object.type_champ
.form-inline{ class: (type_champ == TypeDeChamp.type_champs.fetch(:header_section) ? 'header-section' : nil) }
@ -8,7 +8,7 @@
.form-group.type
%h4 Type
= ff.select :type_champ, tdc_options, {}, { class: 'form-control type-champ' }
= ff.select :type_champ, type_de_champ_service.options, {}, { class: 'form-control type-champ' }
.form-group.description
%h4 Description
@ -65,8 +65,8 @@
- if ff.object.id.present?
.form-group
%br &nbsp;
= 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: @types_de_champ_facade.move_down_url(ff), private: @types_de_champ_facade.private)
= ff.object.button_up(index: ff.index, url: type_de_champ_service.move_up_url(ff), private: type_de_champ_service.private?)
= ff.object.button_down(index: ff.index, url: type_de_champ_service.move_down_url(ff), private: type_de_champ_service.private?)
.form-group
%h4 position
@ -76,10 +76,10 @@
%br &nbsp;
- if ff.object.id.nil?
= f.button 'Ajouter le champ',
id: @types_de_champ_facade.add_button_id,
id: type_de_champ_service.add_button_id,
class: 'btn btn-success',
data: { disable: true }
- else
= 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) )
= link_to("", type_de_champ_service.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) )
%div{ style: 'background-color: rgb(204, 204, 204); height: 1px; margin: 30px auto;' }

View file

@ -1,5 +1,5 @@
= form_for [:admin, @procedure], url: @types_de_champ_facade.url, remote: true do |f|
= render partial: 'admin/types_de_champ/fields', locals: { types_de_champ: @types_de_champ_facade.types_de_champ, f: f }
= form_for [:admin, procedure], url: type_de_champ_service.url, remote: true do |f|
= render partial: 'admin/types_de_champ/fields', locals: { type_de_champ_service: type_de_champ_service, types_de_champ: type_de_champ_service.types_de_champ, f: f }
= f.button 'Enregistrer',
id: :save,
@ -8,4 +8,4 @@
%hr
#new_type_de_champ
= render partial: 'admin/types_de_champ/fields', locals: { types_de_champ: @types_de_champ_facade.new_type_de_champ, f: f }
= render partial: 'admin/types_de_champ/fields', locals: { type_de_champ_service: type_de_champ_service, types_de_champ: type_de_champ_service.new_type_de_champ, f: f }

View file

@ -1,3 +1,3 @@
.row.white-back
#liste-champ
= render partial: 'admin/types_de_champ/form'
= render partial: 'admin/types_de_champ/form', locals: { procedure: @procedure, type_de_champ_service: @type_de_champ_service }

View file

@ -1,2 +1,2 @@
<%= render_flash(timeout: 3000, sticky: true) %>
<%= render_to_element('#liste-champ', partial: 'admin/types_de_champ/form', locals: { procedure: @procedure, types_de_champ: @types_de_champ }) %>
<%= render_to_element('#liste-champ', partial: 'admin/types_de_champ/form', locals: { procedure: @procedure, type_de_champ_service: @type_de_champ_service }) %>

View file

@ -1 +1 @@
= render partial: 'layouts/left_panels/left_panel_admin_procedurescontroller_navbar', locals: { active: @types_de_champ_facade.active }
= render partial: 'layouts/left_panels/left_panel_admin_procedurescontroller_navbar', locals: { active: @type_de_champ_service.active }

View file

@ -14,7 +14,7 @@ describe 'admin/types_de_champ/show.html.haml', type: :view do
before do
procedure.reload
assign(:procedure, procedure)
assign(:types_de_champ_facade, AdminTypesDeChampFacades.new(false, procedure))
assign(:type_de_champ_service, TypesDeChampService.new(procedure))
render
end
it 'sorts by order place' do
@ -26,7 +26,7 @@ describe 'admin/types_de_champ/show.html.haml', type: :view do
subject do
procedure.reload
assign(:procedure, procedure)
assign(:types_de_champ_facade, AdminTypesDeChampFacades.new(false, procedure))
assign(:type_de_champ_service, TypesDeChampService.new(procedure))
render
rendered
end

View file

@ -14,7 +14,7 @@ describe 'admin/types_de_champ/show.html.haml', type: :view do
before do
procedure.reload
assign(:procedure, procedure)
assign(:types_de_champ_facade, AdminTypesDeChampFacades.new(true, procedure))
assign(:type_de_champ_service, TypesDeChampService.new(procedure, true))
render
end
it 'sorts by order place' do
@ -26,7 +26,7 @@ describe 'admin/types_de_champ/show.html.haml', type: :view do
subject do
procedure.reload
assign(:procedure, procedure)
assign(:types_de_champ_facade, AdminTypesDeChampFacades.new(true, procedure))
assign(:type_de_champ_service, TypesDeChampService.new(procedure, true))
render
rendered
end