]> source.dussan.org Git - sonarqube.git/commitdiff
Refactor way to load period labels in ruby
authorSimon Brandhof <simon.brandhof@gmail.com>
Thu, 6 Dec 2012 11:45:16 +0000 (12:45 +0100)
committerSimon Brandhof <simon.brandhof@gmail.com>
Thu, 6 Dec 2012 11:45:16 +0000 (12:45 +0100)
sonar-server/src/main/webapp/WEB-INF/app/helpers/alerts_helper.rb
sonar-server/src/main/webapp/WEB-INF/app/helpers/application_helper.rb
sonar-server/src/main/webapp/WEB-INF/app/helpers/dashboard_helper.rb
sonar-server/src/main/webapp/WEB-INF/app/helpers/measures_helper.rb
sonar-server/src/main/webapp/WEB-INF/app/models/api/utils.rb
sonar-server/src/main/webapp/WEB-INF/app/models/snapshot.rb
sonar-server/src/main/webapp/WEB-INF/app/views/measures/_display_list.html.erb
sonar-server/src/main/webapp/WEB-INF/app/views/measures/search.html.erb

index 97c34292b85fe77734fb949f98c6f3602d318d82..247d46f8ce27084c11f76d329d8b971500721706 100644 (file)
@@ -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)
-      "<option value='#{index}' #{selected}>&Delta; #{period_label}</option>"
+      "<option value='#{index}' #{selected}>&Delta; #{Api::Utils.period_label(index)}</option>"
     else
       selected = (alert.period ? 'selected' : '')
       "<option value='' #{selected}>#{message('value')}</option>"
index 1ec33fa6be70cd2adb06561b7ffeee3a3642e003..7a992b719b9511bc81800d7b2cde00e3c5ceb23e 100644 (file)
@@ -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
 
     "<a href='#{url}' modal-width='#{width}' class='open-modal #{clazz}' #{id}>#{h label}</a>"
   end
+
 end
index 8023363dea14f136272a47d45476741d0dcf8bef..57a1658c5dfc6043ef61a5607fac7f66255c462a 100644 (file)
@@ -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' : '')
       "<option value='#{index}' #{selected}>&Delta; #{label}</option>"
index accc20e7455db3a32117bdc1ec12d90548605f70..20a939293400f37c4e833b81670c163882050da8 100644 (file)
@@ -26,7 +26,7 @@ module MeasuresHelper
       html=h(column.title_label)
     end
     if column.period
-      html += "<br><span class='note'>Period #{column.period}</small>"
+      html += "<br><span class='note'>#{Api::Utils.period_label(column.period)}</small>"
     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
index b96e859c9ac34be5e39123ef21bce6767994ccad..35adebd944c0bda0cc3409e4ab3bf8d2f1f9e250 100644 (file)
@@ -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
index e15b08a45ef81929000809dba124b8eefab71138..758ef91fe6b523050739768a522d6e1d17f8edcf 100644 (file)
@@ -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
index 482efb095f2db5099bba3b1e67c422b1a4694bed..81836524f4b29bc93c94ea29ebae6e21bfc62d28 100644 (file)
@@ -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']] -%>
         <select id="select-period" style="display: none;">
           <option value="">Value</option>
-          <% period_names.each_with_index do |period_name, index| %>
-            <option value="<%= index + 1 -%>"><%= period_name -%></option>
+          <% period_labels.each_with_index do |period_label, index| %>
+            <option value="<%= index + 1 -%>"><%= period_label -%></option>
           <% end %>
         </select>
 
index d77833b6ed9826512ba689f33f43b7361e17d3d9..e053664229081da83dfd8fd48e94d69150f7bd19 100644 (file)
@@ -13,7 +13,7 @@
                if @filter.display.key==:list && !edit_mode
             %>
               <li>
-                <a id="edit" href="<%= url_for params.merge({:edit => true, :id => @filter.id}) -%>"><%= message('measure_filter.configure_columns') -%></a>
+                <a id="configure-columns" href="<%= url_for params.merge({:edit => true, :id => @filter.id}) -%>"><%= message('measure_filter.configure_columns') -%></a>
               </li>
             <% end %>
             <li>