Class: Card::Act::ActRenderer

Inherits:
Object
  • Object
show all
Includes:
Bootstrapper
Defined in:
lib/card/act/act_renderer.rb,
lib/card/act/act_renderer/board_act_renderer.rb,
lib/card/act/act_renderer/absolute_act_renderer.rb,
lib/card/act/act_renderer/relative_act_renderer.rb

Direct Known Subclasses

AbsoluteActRenderer, RelativeActRenderer

Defined Under Namespace

Classes: AbsoluteActRenderer, BoardActRenderer, RelativeActRenderer

Instance Method Summary collapse

Constructor Details

#initialize(format, act, args) ⇒ ActRenderer

Returns a new instance of ActRenderer.



4
5
6
7
8
9
10
11
# File '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 '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_titleObject



45
46
47
# File 'lib/card/act/act_renderer.rb', line 45

def absolute_title
  @act_card.name
end

#accordion_itemObject



110
111
112
113
114
115
# File 'lib/card/act/act_renderer.rb', line 110

def accordion_item
  # context = @act.main_action&.draft ? :warning : :default
  @format.accordion_item header,
                         subheader: act_links,
                         body: details, collapse_id: "act-id-#{@act.id}"
end


72
73
74
75
76
77
# File '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

#act_typeObject



117
118
119
# File '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 '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_agoObject



49
50
51
# File '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_actionsObject



90
91
92
93
# File 'lib/card/act/act_renderer.rb', line 90

def approved_actions
  @approved_actions ||= actions.select { |a| a.card&.ok?(:read) }
  # FIXME: should not need to test for presence of card here.
end

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, "#{@args[:hide_diff] ? '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 '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_typesObject



95
96
97
98
99
100
101
102
# File '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

#detailsObject



53
54
55
56
57
# File '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_agoObject



104
105
106
107
108
# File '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

#headerObject



31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/card/act/act_renderer.rb', line 31

def header
  # Card::Bootstrap.new(self).render do
  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
end


79
80
81
# File '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


83
84
85
86
87
88
# File '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

#renderObject



27
28
29
# File 'lib/card/act/act_renderer.rb', line 27

def render
  @act_card ? accordion_item : ""
end

#respond_to_missing?(method_name, _include_private = false) ⇒ Boolean

Returns:

  • (Boolean)


23
24
25
# File 'lib/card/act/act_renderer.rb', line 23

def respond_to_missing? method_name, _include_private=false
  @format.respond_to? method_name
end

#summaryObject



59
60
61
62
63
# File '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