Module: Card::Set::All::ContentHistory
- Extended by:
- Card::Set
- Defined in:
- tmpsets/set/mod003-history/all/content_history.rb
Constant Summary
Constants included
from Format
Format::TEMPLATE_DIR
Instance Method Summary
collapse
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
#abstract_set?, #all_set?, #num_set_parts, #shortname, #underscore
#attachment, #ensure_set, #stage_method
Methods included from Format
#all_set_format_mod!, #before, #define_on_format, #format, layout_method_name, #register_set_format, #view, #view_for_override, view_method_name, wrapper_method_name
#include_set, #include_set_formats
Methods included from Basket
#abstract_basket, #add_to_basket, #basket
Methods included from Trait
#card_accessor, #card_reader, #card_writer, #require_field
Methods included from Event::Api
#event
Instance Method Details
#acted_at ⇒ Object
124
125
126
|
# File 'tmpsets/set/mod003-history/all/content_history.rb', line 124
def acted_at
last_act.acted_at
end
|
#clean_html? ⇒ Boolean
149
150
151
|
# File 'tmpsets/set/mod003-history/all/content_history.rb', line 149
def clean_html?
true
end
|
#content ⇒ Object
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.
8
9
10
11
12
13
14
15
16
17
18
|
# File 'tmpsets/set/mod003-history/all/content_history.rb', line 8
def content
if @selected_action_id
@selected_content ||= begin
change = last_change_on :db_content, not_after: @selected_action_id,
including_drafts: true
(change && change.value) || db_content
end
else
super
end
end
|
#content=(value) ⇒ Object
20
21
22
23
|
# File 'tmpsets/set/mod003-history/all/content_history.rb', line 20
def content= value
@selected_content = nil
super
end
|
#creator ⇒ Object
141
142
143
|
# File 'tmpsets/set/mod003-history/all/content_history.rb', line 141
def creator
Card[creator_id]
end
|
#draft_acts ⇒ Object
153
154
155
|
# File 'tmpsets/set/mod003-history/all/content_history.rb', line 153
def draft_acts
drafts.created_by(Card::Auth.current_id).map(&:act)
end
|
#last_act ⇒ Object
110
111
112
113
114
115
116
117
118
119
120
121
122
|
# File 'tmpsets/set/mod003-history/all/content_history.rb', line 110
def last_act
@last_act ||=
if (action = last_action)
last_act_on_self = acts.last
if last_act_on_self &&
(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
92
93
94
|
# File 'tmpsets/set/mod003-history/all/content_history.rb', line 92
def last_action
actions.where("id IS NOT NULL").last
end
|
#last_action_id ⇒ Object
88
89
90
|
# File 'tmpsets/set/mod003-history/all/content_history.rb', line 88
def last_action_id
(la = last_action) && la.id
end
|
#last_actor ⇒ Object
106
107
108
|
# File 'tmpsets/set/mod003-history/all/content_history.rb', line 106
def last_actor
last_act.actor
end
|
#last_change_on(field, opts = {}) ⇒ Object
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
|
# File 'tmpsets/set/mod003-history/all/content_history.rb', line 33
def last_change_on field, opts={}
where_sql = "card_actions.card_id = :card_id AND field = :field"
where_sql += " AND (draft is not true)" unless opts[:including_drafts]
if opts[:before]
where_sql += " AND card_action_id < :action_id"
elsif opts[:not_after]
where_sql += " AND card_action_id <= :action_id"
end
action_arg = opts[:before] || opts[:not_after]
action_id = action_arg.is_a?(Card::Action) ? action_arg.id : action_arg
Change.joins(:action).where(
where_sql, card_id: id,
field: Card::Change.field_index(field),
action_id: action_id
).order(:id).last
end
|
#last_content_action ⇒ Object
96
97
98
99
|
# File 'tmpsets/set/mod003-history/all/content_history.rb', line 96
def last_content_action
l_c = last_change_on :db_content
l_c && l_c.action
end
|
#last_content_action_id ⇒ Object
101
102
103
104
|
# File 'tmpsets/set/mod003-history/all/content_history.rb', line 101
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
81
82
83
84
85
86
|
# File 'tmpsets/set/mod003-history/all/content_history.rb', line 81
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
128
129
130
131
132
133
134
135
|
# File 'tmpsets/set/mod003-history/all/content_history.rb', line 128
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
137
138
139
|
# File 'tmpsets/set/mod003-history/all/content_history.rb', line 137
def revised_at
(last_action && (act = last_action.act) && act.acted_at) || Time.zone.now
end
|
#save_content_draft(content) ⇒ Object
25
26
27
28
29
30
31
|
# File 'tmpsets/set/mod003-history/all/content_history.rb', line 25
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
61
62
63
|
# File 'tmpsets/set/mod003-history/all/content_history.rb', line 61
def selected_action
selected_action_id && Action.fetch(selected_action_id)
end
|
#selected_action_id ⇒ Object
51
52
53
54
|
# File 'tmpsets/set/mod003-history/all/content_history.rb', line 51
def selected_action_id
@selected_action_id || (@current_action && @current_action.id) ||
last_action_id
end
|
#selected_action_id=(action_id) ⇒ Object
56
57
58
59
|
# File 'tmpsets/set/mod003-history/all/content_history.rb', line 56
def selected_action_id= action_id
@selected_content = nil
@selected_action_id = action_id
end
|
#selected_content_action_id ⇒ Object
77
78
79
|
# File 'tmpsets/set/mod003-history/all/content_history.rb', line 77
def selected_content_action_id
@selected_action_id || new_content_action_id || last_content_action_id
end
|
#updater ⇒ Object
145
146
147
|
# File 'tmpsets/set/mod003-history/all/content_history.rb', line 145
def updater
Card[updater_id]
end
|
#with_selected_action_id(action_id) ⇒ Object
65
66
67
68
69
70
71
72
73
74
75
|
# File 'tmpsets/set/mod003-history/all/content_history.rb', line 65
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
|