aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-server/src
diff options
context:
space:
mode:
authorsimonbrandhof <simon.brandhof@gmail.com>2010-12-22 14:09:53 +0000
committersimonbrandhof <simon.brandhof@gmail.com>2010-12-22 14:09:53 +0000
commita8feb7c18b4d3ce67f5013439c12213acca29704 (patch)
tree24fc824740b3b6c738e41701f8ec7f1222f3f8be /sonar-server/src
parent5678f4236e27ae81c05bba5d611f6e579695c2ab (diff)
downloadsonarqube-a8feb7c18b4d3ce67f5013439c12213acca29704.tar.gz
sonarqube-a8feb7c18b4d3ce67f5013439c12213acca29704.zip
SONAR-1722 improve rendering of inheritance of rules
Diffstat (limited to 'sonar-server/src')
-rw-r--r--sonar-server/src/main/webapp/WEB-INF/app/controllers/rules_configuration_controller.rb41
-rw-r--r--sonar-server/src/main/webapp/WEB-INF/app/models/active_rule.rb8
-rw-r--r--sonar-server/src/main/webapp/WEB-INF/app/views/rules_configuration/_rule.html.erb25
3 files changed, 40 insertions, 34 deletions
diff --git a/sonar-server/src/main/webapp/WEB-INF/app/controllers/rules_configuration_controller.rb b/sonar-server/src/main/webapp/WEB-INF/app/controllers/rules_configuration_controller.rb
index 163b5e29de1..a4df4d785a1 100644
--- a/sonar-server/src/main/webapp/WEB-INF/app/controllers/rules_configuration_controller.rb
+++ b/sonar-server/src/main/webapp/WEB-INF/app/controllers/rules_configuration_controller.rb
@@ -54,7 +54,7 @@ class RulesConfigurationController < ApplicationController
@select_plugins = ANY_SELECTION + java_facade.getRuleRepositoriesByLanguage(@profile.language).collect { |repo| [repo.getName(true), repo.getKey()]}.sort
@select_priority = ANY_SELECTION + RULE_PRIORITIES
@select_status = [['Any',''], ["Active", STATUS_ACTIVE], ["Inactive", STATUS_INACTIVE]]
-
+
@rules = Rule.search(java_facade, {
:profile => @profile, :status => @status, :priorities => @priorities,
:plugins => @plugins, :searchtext => @searchtext, :include_parameters => true, :language => @profile.language})
@@ -73,20 +73,20 @@ class RulesConfigurationController < ApplicationController
end
end
-
-
- #
- #
- # POST /rules_configuration/revert_rule?id=<profile id>&active_rule_id=<active rule id>
- #
- #
- def revert_rule
- id = params[:id].to_i
- rule_id = params[:active_rule_id].to_i
- java_facade.revertRule(id, rule_id)
- redirect_to :action => 'index', :id => params[:id]
- end
-
+
+
+ #
+ #
+ # POST /rules_configuration/revert_rule?id=<profile id>&active_rule_id=<active rule id>
+ #
+ #
+ def revert_rule
+ id = params[:id].to_i
+ rule_id = params[:active_rule_id].to_i
+ java_facade.revertRule(id, rule_id)
+ redirect_to :action => 'index', :id => params[:id]
+ end
+
#
#
@@ -106,7 +106,7 @@ class RulesConfigurationController < ApplicationController
# deactivate the rule
active_rule.destroy if active_rule
active_rule=nil
- java_facade.ruleDeactivated(profile.id, rule.id)
+ java_facade.ruleDeactivated(profile.id, rule.id)
else
# activate the rule
if active_rule.nil?
@@ -117,8 +117,9 @@ class RulesConfigurationController < ApplicationController
end
active_rule.failure_level=Sonar::RulePriority.id(priority)
active_rule.save!
- java_facade.ruleActivatedOrChanged(profile.id, active_rule.id)
+ java_facade.ruleActivatedOrChanged(profile.id, active_rule.id)
end
+ active_rule.reload
is_admin=true # security has already been checked by controller filters
render :update do |page|
@@ -290,7 +291,7 @@ class RulesConfigurationController < ApplicationController
active_param.destroy
active_param = nil
end
- java_facade.ruleActivatedOrChanged(profile.id, active_rule.id)
+ java_facade.ruleActivatedOrChanged(profile.id, active_rule.id)
end
render :partial => 'rule_param', :object => nil,
:locals => {:parameter => rule_param, :active_parameter => active_param, :profile => profile, :active_rule => active_rule, :is_admin => is_admin }
@@ -307,7 +308,7 @@ class RulesConfigurationController < ApplicationController
count = rules_to_activate.size
rules_to_activate.each do |rule|
active_rule = profile.active_rules.create(:rule => rule, :failure_level => rule.priority)
- java_facade.ruleActivatedOrChanged(profile.id, active_rule.id)
+ java_facade.ruleActivatedOrChanged(profile.id, active_rule.id)
end
end
count
@@ -318,7 +319,7 @@ class RulesConfigurationController < ApplicationController
profile.active_rules.each do |ar|
if rule_ids.include?(ar.rule_id) && !ar.inherited
ar.destroy
- java_facade.ruleDeactivated(profile.id, ar.rule_id)
+ java_facade.ruleDeactivated(profile.id, ar.rule_id)
count+=1
end
end
diff --git a/sonar-server/src/main/webapp/WEB-INF/app/models/active_rule.rb b/sonar-server/src/main/webapp/WEB-INF/app/models/active_rule.rb
index 92d87ce3fed..cc325a3ccbc 100644
--- a/sonar-server/src/main/webapp/WEB-INF/app/models/active_rule.rb
+++ b/sonar-server/src/main/webapp/WEB-INF/app/models/active_rule.rb
@@ -99,4 +99,12 @@ class ActiveRule < ActiveRecord::Base
end
new_active_rule
end
+
+ def inherited?
+ inherited==1
+ end
+
+ def overridden?
+ inherited==2
+ end
end
diff --git a/sonar-server/src/main/webapp/WEB-INF/app/views/rules_configuration/_rule.html.erb b/sonar-server/src/main/webapp/WEB-INF/app/views/rules_configuration/_rule.html.erb
index a1afa263d1b..e5511c16196 100644
--- a/sonar-server/src/main/webapp/WEB-INF/app/views/rules_configuration/_rule.html.erb
+++ b/sonar-server/src/main/webapp/WEB-INF/app/views/rules_configuration/_rule.html.erb
@@ -1,10 +1,4 @@
<td nowrap valign="top" class="left" x="<%= active_rule.failure_level if active_rule -%>" width="1%">
- <% if active_rule.nil? || active_rule.inherited.nil?
- inheritance_status = 0
- else
- inheritance_status = active_rule.inherited
- end
- %>
<form id="levels_<%= rule.id -%>" action="">
<% enable_modification = is_admin && !profile.provided?
select_box_id = "levels_select_#{rule.id}"
@@ -20,20 +14,20 @@
:loading => "$('levels_#{rule.id}').replace('<img src=\"#{ApplicationController.root_context}/images/loading.gif\"/>');",
:with => "'level=' + get_level_for_rule(#{rule_select_box},#{rule_check_box})")
%>
- <%= check_box_tag(check_box_id, 'yes', (!active_rule.nil?), :onclick => activate_rule, :disabled => !enable_modification || inheritance_status > 0) %>
+ <%= check_box_tag(check_box_id, 'yes', (!active_rule.nil?), :onclick => activate_rule, :disabled => !enable_modification || (active_rule && (active_rule.inherited? || active_rule.overridden?))) %>
<%= select_tag(select_box_id, options_for_select(RulesConfigurationController::RULE_PRIORITIES, (active_rule.nil? ? rule.priority_text : active_rule.priority_text)),
{:onchange => changel_level, :disabled => (!(enable_modification) || active_rule.nil?)}) %>
+ <% if active_rule %>
+ <% if active_rule.inherited? %>
+ <img src="<%= ApplicationController.root_context -%>/images/relation-vertical-green.png" alt="Inherited from parent" title="Inherited from parent"/>
+ <% elsif active_rule.overridden? %>
+ <img src="<%= ApplicationController.root_context -%>/images/relation-vertical-red.png" alt="Overrides parent definition" title="Overrides parent definition"/>
+ <% end %>
+ <% end %>
</form>
</td>
<td valign="top" class="left">
- <% if inheritance_status == 1 %>
- Inherited from parent profile.<br/>
- <% elsif inheritance_status == 2 %>
- Overrides rule from parent profile.<br/>
- <%= button_to "Revert", :action => 'revert_rule', :id => profile.id, :active_rule_id => active_rule.id %><br/>
- <% end %>
-
<%= link_to_function("#{h rule.name}", nil, :class => "") do |page|
page.toggle "desc_#{rule.id}"
end
@@ -62,6 +56,9 @@
<% if rule.editable? %>
<%= button_to "Edit rule", :action => 'edit', :id => profile.id, :rule_id => rule.id %>
<% end %>
+ <% if active_rule && active_rule.overridden? %>
+ <%= button_to "Revert to parent definition", :action => 'revert_rule', :id => profile.id, :active_rule_id => active_rule.id %><br/>
+ <% end %>
<% end %>
</div>
</td>