From da7f8473a044d8963e7d8c1f13a5d9ea7037de9b Mon Sep 17 00:00:00 2001 From: Jean-Baptiste Lievremont Date: Wed, 22 Jan 2014 12:45:08 +0100 Subject: SONAR-4326 Allow creation of new tags from coding rules page --- .../main/resources/org/sonar/l10n/core.properties | 5 +++ .../controllers/rules_configuration_controller.rb | 27 +++++++++++----- .../app/views/rules_configuration/_rule.html.erb | 4 ++- .../rules_configuration/_select_tags.html.erb | 37 ++++++++++++++-------- .../rules_configuration/_select_tags_list.html.erb | 9 ++++++ 5 files changed, 60 insertions(+), 22 deletions(-) create mode 100644 sonar-server/src/main/webapp/WEB-INF/app/views/rules_configuration/_select_tags_list.html.erb diff --git a/plugins/sonar-core-plugin/src/main/resources/org/sonar/l10n/core.properties b/plugins/sonar-core-plugin/src/main/resources/org/sonar/l10n/core.properties index 198edd9c0aa..21271004625 100644 --- a/plugins/sonar-core-plugin/src/main/resources/org/sonar/l10n/core.properties +++ b/plugins/sonar-core-plugin/src/main/resources/org/sonar/l10n/core.properties @@ -1671,6 +1671,11 @@ rules_configuration.creation_date=Creation date rules_configuration.removal_date=Removal date rules_configuration.available_since=Available since rules_configuration.removed_since=Removed since +rules_configuration.select_tags=Select Tags +rules_configuration.select_tags_for_rule=Select Tags for Rule: +rules_configuration.update_tags=Update Tags +rules_configuration.new_tag=New Tag... +rules_configuration.create_tag=Create Tag #------------------------------------------------------------------------------ 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 7e07b0a35b4..533cebab6ef 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 @@ -339,14 +339,7 @@ class RulesConfigurationController < ApplicationController def show_select_tags rule = Internal.quality_profiles.findByRule(params[:rule_id].to_i) - tags = [] - Internal.rule_tags.listAllTags().sort.each do |tag| - tags.push({ - :value => tag, - :selected => (rule.systemTags.contains?(tag) || rule.adminTags.contains?(tag)), - :read_only => rule.systemTags.contains?(tag) - }) - end + tags = tag_selection_for_rule(rule) render :partial => 'select_tags', :locals => { :rule => rule, :tags => tags, :profile_id => params[:profile_id] } end @@ -355,6 +348,14 @@ class RulesConfigurationController < ApplicationController render :partial => 'rule_tags', :locals => {:rule => rule} end + def create_tag + Internal.rule_tags.create(params[:new_tag]) + rule = Internal.quality_profiles.findByRule(params[:rule_id].to_i) + tags = tag_selection_for_rule(rule) + + render :partial => 'select_tags_list', :locals => {:tags => tags} + end + private def init_params @@ -396,4 +397,14 @@ class RulesConfigurationController < ApplicationController new_params end + def tag_selection_for_rule(rule) + Internal.rule_tags.listAllTags().sort.collect do |tag| + { + :value => tag, + :selected => (rule.systemTags.contains?(tag) || rule.adminTags.contains?(tag)), + :read_only => rule.systemTags.contains?(tag) + } + end + 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 6ad68ac712a..8422749efee 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 @@ -94,7 +94,9 @@ <% if profiles_administrator? %>
- Select Tags + + <%= message('rules_configuration.select_tags') -%>
<% end %> diff --git a/sonar-server/src/main/webapp/WEB-INF/app/views/rules_configuration/_select_tags.html.erb b/sonar-server/src/main/webapp/WEB-INF/app/views/rules_configuration/_select_tags.html.erb index e58680e8164..6c522e50458 100644 --- a/sonar-server/src/main/webapp/WEB-INF/app/views/rules_configuration/_select_tags.html.erb +++ b/sonar-server/src/main/webapp/WEB-INF/app/views/rules_configuration/_select_tags.html.erb @@ -1,4 +1,26 @@ <% #locals = rule, tags, profile_id -%> + + +
+ <%= hidden_field_tag :rule_id, rule.id -%> +
+ +
+
+
-

Select Tags for Rule: <%= h rule.name -%>

<%# TODO i18n?-%> - -