mod/01_history/set/all/content_history.rb in card-1.16.3 vs mod/01_history/set/all/content_history.rb in card-1.16.4
- old
+ new
@@ -2,11 +2,11 @@
# 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.
def content
if @selected_action_id
@selected_content ||= begin
- (change = last_change_on( :db_content, :not_after=> @selected_action_id ) and change.value) || db_content
+ (change = last_change_on( :db_content, :not_after=> @selected_action_id, :including_drafts=>true ) and change.value) || db_content
end
else
super
end
end
@@ -22,11 +22,14 @@
act.actions.build(:draft => true, :card_id=>id).card_changes.build(:field=>:db_content, :value=>content)
end
end
def last_change_on(field, opts={})
- where_sql = 'card_actions.card_id = :card_id AND field = :field AND (draft is not true) '
+ 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
@@ -50,9 +53,21 @@
@selected_action_id = action_id
end
def selected_action
selected_action_id and Action.fetch(selected_action_id)
+end
+
+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
def selected_content_action_id
@selected_action_id ||
(@current_action && (new_card? || @current_action.new_content? || db_content_changed?) && @current_action.id) ||