From: Jean-Philippe Lang Date: Sat, 23 Nov 2013 10:50:41 +0000 (+0000) Subject: Extract generic formatting options to an helper. X-Git-Tag: 2.5.0~508 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=8578a46b357f5d17b61dc545e6ec10036d7a9c9e;p=redmine.git Extract generic formatting options to an helper. git-svn-id: http://svn.redmine.org/redmine/trunk@12319 e93f8b46-1217-0410-a6f0-8f06a7374b81 --- diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 7bee2117e..bb9121031 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -155,6 +155,34 @@ module ApplicationHelper end end + # Helper that formats object for html or text rendering + def format_object(object, html=true) + case object.class.name + when 'Time' + format_time(object) + when 'Date' + format_date(object) + when 'Fixnum' + object.to_s + when 'Float' + sprintf "%.2f", object + when 'User' + html ? link_to_user(object) : object.to_s + when 'Project' + html ? link_to_project(object) : object.to_s + when 'Version' + html ? link_to(object.name, version_path(object)) : version.to_s + when 'TrueClass' + l(:general_text_Yes) + when 'FalseClass' + l(:general_text_No) + when 'Issue' + object.visible? && html ? link_to_issue(object) : "##{object.id}" + else + html ? h(object) : object.to_s + end + end + def wiki_page_path(page, options={}) url_for({:controller => 'wiki', :action => 'show', :project_id => page.project, :id => page.title}.merge(options)) end diff --git a/app/helpers/queries_helper.rb b/app/helpers/queries_helper.rb index 429dcdad2..108012fd8 100644 --- a/app/helpers/queries_helper.rb +++ b/app/helpers/queries_helper.rb @@ -90,48 +90,22 @@ module QueriesHelper end def column_value(column, issue, value) - case value.class.name - when 'String' - if column.name == :subject - link_to(h(value), :controller => 'issues', :action => 'show', :id => issue) - elsif column.name == :description - issue.description? ? content_tag('div', textilizable(issue, :description), :class => "wiki") : '' - else - h(value) - end - when 'Time' - format_time(value) - when 'Date' - format_date(value) - when 'Fixnum' - if column.name == :id - link_to value, issue_path(issue) - elsif column.name == :done_ratio - progress_bar(value, :width => '80px') - else - value.to_s - end - when 'Float' - sprintf "%.2f", value - when 'User' - link_to_user value - when 'Project' - link_to_project value - when 'Version' - link_to(h(value), :controller => 'versions', :action => 'show', :id => value) - when 'TrueClass' - l(:general_text_Yes) - when 'FalseClass' - l(:general_text_No) - when 'Issue' - value.visible? ? link_to_issue(value) : "##{value.id}" - when 'IssueRelation' + case column.name + when :id + link_to value, issue_path(issue) + when :subject + link_to value, issue_path(issue) + when :description + issue.description? ? content_tag('div', textilizable(issue, :description), :class => "wiki") : '' + when :done_ratio + progress_bar(value, :width => '80px') + when :relations other = value.other_issue(issue) content_tag('span', (l(value.label_for(issue)) + " " + link_to_issue(other, :subject => false, :tracker => false)).html_safe, :class => value.css_classes_for(issue)) else - h(value) + format_object(value) end end