Class: Api::NodesController

Inherits:
BaseController
  • Object
show all
Defined in:
app/controllers/alchemy/api/nodes_controller.rb

Instance Method Summary collapse

Instance Method Details

#indexObject



8
9
10
11
12
13
14
15
16
17
18
19
# File 'app/controllers/alchemy/api/nodes_controller.rb', line 8

def index
  @nodes = Node.all
  @nodes = @nodes.includes(:parent)
  @nodes = @nodes.where(language_id: params[:language_id]) if params[:language_id]
  @nodes = @nodes.ransack(params[:filter]).result.order(:lft)

  if params[:page]
    @nodes = @nodes.page(params[:page]).per(params[:per_page])
  end

  render json: @nodes, adapter: :json, root: "data", meta: , include: params[:include]
end

#moveObject



21
22
23
24
25
# File 'app/controllers/alchemy/api/nodes_controller.rb', line 21

def move
  target_parent_node = Node.find(params[:target_parent_id])
  @node.move_to_child_with_index(target_parent_node, params[:new_position])
  render json: @node, serializer: NodeSerializer
end

#toggle_foldedObject



27
28
29
30
# File 'app/controllers/alchemy/api/nodes_controller.rb', line 27

def toggle_folded
  @node.update(folded: !@node.folded)
  render json: @node, serializer: NodeSerializer
end