]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-3323 slight improvements of snapshot#metric_keys
authorSimon Brandhof <simon.brandhof@gmail.com>
Tue, 27 Mar 2012 11:39:25 +0000 (13:39 +0200)
committerSimon Brandhof <simon.brandhof@gmail.com>
Tue, 27 Mar 2012 13:02:57 +0000 (15:02 +0200)
sonar-server/src/main/webapp/WEB-INF/app/controllers/dashboard_controller.rb
sonar-server/src/main/webapp/WEB-INF/app/controllers/drilldown_controller.rb
sonar-server/src/main/webapp/WEB-INF/app/controllers/resource_controller.rb
sonar-server/src/main/webapp/WEB-INF/app/models/snapshot.rb
sonar-server/src/main/webapp/WEB-INF/app/views/layouts/_layout.html.erb

index 674d65090761fdcb7f082d0471cff5cbfad649c7..6b27afd7a08d3dbb24347e1b0393c66df3acbbed 100644 (file)
@@ -186,7 +186,7 @@ class DashboardController < ApplicationController
 
   def load_authorized_widget_definitions
     if @resource
-      @authorized_widget_definitions = java_facade.getWidgets(@resource.scope, @resource.qualifier, @resource.language, @snapshot.available_measures)
+      @authorized_widget_definitions = java_facade.getWidgets(@resource.scope, @resource.qualifier, @resource.language, @snapshot.metric_keys.to_java(:string))
       @authorized_widget_definitions=@authorized_widget_definitions.select do |widget|
         authorized=widget.getUserRoles().size==0
         unless authorized
index feb4f8e64eb7c4bcfda41b26c1e1fbb42154becb..b7500f6999a1070fd3bff9c7e249718e903ba234 100644 (file)
@@ -173,7 +173,7 @@ class DrilldownController < ApplicationController
 
   def display_metric_viewers?(resource, metric_key)
     return true if resource.file?
-    java_facade.getResourceTabsForMetric(resource.scope, resource.qualifier, resource.language, resource.last_snapshot.available_measures, metric_key).each do |tab|
+    java_facade.getResourceTabsForMetric(resource.scope, resource.qualifier, resource.language, resource.last_snapshot.metric_keys.to_java(:string), metric_key).each do |tab|
       tab.getUserRoles().each do |role|
         if has_role?(role, resource)
           return true
index bf970cf2a9676bf658e55d57936106710f13c3f3..631ca73e1a25225d7911a1ac113a1879ade5f44d 100644 (file)
@@ -113,7 +113,7 @@ class ResourceController < ApplicationController
 
   def load_extensions
     @extensions=[]
-    java_facade.getResourceTabs(@resource.scope, @resource.qualifier, @resource.language, @snapshot.available_measures).each do |tab|
+    java_facade.getResourceTabs(@resource.scope, @resource.qualifier, @resource.language, @snapshot.metric_keys.to_java(:string)).each do |tab|
       if tab.getUserRoles().empty?
         @extensions<<tab
       else
index 6d7f8b6e25c415c5f689dc273602d122f81fa47d..92c6a6f5be11bfaf36737b16a755d484b36a4b0c 100644 (file)
@@ -139,17 +139,6 @@ class Snapshot < ActiveRecord::Base
     end
   end
 
-  def metrics
-    if @metrics.nil?
-      @metrics = []
-      measures_hash.each_key do |metric_id|
-        @metrics << Metric::by_id(metric_id)
-      end
-      @metrics.uniq!
-    end
-    @metrics
-  end
-
   def measure(metric)
     unless metric.is_a? Metric
       metric=Metric.by_key(metric)
@@ -248,14 +237,19 @@ class Snapshot < ActiveRecord::Base
     project_snapshot.send "period#{period_index}_date"
   end
 
-  # IMPORTANT: this is method must used only to pass arguments to the java_facade, as it returns
-  # an array of java.lang.String objects.
-  # It is used to know which views (page, tab, widget, ...) to display on for a given snapshot
-  def available_measures
-    if @available_measures.nil?
-      @available_measures = metrics.map {|m| m.name}.to_java(java.lang.String)
-    end
-    @available_measures
+  def metrics
+    @metrics ||=
+      begin
+        measures_hash.keys.map { |metric_id| Metric::by_id(metric_id) }.uniq
+      end
+  end
+
+  # metrics of all the available measures
+  def metric_keys
+    @metric_keys ||=
+      begin
+        metrics.map { |m| m.name }
+      end
   end
 
   private
index e7bc7ca6d6aaf531f9aa90985216230fb77ca730..a5dcaecb2d225bc30d102157ca511d10601fab75 100644 (file)
@@ -57,7 +57,7 @@
               <a href="<%= ApplicationController.root_context -%>/drilldown/violations/<%= @project.id -%><%= "?"+period_param if period_param -%>"><%= message('violations_drilldown.page') -%></a></li>
             <li class="<%= 'selected' if request.request_uri.include?('/cloud/index') -%>">
               <a href="<%= ApplicationController.root_context -%>/cloud/index/<%= @project.id -%>"><%= message('clouds.page') -%></a></li>
-            <% controller.java_facade.getPages(Navigation::SECTION_RESOURCE, @project.scope, @project.qualifier, @project.language, @project.last_snapshot.available_measures).each do |page| %>
+            <% controller.java_facade.getPages(Navigation::SECTION_RESOURCE, @project.scope, @project.qualifier, @project.language, @project.last_snapshot.metric_keys.to_java(:string)).each do |page| %>
               <li class="<%= 'selected' if request.request_uri.include?("page=#{page.getId()}") -%>">
                 <a href="<%= ApplicationController.root_context -%>/plugins/resource/<%= @project.id -%>?page=<%= page.getId() -%>"><%= message(page.getId() + '.page', :default => page.getTitle()) %></a>
               </li>