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/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 ⇒ 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.
- #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 ⇒ Array of Actions
all actions that current user has permission to view
56 57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'mod/history/lib/card/act.rb', line 56 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)
34 35 36 37 38 39 40 |
# File 'mod/history/lib/card/act.rb', line 34 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)
28 29 30 31 |
# File 'mod/history/lib/card/act.rb', line 28 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
47 48 49 50 51 52 |
# File 'mod/history/lib/card/act.rb', line 47 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).distinct.order(:id).reverse_order end |
Instance Method Details
#action_on(card_id) ⇒ Card::Action
act's action on the card in question
82 83 84 |
# File 'mod/history/lib/card/act.rb', line 82 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
105 106 107 108 109 110 |
# File 'mod/history/lib/card/act.rb', line 105 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
73 74 75 76 77 |
# File 'mod/history/lib/card/act.rb', line 73 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
92 93 94 |
# File 'mod/history/lib/card/act.rb', line 92 def draft? main_action.draft end |
#elapsed_time ⇒ String
time (in words) since act took place
98 99 100 |
# File 'mod/history/lib/card/act.rb', line 98 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
88 89 90 |
# File 'mod/history/lib/card/act.rb', line 88 def main_action action_on(card_id) || actions.first end |