Class: Glib::HomeController

Inherits:
ApplicationController
  • Object
show all
Defined in:
app/controllers/glib/home_controller.rb

Instance Method Summary collapse

Instance Method Details

#chatObject



42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'app/controllers/glib/home_controller.rb', line 42

def chat
  chat_params = params[:chat]

  payload = {
    action: 'lists/append',
    targetId: 'list-1',
    row: {
      template: 'thumbnail', title: chat_params[:user], subtitle: chat_params[:body]
    }
  }

  Glib::Channel::ChatChannel.broadcast_to("chat_#{chat_params[:room]}", payload)

  render template: 'json_ui/garage/empty'
end

#index_order(prop_name, direction) ⇒ Object



67
68
69
70
71
72
73
# File 'app/controllers/glib/home_controller.rb', line 67

def index_order(prop_name, direction)
  # In a real app, apply ordering to the model. For example:
  # @users = @users.order(prop_name => direction)

  # Garage example
  @order_headings[prop_name] = direction
end

#init_ordersObject



58
59
60
61
62
63
64
65
# File 'app/controllers/glib/home_controller.rb', line 58

def init_orders
  @order_headings = {}
  @orders = params[:orders] || []
  @orders.each do |order|
    prop_name, direction = order.split('-')
    index_order(prop_name, direction)
  end
end

#json_ui_garageObject



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
# File 'app/controllers/glib/home_controller.rb', line 12

def json_ui_garage
  init_orders

  @path_prefix = 'json_ui/garage'

  @__glib_head_code =<<-eos
    <style>
    .custom-container .pages-body > div > .panels-responsive {
      max-width: 800px;
      width: 100%;
      margin-right: auto;
      margin-left: auto;
    }

    .rounded-corner {
      border-radius: 16px;
    }

    /* Make sure the hover highlight effect also has rounded corners */
    .rounded-corner:hover:before {
      border-radius: 16px;
    }
    </style>
  eos

  # We can't use prepend_view_path because it affects the app, not the gem
  path = "#{@path_prefix}/#{params[:path] || 'home/index'}"
  render path
end

#reversed_order(order) ⇒ Object



75
76
77
# File 'app/controllers/glib/home_controller.rb', line 75

def reversed_order(order)
  order.to_sym == :asc ? :desc : :asc
end

#reversed_order_params(prop_name) ⇒ Object



79
80
81
82
83
84
85
86
87
88
89
90
# File 'app/controllers/glib/home_controller.rb', line 79

def reversed_order_params(prop_name)
  prop_value = :asc
  remaining = @orders.reject do |o|
    tuple = o.split('-')
    if tuple.first == prop_name.to_s
      prop_value = reversed_order(tuple.second)
      true
    end
  end
  # Sort the params to produce predictable URLs which are useful for SEO
  (["#{prop_name}-#{prop_value}"] + remaining).sort
end