Module: Card::Set::All::History::ActListing::HtmlFormat

Extended by:
Card::Set::AbstractFormat
Defined in:
tmpsets/set/mod005-history/all/history/act_listing.rb

Instance Method Summary collapse

Instance Method Details

#act_accordion(acts, context, &block) ⇒ Object



54
55
56
# File 'tmpsets/set/mod005-history/all/history/act_listing.rb', line 54

def act_accordion acts, context, &block
  accordion_group acts_for_accordion(acts, context, &block), nil, class: "clear-both"
end

#act_from_contextObject



11
12
13
14
15
16
17
# File 'tmpsets/set/mod005-history/all/history/act_listing.rb', line 11

def act_from_context
  if (act_id = params["act_id"])
    Act.find(act_id) || raise(Card::NotFound, "act not found")
  else
    card.last_action.act
  end
end

#act_list(acts, context) ⇒ Object



32
33
34
35
36
37
# File 'tmpsets/set/mod005-history/all/history/act_listing.rb', line 32

def act_list acts, context
  act_accordion acts, context do |act, seq|
    fmt = context == :relative ? self : act.card.format(:html)
    fmt.act_listing act, seq, context
  end
end

#act_list_starting_seq(acts) ⇒ Object



84
85
86
# File 'tmpsets/set/mod005-history/all/history/act_listing.rb', line 84

def act_list_starting_seq acts
  acts.size - (acts_page_from_params - 1) * acts_per_page
end

#act_listing(act, seq = nil, context = nil) ⇒ Object



39
40
41
42
43
44
# File 'tmpsets/set/mod005-history/all/history/act_listing.rb', line 39

def act_listing act, seq=nil, context=nil
  opts = act_listing_opts_from_params(seq)
  opts[:slot_class] = "revision-#{act.id} history-slot list-group-item"
  context ||= (params[:act_context] || :absolute).to_sym
  act_renderer(context).new(self, act, opts).render
end

#act_listing_opts_from_params(seq) ⇒ Object

TODO: consider putting all these under one top-level param, eg: act: { seq: X, diff: [show/hide], action_view: Y }



48
49
50
51
52
# File 'tmpsets/set/mod005-history/all/history/act_listing.rb', line 48

def act_listing_opts_from_params seq
  { act_seq: (seq || params["act_seq"]),
    action_view: (params["action_view"] || "summary").to_sym,
    hide_diff: params["hide_diff"].to_s.strip == "true" }
end

#act_paging(acts, context) ⇒ Object



96
97
98
99
100
101
102
103
# File 'tmpsets/set/mod005-history/all/history/act_listing.rb', line 96

def act_paging acts, context
  wrap_with :span, class: "slotter" do
    acts = current_page_acts acts
    opts = { remote: true, theme: "twitter-bootstrap-4" }
    opts[:total_pages] = 10 if limited_paging? context
    paginate acts, opts
  end
end

#action_icon(action_type, extra_class = nil) ⇒ Object



109
110
111
112
113
114
115
116
117
# File 'tmpsets/set/mod005-history/all/history/act_listing.rb', line 109

def action_icon action_type, extra_class=nil
  icon = case action_type
         when :create then :add_circle
         when :update then :pencil
         when :delete then :remove_circle
         when :draft then :wrench
         end
  icon_tag icon, extra_class
end

#acts_for_accordion(acts, context) ⇒ Object



58
59
60
61
62
63
64
# File 'tmpsets/set/mod005-history/all/history/act_listing.rb', line 58

def acts_for_accordion acts, context
  clean_acts(current_page_acts(acts)).map do |act|
    with_act_seq(context, acts) do |seq|
      yield act, seq
    end
  end
end

#acts_layout(acts, context, draft_legend = :hide) ⇒ Object

used (by history and recent)for rendering act lists with legend and paging

Parameters:

  • acts (ActiveRecord::Relation)

    relation that will return acts objects

  • context (Symbol)

    :relative or :absolute

  • draft_legend (Symbol) (defaults to: :hide)

    :show or :hide



24
25
26
27
28
29
30
# File 'tmpsets/set/mod005-history/all/history/act_listing.rb', line 24

def acts_layout acts, context, draft_legend=:hide
  bs_layout container: false, fluid: false do
    html _render_act_legend(draft_legend => :draft_legend)
    row(12) { act_list acts, context }
    row(12) { act_paging acts, context }
  end
end

#acts_page_from_paramsObject



92
93
94
# File 'tmpsets/set/mod005-history/all/history/act_listing.rb', line 92

def acts_page_from_params
  @acts_page_from_params ||= params["page"].present? ? params["page"].to_i : 1
end

#acts_per_pageObject



88
89
90
# File 'tmpsets/set/mod005-history/all/history/act_listing.rb', line 88

def acts_per_page
  @acts_per_page || ACTS_PER_PAGE
end

#clean_acts(acts) ⇒ Object



74
75
76
77
78
# File 'tmpsets/set/mod005-history/all/history/act_listing.rb', line 74

def clean_acts acts
  # FIXME: if we get rid of bad act data, this will not be necessary
  # The current
  acts.select(&:card)
end

#current_act_seq(acts) ⇒ Object



70
71
72
# File 'tmpsets/set/mod005-history/all/history/act_listing.rb', line 70

def current_act_seq acts
  @act_seq = @act_seq ? (@act_seq -= 1) : act_list_starting_seq(acts)
end

#current_page_acts(acts) ⇒ Object



80
81
82
# File 'tmpsets/set/mod005-history/all/history/act_listing.rb', line 80

def current_page_acts acts
  acts.page(acts_page_from_params).per acts_per_page
end

#limited_paging?(context) ⇒ Boolean

Returns:

  • (Boolean)


105
106
107
# File 'tmpsets/set/mod005-history/all/history/act_listing.rb', line 105

def limited_paging? context
  context == :absolute && Act.count > 1000
end

#with_act_seq(context, acts) {|context == :absolute ? nil : current_act_seq(acts)| ... } ⇒ Object

Yields:



66
67
68
# File 'tmpsets/set/mod005-history/all/history/act_listing.rb', line 66

def with_act_seq context, acts
  yield(context == :absolute ? nil : current_act_seq(acts))
end