Module: Card::Set::All::History::Events

Extended by:
Card::Set
Defined in:
card/tmpsets/set/mod013-card-mod-history/all/history/events.rb,
card/tmpsets/set/mod012-card-mod-history/all/history/events.rb

Overview

Set: All cards (History, Events)

must be called on all actions and before :set_name, :process_subcards and

Constant Summary

Constants included from Helpers

Helpers::SET_PATTERN_TEST_REGEXP

Constants included from Event::Api

Event::Api::OPTIONS

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Card::Set

reset_modules

Methods included from I18nScope

#mod_name, #scope

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, #define_set_from_error, #ensure_set, #setting_opts, #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

#event

Class Method Details

.source_locationObject



8
# File 'card/tmpsets/set/mod013-card-mod-history/all/history/events.rb', line 8

def self.source_location; "/Users/ethan/dev/decko/gem/card-mod-history/set/all/history/events.rb"; end

Instance Method Details

#actionable?Boolean

can we store an action? (can be overridden, eg in files)

Returns:

  • (Boolean)


23
24
25
# File 'card/tmpsets/set/mod013-card-mod-history/all/history/events.rb', line 23

def actionable?
  history?
end

#edit_conflict?Boolean

Returns:

  • (Boolean)


31
32
33
34
35
36
# File 'card/tmpsets/set/mod013-card-mod-history/all/history/events.rb', line 31

def edit_conflict?
  last_action_id_before_edit &&
    last_action_id_before_edit.to_i != last_action_id &&
    (la = last_action) &&
    la.act.actor_id != Auth.current_id
end

#event: assign_actionObject

:validate_delete_children



10
11
12
13
14
15
16
17
18
19
20
# File 'card/tmpsets/set/mod013-card-mod-history/all/history/events.rb', line 10

event :assign_action, :initialize, when: :actionable? do
  act = director.need_act
  @current_action = Card::Action.create(
    card_act_id: act.id,
    action_type: action,
    draft: (Env.params["draft"] == "true")
  )
  if @supercard && @supercard != self
    @current_action.super_action = @supercard.current_action
  end
end

#event: detect_conflictObject



27
28
29
# File 'card/tmpsets/set/mod013-card-mod-history/all/history/events.rb', line 27

event :detect_conflict, :validate, on: :update, when: :edit_conflict? do
  errors.add :conflict, tr(:error_not_latest_revision)
end

#event: finalize_actObject



96
97
98
# File 'card/tmpsets/set/mod013-card-mod-history/all/history/events.rb', line 96

event :finalize_act, after: :finalize_action, when: :act_card? do
  Card::Director.act.update! card_id: id
end

#event: finalize_actionObject

stores changes in the changes table and assigns them to the current action removes the action if there are no changes



40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'card/tmpsets/set/mod013-card-mod-history/all/history/events.rb', line 40

event :finalize_action, :finalize, when: :finalize_action? do
  if changed_fields.present?
    @current_action.update! card_id: id

    # Note: #last_change_on uses the id to sort by date
    # so the changes for the create changes have to be created before the first change
    store_card_changes_for_create_action if first_change?
    store_card_changes unless first_create?
    # FIXME: a `@current_action.card` call here breaks specs in solid_cache_spec.rb
  elsif @current_action.card_changes.reload.empty?
    @current_action.delete
    @current_action = nil
  end
end

#event: remove_empty_actObject



100
101
102
103
# File 'card/tmpsets/set/mod013-card-mod-history/all/history/events.rb', line 100

event :remove_empty_act, :integrate_with_delay_final, when: :remove_empty_act? do
  # Card::Director.act.delete
  # Card::Director.act = nil
end

#event: rollback_actionsObject



88
89
90
91
92
93
94
# File 'card/tmpsets/set/mod013-card-mod-history/all/history/events.rb', line 88

event :rollback_actions, :prepare_to_validate, on: :update, when: :rollback_request? do
  update_args = process_revert_actions
  Env.params["revert_actions"] = nil
  update! update_args
  clear_drafts
  abort :success
end

#finalize_action?Boolean

Returns:

  • (Boolean)


84
85
86
# File 'card/tmpsets/set/mod013-card-mod-history/all/history/events.rb', line 84

def finalize_action?
  actionable? && current_action
end

#remove_empty_act?Boolean

Returns:

  • (Boolean)


105
106
107
# File 'card/tmpsets/set/mod013-card-mod-history/all/history/events.rb', line 105

def remove_empty_act?
  act_card? && Director.act&.ar_actions&.reload&.empty?
end

#store_card_changesObject



63
64
65
66
67
# File 'card/tmpsets/set/mod013-card-mod-history/all/history/events.rb', line 63

def store_card_changes
  store_each_history_field @current_action.id, changed_fields do |field|
    self[field]
  end
end

#store_card_changes_for_create_actionObject

changes for the create action are stored after the first update



56
57
58
59
60
61
# File 'card/tmpsets/set/mod013-card-mod-history/all/history/events.rb', line 56

def store_card_changes_for_create_action
  Card::Action.cache.delete "#{create_action.id}-changes"
  store_each_history_field create_action.id do |field|
    attribute_before_act field
  end
end

#store_each_history_field(action_id, fields = nil) ⇒ Object



69
70
71
72
73
74
75
76
77
78
79
80
81
82
# File 'card/tmpsets/set/mod013-card-mod-history/all/history/events.rb', line 69

def store_each_history_field action_id, fields=nil
  fields ||= Card::Change::TRACKED_FIELDS
  if false # Card::Change.supports_import?
    # attach.feature fails with this
    values = fields.map.with_index { |field, index| [index, yield(field), action_id] }
    Card::Change.import [:field, :value, :card_action_id], values #, validate: false
  else
    fields.each do |field|
      Card::Change.create field: field,
                          value: yield(field),
                          card_action_id: action_id
    end
  end
end