Class: Maglev::Editor::SectionsController

Inherits:
BaseController show all
Defined in:
app/controllers/maglev/editor/sections_controller.rb

Instance Method Summary collapse

Methods included from ResourceIdConcern

#resource_id

Instance Method Details

#createObject



24
25
26
27
28
29
30
31
32
33
34
# File 'app/controllers/maglev/editor/sections_controller.rb', line 24

def create
  @section = services.add_section.call(
    page: current_maglev_page,
    section_type: params[:section_type],
    position: params[:position].to_i
  )
  redirect_to edit_editor_section_path(@section[:id], maglev_editing_route_context),
              flash: newly_added_section_to_flash,
              notice: flash_t(:success),
              status: :see_other
end

#destroyObject



54
55
56
57
# File 'app/controllers/maglev/editor/sections_controller.rb', line 54

def destroy
  services.delete_section.call(page: current_maglev_page, section_id: params[:id])
  redirect_to_sections_path
end

#editObject



36
37
38
# File 'app/controllers/maglev/editor/sections_controller.rb', line 36

def edit
  newly_added_section_to_headers
end

#newObject



16
17
18
19
20
21
22
# File 'app/controllers/maglev/editor/sections_controller.rb', line 16

def new
  set_query_and_category_id
  @position = (params[:position] || -1).to_i
  @theme_sections = maglev_theme.sections.filter(current_maglev_sections, keyword: @query,
                                                                          category_id: @category_id)
  render layout: false
end

#showObject



12
13
14
# File 'app/controllers/maglev/editor/sections_controller.rb', line 12

def show
  redirect_to edit_editor_section_path(params[:id], maglev_editing_route_context)
end

#sortObject



45
46
47
48
49
50
51
52
# File 'app/controllers/maglev/editor/sections_controller.rb', line 45

def sort
  current_maglev_page.reorder_sections(params[:item_ids], params[:lock_version])
  if current_maglev_page.save
    redirect_to_sections_path
  else
    render_index_with_error
  end
end

#updateObject



40
41
42
43
# File 'app/controllers/maglev/editor/sections_controller.rb', line 40

def update
  update_section
  flash.now[:notice] = flash_t(:success)
end