Class: Card::Act::ActRenderer

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

Direct Known Subclasses

AbsoluteActRenderer, RelativeActRenderer

Defined Under Namespace

Classes: AbsoluteActRenderer, BridgeActRenderer, RelativeActRenderer

Instance Method Summary collapse

Methods included from Bootstrapper

#bootstrap, #bs

Methods included from Bootstrap::ComponentLoader

#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 'card-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 'card-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_titleObject



47
48
49
# File 'card-mod-history/lib/card/act/act_renderer.rb', line 47

def absolute_title
  accordion_expand_link(@act_card.name)
end


114
115
116
117
118
119
120
# File 'card-mod-history/lib/card/act/act_renderer.rb', line 114

def accordion_expand_link text
  <<-HTML
    <a>
      #{text}
    </a>
  HTML
end

#accordion_expand_optionsObject



134
135
136
137
138
139
140
141
# File 'card-mod-history/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_accordionObject

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



125
126
127
128
129
130
131
132
# File 'card-mod-history/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_bodyObject



157
158
159
160
161
162
163
# File 'card-mod-history/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_headingObject



151
152
153
154
155
# File 'card-mod-history/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_panelObject



147
148
149
# File 'card-mod-history/lib/card/act/act_renderer.rb', line 147

def act_accordion_panel
  act_accordion_heading + act_accordion_body
end


66
67
68
69
70
71
# File 'card-mod-history/lib/card/act/act_renderer.rb', line 66

def act_links
  [
    link_to_history,
    (link_to_act_card unless @act_card.trash)
  ].compact.join " "
end

#act_panel_optionsObject



143
144
145
# File 'card-mod-history/lib/card/act/act_renderer.rb', line 143

def act_panel_options
  { class: "card-header", role: "tab", id: "heading-#{collapse_id}" }
end

#act_typeObject



194
195
196
# File 'card-mod-history/lib/card/act/act_renderer.rb', line 194

def act_type
  @act.main_action.action_type
end

#action_header?Boolean

Returns:

  • (Boolean)


89
90
91
92
93
# File 'card-mod-history/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_actionsObject



84
85
86
87
# File 'card-mod-history/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


209
210
211
212
213
214
# File 'card-mod-history/lib/card/act/act_renderer.rb', line 209

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

#collapse_idObject



110
111
112
# File 'card-mod-history/lib/card/act/act_renderer.rb', line 110

def collapse_id
  "act-id-#{@act.id}"
end

#count_typesObject



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

#deletion_act?Boolean

Returns:

  • (Boolean)


190
191
192
# File 'card-mod-history/lib/card/act/act_renderer.rb', line 190

def deletion_act?
  act_type == :delete
end

#detailsObject



51
52
53
54
55
56
# File 'card-mod-history/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_agoObject



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

#headerObject



33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'card-mod-history/lib/card/act/act_renderer.rb', line 33

def header
  #::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


73
74
75
# File 'card-mod-history/lib/card/act/act_renderer.rb', line 73

def link_to_act_card
  link_to_card @act_card, icon_tag(:new_window), class: "_stop_propagation"
end


77
78
79
80
81
82
# File 'card-mod-history/lib/card/act/act_renderer.rb', line 77

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
30
31
# File 'card-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

Returns:

  • (Boolean)


23
24
25
# File 'card-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: current update Restore: current deletion Revert and Restore: old deletions blank: current create save as current: not current, not deletion



175
176
177
178
179
180
181
182
183
184
185
186
187
188
# File 'card-mod-history/lib/card/act/act_renderer.rb', line 175

def rollback_link
  return unless @card.ok? :update

  wrap_with :div, class: "act-link collapse #{collapse_id} float-right" do
    (:small, revert_link)

    # 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


198
199
200
201
202
203
204
205
206
207
# File 'card-mod-history/lib/card/act/act_renderer.rb', line 198

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: @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

#summaryObject



58
59
60
61
62
63
64
# File 'card-mod-history/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