Class: Card::Act
- Defined in:
- mod/01_history/lib/card/act.rb
Class Method Summary collapse
- .all_viewable ⇒ Object
- .delete_actionless ⇒ Object
- .delete_cardless ⇒ Object
- .find_all_with_actions_on(card_ids, args = {}) ⇒ Object
Instance Method Summary collapse
- #action_on(card_id) ⇒ Object
- #card ⇒ Object
- #elapsed_time ⇒ Object
- #main_action ⇒ Object
- #relevant_actions_for(card) ⇒ Object
- #relevant_drafts_for(card) ⇒ Object
- #set_actor ⇒ Object
Class Method Details
.all_viewable ⇒ Object
38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'mod/01_history/lib/card/act.rb', line 38 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
23 24 25 26 27 28 29 |
# File 'mod/01_history/lib/card/act.rb', line 23 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
18 19 20 21 |
# File 'mod/01_history/lib/card/act.rb', line 18 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 = {}) ⇒ Object
31 32 33 34 35 36 |
# File 'mod/01_history/lib/card/act.rb', line 31 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) ⇒ Object
56 57 58 |
# File 'mod/01_history/lib/card/act.rb', line 56 def action_on card_id actions.where("card_id = #{card_id} and draft is not true").first end |
#card ⇒ Object
13 14 15 |
# File 'mod/01_history/lib/card/act.rb', line 13 def card Card.fetch card_id, look_in_trash: true, skip_modules: true end |
#elapsed_time ⇒ Object
64 65 66 |
# File 'mod/01_history/lib/card/act.rb', line 64 def elapsed_time DateTime.new(acted_at).distance_of_time_in_words_to_now end |
#main_action ⇒ Object
60 61 62 |
# File 'mod/01_history/lib/card/act.rb', line 60 def main_action action_on(card_id) || actions.first end |
#relevant_actions_for(card) ⇒ Object
75 76 77 78 79 80 |
# File 'mod/01_history/lib/card/act.rb', line 75 def relevant_actions_for card actions.select do |action| (card.id == action.card_id) || card.included_card_ids.include?(action.card_id) end end |
#relevant_drafts_for(card) ⇒ Object
68 69 70 71 72 73 |
# File 'mod/01_history/lib/card/act.rb', line 68 def relevant_drafts_for card drafts.select do |action| card.included_card_ids.include?(action.card_id) || (card.id == action.card_id) end end |
#set_actor ⇒ Object
52 53 54 |
# File 'mod/01_history/lib/card/act.rb', line 52 def set_actor self.actor_id ||= Auth.current_id end |