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?, clean_empty_module_from_hash, clean_empty_modules, define_on_format, each_format, ensure_set, extended, format, include_set, include_set_formats, process_base_module_list, process_base_modules, register_set, register_set_format, shortname, stage_method, view, write_tmp_file
Methods included from Trait
#card_accessor, #card_reader, #card_writer
Methods included from Event
#define_event, #event
Instance Method Details
118
119
120
|
# File 'tmpsets/set/mod002-01_history/all/content_history.rb', line 118
def acted_at
last_act.acted_at
end
|
#clean_html? ⇒ Boolean
144
145
146
|
# File 'tmpsets/set/mod002-01_history/all/content_history.rb', line 144
def clean_html?
true
end
|
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.
7
8
9
10
11
12
13
14
15
|
# File 'tmpsets/set/mod002-01_history/all/content_history.rb', line 7
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
17
18
19
20
|
# File 'tmpsets/set/mod002-01_history/all/content_history.rb', line 17
def content= value
@selected_content = nil
super
end
|
136
137
138
|
# File 'tmpsets/set/mod002-01_history/all/content_history.rb', line 136
def creator
Card[ creator_id ]
end
|
#draft_acts ⇒ Object
148
149
150
|
# File 'tmpsets/set/mod002-01_history/all/content_history.rb', line 148
def draft_acts
drafts.created_by(Card::Auth.current_id).map(&:act)
end
|
107
108
109
110
111
112
113
114
115
116
|
# File 'tmpsets/set/mod002-01_history/all/content_history.rb', line 107
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_action ⇒ Object
89
90
91
|
# File 'tmpsets/set/mod002-01_history/all/content_history.rb', line 89
def last_action
actions.where('id IS NOT NULL').last
end
|
#last_action_id ⇒ Object
85
86
87
|
# File 'tmpsets/set/mod002-01_history/all/content_history.rb', line 85
def last_action_id
la = last_action and la.id
end
|
#last_actor ⇒ Object
103
104
105
|
# File 'tmpsets/set/mod002-01_history/all/content_history.rb', line 103
def last_actor
last_act.actor
end
|
#last_change_on(field, opts = {}) ⇒ Object
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
|
# File 'tmpsets/set/mod002-01_history/all/content_history.rb', line 29
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_action ⇒ Object
93
94
95
96
|
# File 'tmpsets/set/mod002-01_history/all/content_history.rb', line 93
def last_content_action
l_c = last_change_on :db_content
l_c && l_c.action
end
|
#last_content_action_id ⇒ Object
98
99
100
101
|
# File 'tmpsets/set/mod002-01_history/all/content_history.rb', line 98
def last_content_action_id
l_c = last_change_on :db_content
l_c && l_c.card_action_id
end
|
#new_content_action_id ⇒ Object
79
80
81
82
83
|
# File 'tmpsets/set/mod002-01_history/all/content_history.rb', line 79
def new_content_action_id
if @current_action && (new_card? || @current_action.new_content? || db_content_changed?)
@current_action.id
end
end
|
#previous_action(action_id) ⇒ Object
123
124
125
126
127
128
129
130
|
# File 'tmpsets/set/mod002-01_history/all/content_history.rb', line 123
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_at ⇒ Object
132
133
134
|
# File 'tmpsets/set/mod002-01_history/all/content_history.rb', line 132
def revised_at
(last_action and act=last_action.act and act.acted_at) or Time.now
end
|
#save_content_draft(content) ⇒ Object
22
23
24
25
26
27
|
# File 'tmpsets/set/mod002-01_history/all/content_history.rb', line 22
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_action ⇒ Object
59
60
61
|
# File 'tmpsets/set/mod002-01_history/all/content_history.rb', line 59
def selected_action
selected_action_id and Action.fetch(selected_action_id)
end
|
#selected_action_id ⇒ Object
50
51
52
|
# File 'tmpsets/set/mod002-01_history/all/content_history.rb', line 50
def selected_action_id
@selected_action_id || (@current_action and @current_action.id) || last_action_id
end
|
#selected_action_id=(action_id) ⇒ Object
54
55
56
57
|
# File 'tmpsets/set/mod002-01_history/all/content_history.rb', line 54
def selected_action_id= action_id
@selected_content = nil
@selected_action_id = action_id
end
|
#selected_content_action_id ⇒ Object
75
76
77
|
# File 'tmpsets/set/mod002-01_history/all/content_history.rb', line 75
def selected_content_action_id
@selected_action_id || new_content_action_id || last_content_action_id
end
|
140
141
142
|
# File 'tmpsets/set/mod002-01_history/all/content_history.rb', line 140
def updater
Card[ updater_id ]
end
|
#with_selected_action_id(action_id) ⇒ Object
63
64
65
66
67
68
69
70
71
72
73
|
# File 'tmpsets/set/mod002-01_history/all/content_history.rb', line 63
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
|