change rule to display arrow button for type de champ
This commit is contained in:
parent
41c0ca27d9
commit
c4e8c6c989
3 changed files with 47 additions and 12 deletions
|
@ -1,11 +1,37 @@
|
|||
|
||||
class TypeDeChampDecorator < Draper::Decorator
|
||||
delegate_all
|
||||
def button_up index
|
||||
h.button_tag '', class: %w(btn btn-default form-control fa fa-chevron-up), id: "btn_up_#{index}" unless index == 0
|
||||
def button_up params
|
||||
h.button_tag '', class: up_classes, id: "btn_up_#{params[:index]}", remote: true, method: :post if display_up_button?(params[:index])
|
||||
end
|
||||
|
||||
def button_down index
|
||||
h.button_tag '', class: %w(btn btn-default form-control fa fa-chevron-down), id: "btn_down_#{index}" if persisted?
|
||||
def button_down params
|
||||
h.button_tag '', class: down_classes, id: "btn_down_#{params[:index]}", remote: true if display_down_button?(params[:index])
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def up_classes
|
||||
base_classes << 'fa-chevron-up'
|
||||
end
|
||||
|
||||
def down_classes
|
||||
base_classes << 'fa-chevron-down'
|
||||
end
|
||||
|
||||
def base_classes
|
||||
%w(btn btn-default form-control fa)
|
||||
end
|
||||
|
||||
def display_up_button?(index)
|
||||
!(index == 0 || count_type_de_champ < 2)
|
||||
end
|
||||
|
||||
def display_down_button?(index)
|
||||
(index + 1) < count_type_de_champ
|
||||
end
|
||||
|
||||
def count_type_de_champ
|
||||
@count_type_de_champ ||= procedure.types_de_champ.count
|
||||
end
|
||||
end
|
|
@ -12,10 +12,11 @@
|
|||
.form-group
|
||||
= ff.hidden_field :order_place, value: ff.index
|
||||
= ff.hidden_field :id
|
||||
.form-group
|
||||
%br
|
||||
= ff.object.button_up(ff.index)
|
||||
= ff.object.button_down(ff.index)
|
||||
- unless ff.object.id.nil?
|
||||
.form-group
|
||||
%br
|
||||
= ff.object.button_up(index: ff.index)
|
||||
= ff.object.button_down(index: ff.index)
|
||||
|
||||
- unless ff.object.id.nil?
|
||||
.form-group
|
||||
|
|
|
@ -25,15 +25,23 @@ describe 'admin/types_de_champ/show.html.haml', type: :view do
|
|||
render
|
||||
rendered
|
||||
end
|
||||
context 'when there is only one field' do
|
||||
context 'when there is no field in database' do
|
||||
it { expect(subject).not_to have_css('.fa-chevron-down') }
|
||||
it { expect(subject).not_to have_css('.fa-chevron-up') }
|
||||
end
|
||||
context 'when two fields' do
|
||||
context 'when there is only one field in database' do
|
||||
let!(:type_de_champ_0) { create(:type_de_champ, procedure: procedure, order_place: 0) }
|
||||
it { expect(subject).to have_css('#btn_down_0.fa-chevron-down') }
|
||||
it { expect(subject).not_to have_css('#btn_down_0') }
|
||||
it { expect(subject).not_to have_css('#btn_up_0') }
|
||||
it { expect(subject).not_to have_css('#btn_up_1') }
|
||||
it { expect(subject).not_to have_css('#btn_down_1') }
|
||||
end
|
||||
context 'when there are 2 fields in database' do
|
||||
let!(:type_de_champ_0) { create(:type_de_champ, procedure: procedure, order_place: 0) }
|
||||
let!(:type_de_champ_1) { create(:type_de_champ, procedure: procedure, order_place: 1) }
|
||||
it { expect(subject).to have_css('#btn_down_0') }
|
||||
it { expect(subject).not_to have_css('#btn_up_0') }
|
||||
it { expect(subject).to have_css('#btn_up_1.fa-chevron-up') }
|
||||
it { expect(subject).to have_css('#btn_up_1') }
|
||||
it { expect(subject).not_to have_css('#btn_down_1') }
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue