From aecb868b854a742a09a7ee9644ff8168624b11a6 Mon Sep 17 00:00:00 2001 From: Tim Felgentreff Date: Wed, 14 Jul 2010 19:00:03 +0200 Subject: [PATCH] remove more journal specific functionality --- app/controllers/issues_controller.rb | 10 ++-- app/helpers/issues_helper.rb | 76 ---------------------------- app/models/issue.rb | 71 ++++---------------------- app/views/issues/_history.rhtml | 8 +-- lib/redmine/activity/fetcher.rb | 7 +-- lib/redmine/export/pdf.rb | 2 +- 6 files changed, 25 insertions(+), 149 deletions(-) diff --git a/app/controllers/issues_controller.rb b/app/controllers/issues_controller.rb index 8b5d73fa..794b0af6 100644 --- a/app/controllers/issues_controller.rb +++ b/app/controllers/issues_controller.rb @@ -111,8 +111,8 @@ class IssuesController < ApplicationController end def show - @journals = @issue.journals.find(:all, :include => [:user, :details], :order => "#{Journal.table_name}.created_on ASC") - @journals.each_with_index {|j,i| j.indice = i+1} + @journals = @issue.journals.find(:all, :include => [:user], :order => "#{Journal.table_name}.created_at ASC") + @journals.each_with_index {|j,i| j.number = i+1} @journals.reverse! if User.current.wants_comments_in_reverse_order? @changesets = @issue.changesets.visible.all @changesets.reverse! if User.current.wants_comments_in_reverse_order? @@ -234,7 +234,7 @@ class IssuesController < ApplicationController unsaved_issue_ids = [] @issues.each do |issue| issue.reload - journal = issue.init_journal(User.current, params[:notes]) + journal = issue.init_journal(params[:notes]) issue.safe_attributes = attributes call_hook(:controller_issues_bulk_edit_before_save, { :params => params, :issue => issue }) unless issue.save @@ -270,7 +270,7 @@ class IssuesController < ApplicationController changed_attributes[valid_attribute] = (params[valid_attribute] == 'none' ? nil : params[valid_attribute]) end end - issue.init_journal(User.current) + issue.init_journal call_hook(:controller_issues_move_before_save, { :params => params, :issue => issue, :target_project => @target_project, :copy => !!@copy }) if r = issue.move_to_project(@target_project, new_tracker, {:copy => @copy, :attributes => changed_attributes}) moved_issues << r @@ -436,7 +436,7 @@ private @time_entry = TimeEntry.new @notes = params[:notes] - @issue.init_journal(User.current, @notes) + @issue.init_journal(@notes) # User can change issue attributes only if he has :edit permission or if a workflow transition is allowed if (@edit_allowed || !@allowed_statuses.empty?) && params[:issue] attrs = params[:issue].dup diff --git a/app/helpers/issues_helper.rb b/app/helpers/issues_helper.rb index 60798fed..fee4a653 100644 --- a/app/helpers/issues_helper.rb +++ b/app/helpers/issues_helper.rb @@ -100,82 +100,6 @@ module IssuesHelper @sidebar_queries end - def show_detail(detail, no_html=false) - case detail.property - when 'attr' - field = detail.prop_key.to_s.gsub(/\_id$/, "") - label = l(("field_" + field).to_sym) - case - when ['due_date', 'start_date'].include?(detail.prop_key) - value = format_date(detail.value.to_date) if detail.value - old_value = format_date(detail.old_value.to_date) if detail.old_value - - when ['project_id', 'status_id', 'tracker_id', 'assigned_to_id', 'priority_id', 'category_id', 'fixed_version_id'].include?(detail.prop_key) - value = find_name_by_reflection(field, detail.value) - old_value = find_name_by_reflection(field, detail.old_value) - - when detail.prop_key == 'estimated_hours' - value = "%0.02f" % detail.value.to_f unless detail.value.blank? - old_value = "%0.02f" % detail.old_value.to_f unless detail.old_value.blank? - - when detail.prop_key == 'parent_id' - label = l(:field_parent_issue) - value = "##{detail.value}" unless detail.value.blank? - old_value = "##{detail.old_value}" unless detail.old_value.blank? - end - when 'cf' - custom_field = CustomField.find_by_id(detail.prop_key) - if custom_field - label = custom_field.name - value = format_value(detail.value, custom_field.field_format) if detail.value - old_value = format_value(detail.old_value, custom_field.field_format) if detail.old_value - end - when 'attachment' - label = l(:label_attachment) - end - call_hook(:helper_issues_show_detail_after_setting, {:detail => detail, :label => label, :value => value, :old_value => old_value }) - - label ||= detail.prop_key - value ||= detail.value - old_value ||= detail.old_value - - unless no_html - label = content_tag('strong', label) - old_value = content_tag("i", h(old_value)) if detail.old_value - old_value = content_tag("strike", old_value) if detail.old_value and (!detail.value or detail.value.empty?) - if detail.property == 'attachment' && !value.blank? && a = Attachment.find_by_id(detail.prop_key) - # Link to the attachment if it has not been removed - value = link_to_attachment(a) - else - value = content_tag("i", h(value)) if value - end - end - - if !detail.value.blank? - case detail.property - when 'attr', 'cf' - if !detail.old_value.blank? - l(:text_journal_changed, :label => label, :old => old_value, :new => value) - else - l(:text_journal_set_to, :label => label, :value => value) - end - when 'attachment' - l(:text_journal_added, :label => label, :value => value) - end - else - l(:text_journal_deleted, :label => label, :old => old_value) - end - end - - # Find the name of an associated record stored in the field attribute - def find_name_by_reflection(field, id) - association = Issue.reflect_on_association(field.to_sym) - if association - record = association.class_name.constantize.find_by_id(id) - return record.name if record - end - end - def issues_to_csv(issues, project = nil) ic = Iconv.new(l(:general_csv_encoding), 'UTF-8') decimal_separator = l(:general_csv_decimal_separator) diff --git a/app/models/issue.rb b/app/models/issue.rb index a8e0bd7e..1d85493d 100644 --- a/app/models/issue.rb +++ b/app/models/issue.rb @@ -38,17 +38,16 @@ class Issue < ActiveRecord::Base acts_as_journalized :event_title => Proc.new {|o| "#{o.tracker.name} ##{o.id} (#{o.status}): #{o.subject}"}, :event_type => Proc.new {|o| 'issue' + (o.closed? ? ' closed' : '') }, - :activity_find_options => {:include => [:project, :author, :tracker]} + :activity_find_options => {:include => [:project, :author, :tracker]}, + :activity_author_key => :author_id acts_as_searchable :columns => ['subject', "#{table_name}.description", "#{Journal.table_name}.notes"], - :include => [:project, :changes], + :include => [:project, :journals], # sort by id so that limited eager loading doesn't break with postgresql :order_column => "#{table_name}.id" DONE_RATIO_OPTIONS = %w(issue_field issue_status) - attr_reader :current_journal - validates_presence_of :subject, :priority, :project, :tracker, :author, :status validates_length_of :subject, :maximum => 255 @@ -67,7 +66,7 @@ class Issue < ActiveRecord::Base before_create :default_assign before_save :reschedule_following_issues, :close_duplicates, :update_done_ratio_from_issue_status - after_save :update_nested_set_attributes, :update_parent_attributes, :create_journal + after_save :update_nested_set_attributes, :update_parent_attributes after_destroy :destroy_children after_destroy :update_parent_attributes @@ -310,18 +309,7 @@ class Issue < ActiveRecord::Base self.done_ratio = status.default_done_ratio end end - - def init_journal(user, notes = "") - @current_journal ||= Journal.new(:journalized => self, :user => user, :notes => notes) - @issue_before_change = self.clone - @issue_before_change.status = self.status - @custom_values_before_change = {} - self.custom_values.each {|c| @custom_values_before_change.store c.custom_field_id, c.value } - # Make sure updated_on is updated when adding a note. - updated_on_will_change! - @current_journal - end - + # Return true if the issue is closed, otherwise false def closed? self.status.is_closed? @@ -496,13 +484,12 @@ class Issue < ActiveRecord::Base if valid? attachments = Attachment.attach_files(self, params[:attachments]) - attachments[:files].each {|a| @current_journal.details << JournalDetail.new(:property => 'attachment', :prop_key => a.id, :value => a.filename)} # TODO: Rename hook - Redmine::Hook.call_hook(:controller_issues_edit_before_save, { :params => params, :issue => self, :time_entry => @time_entry, :journal => @current_journal}) + Redmine::Hook.call_hook(:controller_issues_edit_before_save, { :params => params, :issue => self, :time_entry => @time_entry, :journal => current_journal}) begin if save # TODO: Rename hook - Redmine::Hook.call_hook(:controller_issues_edit_after_save, { :params => params, :issue => self, :time_entry => @time_entry, :journal => @current_journal}) + Redmine::Hook.call_hook(:controller_issues_edit_after_save, { :params => params, :issue => self, :time_entry => @time_entry, :journal => current_journal}) else raise ActiveRecord::Rollback end @@ -718,22 +705,12 @@ class Issue < ActiveRecord::Base ).each do |issue| next if issue.project.nil? || issue.fixed_version.nil? unless issue.project.shared_versions.include?(issue.fixed_version) - issue.init_journal(User.current) issue.fixed_version = nil issue.save end end end - # Callback on attachment deletion - def attachment_removed(obj) - journal = init_journal(User.current) - journal.details << JournalDetail.new(:property => 'attachment', - :prop_key => obj.id, - :old_value => obj.filename) - journal.save - end - # Default assignment based on category def default_assign if assigned_to.nil? && category && category.assigned_to @@ -758,40 +735,14 @@ class Issue < ActiveRecord::Base duplicate.reload # Don't re-close it if it's already closed next if duplicate.closed? - # Same user and notes - if @current_journal - duplicate.init_journal(@current_journal.user, @current_journal.notes) - end + # Implicitely creates a new journal duplicate.update_attribute :status, self.status + # Same user and notes + duplicate.versions.last.user = current_journal.user + duplicate.versions.last.notes = current_journal.notes end end end - - # Saves the changes in a Journal - # Called after_save - def create_journal - if @current_journal - # attributes changes - (Issue.column_names - %w(id description root_id lft rgt lock_version created_on updated_on)).each {|c| - @current_journal.details << JournalDetail.new(:property => 'attr', - :prop_key => c, - :old_value => @issue_before_change.send(c), - :value => send(c)) unless send(c)==@issue_before_change.send(c) - } - # custom fields changes - custom_values.each {|c| - next if (@custom_values_before_change[c.custom_field_id]==c.value || - (@custom_values_before_change[c.custom_field_id].blank? && c.value.blank?)) - @current_journal.details << JournalDetail.new(:property => 'cf', - :prop_key => c.custom_field_id, - :old_value => @custom_values_before_change[c.custom_field_id], - :value => c.value) - } - @current_journal.save - # reset current journal - init_journal @current_journal.user, @current_journal.notes - end - end # Query generator for selecting groups of issue counts for a project # based on specific criteria diff --git a/app/views/issues/_history.rhtml b/app/views/issues/_history.rhtml index 7459eb35..219be05d 100644 --- a/app/views/issues/_history.rhtml +++ b/app/views/issues/_history.rhtml @@ -1,15 +1,15 @@ <% reply_links = authorize_for('issues', 'edit') -%> <% for journal in journals %>
-

<%= link_to "##{journal.indice}", :anchor => "note-#{journal.indice}" %>
+

<%= link_to "##{journal.number}", :anchor => "note-#{journal.number}" %>
<%= avatar(journal.user, :size => "24") %> - <%= content_tag('a', '', :name => "note-#{journal.indice}")%> - <%= authoring journal.created_on, journal.user, :label => :label_updated_time_by %>

+ <%= content_tag('a', '', :name => "note-#{journal.number}")%> + <%= authoring journal.created_at, journal.user, :label => :label_updated_time_by %> <% if journal.details.any? %> <% end %> diff --git a/lib/redmine/activity/fetcher.rb b/lib/redmine/activity/fetcher.rb index fb73d5d2..89dbbf1e 100644 --- a/lib/redmine/activity/fetcher.rb +++ b/lib/redmine/activity/fetcher.rb @@ -68,6 +68,7 @@ module Redmine # Returns an array of events for the given date range # sorted in reverse chronological order def events(from = nil, to = nil, options={}) + require 'ruby-debug'; debugger e = [] @options[:limit] = options[:limit] @@ -76,15 +77,15 @@ module Redmine e += provider.find_events(event_type, @user, from, to, @options) end end - + e.sort! {|a,b| b.event_datetime <=> a.event_datetime} - + if options[:limit] e = e.slice(0, options[:limit]) end e end - + private def constantized_providers(event_type) diff --git a/lib/redmine/export/pdf.rb b/lib/redmine/export/pdf.rb index c2492165..1583fe9d 100644 --- a/lib/redmine/export/pdf.rb +++ b/lib/redmine/export/pdf.rb @@ -282,7 +282,7 @@ module Redmine pdf.Ln for journal in issue.journals.find(:all, :include => [:user, :details], :order => "#{Journal.table_name}.created_on ASC") pdf.SetFontStyle('B',8) - pdf.Cell(190,5, format_time(journal.created_on) + " - " + journal.user.name) + pdf.Cell(190,5, format_time(journal.created_at) + " - " + journal.user.name) pdf.Ln pdf.SetFontStyle('I',8) for detail in journal.details