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 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.("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_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
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
100 101 102 103 104 105 |
# File 'mod/history/lib/card/act.rb', line 100 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
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 |
#elapsed_time ⇒ String
time (in words) since act took place
93 94 95 |
# File 'mod/history/lib/card/act.rb', line 93 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
87 88 89 |
# File 'mod/history/lib/card/act.rb', line 87 def main_action action_on(card_id) || actions.first end |