summaryrefslogtreecommitdiff
path: root/app/controllers/admin_controller.rb
blob: 37fd78b3acfdf18d8380bdede6c9fb023943a2b7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
class AdminController < ApplicationController

  # Private

  before_action :login_required

  def index
    @drafts = Node.drafts_and_autosaves(current_user_id: current_user.id).limit(5)
    @recent_changes = Node.recently_changed.limit(5)
  end

  def conventions
    @node_kinds = CccConventions::NODE_KINDS
  end

  def search
    @results = Node.editor_search(params[:search_term])

    respond_to do |format|
      format.html do
        render :template => 'admin/search_results'
      end
      format.js do
        render( :json => @results.map do |node|
            if node
              { :id => node.id, :title => node.title, :unique_name => node.unique_name, :node_path => node_path(node) }
            end
          end
        )

      end
    end
  end

  def dashboard_search
    term = params[:search_term]

    if term.blank?
      render json: { tags: [], nodes: [] }
      return
    end

    render json: {
      tags: ActsAsTaggableOn::Tag.named_like(term).limit(5).map { |tag|
        { name: tag.name, tag_path: tags_nodes_path(tags: tag.name) }
      },
      nodes: Node.editor_search(term).limit(10).map { |node|
        { node_id: node.id, title: node.title, unique_name: node.unique_name, node_path: node_path(node) }
      }
    }
  end

  def menu_search
    if params[:search_term] == "Root"
      @results = [Node.root]
    else
      @results = Node.editor_search(params[:search_term])
    end

    respond_to do |format|
      format.html do
        render :partial => 'admin/menu_search_results'
      end

      format.js do
        render( :json => @results.map do |node|
          {:node_id => node.id, :title => node.title, :unique_name => node.unique_name, :node_path => node_path(node)}
          end
        )

      end
    end
  end
end