Project

General

Profile

Feature #11152 » patch_time_log_comment.diff

Jonathan Rajotte, 2012-07-12 19:33

View differences:

app/models/changeset.rb (working copy)
1

  
1 2
# Redmine - project management software
2 3
# Copyright (C) 2006-2011  Jean-Philippe Lang
3 4
#
......
103 104

  
104 105
  TIMELOG_RE = /
105 106
    (
106
    ((\d+)(h|hours?))((\d+)(m|min)?)?
107
    ((\d+)(h|hours?))((\d+)(min|m)?)?
107 108
    |
108
    ((\d+)(h|hours?|m|min))
109
    ((\d+)(h|hours?|min|m))
109 110
    |
110 111
    (\d+):(\d+)
111 112
    |
......
124 125
    kw_regexp = (ref_keywords + fix_keywords).collect{|kw| Regexp.escape(kw)}.join("|")
125 126

  
126 127
    referenced_issues = []
128
  
129
	comments.scan(/([\s\(\[,-]|^)((#{kw_regexp})[\s:]+)?(#\d+((\s+@#{TIMELOG_RE})?(\s+&(.*?)&)?)([\s,;&]+#\d+(\s+@#{TIMELOG_RE})?(\s+&(.*?)&)?)*)(?=[[:punct:]]|\s|<|$)/i) do |match|
127 130

  
128
    comments.scan(/([\s\(\[,-]|^)((#{kw_regexp})[\s:]+)?(#\d+(\s+@#{TIMELOG_RE})?([\s,;&]+#\d+(\s+@#{TIMELOG_RE})?)*)(?=[[:punct:]]|\s|<|$)/i) do |match|
129
      action, refs = match[2], match[3]
130
      next unless action.present? || ref_keywords_any
131

  
132
      refs.scan(/#(\d+)(\s+@#{TIMELOG_RE})?/).each do |m|
133
        issue, hours = find_referenced_issue_by_id(m[0].to_i), m[2]
134
        if issue
131
	action, refs = match[2], match[3]
132
     next unless action.present? || ref_keywords_any
133
    	refs.scan(/#(\d+)(\s+@#{TIMELOG_RE})(\s+&(.*?)&)?/).each do |m|	      
134
		issue, hours = find_referenced_issue_by_id(m[0].to_i), m[2]
135
        log_comment = m[17]
136
	if issue
135 137
          referenced_issues << issue
136 138
          fix_issue(issue) if fix_keywords.include?(action.to_s.downcase)
137
          log_time(issue, hours) if hours && Setting.commit_logtime_enabled?
139
          log_time(issue, hours, log_comment) if hours && Setting.commit_logtime_enabled?
138 140
        end
139 141
      end
140 142
    end
......
242 244
    issue
243 245
  end
244 246

  
245
  def log_time(issue, hours)
246
    time_entry = TimeEntry.new(
247
  def log_time(issue, hours, comment)
248
    if comment.nil? 
249
	comment=l(:text_time_logged_by_changeset, :value => text_tag(issue.project),:locale => Setting.default_language) 
250
    else 
251
	comment+= " [" +  text_tag(issue.project) +"]" 
252
    end		
253
	time_entry = TimeEntry.new(
247 254
      :user => user,
248 255
      :hours => hours,
249 256
      :issue => issue,
250 257
      :spent_on => commit_date,
251
      :comments => l(:text_time_logged_by_changeset, :value => text_tag(issue.project),
252
                     :locale => Setting.default_language)
253
      )
258
      :comments => comment
259
	)
254 260
    time_entry.activity = log_time_activity unless log_time_activity.nil?
255 261

  
256 262
    unless time_entry.save
(3-3/5)