Class: Binda::ComponentsController
Instance Method Summary
collapse
#bytes_to_megabytes, #fieldable_params, #return_image_details, #return_video_details, #upload_details, #upload_params
#after_sign_in_path_for, #after_sign_out_path_for
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
63
|
# File 'app/controllers/binda/components_controller.rb', line 58
def new_repeater
@repeater_setting = FieldSetting.find( params[:repeater_setting_id] )
position = @instance.repeaters.find_all{|r| r.field_setting_id=@repeater_setting.id }.length + 1
@repeater = @instance.repeaters.create( field_setting: @repeater_setting, position: position )
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
72
73
74
75
76
77
|
# File 'app/controllers/binda/components_controller.rb', line 72
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
79
80
81
82
|
# File 'app/controllers/binda/components_controller.rb', line 79
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
65
66
67
68
69
70
|
# File 'app/controllers/binda/components_controller.rb', line 65
def sort_repeaters
params[:repeater].each_with_index do |id, i|
Repeater.find( id ).update({ position: i + 1 })
end
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
84
85
86
87
88
89
90
|
# File 'app/controllers/binda/components_controller.rb', line 84
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
|