Class: Glib::HomeController

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

Instance Method Summary collapse

Instance Method Details

#chatObject



51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'app/controllers/glib/home_controller.rb', line 51

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



76
77
78
79
80
81
82
# File 'app/controllers/glib/home_controller.rb', line 76

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



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

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
41
42
43
44
45
46
47
48
49
# 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;
    }

    .ma-2 {
      margin: 8px;
    }

    .align-right {
      display: flex;
      flex-direction: row-reverse;
    }
    </style>
  eos

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

#reversed_order(order) ⇒ Object



84
85
86
# File 'app/controllers/glib/home_controller.rb', line 84

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

#reversed_order_params(prop_name) ⇒ Object



88
89
90
91
92
93
94
95
96
97
98
99
# File 'app/controllers/glib/home_controller.rb', line 88

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