class Card::Act::ActRenderer

Public Class Methods

new(format, act, args) click to toggle source
# 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

Public Instance Methods

absolute_title() click to toggle source
# File lib/card/act/act_renderer.rb, line 47
def absolute_title
  accordion_expand_link(@act_card.name)
end
accordion_expand_options() click to toggle source
# File lib/card/act/act_renderer.rb, line 134
def accordion_expand_options
  {
    "data-toggle" => "collapse",
    "data-target" => ".#{collapse_id}",
    "aria-expanded" => true,
    "aria-controls" => collapse_id
  }
end
act_accordion() click to toggle source

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
# File lib/card/act/act_renderer.rb, line 125
      def act_accordion
        context = @act.main_action&.draft ? :warning : :default
        <<-HTML
        <div class="card card-#{context} nodblclick">
          #{act_accordion_panel}
        </div>
        HTML
      end
act_accordion_body() click to toggle source
# File lib/card/act/act_renderer.rb, line 157
def act_accordion_body
  wrap_with :div, id: collapse_id,
                  class: "collapse #{collapse_id}",
                  "data-parent": ".act-accordion-group" do
    wrap_with :div, details, class: "card-body"
  end
end
act_accordion_heading() click to toggle source
# File lib/card/act/act_renderer.rb, line 151
def act_accordion_heading
  wrap_with :div, act_panel_options.merge(accordion_expand_options) do
    wrap_with(:h5, header, class: "mb-0") + subtitle
  end
end
act_accordion_panel() click to toggle source
# File lib/card/act/act_renderer.rb, line 147
def act_accordion_panel
  act_accordion_heading + act_accordion_body
end
act_panel_options() click to toggle source
# File lib/card/act/act_renderer.rb, line 143
def act_panel_options
  { class: "card-header", role: "tab", id: "heading-#{collapse_id}" }
end
act_type() click to toggle source
# File lib/card/act/act_renderer.rb, line 194
def act_type
  @act.main_action.action_type
end
action_header?() click to toggle source
# File lib/card/act/act_renderer.rb, line 89
def action_header?
  true
  # @action_header ||= approved_actions.size != 1 ||
  #                   approved_actions[0].card_id != @format.card.id
end
approved_actions() click to toggle source
# File lib/card/act/act_renderer.rb, line 84
def approved_actions
  @approved_actions ||= actions.select { |a| a.card&.ok?(:read) }
  # FIXME: should not need to test for presence of card here.
end
collapse_id() click to toggle source
# File lib/card/act/act_renderer.rb, line 110
def collapse_id
  "act-id-#{@act.id}"
end
count_types() click to toggle source
# 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
deletion_act?() click to toggle source
# File lib/card/act/act_renderer.rb, line 190
def deletion_act?
  act_type == :delete
end
details() click to toggle source
# File lib/card/act/act_renderer.rb, line 51
def details
  approved_actions[0..20].map do |action|
    Action::ActionRenderer.new(@format, action, action_header?,
                               :summary).render
  end.join
end
edited_ago() click to toggle source
# 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
header() click to toggle source
# File lib/card/act/act_renderer.rb, line 33
def header
  # Card::Bootstrap.new(self).render do
  bs_layout do
    row xs: [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
end
method_missing(method_name, *args, &block) click to toggle source
# 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
render() click to toggle source
# File 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) click to toggle source
# File lib/card/act/act_renderer.rb, line 23
def respond_to_missing? method_name, _include_private=false
  @format.respond_to? method_name
end
summary() click to toggle source
# File lib/card/act/act_renderer.rb, line 58
def summary
  %i[create update delete draft].map do |type|
    next unless count_types[type].positive?

    "#{@format.action_icon type}<small> #{count_types[type]}</small>"
  end.compact.join "<small class='text-muted'> | </small>"
end