Class: Card::Act

Inherits:
ActiveRecord::Base
  • Object
show all
Defined in:
mod/history/lib/card/act.rb,
mod/history/lib/card/act/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

Overview

An "act" is a group of recorded actions on cards. Together, acts, actions, and changes comprise a comprehensive card history tracking system.

For example, if a given web form submissions updates the contents of three cards, then the submission will result in the recording of three actions, each of which is tied to one act.

Each act records:

  • the actor_id (an id associated with the account responsible)
  • the card_id of the act's primary card
  • acted_at, a timestamp of the action
  • the ip_address of the actor where applicable.

Defined Under Namespace

Classes: ActRenderer

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.all_viewableArray of Actions

all actions that current user has permission to view

Returns:

  • (Array of Actions)


55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'mod/history/lib/card/act.rb', line 55

def all_viewable
  card_join = "JOIN cards ON cards.id = card_actions.card_id"
  action_conditions = [
    "card_acts.id = card_act_id",
    "card_actions.card_id is not null",
    "draft is not true",
    Query::SqlStatement.new.permission_conditions("cards")
  ].compact.join " AND "

  viewable_actions =
    Action.joins(card_join).where(action_conditions).to_sql
  where("card_id is not null AND EXISTS (#{viewable_actions})")
end

.delete_actionlessObject

remove all acts that have no action. (janitorial)



33
34
35
36
37
38
39
# File 'mod/history/lib/card/act.rb', line 33

def delete_actionless
  joins(
    "LEFT JOIN card_actions ON card_acts.id = card_act_id"
  ).where(
    "card_actions.id is null"
  ).delete_all
end

.delete_cardlessObject

remove all acts that have no card. (janitorial)



27
28
29
30
# File 'mod/history/lib/card/act.rb', line 27

def delete_cardless
  left_join = "LEFT JOIN cards ON card_acts.card_id = cards.id"
  joins(left_join).where("cards.id IS NULL").delete_all
end

.find_all_with_actions_on(card_ids, args = {}) ⇒ Array of Actions

all actions on a set of card ids

Parameters:

  • card_ids (Array of Integers)
  • args (Hash) (defaults to: {})

    with_drafts: [true, false]

Returns:

  • (Array of Actions)


46
47
48
49
50
51
# File 'mod/history/lib/card/act.rb', line 46

def find_all_with_actions_on card_ids, args={}
  sql = "card_actions.card_id IN (:card_ids) AND ( (draft is not true) "
  sql << (args[:with_drafts] ? "OR actor_id = :current_user_id)" : ")")
  vars = { card_ids: card_ids, current_user_id: Card::Auth.current_id }
  joins(:actions).where(sql, vars).uniq.order(:id).reverse_order
end

Instance Method Details

#action_on(card_id) ⇒ Card::Action

act's action on the card in question

Parameters:

  • card_id (Integer)

Returns:



81
82
83
# File 'mod/history/lib/card/act.rb', line 81

def action_on card_id
  actions.where("card_id = #{card_id} and draft is not true").first
end

#actions_affecting(card) ⇒ Array of Actions

act's actions on either the card itself or another card that includes it

Parameters:

Returns:

  • (Array of Actions)


104
105
106
107
108
109
# File 'mod/history/lib/card/act.rb', line 104

def actions_affecting card
  actions.select do |action|
    (card.id == action.card_id) ||
      card.included_card_ids.include?(action.card_id)
  end
end

#cardCard

the act's primary card

Returns:



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

def card
  res = Card.fetch card_id, look_in_trash: true, skip_modules: true
  return res unless res && res.type_id.in?([FileID, ImageID])
  res.include_set_modules
end

#draft?Boolean

Returns:

  • (Boolean)


91
92
93
# File 'mod/history/lib/card/act.rb', line 91

def draft?
  main_action.draft
end

#elapsed_timeString

time (in words) since act took place

Returns:

  • (String)


97
98
99
# File 'mod/history/lib/card/act.rb', line 97

def elapsed_time
  DateTime.new(acted_at).distance_of_time_in_words_to_now
end

#main_actionCard::Action

act's action on primary card if it exists. otherwise act's first action

Returns:



87
88
89
# File 'mod/history/lib/card/act.rb', line 87

def main_action
  action_on(card_id) || actions.first
end