Class: Card::Act
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- Card::Act
- Defined in:
- mod/history/lib/card/act.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.
Class Method Summary collapse
-
.all_viewable ⇒ Array of Actions
all actions that current user has permission to view.
-
.delete_actionless ⇒ Object
remove all acts that have no action.
-
.delete_cardless ⇒ Object
remove all acts that have no card.
-
.find_all_with_actions_on(card_ids, args = {}) ⇒ Array of Actions
all actions on a set of card ids.
Instance Method Summary collapse
-
#action_on(card_id) ⇒ Card::Action
act's action on the card in question.
-
#actions_affecting(card) ⇒ Array of Actions
act's actions on either the card itself or another card that includes it.
-
#card ⇒ Card
the act's primary card.
-
#elapsed_time ⇒ String
time (in words) since act took place.
-
#main_action ⇒ Card::Action
act's action on primary card if it exists.
Class Method Details
.all_viewable ⇒ Array of Actions
all actions that current user has permission to view
55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'mod/history/lib/card/act.rb', line 55 def all_viewable joins = "JOIN card_actions ON card_acts.id = card_act_id " \ "JOIN cards ON cards.id = card_actions.card_id" where = [ "card_actions.id is not null", # data check. should not be needed "cards.id is not null", # ditto "draft is not true", Card::Query::SqlStatement.new.("cards") ].compact.join " AND " joins(joins).where(where).uniq end |
.delete_actionless ⇒ Object
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_cardless ⇒ Object
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
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
78 79 80 |
# File 'mod/history/lib/card/act.rb', line 78 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
97 98 99 100 101 102 |
# File 'mod/history/lib/card/act.rb', line 97 def actions_affecting card actions.select do |action| (card.id == action.card_id) || card.included_card_ids.include?(action.card_id) end end |
#card ⇒ Card
the act's primary card
71 72 73 |
# File 'mod/history/lib/card/act.rb', line 71 def card Card.fetch card_id, look_in_trash: true, skip_modules: true end |
#elapsed_time ⇒ String
time (in words) since act took place
90 91 92 |
# File 'mod/history/lib/card/act.rb', line 90 def elapsed_time DateTime.new(acted_at).distance_of_time_in_words_to_now end |
#main_action ⇒ Card::Action
act's action on primary card if it exists. otherwise act's first action
84 85 86 |
# File 'mod/history/lib/card/act.rb', line 84 def main_action action_on(card_id) || actions.first end |