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
# File 'app/controllers/alchemy/api/nodes_controller.rb', line 8

def index
  @nodes = Node.all
  @nodes = @nodes.includes(:parent)
  @nodes = @nodes.ransack(params[:filter]).result

  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


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

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


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

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