Class: Decidim::DecidimAwesome::Admin::LandingMenuItemsController

Inherits:
ApplicationController
  • Object
show all
Includes:
LandingMenuItemPresetBuilder
Defined in:
app/controllers/decidim/decidim_awesome/admin/landing_menu_items_controller.rb

Instance Method Summary collapse

Methods included from LandingMenuItemPresetBuilder

#landing_menu_item_presets_options

Methods inherited from ApplicationController

#permission_class_chain

Instance Method Details

#createObject



18
19
20
21
22
23
24
25
26
27
28
# File 'app/controllers/decidim/decidim_awesome/admin/landing_menu_items_controller.rb', line 18

def create
  @form = form(LandingMenuItemForm).from_params(params)

  return render :new, status: :unprocessable_entity unless @form.valid?

  items = current_items
  items << form_to_hash(@form)
  save_items!(items)

  head :ok
end

#destroyObject



50
51
52
53
54
55
56
57
58
# File 'app/controllers/decidim/decidim_awesome/admin/landing_menu_items_controller.rb', line 50

def destroy
  items = current_items
  return head(:not_found) unless items[item_index]

  items.delete_at(item_index)
  save_items!(items)

  redirect_back fallback_location: decidim_admin.root_path
end

#newObject



14
15
16
# File 'app/controllers/decidim/decidim_awesome/admin/landing_menu_items_controller.rb', line 14

def new
  @form = form(LandingMenuItemForm).from_params(default_params)
end

#reorderObject



70
71
72
73
74
75
76
77
78
79
80
81
# File 'app/controllers/decidim/decidim_awesome/admin/landing_menu_items_controller.rb', line 70

def reorder
  return head(:bad_request) unless params[:order_ids].is_a?(Array)

  items = current_items
  order = params[:order_ids].map(&:to_i)
  return head(:bad_request) unless order.sort == (0...items.length).to_a

  reordered = order.map { |index| items[index] }
  save_items!(reordered)

  head :ok
end

#showObject



30
31
32
33
34
35
# File 'app/controllers/decidim/decidim_awesome/admin/landing_menu_items_controller.rb', line 30

def show
  item = current_items[item_index]
  return head(:not_found) unless item

  @form = form(LandingMenuItemForm).from_params(item_to_form_params(item))
end

#toggle_visibleObject



60
61
62
63
64
65
66
67
68
# File 'app/controllers/decidim/decidim_awesome/admin/landing_menu_items_controller.rb', line 60

def toggle_visible
  items = current_items
  return head(:not_found) unless items[item_index]

  items[item_index]["visible"] = !items[item_index].fetch("visible", true)
  save_items!(items)

  redirect_back fallback_location: decidim_admin.root_path
end

#updateObject



37
38
39
40
41
42
43
44
45
46
47
48
# File 'app/controllers/decidim/decidim_awesome/admin/landing_menu_items_controller.rb', line 37

def update
  @form = form(LandingMenuItemForm).from_params(params)

  items = current_items
  return head(:not_found) unless items[item_index]
  return render :show, status: :unprocessable_entity unless @form.valid?

  items[item_index] = form_to_hash(@form)
  save_items!(items)

  head :ok
end