Class: Glib::HomeController

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

Instance Method Summary collapse

Instance Method Details

#chatObject



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

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



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

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



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

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

def json_ui_garage
  init_orders

  @path_prefix = 'json_ui/garage'

  @__glib_head_code =<<-eos
    <script type="text/javascript" src="https://js.stripe.com/v3/"></script>

    <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



86
87
88
# File 'app/controllers/glib/home_controller.rb', line 86

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

#reversed_order_params(prop_name) ⇒ Object



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

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