Module: Card::Set::All::Actions

Extended by:
Card::Set
Defined in:
tmpsets/set/mod002-01_history/all/actions.rb

Instance Method Summary collapse

Methods included from Card::Set

abstract_set?, all_set?, card_accessor, card_reader, card_writer, clean_empty_module_from_hash, clean_empty_modules, define_active_job, define_event_method, define_event_perform_later_method, define_on_format, ensure_set, event, extended, format, phase_method, process_base_module_list, process_base_modules, register_set, register_set_format, shortname, view, write_tmp_file

Instance Method Details

#delete_old_actionsObject



48
49
50
51
52
53
54
55
56
57
58
59
# File 'tmpsets/set/mod002-01_history/all/actions.rb', line 48

def delete_old_actions
  Card::TRACKED_FIELDS.each do |field|
    # assign previous changes on each tracked field to the last action
    if (la = last_action) && !la.change_for(field).present? &&
       (last_change = last_change_on field)
      # last_change comes as readonly record
      last_change = Card::Change.find(last_change.id)
      last_change.update_attributes!(card_action_id: last_action_id)
    end
  end
  actions.where('id != ?', last_action_id).delete_all
end

#find_action_by_params(args) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'tmpsets/set/mod002-01_history/all/actions.rb', line 13

def find_action_by_params args
  if args[:rev]
    nth_action args[:rev]
  elsif Integer === args[:rev_id] || args[:rev_id] =~ /^\d+$/
    if (action = Action.fetch(args[:rev_id])) && action.card_id == id
      action
    end
  # revision id is probalby a mod (e.g. if you request
  # files/:logo/05_standard.png)
  elsif args[:rev_id]
    last_action
  end
end

#nth_action(index) ⇒ Object



27
28
29
30
31
32
# File 'tmpsets/set/mod002-01_history/all/actions.rb', line 27

def nth_action index
  index = index.to_i
  return unless id && index > 0
  Action.where("draft is not true AND card_id = #{id}")
    .order(:id).limit(1).offset(index - 1).first
end

#revision(action) ⇒ Object



34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'tmpsets/set/mod002-01_history/all/actions.rb', line 34

def revision action
  # a "revision" refers to the state of all tracked fields
  # at the time of a given action
  if action.is_a? Integer
    action = Card::Action.fetch(action)
  end
  action && Card::TRACKED_FIELDS.inject({}) do |attr_changes, field|
    last_change = action.card_changes.find_by_field_name(field) ||
                  last_change_on(field, not_after: action)
    attr_changes[field.to_sym] = (last_change ? last_change.value : self[field])
    attr_changes
  end
end

#select_action_by_params(params) ⇒ Object

-*- encoding : utf-8 -*-



6
7
8
9
10
11
# File 'tmpsets/set/mod002-01_history/all/actions.rb', line 6

def select_action_by_params params
  return unless (action = find_action_by_params(params))
  run_callbacks :select_action do
    self.selected_action_id = action.id
  end
end