Class: Card::Act::ActRenderer
- Inherits:
-
Object
show all
- Includes:
- Bootstrapper
- Defined in:
- mod/history/lib/card/act/act_renderer.rb,
mod/history/lib/card/act/act_renderer/board_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, BoardActRenderer, RelativeActRenderer
Instance Method Summary
collapse
-
#absolute_title ⇒ Object
-
#accordion_item ⇒ Object
-
#act_links ⇒ Object
-
#act_type ⇒ Object
-
#action_summary(type) ⇒ Object
-
#actor_and_ago ⇒ Object
-
#approved_actions ⇒ Object
-
#autosaved_draft_link(opts = {}) ⇒ Object
TODO: get this working again, perhaps in action def show_or_hide_changes_link wrap_with :div, class: “act-link” do @format.link_to_view( :act, “#? ‘Show’ : ‘Hide’ changes”, path: { act_id: @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.
-
#count_types ⇒ Object
-
#details ⇒ Object
-
#edited_ago ⇒ Object
-
#header ⇒ Object
-
#initialize(format, act, args) ⇒ ActRenderer
constructor
A new instance of ActRenderer.
-
#link_to_act_card ⇒ Object
-
#link_to_history ⇒ Object
-
#method_missing(method_name, *args, &block) ⇒ Object
-
#render ⇒ Object
-
#respond_to_missing?(method_name, _include_private = false) ⇒ Boolean
-
#summary ⇒ Object
#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
45
46
47
|
# File 'mod/history/lib/card/act/act_renderer.rb', line 45
def absolute_title
@act_card.name
end
|
#accordion_item ⇒ Object
110
111
112
113
114
115
|
# File 'mod/history/lib/card/act/act_renderer.rb', line 110
def accordion_item
@format.accordion_item ,
subheader: act_links,
body: details, collapse_id: "act-id-#{@act.id}"
end
|
#act_links ⇒ Object
72
73
74
75
76
77
|
# File 'mod/history/lib/card/act/act_renderer.rb', line 72
def act_links
[
link_to_history,
(link_to_act_card unless @act_card.trash)
].compact.join " "
end
|
117
118
119
|
# File 'mod/history/lib/card/act/act_renderer.rb', line 117
def act_type
@act.main_action.action_type
end
|
#action_summary(type) ⇒ Object
65
66
67
68
69
70
|
# File 'mod/history/lib/card/act/act_renderer.rb', line 65
def action_summary type
count = count_types[type]
return unless count.positive?
"#{@format.action_icon type}<small> #{count if count > 1}</small>"
end
|
#actor_and_ago ⇒ Object
49
50
51
|
# File 'mod/history/lib/card/act/act_renderer.rb', line 49
def actor_and_ago
wrap_with(:small) { [@format.link_to_card(@act.actor), edited_ago] }
end
|
#approved_actions ⇒ Object
90
91
92
93
|
# File 'mod/history/lib/card/act/act_renderer.rb', line 90
def approved_actions
@approved_actions ||= actions.select { |a| a.card&.ok?(:read) }
end
|
#autosaved_draft_link(opts = {}) ⇒ Object
TODO: get this working again, perhaps in action
def show_or_hide_changes_link
wrap_with :div, class: “act-link” do
@format.link_to_view(
:act, “#? ‘Show’ : ‘Hide’ changes”,
path: { act_id: @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
133
134
135
136
137
138
|
# File 'mod/history/lib/card/act/act_renderer.rb', line 133
def autosaved_draft_link opts={}
text = opts.delete(:text) || "autosaved draft"
opts[:path] = { edit_draft: true }
add_class opts, "navbar-link"
link_to_view :edit, text, opts
end
|
#count_types ⇒ Object
95
96
97
98
99
100
101
102
|
# File 'mod/history/lib/card/act/act_renderer.rb', line 95
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
|
53
54
55
56
57
|
# File 'mod/history/lib/card/act/act_renderer.rb', line 53
def details
approved_actions[0..20].map do |action|
Action::ActionRenderer.new(@format, action, true, :summary).render
end.join
end
|
#edited_ago ⇒ Object
104
105
106
107
108
|
# File 'mod/history/lib/card/act/act_renderer.rb', line 104
def edited_ago
return "" unless @act.acted_at
"#{time_ago_in_words(@act.acted_at)} ago"
end
|
31
32
33
34
35
36
37
38
39
40
41
42
43
|
# File 'mod/history/lib/card/act/act_renderer.rb', line 31
def
bs_layout do
row xs: [8, 4], class: "w-100" do
column do
html title
tag(:span, "text-muted ps-1 badge") { summary }
end
column subtitle, class: "text-end"
end
end
end
|
#link_to_act_card ⇒ Object
79
80
81
|
# File 'mod/history/lib/card/act/act_renderer.rb', line 79
def link_to_act_card
link_to_card @act_card, icon_tag(:full_page), class: "_stop_propagation"
end
|
#link_to_history ⇒ Object
83
84
85
86
87
88
|
# File 'mod/history/lib/card/act/act_renderer.rb', line 83
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
|
27
28
29
|
# File 'mod/history/lib/card/act/act_renderer.rb', line 27
def render
@act_card ? accordion_item : ""
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
|
59
60
61
62
63
|
# File 'mod/history/lib/card/act/act_renderer.rb', line 59
def summary
%i[create update delete draft].map do |type|
action_summary type
end.compact.join "<small class='text-muted'> | </small>"
end
|