From: simonbrandhof Date: Wed, 22 Dec 2010 14:09:53 +0000 (+0000) Subject: SONAR-1722 improve rendering of inheritance of rules X-Git-Tag: 2.6~246 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=a8feb7c18b4d3ce67f5013439c12213acca29704;p=sonarqube.git SONAR-1722 improve rendering of inheritance of rules --- 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=&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=&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 @@ - <% if active_rule.nil? || active_rule.inherited.nil? - inheritance_status = 0 - else - inheritance_status = active_rule.inherited - end - %>
<% enable_modification = is_admin && !profile.provided? select_box_id = "levels_select_#{rule.id}" @@ -20,20 +14,20 @@ :loading => "$('levels_#{rule.id}').replace('');", :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? %> + Inherited from parent + <% elsif active_rule.overridden? %> + Overrides parent definition + <% end %> + <% end %>
- <% if inheritance_status == 1 %> - Inherited from parent profile.
- <% elsif inheritance_status == 2 %> - Overrides rule from parent profile.
- <%= button_to "Revert", :action => 'revert_rule', :id => profile.id, :active_rule_id => active_rule.id %>
- <% 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 %>
+ <% end %> <% end %>