Changed the printed label to contain the translated text instead of symbols to be translated when finally printing out

pull/6827/head
Sebastian Schuster 12 years ago
parent b82dd87496
commit f71001dc15
  1. 2
      lib/report/chainable.rb
  2. 60
      lib/report/operator.rb
  3. 4
      lib/widget/controls/save_as.rb
  4. 4
      lib/widget/filters.rb
  5. 4
      lib/widget/filters/date.rb
  6. 2
      lib/widget/filters/label.rb
  7. 2
      lib/widget/filters/multi_values.rb
  8. 6
      lib/widget/filters/operators.rb
  9. 11
      lib/widget/group_bys.rb

@ -84,7 +84,7 @@ class Report < ActiveRecord::Base
@cache_key ||= underscore_name @cache_key ||= underscore_name
end end
inherited_attribute :label, :default => :translation_needed inherited_attribute :label, :default => "Translation needed"
inherited_attribute :properties, :list => true inherited_attribute :properties, :list => true
class << self class << self

@ -26,19 +26,19 @@ class Report::Operator
end end
def label def label
@label ||= self.class.name.to_sym @label ||= self.class.name
end end
end end
# Operators from Redmine # Operators from Redmine
new ">t-", :label => :label_less_than_ago do new ">t-", :label => I18n.t(:label_less_than_ago) do
include DateRange include DateRange
def modify(query, field, value) def modify(query, field, value)
super query, field, -value.to_i, 0 super query, field, -value.to_i, 0
end end
end end
new "w", :arity => 0, :label => :label_this_week do new "w", :arity => 0, :label => I18n.t(:label_this_week) do
def modify(query, field, offset = nil) def modify(query, field, offset = nil)
offset ||= 0 offset ||= 0
first_day = begin first_day = begin
@ -53,16 +53,16 @@ class Report::Operator
end end
end end
new "t+", :label => :label_in do new "t+", :label => I18n.t(:label_in) do
include DateRange include DateRange
def modify(query, field, *values) def modify(query, field, *values)
super query, field, values.first.to_i, values.first.to_i super query, field, values.first.to_i, values.first.to_i
end end
end end
new "<=", :label => :label_less_or_equal new "<=", :label => I18n.t(:label_less_or_equal)
new "!", :label => :label_not_equals do new "!", :label => I18n.t(:label_not_equals) do
def modify(query, field, *values) def modify(query, field, *values)
where_clause = "(#{field} IS NULL" where_clause = "(#{field} IS NULL"
where_clause += " OR #{field} NOT IN #{collection(*values)}" unless values.compact.empty? where_clause += " OR #{field} NOT IN #{collection(*values)}" unless values.compact.empty?
@ -72,14 +72,14 @@ class Report::Operator
end end
end end
new "t-", :label => :label_ago do new "t-", :label => I18n.t(:label_ago) do
include DateRange include DateRange
def modify(query, field, *values) def modify(query, field, *values)
super query, field, -values.first.to_i, -values.first.to_i super query, field, -values.first.to_i, -values.first.to_i
end end
end end
new "!~", :arity => 1, :label => :label_not_contains do new "!~", :arity => 1, :label => I18n.t(:label_not_contains) do
def modify(query, field, *values) def modify(query, field, *values)
value = values.first || '' value = values.first || ''
query.where "LOWER(#{field}) NOT LIKE '%#{quote_string(value.to_s.downcase)}%'" query.where "LOWER(#{field}) NOT LIKE '%#{quote_string(value.to_s.downcase)}%'"
@ -87,7 +87,7 @@ class Report::Operator
end end
end end
new "=", :label => :label_equals do new "=", :label => I18n.t(:label_equals) do
def modify(query, field, *values) def modify(query, field, *values)
case case
when values.size == 1 && values.first.nil? when values.size == 1 && values.first.nil?
@ -101,7 +101,7 @@ class Report::Operator
end end
end end
new "~", :arity => 1, :label => :label_contains do new "~", :arity => 1, :label => I18n.t(:label_contains) do
def modify(query, field, *values) def modify(query, field, *values)
value = values.first || '' value = values.first || ''
query.where "LOWER(#{field}) LIKE '%#{quote_string(value.to_s.downcase)}%'" query.where "LOWER(#{field}) LIKE '%#{quote_string(value.to_s.downcase)}%'"
@ -109,70 +109,70 @@ class Report::Operator
end end
end end
new "<t+", :label => :label_in_less_than do new "<t+", :label => I18n.t(:label_in_less_than) do
include DateRange include DateRange
def modify(query, field, value) def modify(query, field, value)
super query, field, 0, value.to_i super query, field, 0, value.to_i
end end
end end
new "t", :label => :label_today do new "t", :label => I18n.t(:label_today) do
include DateRange include DateRange
def modify(query, field) def modify(query, field)
super query, field, 0, 0 super query, field, 0, 0
end end
end end
new ">=", :label => :label_greater_or_equal new ">=", :label => I18n.t(:label_greater_or_equal)
new "!*", :arity => 0, :where_clause => "%s IS NULL", :label => :label_none new "!*", :arity => 0, :where_clause => "%s IS NULL", :label => I18n.t(:label_none)
new "<t-", :label => :label_more_than_ago do new "<t-", :label => I18n.t(:label_more_than_ago) do
include DateRange include DateRange
def modify(query, field, value) def modify(query, field, value)
super query, field, nil, -value.to_i super query, field, nil, -value.to_i
end end
end end
new ">t+", :label => :label_in_more_than do new ">t+", :label => I18n.t(:label_in_more_than) do
include DateRange include DateRange
def modify(query, field, value) def modify(query, field, value)
super query, field, value.to_i, nil super query, field, value.to_i, nil
end end
end end
new "*", :arity => 0, :where_clause => "%s IS NOT NULL", :label => :label_all new "*", :arity => 0, :where_clause => "%s IS NOT NULL", :label => I18n.t(:label_all)
# Our own operators # Our own operators
new "<", :label => :label_less new "<", :label => I18n.t(:label_less)
new ">", :label => :label_greater new ">", :label => I18n.t(:label_greater)
new "=n", :label => :label_equals do new "=n", :label => I18n.t(:label_equals) do
def modify(query, field, value) def modify(query, field, value)
query.where "#{field} = #{clean_currency(value)}" query.where "#{field} = #{clean_currency(value)}"
query query
end end
end end
new "0", :label => :label_none, :where_clause => "%s = 0" new "0", :label => I18n.t(:label_none), :where_clause => "%s = 0"
new "y", :label => :label_yes, :arity => 0, :where_clause => "%s IS NOT NULL" new "y", :label => I18n.t(:label_yes), :arity => 0, :where_clause => "%s IS NOT NULL"
new "n", :label => :label_no, :arity => 0, :where_clause => "%s IS NULL" new "n", :label => I18n.t(:label_no), :arity => 0, :where_clause => "%s IS NULL"
new "<d", :label => :label_less_or_equal, :validate => :dates do new "<d", :label => I18n.t(:label_less_or_equal), :validate => :dates do
def modify(query, field, value) def modify(query, field, value)
return query if value.to_s.empty? return query if value.to_s.empty?
"<=".to_operator.modify query, field, quoted_date(value) "<=".to_operator.modify query, field, quoted_date(value)
end end
end end
new ">d", :label => :label_greater_or_equal, :validate => :dates do new ">d", :label => I18n.t(:label_greater_or_equal), :validate => :dates do
def modify(query, field, value) def modify(query, field, value)
return query if value.to_s.empty? return query if value.to_s.empty?
">=".to_operator.modify query, field, quoted_date(value) ">=".to_operator.modify query, field, quoted_date(value)
end end
end end
new "<>d", :label => :label_between, :validate => :dates do new "<>d", :label => I18n.t(:label_between), :validate => :dates do
def modify(query, field, from, to) def modify(query, field, from, to)
return query if from.to_s.empty? || to.to_s.empty? return query if from.to_s.empty? || to.to_s.empty?
query.where "#{field} BETWEEN '#{quoted_date from}' AND '#{quoted_date to}'" query.where "#{field} BETWEEN '#{quoted_date from}' AND '#{quoted_date to}'"
@ -180,14 +180,14 @@ class Report::Operator
end end
end end
new "=d", :label => :label_date_on, :validate => :dates do new "=d", :label => I18n.t(:label_date_on), :validate => :dates do
def modify(query, field, value) def modify(query, field, value)
return query if value.to_s.empty? return query if value.to_s.empty?
"=".to_operator.modify query, field, quoted_date(value) "=".to_operator.modify query, field, quoted_date(value)
end end
end end
new ">=d", :label => :label_days_ago, :validate => :integers do new ">=d", :label => I18n.t(:label_days_ago), :validate => :integers do
force! :integers force! :integers
def modify(query, field, value) def modify(query, field, value)
@ -197,7 +197,7 @@ class Report::Operator
end end
end end
new "?=", :label => :label_null_or_equal do new "?=", :label => I18n.t(:label_null_or_equal) do
def modify(query, field, *values) def modify(query, field, *values)
where_clause = "(#{field} IS NULL" where_clause = "(#{field} IS NULL"
where_clause += " OR #{field} IN #{collection(*values)}" unless values.compact.empty? where_clause += " OR #{field} IN #{collection(*values)}" unless values.compact.empty?
@ -207,7 +207,7 @@ class Report::Operator
end end
end end
new "?!", :label => :label_not_null_and_not_equal do new "?!", :label => I18n.t(:label_not_null_and_not_equal) do
def modify(query, field, *values) def modify(query, field, *values)
where_clause = "(#{field} IS NOT NULL" where_clause = "(#{field} IS NOT NULL"
where_clause += " AND #{field} NOT IN #{collection(*values)}" unless values.compact.empty? where_clause += " AND #{field} NOT IN #{collection(*values)}" unless values.compact.empty?

@ -20,12 +20,12 @@ class Widget::Controls::SaveAs < Widget::Controls
def render_popup_form def render_popup_form
name = content_tag :p do name = content_tag :p do
label_tag(:query_name, l(:field_name)) + label_tag(:query_name, Query.human_attribute_name(:name)) +
text_field_tag(:query_name, @subject.name) text_field_tag(:query_name, @subject.name)
end end
if @options[:can_save_as_public] if @options[:can_save_as_public]
box = content_tag :p do box = content_tag :p do
label_tag(:query_is_public, l(:field_is_public)) + label_tag(:query_is_public, Query.human_attribute_name(:is_public)) +
check_box_tag(:query_is_public) check_box_tag(:query_is_public)
end end
name + box name + box

@ -27,11 +27,11 @@ class Widget::Filters < Widget::Base
def selectables def selectables
filters = engine::Filter.all filters = engine::Filter.all
filters.sort_by do |filter| filters.sort_by do |filter|
l(filter.label) filter.label
end.select do |filter| end.select do |filter|
filter.selectable? filter.selectable?
end.collect do |filter| end.collect do |filter|
[ l(filter.label), filter.underscore_name ] [ filter.label, filter.underscore_name ]
end end
end end

@ -16,7 +16,7 @@ class Widget::Filters::Date < Widget::Filters::Base
write(content_tag(:td) do write(content_tag(:td) do
label1 = label_tag "#{id_prefix}arg_1_val", label1 = label_tag "#{id_prefix}arg_1_val",
h(l(filter_class.label)) + " " + l(:label_filter_value), h(filter_class.label) + " " + l(:label_filter_value),
:class => 'hidden-for-sighted' :class => 'hidden-for-sighted'
arg1 = content_tag :span, :id => "#{id_prefix}arg_1", :class => "filter_values" do arg1 = content_tag :span, :id => "#{id_prefix}arg_1", :class => "filter_values" do
@ -29,7 +29,7 @@ class Widget::Filters::Date < Widget::Filters::Base
label1 + text1 + cal1 label1 + text1 + cal1
end end
label2 = label_tag "#{id_prefix}arg_2_val", label2 = label_tag "#{id_prefix}arg_2_val",
h(l(filter_class.label)) + " " + l(:label_filter_value), h(filter_class.label) + " " + l(:label_filter_value),
:class => 'hidden-for-sighted' :class => 'hidden-for-sighted'
arg2 = content_tag :span, :id => "#{id_prefix}arg_2", :class => "between_tags" do arg2 = content_tag :span, :id => "#{id_prefix}arg_2", :class => "between_tags" do

@ -9,7 +9,7 @@ class Widget::Filters::Label < Widget::Filters::Base
options.merge! :class => 'dependent-filter-label' options.merge! :class => 'dependent-filter-label'
end end
content_tag(:label, options) do content_tag(:label, options) do
h(l(filter_class.label)) h(filter_class.label)
end end
end) end)
end end

@ -31,7 +31,7 @@ class Widget::Filters::MultiValues < Widget::Filters::Base
select_options.merge! :"data-dependent" => true if filter_class.is_dependent? select_options.merge! :"data-dependent" => true if filter_class.is_dependent?
box_content = "".html_safe box_content = "".html_safe
label = label_tag "#{filter_class.underscore_name}_arg_1_val", label = label_tag "#{filter_class.underscore_name}_arg_1_val",
h(l(filter_class.label)) + ' ' + l(:label_filter_value), h(filter_class.label) + ' ' + l(:label_filter_value),
:class => 'hidden-for-sighted' :class => 'hidden-for-sighted'
box = content_tag :select, select_options, :id => "#{filter_class.underscore_name}_select_1" do box = content_tag :select, select_options, :id => "#{filter_class.underscore_name}_select_1" do

@ -17,16 +17,16 @@ class Widget::Filters::Operators < Widget::Filters::Base
opts = {:value => h(o.to_s), :"data-arity" => o.arity} opts = {:value => h(o.to_s), :"data-arity" => o.arity}
opts.reverse_merge! :"data-forced" => o.forced if o.forced? opts.reverse_merge! :"data-forced" => o.forced if o.forced?
opts[:selected] = "selected" if filter.operator.to_s == o.to_s opts[:selected] = "selected" if filter.operator.to_s == o.to_s
content_tag(:option, opts) { h(l(o.label)) } content_tag(:option, opts) { h(o.label) }
end.join.html_safe end.join.html_safe
end end
label1 = content_tag :label, label1 = content_tag :label,
h(l(filter_class.label)) + " " + l(:label_operator), h(filter_class.label) + " " + l(:label_operator),
:for => "operators[#{filter_class.underscore_name}]", :for => "operators[#{filter_class.underscore_name}]",
:class => 'hidden-for-sighted' :class => 'hidden-for-sighted'
label = content_tag :label do label = content_tag :label do
if filter_class.available_operators.any? if filter_class.available_operators.any?
l(filter_class.available_operators.first.label) filter_class.available_operators.first.label
end end
end end
hide_select_box ? label1 + select_box + label : label1 + select_box hide_select_box ? label1 + select_box + label : label1 + select_box

@ -1,12 +1,14 @@
puts 'XXX: lib/reporting_engine/widget/group_bys.rb'
class Widget::GroupBys < Widget::Base class Widget::GroupBys < Widget::Base
def render_options(group_by_ary) def render_options(group_by_ary)
group_by_ary.sort_by do |group_by| group_by_ary.sort_by do |group_by|
l(group_by.label) group_by.label
end.collect do |group_by| end.collect do |group_by|
next unless group_by.selectable? next unless group_by.selectable?
content_tag :option, :value => group_by.underscore_name, :'data-label' => "#{CGI::escapeHTML(h(l(group_by.label)))}" do content_tag :option, :value => group_by.underscore_name, :'data-label' => "#{CGI::escapeHTML(h(group_by.label))}" do
h(l(group_by.label)) h(group_by.label)
end end
end.join.html_safe end.join.html_safe
end end
@ -23,7 +25,7 @@ class Widget::GroupBys < Widget::Base
def render_group(type, initially_selected, show_help = false) def render_group(type, initially_selected, show_help = false)
initially_selected = initially_selected.map do |group_by| initially_selected = initially_selected.map do |group_by|
[group_by.class.underscore_name, h(l(group_by.class.label))] [group_by.class.underscore_name, h(group_by.class.label)]
end end
content_tag :fieldset, content_tag :fieldset,
@ -49,7 +51,6 @@ class Widget::GroupBys < Widget::Base
render_options group_by_ary render_options group_by_ary
end end
end.join.html_safe end.join.html_safe
content content
end end

Loading…
Cancel
Save