add arrow in view for order place managment
This commit is contained in:
parent
cf81623937
commit
1ab89b63aa
4 changed files with 50 additions and 21 deletions
11
app/decorators/type_de_champ_decorator.rb
Normal file
11
app/decorators/type_de_champ_decorator.rb
Normal file
|
@ -0,0 +1,11 @@
|
|||
|
||||
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
|
||||
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?
|
||||
end
|
||||
end
|
|
@ -12,16 +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)
|
||||
|
||||
/ .form-group.order_type_de_champ_button{id: "order_type_de_champ_#{type_de_champ.id || index}_button", style: ("display:none" if type_de_champ.id.nil?)}
|
||||
/ .form-group
|
||||
/ %br
|
||||
/ %button.form-control.btn.btn-default.button_up.fa.fa-chevron-up{type: 'button'}
|
||||
/ , id: "order_type_de_champ_#{type_de_champ.id || index}_up_procedure"}
|
||||
/ %button.form-control.btn.btn-default.button_down.fa.fa-chevron-down{type: 'button'}
|
||||
/ , id: "order_type_de_champ_#{type_de_champ.id || index}_down_procedure"}
|
||||
|
||||
/ .form-group{ id: "delete_type_de_champ_#{type_de_champ.id || index}_button", style: ("display:none" if type_de_champ.id.nil?)}
|
||||
- unless ff.object.id.nil?
|
||||
.form-group
|
||||
%br
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
= form_for [:admin, @procedure], url: admin_procedure_types_de_champ_path(@procedure) , remote: true do |f|
|
||||
= render partial: 'fields', locals: { types_de_champ: @procedure.types_de_champ_ordered, f: f }
|
||||
= render partial: 'fields', locals: { types_de_champ: @procedure.types_de_champ_ordered.decorate, f: f }
|
||||
#new_type_de_champ
|
||||
= render partial: 'fields', locals: { types_de_champ: TypeDeChamp.new, f: f }
|
||||
= render partial: 'fields', locals: { types_de_champ: TypeDeChamp.new.decorate, f: f }
|
||||
= f.submit "Ajouter un champ", class: 'btn btn-success', id: :add_type_de_champ
|
|
@ -2,16 +2,39 @@ require 'spec_helper'
|
|||
|
||||
describe 'admin/types_de_champ/show.html.haml', type: :view do
|
||||
let(:procedure) { create(:procedure) }
|
||||
let(:first_libelle) { 'salut la compagnie' }
|
||||
let(:last_libelle) { 'je suis bien sur la page' }
|
||||
let!(:type_de_champ_1) { create(:type_de_champ, procedure: procedure, order_place: 1, libelle: last_libelle) }
|
||||
let!(:type_de_champ_0) { create(:type_de_champ, procedure: procedure, order_place: 0, libelle: first_libelle) }
|
||||
before do
|
||||
procedure.reload
|
||||
assign(:procedure, procedure)
|
||||
render
|
||||
|
||||
describe 'fields sorted' do
|
||||
let(:first_libelle) { 'salut la compagnie' }
|
||||
let(:last_libelle) { 'je suis bien sur la page' }
|
||||
let!(:type_de_champ_1) { create(:type_de_champ, procedure: procedure, order_place: 1, libelle: last_libelle) }
|
||||
let!(:type_de_champ_0) { create(:type_de_champ, procedure: procedure, order_place: 0, libelle: first_libelle) }
|
||||
before do
|
||||
procedure.reload
|
||||
assign(:procedure, procedure)
|
||||
render
|
||||
end
|
||||
it 'sorts by order place' do
|
||||
expect(rendered).to match(/#{first_libelle}.*#{last_libelle}/m)
|
||||
end
|
||||
end
|
||||
it 'sorts by order place' do
|
||||
expect(rendered).to match(/#{first_libelle}.*#{last_libelle}/m)
|
||||
|
||||
describe 'arrow button' do
|
||||
subject do
|
||||
procedure.reload
|
||||
assign(:procedure, procedure)
|
||||
render
|
||||
rendered
|
||||
end
|
||||
context 'when there is only one field' 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
|
||||
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_up_0') }
|
||||
it { expect(subject).to have_css('#btn_up_1.fa-chevron-up') }
|
||||
it { expect(subject).not_to have_css('#btn_down_1') }
|
||||
end
|
||||
end
|
||||
end
|
Loading…
Add table
Add a link
Reference in a new issue