Class: Binda::ComponentsController
Instance Method Summary
collapse
#bytes_to_megabytes, #fieldable_params, #nested_fieldable_params, #return_audio_details, #return_image_details, #return_svg_details, #return_video_details, #upload_details, #upload_params
#after_sign_in_path_for, #after_sign_out_path_for, #set_locale
Instance Method Details
#create ⇒ Object
34
35
36
37
38
39
40
41
42
43
|
# File 'app/controllers/binda/components_controller.rb', line 34
def create
@component = @structure.components.build(component_params)
if @component.save
redirect_to structure_component_path(@structure.slug, @component.slug), notice: "#{ @structure.name } was successfully created."
else
@instance = @component
render :edit, flash: { alert: @component.errors }
end
end
|
#destroy ⇒ Object
53
54
55
56
|
# File 'app/controllers/binda/components_controller.rb', line 53
def destroy
@component.destroy
redirect_to structure_components_url(@structure.slug), notice: "#{ @structure.name.capitalize } was successfully destroyed."
end
|
#edit ⇒ Object
31
32
|
# File 'app/controllers/binda/components_controller.rb', line 31
def edit
end
|
#index ⇒ Object
11
12
13
14
15
16
17
18
19
|
# File 'app/controllers/binda/components_controller.rb', line 11
def index
order = 'LOWER(name) ASC'
unless params[:order].nil?
order_hash = params[:order].permit(:name, :publish_state).to_h
order = order_hash.map{|k,v| "LOWER(#{k}) #{v}"}.join(', ') if order_hash.any?
end
@components = @structure.components.order(order).all.page params[:page]
end
|
#new ⇒ Object
25
26
27
28
29
|
# File 'app/controllers/binda/components_controller.rb', line 25
def new
@component = @structure.components.build()
@instance = @component
end
|
#new_repeater ⇒ Object
58
59
60
61
62
|
# File 'app/controllers/binda/components_controller.rb', line 58
def new_repeater
@repeater_setting = FieldSetting.find(params[:repeater_setting_id])
@repeater = @instance.repeaters.create!(field_setting: @repeater_setting)
render 'binda/fieldable/_form_item_new_repeater', layout: false
end
|
#show ⇒ Object
21
22
23
|
# File 'app/controllers/binda/components_controller.rb', line 21
def show
redirect_to action: :edit
end
|
#sort ⇒ Object
69
70
71
72
73
74
|
# File 'app/controllers/binda/components_controller.rb', line 69
def sort
params[:component].each_with_index do |id, i|
Component.find(id).update_column('position', i+1) end
render json: { id: "##{params[:id]}" }, status: 200
end
|
#sort_index ⇒ Object
76
77
78
79
|
# File 'app/controllers/binda/components_controller.rb', line 76
def sort_index
return redirect_to structure_components_path, alert: "There are too many #{@structure.name.pluralize}. It's not possible to sort more than #{Component.sort_limit} #{@structure.name.pluralize}." if @structure.components.length > Component.sort_limit
@components = @structure.components.order('position').all
end
|
#sort_repeaters ⇒ Object
64
65
66
67
|
# File 'app/controllers/binda/components_controller.rb', line 64
def sort_repeaters
sort_repeaters_by(params["form--list-item"])
render json: { id: "##{params[:id]}" }, status: 200
end
|
#update ⇒ Object
45
46
47
48
49
50
51
|
# File 'app/controllers/binda/components_controller.rb', line 45
def update
if @component.update(component_params)
redirect_to structure_component_path(@structure.slug, @component.slug), notice: "#{ @structure.name.capitalize } was successfully updated."
else
render :edit, flash: { alert: @component.errors }
end
end
|
#upload ⇒ Object
81
82
83
84
85
86
87
|
# File 'app/controllers/binda/components_controller.rb', line 81
def upload
if @component.update(upload_params(:component))
render json: upload_details, status: 200
else
render json: @component.errors.full_messages, status: 400
end
end
|