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.
4
5
6
7
8
9
10
11
|
# File 'mod/history/lib/card/act/act_renderer.rb', line 4
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
15
16
17
18
19
20
21
|
# File 'mod/history/lib/card/act/act_renderer.rb', line 15
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
46
47
48
|
# File 'mod/history/lib/card/act/act_renderer.rb', line 46
def absolute_title
accordion_expand_link(@act_card.name)
end
|
#accordion_expand_link(text) ⇒ Object
111
112
113
114
115
116
117
|
# File 'mod/history/lib/card/act/act_renderer.rb', line 111
def accordion_expand_link text
<<-HTML
<a>
#{text}
</a>
HTML
end
|
#accordion_expand_options ⇒ Object
131
132
133
134
135
136
137
138
139
|
# File 'mod/history/lib/card/act/act_renderer.rb', line 131
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
122
123
124
125
126
127
128
129
|
# File 'mod/history/lib/card/act/act_renderer.rb', line 122
def act_accordion
context = @act.main_action.draft ? :warning : :default
<<-HTML
<div class="card card-#{context}">
#{act_accordion_panel}
</div>
HTML
end
|
#act_accordion_body ⇒ Object
155
156
157
158
159
160
|
# File 'mod/history/lib/card/act/act_renderer.rb', line 155
def act_accordion_body
wrap_with :div, id: collapse_id,
class: "collapse #{collapse_id}" do
wrap_with :div, details, class: "card-block"
end
end
|
#act_accordion_heading ⇒ Object
149
150
151
152
153
|
# File 'mod/history/lib/card/act/act_renderer.rb', line 149
def act_accordion_heading
wrap_with :div, act_panel_options.merge(accordion_expand_options) do
wrap_with(:h5, , class: "mb-0") + subtitle
end
end
|
#act_accordion_panel ⇒ Object
145
146
147
|
# File 'mod/history/lib/card/act/act_renderer.rb', line 145
def act_accordion_panel
act_accordion_heading + act_accordion_body
end
|
#act_links ⇒ Object
64
65
66
67
68
69
|
# File 'mod/history/lib/card/act/act_renderer.rb', line 64
def act_links
[
link_to_history,
(link_to_act_card unless @act_card.trash)
].compact.join " "
end
|
#act_panel_options ⇒ Object
141
142
143
|
# File 'mod/history/lib/card/act/act_renderer.rb', line 141
def act_panel_options
{ class: "card-header", role: "tab", id: "heading-#{collapse_id}" }
end
|
#act_type ⇒ Object
207
208
209
|
# File 'mod/history/lib/card/act/act_renderer.rb', line 207
def act_type
@act.main_action.action_type
end
|
87
88
89
90
91
|
# File 'mod/history/lib/card/act/act_renderer.rb', line 87
def
true
end
|
#approved_actions ⇒ Object
82
83
84
85
|
# File 'mod/history/lib/card/act/act_renderer.rb', line 82
def approved_actions
@approved_actions ||= actions end
|
#collapse_id ⇒ Object
107
108
109
|
# File 'mod/history/lib/card/act/act_renderer.rb', line 107
def collapse_id
"act-id-#{@act.id}"
end
|
#count_types ⇒ Object
93
94
95
96
97
98
99
100
|
# File 'mod/history/lib/card/act/act_renderer.rb', line 93
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
|
#deletion_act? ⇒ Boolean
203
204
205
|
# File 'mod/history/lib/card/act/act_renderer.rb', line 203
def deletion_act?
act_type == :delete
end
|
#details ⇒ Object
50
51
52
53
54
55
|
# File 'mod/history/lib/card/act/act_renderer.rb', line 50
def details
approved_actions[0..20].map do |action|
Action::ActionRenderer.new(@format, action, ,
:summary).render
end.join
end
|
#edited_ago ⇒ Object
102
103
104
105
|
# File 'mod/history/lib/card/act/act_renderer.rb', line 102
def edited_ago
return "" unless @act.acted_at
"#{time_ago_in_words(@act.acted_at)} ago"
end
|
32
33
34
35
36
37
38
39
40
41
42
43
44
|
# File 'mod/history/lib/card/act/act_renderer.rb', line 32
def
bs_layout do
row 10, 2 do
column do
html title
tag(:span, "text-muted pl-1 badge") {summary}
end
column act_links, class: "text-right"
end
end
end
|
#link_to_act_card ⇒ Object
71
72
73
|
# File 'mod/history/lib/card/act/act_renderer.rb', line 71
def link_to_act_card
link_to_card @act_card, icon_tag(:new_window), class: "_stop_propagation"
end
|
#link_to_history ⇒ Object
75
76
77
78
79
80
|
# File 'mod/history/lib/card/act/act_renderer.rb', line 75
def link_to_history
link_to_card @act_card, icon_tag(:history),
path: { view: :history, look_in_trash: true },
class: "_stop_propagation",
rel: "nofollow"
end
|
#render ⇒ Object
27
28
29
30
|
# File 'mod/history/lib/card/act/act_renderer.rb', line 27
def render
return "" unless @act_card
act_accordion
end
|
#respond_to_missing?(method_name, _include_private = false) ⇒ Boolean
23
24
25
|
# File 'mod/history/lib/card/act/act_renderer.rb', line 23
def respond_to_missing? method_name, _include_private=false
@format.respond_to? method_name
end
|
#revert_actions_link(link_text, revert_to: :this, slot_selector:) ⇒ Object
192
193
194
195
196
197
198
199
200
201
|
# File 'mod/history/lib/card/act/act_renderer.rb', line 192
def revert_actions_link link_text, revert_to: :this, slot_selector:
return unless card.ok? :update
args = { remote: true, method: :post, rel: "nofollow",
path: { action: :update, view: :open, look_in_trash: true,
revert_actions: @act.actions.map(&:id),
"data-slot-selector" => slot_selector } }
add_class args, "slotter"
args[:path][:revert_to] = revert_to
link_to link_text, args
end
|
#revert_link ⇒ Object
187
188
189
190
|
# File 'mod/history/lib/card/act/act_renderer.rb', line 187
def revert_link
revert_actions_link "revert to this", revert_to: :this,
slot_selector: ".card-slot.history-view"
end
|
#rollback_link ⇒ Object
Revert:
current update
Restore:
current deletion
Revert and Restore:
old deletions
blank:
current create
save as current:
not current, not deletion
172
173
174
175
176
177
178
179
180
181
182
183
184
185
|
# File 'mod/history/lib/card/act/act_renderer.rb', line 172
def rollback_link
return unless card.ok? :update
wrap_with :div, class: "act-link collapse #{collapse_id} pull-right" do
revert_link
end
end
|
#show_or_hide_changes_link ⇒ Object
211
212
213
214
215
216
217
218
219
220
221
|
# File 'mod/history/lib/card/act/act_renderer.rb', line 211
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
57
58
59
60
61
62
|
# File 'mod/history/lib/card/act/act_renderer.rb', line 57
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
|