From 9a19e7426a5b45304df240acf7c545b60e21f8f3 Mon Sep 17 00:00:00 2001 From: Simon Brandhof Date: Thu, 6 Dec 2012 12:45:16 +0100 Subject: [PATCH] Refactor way to load period labels in ruby --- .../src/main/webapp/WEB-INF/app/helpers/alerts_helper.rb | 3 +-- .../webapp/WEB-INF/app/helpers/application_helper.rb | 9 +-------- .../main/webapp/WEB-INF/app/helpers/dashboard_helper.rb | 2 +- .../main/webapp/WEB-INF/app/helpers/measures_helper.rb | 9 +++------ .../src/main/webapp/WEB-INF/app/models/api/utils.rb | 7 ++++++- .../src/main/webapp/WEB-INF/app/models/snapshot.rb | 9 +++++++++ .../WEB-INF/app/views/measures/_display_list.html.erb | 4 ++-- .../webapp/WEB-INF/app/views/measures/search.html.erb | 2 +- 8 files changed, 24 insertions(+), 21 deletions(-) diff --git a/sonar-server/src/main/webapp/WEB-INF/app/helpers/alerts_helper.rb b/sonar-server/src/main/webapp/WEB-INF/app/helpers/alerts_helper.rb index 97c34292b85..247d46f8ce2 100644 --- a/sonar-server/src/main/webapp/WEB-INF/app/helpers/alerts_helper.rb +++ b/sonar-server/src/main/webapp/WEB-INF/app/helpers/alerts_helper.rb @@ -91,8 +91,7 @@ module AlertsHelper def period_select_options(alert, index) if index selected = (alert.period == index ? 'selected' : '') - period_label = Api::Utils.java_facade.getPeriodLabel(index) - "" + "" else selected = (alert.period ? 'selected' : '') "" diff --git a/sonar-server/src/main/webapp/WEB-INF/app/helpers/application_helper.rb b/sonar-server/src/main/webapp/WEB-INF/app/helpers/application_helper.rb index 1ec33fa6be7..7a992b719b9 100644 --- a/sonar-server/src/main/webapp/WEB-INF/app/helpers/application_helper.rb +++ b/sonar-server/src/main/webapp/WEB-INF/app/helpers/application_helper.rb @@ -80,14 +80,6 @@ module ApplicationHelper params['configuring']=='true' end - def period_label(snapshot, period_index) - return nil if snapshot.nil? || snapshot.project_snapshot.nil? - mode = snapshot.period_mode(period_index) - mode_param = snapshot.period_param(period_index) - date = snapshot.period_datetime(period_index) - Api::Utils.java_facade.getPeriodLabel(mode, mode_param, date) if mode - end - def configuration(key, default = nil) prop_value = Java::OrgSonarServerUi::JRubyFacade.getInstance().getContainer().getComponentByType(Java::OrgApacheCommonsConfiguration::Configuration.java_class).getProperty(key) prop_value.nil? ? default : prop_value @@ -754,4 +746,5 @@ module ApplicationHelper "#{h label}" end + end diff --git a/sonar-server/src/main/webapp/WEB-INF/app/helpers/dashboard_helper.rb b/sonar-server/src/main/webapp/WEB-INF/app/helpers/dashboard_helper.rb index 8023363dea1..57a1658c5df 100644 --- a/sonar-server/src/main/webapp/WEB-INF/app/helpers/dashboard_helper.rb +++ b/sonar-server/src/main/webapp/WEB-INF/app/helpers/dashboard_helper.rb @@ -43,7 +43,7 @@ module DashboardHelper end def period_select_options(snapshot, index) - label=period_label(snapshot, index) + label=snapshot.period_label(index) if label selected=(params[:period]==index.to_s ? 'selected' : '') "" diff --git a/sonar-server/src/main/webapp/WEB-INF/app/helpers/measures_helper.rb b/sonar-server/src/main/webapp/WEB-INF/app/helpers/measures_helper.rb index accc20e7455..20a93929340 100644 --- a/sonar-server/src/main/webapp/WEB-INF/app/helpers/measures_helper.rb +++ b/sonar-server/src/main/webapp/WEB-INF/app/helpers/measures_helper.rb @@ -26,7 +26,7 @@ module MeasuresHelper html=h(column.title_label) end if column.period - html += "
Period #{column.period}" + html += "
#{Api::Utils.period_label(column.period)}" end if filter.sort_key==column.key html << (filter.sort_asc? ? image_tag("asc12.png") : image_tag("desc12.png")) @@ -93,11 +93,8 @@ module MeasuresHelper size.to_i end - def period_names - period_name1 = Api::Utils.java_facade.getPeriodLabel(1) - period_name2 = Api::Utils.java_facade.getPeriodLabel(2) - period_name3 = Api::Utils.java_facade.getPeriodLabel(3) - [period_name1, period_name2, period_name3] + def period_labels + [Api::Utils.period_label(1), Api::Utils.period_label(2), Api::Utils.period_label(3)] end end diff --git a/sonar-server/src/main/webapp/WEB-INF/app/models/api/utils.rb b/sonar-server/src/main/webapp/WEB-INF/app/models/api/utils.rb index b96e859c9ac..35adebd944c 100644 --- a/sonar-server/src/main/webapp/WEB-INF/app/models/api/utils.rb +++ b/sonar-server/src/main/webapp/WEB-INF/app/models/api/utils.rb @@ -172,7 +172,7 @@ class Api::Utils end def self.language(key) - languages.find {|language| language.key == key} + languages.find { |language| language.key == key } end def self.language_name(key) @@ -180,4 +180,9 @@ class Api::Utils l ? l.name : key end + # Label of global periods + # index is in [1..3] + def self.period_label(index) + java_facade.getPeriodLabel(index) + end end diff --git a/sonar-server/src/main/webapp/WEB-INF/app/models/snapshot.rb b/sonar-server/src/main/webapp/WEB-INF/app/models/snapshot.rb index e15b08a45ef..758ef91fe6b 100644 --- a/sonar-server/src/main/webapp/WEB-INF/app/models/snapshot.rb +++ b/sonar-server/src/main/webapp/WEB-INF/app/models/snapshot.rb @@ -252,6 +252,15 @@ class Snapshot < ActiveRecord::Base end end + def period_label(period_index) + if project_snapshot + mode = period_mode(period_index) + mode_param = period_param(period_index) + date = period_datetime(period_index) + Api::Utils.java_facade.getPeriodLabel(mode, mode_param, date) if mode + end + end + private def measures_hash diff --git a/sonar-server/src/main/webapp/WEB-INF/app/views/measures/_display_list.html.erb b/sonar-server/src/main/webapp/WEB-INF/app/views/measures/_display_list.html.erb index 482efb095f2..81836524f4b 100644 --- a/sonar-server/src/main/webapp/WEB-INF/app/views/measures/_display_list.html.erb +++ b/sonar-server/src/main/webapp/WEB-INF/app/views/measures/_display_list.html.erb @@ -73,8 +73,8 @@ :extra_values => [[message('measure_filter.col.name'), 'name'], [message('measure_filter.col.short_name'), 'short_name'], [message('measure_filter.col.description'), 'description'], [message('measure_filter.col.language'), 'language'], [message('measure_filter.col.version'), 'version']] -%> diff --git a/sonar-server/src/main/webapp/WEB-INF/app/views/measures/search.html.erb b/sonar-server/src/main/webapp/WEB-INF/app/views/measures/search.html.erb index d77833b6ed9..e0536642290 100644 --- a/sonar-server/src/main/webapp/WEB-INF/app/views/measures/search.html.erb +++ b/sonar-server/src/main/webapp/WEB-INF/app/views/measures/search.html.erb @@ -13,7 +13,7 @@ if @filter.display.key==:list && !edit_mode %>
  • - <%= message('measure_filter.configure_columns') -%> + <%= message('measure_filter.configure_columns') -%>
  • <% end %>
  • -- 2.39.5