diff options
5 files changed, 17 insertions, 23 deletions
diff --git a/sonar-server/src/main/webapp/WEB-INF/app/controllers/dashboard_controller.rb b/sonar-server/src/main/webapp/WEB-INF/app/controllers/dashboard_controller.rb index 674d6509076..6b27afd7a08 100644 --- a/sonar-server/src/main/webapp/WEB-INF/app/controllers/dashboard_controller.rb +++ b/sonar-server/src/main/webapp/WEB-INF/app/controllers/dashboard_controller.rb @@ -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 diff --git a/sonar-server/src/main/webapp/WEB-INF/app/controllers/drilldown_controller.rb b/sonar-server/src/main/webapp/WEB-INF/app/controllers/drilldown_controller.rb index feb4f8e64eb..b7500f6999a 100644 --- a/sonar-server/src/main/webapp/WEB-INF/app/controllers/drilldown_controller.rb +++ b/sonar-server/src/main/webapp/WEB-INF/app/controllers/drilldown_controller.rb @@ -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 diff --git a/sonar-server/src/main/webapp/WEB-INF/app/controllers/resource_controller.rb b/sonar-server/src/main/webapp/WEB-INF/app/controllers/resource_controller.rb index bf970cf2a96..631ca73e1a2 100644 --- a/sonar-server/src/main/webapp/WEB-INF/app/controllers/resource_controller.rb +++ b/sonar-server/src/main/webapp/WEB-INF/app/controllers/resource_controller.rb @@ -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 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 6d7f8b6e25c..92c6a6f5be1 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 @@ -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 diff --git a/sonar-server/src/main/webapp/WEB-INF/app/views/layouts/_layout.html.erb b/sonar-server/src/main/webapp/WEB-INF/app/views/layouts/_layout.html.erb index e7bc7ca6d6a..a5dcaecb2d2 100644 --- a/sonar-server/src/main/webapp/WEB-INF/app/views/layouts/_layout.html.erb +++ b/sonar-server/src/main/webapp/WEB-INF/app/views/layouts/_layout.html.erb @@ -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> |