Class: Card::Act
- Inherits:
-
ApplicationRecord
- Object
- ActiveRecord::Base
- ApplicationRecord
- Card::Act
- Defined in:
- mod/history/lib/card/act.rb,
mod/history/lib/card/act/act_renderer.rb,
mod/history/lib/card/act/act_renderer/bridge_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
-
.all_viewable(action_where = nil) ⇒ ActiveRecord Relation
all acts with actions that current user has permission to view.
-
.all_with_actions_on(card_ids, with_drafts = false) ⇒ Array of Acts
all acts with actions on a given list of cards.
- .cache ⇒ Object
-
.delete_actionless ⇒ Object
remove all acts that have no action.
-
.delete_cardless ⇒ Object
remove all acts that have no card.
-
.timestamp_attributes_for_create ⇒ Object
used by rails time_ago timestamp is set by rails on create.
Instance Method Summary collapse
-
#action_on(card_id) ⇒ Card::Action
act's action on the card in question.
-
#actions(cached = true) ⇒ Array
list of all actions that are part of the act.
-
#actions_affecting(card) ⇒ Array of Actions
act's actions on either the card itself or another card that includes it.
- #actor ⇒ Object
-
#card ⇒ Card
the act's primary card.
- #draft? ⇒ Boolean
-
#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(action_where = nil) ⇒ ActiveRecord Relation
all acts with actions that current user has permission to view
52 53 54 55 56 |
# File 'mod/history/lib/card/act.rb', line 52 def all_viewable action_where=nil relation = joins(ar_actions: :ar_card) relation = relation.where(action_where) if action_where relation.where(Query::CardQuery.viewable_sql).where.not(card_id: nil).distinct end |
.all_with_actions_on(card_ids, with_drafts = false) ⇒ Array of Acts
all acts with actions on a given list of cards
44 45 46 47 48 |
# File 'mod/history/lib/card/act.rb', line 44 def all_with_actions_on card_ids, with_drafts=false sql = "card_actions.card_id IN (:card_ids) AND (draft is not true" sql << (with_drafts ? " OR actor_id = :user_id)" : ")") all_viewable([sql, { card_ids: card_ids, user_id: Card::Auth.current_id }]) end |
.cache ⇒ Object
58 59 60 |
# File 'mod/history/lib/card/act.rb', line 58 def cache Card::Cache[Card::Act] end |
.delete_actionless ⇒ Object
remove all acts that have no action. (janitorial)
32 33 34 35 36 37 38 |
# File 'mod/history/lib/card/act.rb', line 32 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)
26 27 28 29 |
# File 'mod/history/lib/card/act.rb', line 26 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 |
.timestamp_attributes_for_create ⇒ Object
used by rails time_ago timestamp is set by rails on create
64 65 66 |
# File 'mod/history/lib/card/act.rb', line 64 def super << "acted_at" end |
Instance Method Details
#action_on(card_id) ⇒ Card::Action
act's action on the card in question
96 97 98 99 100 |
# File 'mod/history/lib/card/act.rb', line 96 def action_on card_id actions.find do |action| action.card_id == card_id && !action.draft end end |
#actions(cached = true) ⇒ Array
list of all actions that are part of the act
87 88 89 90 91 |
# File 'mod/history/lib/card/act.rb', line 87 def actions cached=true return ar_actions unless cached self.class.cache.fetch("#{id}-actions") { ar_actions.find_all.to_a } end |
#actions_affecting(card) ⇒ Array of Actions
act's actions on either the card itself or another card that includes it
121 122 123 124 125 126 |
# File 'mod/history/lib/card/act.rb', line 121 def actions_affecting card actions.select do |action| (card.id == action.card_id) || card.includee_ids.include?(action.card_id) end end |
#actor ⇒ Object
69 70 71 |
# File 'mod/history/lib/card/act.rb', line 69 def actor Card.fetch actor_id end |
#card ⇒ Card
the act's primary card
75 76 77 78 79 80 81 82 83 |
# File 'mod/history/lib/card/act.rb', line 75 def card Card.fetch card_id, look_in_trash: true # , skip_modules: true # FIXME: if the following is necessary, we need to document why. # generally it's a very bad idea to have type-specific code here. # return res unless res&.type_id&.in?([FileID, ImageID]) # res.include_set_modules end |
#draft? ⇒ Boolean
108 109 110 |
# File 'mod/history/lib/card/act.rb', line 108 def draft? main_action.draft end |
#elapsed_time ⇒ String
time (in words) since act took place
114 115 116 |
# File 'mod/history/lib/card/act.rb', line 114 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
104 105 106 |
# File 'mod/history/lib/card/act.rb', line 104 def main_action action_on(card_id) || actions.first end |