From 5e914b3a5ac1a332048810ca6a4e7f3a4f725845 Mon Sep 17 00:00:00 2001 From: Julien Lancelot Date: Wed, 13 Mar 2013 12:32:04 +0100 Subject: [PATCH] SONAR-4193 Improve modal rule window layout --- .../resources/org/sonar/l10n/core.properties | 1 + .../app/controllers/rules_controller.rb | 16 +++++--- .../WEB-INF/app/helpers/application_helper.rb | 4 +- .../WEB-INF/app/views/rules/_show.html.erb | 40 +++++++++++++++++++ .../main/webapp/javascripts/application.js | 6 +-- 5 files changed, 57 insertions(+), 10 deletions(-) create mode 100644 sonar-server/src/main/webapp/WEB-INF/app/views/rules/_show.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 c22e6e18db9..c823e30bc8a 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 @@ -1470,6 +1470,7 @@ rules_configuration.removed_since=Removed since rules.more_about_rule_on_profile_x=More about this rule on profile "{0}" rules.identification=Identification rules.parameters=Parameters +rules.not_found=The rule "{0}" does not exists #------------------------------------------------------------------------------ diff --git a/sonar-server/src/main/webapp/WEB-INF/app/controllers/rules_controller.rb b/sonar-server/src/main/webapp/WEB-INF/app/controllers/rules_controller.rb index 3d3e6850625..e1b03226c4d 100644 --- a/sonar-server/src/main/webapp/WEB-INF/app/controllers/rules_controller.rb +++ b/sonar-server/src/main/webapp/WEB-INF/app/controllers/rules_controller.rb @@ -22,14 +22,18 @@ class RulesController < ApplicationController SECTION=Navigation::SECTION_CONFIGURATION def show - key=params[:id] - if key.to_i==0 - parts=key.split(':') - @rule=Rule.find(:first, :conditions => ['plugin_name=? and plugin_rule_key=?', parts[0], parts[1]]) + @key=params[:id] + if @key.to_i==0 + parts=@key.split(':') + @rule=Rule.first(:conditions => ['plugin_name=? and plugin_rule_key=?', parts[0], parts[1]]) else - @rule=Rule.find(key) + @rule=Rule.find(@key) + end + @page_title=@rule.name if @rule + + if params[:modal] == 'true' + render :partial => 'show' end - @page_title=@rule.name end end 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 081ece9f918..fca03571b60 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 @@ -789,6 +789,8 @@ module ApplicationHelper def process_rule_description(rule) description = rule.description - description.gsub(/\{toRule (.+):(.+)\}/, ""+ '\1:\2' +"") + description.gsub( + /\{toRule (.+):(.+)\}/, + "" + '\1:\2' +"") end end diff --git a/sonar-server/src/main/webapp/WEB-INF/app/views/rules/_show.html.erb b/sonar-server/src/main/webapp/WEB-INF/app/views/rules/_show.html.erb new file mode 100644 index 00000000000..40197c2b4aa --- /dev/null +++ b/sonar-server/src/main/webapp/WEB-INF/app/views/rules/_show.html.erb @@ -0,0 +1,40 @@ +
+ + <% if @rule %> +
+

+ <%= @rule.name %> +

+
+ <%= @rule.plugin_name -%> : <%= @rule.plugin_rule_key -%> +
+
+ <% end %> + +
+ <% if @rule %> + <% if @rule.description.strip.start_with?('

') %> + <%= process_rule_description @rule %> + <% else %> +

<%= process_rule_description @rule %>

+ <% end %> + + <% if @rule.note && !@rule.note.text.strip.blank? %> +

<%= @rule.note.html_text -%>

+ <% end %> + <% else %> +

<%= message('rules.not_found', :params => @key) %> + <% end %> +

+ + + +
+ + diff --git a/sonar-server/src/main/webapp/javascripts/application.js b/sonar-server/src/main/webapp/javascripts/application.js index 15444bd420d..7190f0614ae 100644 --- a/sonar-server/src/main/webapp/javascripts/application.js +++ b/sonar-server/src/main/webapp/javascripts/application.js @@ -248,10 +248,10 @@ Treemap.prototype.initNodes = function () { return this.each(function () { var obj = $j(this); var $link = obj.bind('click', function () { - if ($j('#modal').length) { - return; // another window is already opening + var $dialog = $j('#modal'); + if (!$dialog.length) { + $dialog = $j('').appendTo('body'); } - var $dialog = $j('').appendTo('body'); var url = $link.attr('modal-url') || $link.attr('href'); $j.get(url,function (html) { $dialog.removeClass('ui-widget-overlay'); -- 2.39.5