Module: Card::Set::All::Actions
- Extended by:
- Card::Set
- Defined in:
- tmpsets/set/mod003-history/all/actions.rb
Constant Summary
Constants included from Helpers
Helpers::SET_PATTERN_TEST_REGEXP
Instance Method Summary collapse
- #delete_old_actions ⇒ Object
- #find_action_by_params(args) ⇒ Object
- #nth_action(index) ⇒ Object
- #revision(action) ⇒ Object
-
#select_action_by_params(params) ⇒ Object
-- encoding : utf-8 --.
Methods included from Card::Set
Methods included from I18nScope
Methods included from Loader
#clean_empty_module_from_hash, #clean_empty_modules, #extended, #process_base_modules, #register_set
Methods included from Helpers
#method_missing, #num_set_parts, #pattern_code, #respond_to_missing?, #set_name_parts, #shortname, #underscore
Methods included from Card::Set::AdvancedApi
#attachment, #ensure_set, #stage_method
Methods included from Format
#before, #format, layout_method_name, #view, view_method_name, view_setting_method_name, wrapper_method_name
Methods included from Inheritance
#include_set, #include_set_formats
Methods included from Basket
#abstract_basket, #add_to_basket, #basket, #unshift_basket
Methods included from Trait
#card_accessor, #card_reader, #card_writer, #require_field
Methods included from Event::Api
Instance Method Details
#delete_old_actions ⇒ Object
46 47 48 49 50 51 52 53 54 55 56 |
# File 'tmpsets/set/mod003-history/all/actions.rb', line 46 def delete_old_actions Card::Change::TRACKED_FIELDS.each do |field| # assign previous changes on each tracked field to the last action next unless (la = last_action) && !la.change(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 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/mod003-history/all/actions.rb', line 13 def find_action_by_params args if args[:rev] nth_action args[:rev] elsif args[:rev_id].is_a?(Integer) || 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/standard.png) elsif args[:rev_id] last_action end end |
#nth_action(index) ⇒ Object
27 28 29 30 31 32 |
# File 'tmpsets/set/mod003-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 |
# File 'tmpsets/set/mod003-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 action = Card::Action.fetch(action) if action.is_a? Integer return unless action Card::Change::TRACKED_FIELDS.each_with_object({}) do |field, attr_changes| last_change = action.change(field) || last_change_on(field, not_after: action) attr_changes[field.to_sym] = (last_change ? last_change.value : self[field]) end end |
#select_action_by_params(params) ⇒ Object
-- encoding : utf-8 --
6 7 8 9 10 11 |
# File 'tmpsets/set/mod003-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 |