Redmine Refactor #92: Move Method #reply to JournalsController

Looking over the public methods in IssuesController now, I see that the #reply method is out of place. It’s used to quote a new reply on an issue but it does this via a journal. Since Redmine already has a JournalsController that is used when a journal is edited, it makes more sense to move #reply to that controller.

Before

1
2
3
4
5
6
7
8
9
10
11
12
13
class IssuesController  [:show, :edit, :update, :reply]
 
  def reply
    journal = Journal.find(params[:journal_id]) if params[:journal_id]
    if journal
      user = journal.user
      text = journal.notes
    else
      user = @issue.author
      text = @issue.description
    end
    # Replaces pre blocks with [...]
    text = text.to_s.strip.gsub(%r{<pre>((.|\s)*?)

}m, ‘[…]’)
content = “#{ll(Setting.default_language, :text_user_wrote, user)}\n> ”
content < “) + “\n\n”

render(:update) { |page|
page.<< "$('notes').value = \"#{escape_javascript content}\";"
page.show 'update'
page << "Form.Element.focus('notes');"
page << "Element.scrollTo('update');"
page << "$('notes').scrollTop = $('notes').scrollHeight – $('notes').clientHeight;"
}
end

end

1
2
3
class JournalsController &lt; ApplicationController
  # ...
end

After

1
2
3
class IssuesController &lt; ApplicationController
  # ...
end
1
2
3
4
5
6
7
8
9
10
11
12
13
class JournalsController  [:new]
 
  def new
    journal = Journal.find(params[:journal_id]) if params[:journal_id]
    if journal
      user = journal.user
      text = journal.notes
    else
      user = @issue.author
      text = @issue.description
    end
    # Replaces pre blocks with [...]
    text = text.to_s.strip.gsub(%r{<pre>((.|\s)*?)

}m, ‘[…]’)
content = “#{ll(Setting.default_language, :text_user_wrote, user)}\n> ”
content < “) + “\n\n”

render(:update) { |page|
page.<< "$('notes').value = \"#{escape_javascript content}\";"
page.show 'update'
page << "Form.Element.focus('notes');"
page << "Element.scrollTo('update');"
page << "$('notes').scrollTop = $('notes').scrollHeight – $('notes').clientHeight;"
}
end
end

After using move method I used rename method to rename #reply to #new. This is to make it match the Rails REST conventions, where the #new action is used with a HTTP GET request to render a new form. Little by little, IssuesController is shrinking.

Reference commit