Class: Card::Act::ActRenderer
- Inherits:
-
Object
- Object
- Card::Act::ActRenderer
show all
- Includes:
- Bootstrapper
- Defined in:
- mod/history/lib/card/act/act_renderer.rb,
mod/history/lib/card/act/act_renderer/absolute_act_renderer.rb,
mod/history/lib/card/act/act_renderer/relative_act_renderer.rb
Defined Under Namespace
Classes: AbsoluteActRenderer, RelativeActRenderer
Instance Method Summary
collapse
#bootstrap, #bs
#components, #include_component, #load_components, #to_const
Constructor Details
#initialize(format, act, args) ⇒ ActRenderer
Returns a new instance of ActRenderer.
6
7
8
9
10
11
12
13
|
# File 'mod/history/lib/card/act/act_renderer.rb', line 6
def initialize format, act, args
@format = format
@act = act
@act_card = act.card
@args = args
@card = @format.card
@context = @args[:act_context]
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method_name, *args, &block) ⇒ Object
17
18
19
20
21
22
23
|
# File 'mod/history/lib/card/act/act_renderer.rb', line 17
def method_missing method_name, *args, &block
if block_given?
@format.send(method_name, *args, &block)
else
@format.send(method_name, *args)
end
end
|
Instance Method Details
#absolute_title ⇒ Object
52
53
54
|
# File 'mod/history/lib/card/act/act_renderer.rb', line 52
def absolute_title
accordion_expand_link(@act_card.name)
end
|
#accordion_expand_link(text) ⇒ Object
115
116
117
118
119
120
121
|
# File 'mod/history/lib/card/act/act_renderer.rb', line 115
def accordion_expand_link text
" <a>\n \#{text}\n </a>\n HTML\nend\n"
|
#accordion_expand_options ⇒ Object
135
136
137
138
139
140
141
142
143
|
# File 'mod/history/lib/card/act/act_renderer.rb', line 135
def accordion_expand_options
{
"data-toggle" => "collapse",
"data-parent" => "#accordion-#{collapse_id}",
"data-target" => ".#{collapse_id}",
"aria-expanded" => true,
"aria-controls" => collapse_id
}
end
|
#act_accordion ⇒ Object
TODO: change accordion API in bootstrap/helper.rb so that it can be used
here. The problem is that here we have extra links in the title
that are not supposed to expand the accordion
126
127
128
129
130
131
132
133
|
# File 'mod/history/lib/card/act/act_renderer.rb', line 126
def act_accordion
context = @act.main_action.draft ? :warning : :default
" <div class=\"panel panel-\#{context}\">\n \#{act_accordion_panel}\n </div>\n HTML\nend\n"
|
#act_accordion_body ⇒ Object
159
160
161
162
163
164
|
# File 'mod/history/lib/card/act/act_renderer.rb', line 159
def act_accordion_body
wrap_with :div, id: collapse_id,
class: "panel-collapse collapse #{collapse_id}" do
wrap_with :div, details, class: "panel-body"
end
end
|
#act_accordion_heading ⇒ Object
153
154
155
156
157
|
# File 'mod/history/lib/card/act/act_renderer.rb', line 153
def act_accordion_heading
wrap_with :div, act_panel_options.merge(accordion_expand_options) do
wrap_with :h4, , class: "panel-title"
end
end
|
#act_accordion_panel ⇒ Object
149
150
151
|
# File 'mod/history/lib/card/act/act_renderer.rb', line 149
def act_accordion_panel
act_accordion_heading + act_accordion_body
end
|
#act_links ⇒ Object
70
71
72
73
74
75
|
# File 'mod/history/lib/card/act/act_renderer.rb', line 70
def act_links
[
link_to_history,
(link_to_act_card unless @act_card.trash)
].compact.join " "
end
|
#act_panel_options ⇒ Object
145
146
147
|
# File 'mod/history/lib/card/act/act_renderer.rb', line 145
def act_panel_options
{ class: "panel-heading", role: "tab", id: "heading-#{collapse_id}" }
end
|
92
93
94
95
96
|
# File 'mod/history/lib/card/act/act_renderer.rb', line 92
def
true
end
|
#approved_actions ⇒ Object
87
88
89
90
|
# File 'mod/history/lib/card/act/act_renderer.rb', line 87
def approved_actions
@approved_actions ||= actions.select { |a| a.card && a.card.ok?(:read) }
end
|
#collapse_id ⇒ Object
111
112
113
|
# File 'mod/history/lib/card/act/act_renderer.rb', line 111
def collapse_id
"act-id-#{@act.id}"
end
|
#count_types ⇒ Object
98
99
100
101
102
103
104
105
|
# File 'mod/history/lib/card/act/act_renderer.rb', line 98
def count_types
@count_types ||=
approved_actions.each_with_object(
Hash.new { |h, k| h[k] = 0 }
) do |action, type_cnt|
type_cnt[action.action_type] += 1
end
end
|
#details ⇒ Object
56
57
58
59
60
61
|
# File 'mod/history/lib/card/act/act_renderer.rb', line 56
def details
approved_actions[0..20].map do |action|
Action::ActionRenderer.new(@format, action, ,
:summary).render
end.join
end
|
#edited_ago ⇒ Object
107
108
109
|
# File 'mod/history/lib/card/act/act_renderer.rb', line 107
def edited_ago
"#{time_ago_in_words(@act.acted_at)} ago"
end
|
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
|
# File 'mod/history/lib/card/act/act_renderer.rb', line 34
def
bs_layout do
row 10, 2 do
column do
html title
tag(:span, "text-muted") { summary }
end
column act_links, class: "text-right"
end
row 12 do
column subtitle
end
end
end
|
#link_to_act_card ⇒ Object
77
78
79
|
# File 'mod/history/lib/card/act/act_renderer.rb', line 77
def link_to_act_card
link_to_card @act_card, glyphicon("new-window")
end
|
#link_to_history ⇒ Object
81
82
83
84
85
|
# File 'mod/history/lib/card/act/act_renderer.rb', line 81
def link_to_history
link_to_card @act_card, glyphicon("time"),
path: { view: :history, look_in_trash: true },
rel: "nofollow"
end
|
#previous_action ⇒ Object
179
180
181
182
|
# File 'mod/history/lib/card/act/act_renderer.rb', line 179
def previous_action
actions.reject { |action| action.card.last_action_id == action.id }
end
|
#render ⇒ Object
29
30
31
32
|
# File 'mod/history/lib/card/act/act_renderer.rb', line 29
def render
return "" unless @act_card
act_accordion
end
|
#respond_to_missing?(method_name, _include_private = false) ⇒ Boolean
25
26
27
|
# File 'mod/history/lib/card/act/act_renderer.rb', line 25
def respond_to_missing? method_name, _include_private=false
@format.respond_to? method_name
end
|
#rollback_link ⇒ Object
166
167
168
169
170
171
172
173
174
175
176
177
|
# File 'mod/history/lib/card/act/act_renderer.rb', line 166
def rollback_link
return unless card.ok? :update
return unless (prior = previous_action)
wrap_with :div, class: "act-link collapse #{collapse_id}" do
link_to "Save as current",
class: "slotter", remote: true,
method: :post, rel: "nofollow",
"data-slot-selector" => ".card-slot.history-view",
path: { action: :update, action_ids: prior,
view: :open, look_in_trash: true }
end
end
|
#show_or_hide_changes_link ⇒ Object
184
185
186
187
188
189
190
191
192
193
194
|
# File 'mod/history/lib/card/act/act_renderer.rb', line 184
def show_or_hide_changes_link
wrap_with :div, class: "act-link" do
@format.link_to_view(
:act, "#{@args[:hide_diff] ? 'Show' : 'Hide'} changes",
class: "slotter",
path: { act_id: @args[:act].id, act_seq: @args[:act_seq],
hide_diff: !@args[:hide_diff], action_view: :expanded,
act_context: @args[:act_context], look_in_trash: true }
)
end
end
|
#summary ⇒ Object
63
64
65
66
67
68
|
# File 'mod/history/lib/card/act/act_renderer.rb', line 63
def summary
i[create update delete draft].map do |type|
next unless count_types[type] > 0
"#{@format.action_icon type} #{count_types[type]}"
end.compact.join " | "
end
|