Class: Primer::ViewComponents::TreeViewItemsController

Inherits:
ApplicationController show all
Defined in:
app/controllers/primer/view_components/tree_view_items_controller.rb

Overview

:nodoc: :nocov:

Constant Summary collapse

TREE =
JSON.parse(File.read(File.join(__dir__, "tree_view_items.json"))).freeze

Instance Method Summary collapse

Instance Method Details

#async_alphaObject



43
44
45
46
47
48
49
50
51
52
# File 'app/controllers/primer/view_components/tree_view_items_controller.rb', line 43

def async_alpha
  # delay a bit so loading spinners, etc can be seen
  sleep 1

  render(
    locals: {
      action_menu_expanded: params[:action_menu_expanded] == "true"
    }
  )
end

#indexObject



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
# File 'app/controllers/primer/view_components/tree_view_items_controller.rb', line 13

def index
  # delay a bit so loading spinners, etc can be seen
  sleep 1

  if params[:fail] == "true"
    head :internal_server_error and return
  end

  path = JSON.parse(params[:path])
  node = path.inject(TREE) do |current, segment|
    current["children"][segment]
  end

  entries = (
    node["children"].keys.map { |label| [label, :directory] } +
    node["files"].map { |label| [label, :file] }
  )

  entries.sort_by!(&:first)

  render(
    locals: {
      entries: entries,
      path: path,
      loader: (params[:loader] || :spinner).to_sym,
      select_variant: (params[:select_variant] || :none).to_sym
    }
  )
end