Module: Card::Set::All::ContentHistory

Extended by:
Card::Set
Defined in:
tmpsets/set/mod002-01_history/all/content_history.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, process_base_module_list, process_base_modules, register_set, register_set_format, shortname, view, write_tmp_file

Instance Method Details

#acted_atObject



111
112
113
# File 'tmpsets/set/mod002-01_history/all/content_history.rb', line 111

def acted_at
  last_act.acted_at
end

#clean_html?Boolean

Returns:

  • (Boolean)


137
138
139
# File 'tmpsets/set/mod002-01_history/all/content_history.rb', line 137

def clean_html?
  true
end

#contentObject

if these aren’t in a nested module, the methods just overwrite the base methods, but we need a distict module so that super will be able to refer to the base methods.



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

def content
  if @selected_action_id
    @selected_content ||= begin
      (change = last_change_on( :db_content, :not_after=> @selected_action_id, :including_drafts=>true ) and change.value) || db_content
    end
  else
    super
  end
end

#content=(value) ⇒ Object



16
17
18
19
# File 'tmpsets/set/mod002-01_history/all/content_history.rb', line 16

def content= value
  @selected_content = nil
  super
end

#creatorObject



129
130
131
# File 'tmpsets/set/mod002-01_history/all/content_history.rb', line 129

def creator
  Card[ creator_id ]
end

#draft_actsObject



141
142
143
# File 'tmpsets/set/mod002-01_history/all/content_history.rb', line 141

def draft_acts
  drafts.created_by(Card::Auth.current_id).map(&:act)
end

#last_actObject



100
101
102
103
104
105
106
107
108
109
# File 'tmpsets/set/mod002-01_history/all/content_history.rb', line 100

def last_act
  if action = last_action
    last_act_on_self = acts.last
    if last_act_on_self and ( action.act==last_act_on_self || last_act_on_self.acted_at>action.act.acted_at )
      last_act_on_self
    else
      action.act
    end
  end
end

#last_actionObject



84
85
86
# File 'tmpsets/set/mod002-01_history/all/content_history.rb', line 84

def last_action
  actions.where('id IS NOT NULL').last
end

#last_action_idObject



80
81
82
# File 'tmpsets/set/mod002-01_history/all/content_history.rb', line 80

def last_action_id
  la = last_action and la.id
end

#last_actorObject



96
97
98
# File 'tmpsets/set/mod002-01_history/all/content_history.rb', line 96

def last_actor
  last_act.actor
end

#last_change_on(field, opts = {}) ⇒ Object



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'tmpsets/set/mod002-01_history/all/content_history.rb', line 28

def last_change_on(field, opts={})
  where_sql =  'card_actions.card_id = :card_id AND field = :field '
  if !opts[:including_drafts]
    where_sql += 'AND (draft is not true) '
  end
  where_sql += if opts[:before]
    'AND card_action_id < :action_id'
  elsif opts[:not_after]
    'AND card_action_id <= :action_id'
  else
    ''
  end

  action_arg = opts[:before] || opts[:not_after]
  action_id = action_arg.kind_of?(Card::Action) ? action_arg.id : action_arg
  field_index = Card::TRACKED_FIELDS.index(field.to_s)
  Change.joins(:action).where( where_sql,
    {:card_id=>id, :field=>field_index, :action_id=>action_id}
  ).order(:id).last
end

#last_content_actionObject



88
89
90
# File 'tmpsets/set/mod002-01_history/all/content_history.rb', line 88

def last_content_action
  l_c = last_change_on(:db_content) and l_c.action
end

#last_content_action_idObject



92
93
94
# File 'tmpsets/set/mod002-01_history/all/content_history.rb', line 92

def last_content_action_id
  l_c = last_change_on(:db_content) and l_c.card_action_id
end

#previous_action(action_id) ⇒ Object



116
117
118
119
120
121
122
123
# File 'tmpsets/set/mod002-01_history/all/content_history.rb', line 116

def previous_action action_id
  if action_id
    action_index = actions.find_index do |a|
      a.id == action_id
    end
    actions[action_index - 1] if action_index.to_i != 0
  end
end

#revised_atObject



125
126
127
# File 'tmpsets/set/mod002-01_history/all/content_history.rb', line 125

def revised_at
  (last_action and act=last_action.act and act.acted_at) or Time.now
end

#save_content_draft(content) ⇒ Object



21
22
23
24
25
26
# File 'tmpsets/set/mod002-01_history/all/content_history.rb', line 21

def save_content_draft content
  super
  acts.create do |act|
    act.actions.build(:draft => true, :card_id=>id).card_changes.build(:field=>:db_content, :value=>content)
  end
end

#selected_actionObject



58
59
60
# File 'tmpsets/set/mod002-01_history/all/content_history.rb', line 58

def selected_action
  selected_action_id and Action.fetch(selected_action_id)
end

#selected_action_idObject



49
50
51
# File 'tmpsets/set/mod002-01_history/all/content_history.rb', line 49

def selected_action_id
  @selected_action_id || (@current_action and @current_action.id) || last_action_id
end

#selected_action_id=(action_id) ⇒ Object



53
54
55
56
# File 'tmpsets/set/mod002-01_history/all/content_history.rb', line 53

def selected_action_id= action_id
  @selected_content = nil
  @selected_action_id = action_id
end

#selected_content_action_idObject



74
75
76
77
78
# File 'tmpsets/set/mod002-01_history/all/content_history.rb', line 74

def selected_content_action_id
  @selected_action_id ||
 (@current_action && (new_card? || @current_action.new_content? || db_content_changed?) && @current_action.id) ||
  last_content_action_id
end

#updaterObject



133
134
135
# File 'tmpsets/set/mod002-01_history/all/content_history.rb', line 133

def updater
  Card[ updater_id ]
end

#with_selected_action_id(action_id) ⇒ Object



62
63
64
65
66
67
68
69
70
71
72
# File 'tmpsets/set/mod002-01_history/all/content_history.rb', line 62

def with_selected_action_id action_id
  current_action_id = @selected_action_id
  run_callbacks :select_action do
    self.selected_action_id = action_id
  end
  result = yield
  run_callbacks :select_action do
    self.selected_action_id = current_action_id
  end
  result
end