diff options
author | simonbrandhof <simon.brandhof@gmail.com> | 2010-09-07 12:10:01 +0000 |
---|---|---|
committer | simonbrandhof <simon.brandhof@gmail.com> | 2010-09-07 12:10:01 +0000 |
commit | fbdd9d383da7b3ee7cdddfd3fccc9ef46d9fc206 (patch) | |
tree | a011a53cfb11e941754eb1a09178d542309625b4 /sonar-server | |
parent | 89ee2d1df9b81cf3a8f50adafbd798e28d79ae1a (diff) | |
download | sonarqube-fbdd9d383da7b3ee7cdddfd3fccc9ef46d9fc206.tar.gz sonarqube-fbdd9d383da7b3ee7cdddfd3fccc9ef46d9fc206.zip |
SONAR-1290 Improve SQL requests on the Q profiles page
Diffstat (limited to 'sonar-server')
4 files changed, 14 insertions, 36 deletions
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 0cd379eed98..92ac5eabba9 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 @@ -30,6 +30,14 @@ module ApplicationHelper Java::OrgSonarServerPlatform::Platform.getServer().getVersion() end + # shortcut for the method is_admin?() without parameters. Result is kept in cache. + def administrator? + @is_administrator ||= + begin + is_admin? + end + end + def qualifier_icon(object) qualifier=(object.respond_to?('qualifier') ? object.qualifier : object.to_s) if qualifier diff --git a/sonar-server/src/main/webapp/WEB-INF/app/models/profile.rb b/sonar-server/src/main/webapp/WEB-INF/app/models/profile.rb index f47e279564f..d93bf560f35 100644 --- a/sonar-server/src/main/webapp/WEB-INF/app/models/profile.rb +++ b/sonar-server/src/main/webapp/WEB-INF/app/models/profile.rb @@ -48,20 +48,6 @@ class Profile < ActiveRecord::Base new_rule_profile.errors end - def active_rules_by_category_and_level(categ_id=nil, level=nil) - result=[] - active_rules.each do |active_rule| - if categ_id.nil? - result<<active_rule if active_rule.level==level or level.nil? - elsif level.nil? - result<<active_rule if active_rule.rule.rules_category_id==categ_id - else - result<<active_rule if active_rule.level==level and active_rule.rule.rules_category_id==categ_id - end - end - result - end - def self.default_profile Profile.find(:first, :conditions => {:default_profile => true}) end diff --git a/sonar-server/src/main/webapp/WEB-INF/app/models/rules_profile.rb b/sonar-server/src/main/webapp/WEB-INF/app/models/rules_profile.rb index d2ecd4c3f8e..0cfc127274f 100644 --- a/sonar-server/src/main/webapp/WEB-INF/app/models/rules_profile.rb +++ b/sonar-server/src/main/webapp/WEB-INF/app/models/rules_profile.rb @@ -56,20 +56,6 @@ class RulesProfile < ActiveRecord::Base provided end - def active_rules_by_category_and_level(categ_id=nil, level=nil) - result=[] - active_rules.each do |active_rule| - if categ_id.nil? - result<<active_rule if active_rule.level==level or level.nil? - elsif level.nil? - result<<active_rule if active_rule.rule.rules_category_id==categ_id - else - result<<active_rule if active_rule.level==level and active_rule.rule.rules_category_id==categ_id - end - end - result - end - def active_by_rule_id(rule_id) active_hash_by_rule_id[rule_id] end @@ -88,7 +74,6 @@ class RulesProfile < ActiveRecord::Base name + "_" + language end -# protected @active_hash_by_rule_id=nil def active_hash_by_rule_id diff --git a/sonar-server/src/main/webapp/WEB-INF/app/views/profiles/index.html.erb b/sonar-server/src/main/webapp/WEB-INF/app/views/profiles/index.html.erb index 498b872b59c..a4bbfd86301 100644 --- a/sonar-server/src/main/webapp/WEB-INF/app/views/profiles/index.html.erb +++ b/sonar-server/src/main/webapp/WEB-INF/app/views/profiles/index.html.erb @@ -22,9 +22,8 @@ <td><a href="<%= url_for :controller => 'rules_configuration', :action => 'index', :id => profile.id -%>"><%= h profile.name %></a></td> <td align="right"> - <% activated_rules=profile.active_rules_by_category_and_level(nil, nil).size %> <a id="rules_<%= u profile.key -%>" href="<%= url_for :controller => 'rules_configuration', :action => 'index', :id => profile.id -%>"> - <span id="activated_rules_<%= u profile.key -%>"><%= activated_rules %> rules</span> + <span id="activated_rules_<%= u profile.key -%>"><%= profile.active_rules.count -%> rules</span> </a> </td> @@ -40,7 +39,7 @@ <td align="right"><%= link_to pluralize(profile.alerts.size, 'alert'), profile_alerts_path(profile), :id => "alerts_#{u profile.key}" %></td> <td align="right"> - <% if (!profile.default_profile? && is_admin?) %> + <% if (!profile.default_profile? && administrator?) %> <%= button_to 'Set as default', { :action => 'set_as_default', :id => profile.id }, :class => 'action', :id => "activate_#{u profile.key}", :confirm => "Are you sure that you want to set the profile '#{profile.name}' as default ?", @@ -61,7 +60,7 @@ </td> <td align="right"> - <% if (!profile.provided? && is_admin?) %> + <% if (!profile.provided? && administrator?) %> <% form_tag(:controller => 'rules_configuration', :action => 'backup', :id => profile.id) do -%> <%= hidden_field_tag 'backup_' + profile.id.to_s %> <input type="submit" name="button_backup" id="backup_<%= u profile.key %>" value="Backup"></input> @@ -70,7 +69,7 @@ </td> <td align="right"> - <% if (is_admin?) %> + <% if administrator? %> <% form_tag(:action => 'copy', :id => profile.id) do -%> <%= hidden_field_tag 'copy_' + profile.id.to_s %> <input type="button" name="button_copy" id="copy_<%= u profile.key %>" value="Copy" onClick='var name=prompt("Name for the new profile"); if (name!=null) {$("copy_<%= profile.id %>").value=name; submit();} else {return false;}'> @@ -79,7 +78,7 @@ </td> <td> - <% if (!(profile.provided?) && !(profile.default_profile?) && is_admin?) %> + <% if (!(profile.provided?) && !(profile.default_profile?) && administrator?) %> <%= button_to "Delete", { :action => 'destroy', :id => profile.id }, :class => 'action', :id => "delete_#{u profile.key}", :confirm => "Are you sure that you want to delete the profile '#{profile.name}' ?", @@ -91,7 +90,7 @@ </table> <% end %> -<% if is_admin? %> +<% if administrator? %> <div id="create_profile_row"> <% form_remote_tag :url => {:action => 'new'} do %> <%= submit_tag 'Create profile', :id => 'create_profile' %> |