From af15ec0936f37962e17f2c17e1c7d814a1c90b2e Mon Sep 17 00:00:00 2001 From: Simon Brandhof Date: Thu, 16 May 2013 19:17:18 +0200 Subject: [PATCH] SONAR-4304 add form for manual issues --- .../app/controllers/issue_controller.rb | 20 ++++++++++ .../WEB-INF/app/helpers/application_helper.rb | 7 +++- .../app/views/issue/_create_form.html.erb | 39 +++++++++++++++++++ .../shared/_source_violation_form.html.erb | 2 +- .../src/main/webapp/javascripts/issue.js | 33 +++++++++++++++- .../src/main/webapp/stylesheets/style.css | 2 +- 6 files changed, 98 insertions(+), 5 deletions(-) create mode 100644 sonar-server/src/main/webapp/WEB-INF/app/views/issue/_create_form.html.erb diff --git a/sonar-server/src/main/webapp/WEB-INF/app/controllers/issue_controller.rb b/sonar-server/src/main/webapp/WEB-INF/app/controllers/issue_controller.rb index e0ff09bcc90..dc7e0d07fe2 100644 --- a/sonar-server/src/main/webapp/WEB-INF/app/controllers/issue_controller.rb +++ b/sonar-server/src/main/webapp/WEB-INF/app/controllers/issue_controller.rb @@ -110,6 +110,26 @@ class IssueController < ApplicationController end + def create_form + verify_ajax_request + render :partial => 'issue/create_form' + end + + def create + verify_post_request + require_parameters :rule, :component + + component_key = params[:component] + if Api::Utils.is_integer?(component_key) + component = Project.find(component_key) + component_key = (component ? component.key : nil) + end + + issue = Internal.issues.create(params.merge({:component => component_key})) + + @issue_results = Api.issues.find(issue.key) + render :partial => 'issue/issue', :locals => {:issue => @issue_results.issues.get(0)} + 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 1d77704fd0f..042f2a00505 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 @@ -723,14 +723,14 @@ module ApplicationHelper # * :placeholder - the label to display when nothing is selected. Default is ''. # * :allow_clear - true if value can be de-selected. Default is false. # * :show_search_box - true to display the search box. Default is false. - # * :html_options - hash for html options (id, class, onchange, ...) + # * :open - true to open the select-box. Default is false. Since 3.6. # * :select2_options - hash of select2 options # def dropdown_tag(name, option_tags, options={}, html_options={}) width=options[:width]||'250px' html_id=html_options[:id]||name show_search_box=options[:show_search_box]||false - minimumResultsForSearch=show_search_box ? 0 : option_tags.size + 1; + minimumResultsForSearch=show_search_box ? 0 : option_tags.size + 1 js_options={ 'minimumResultsForSearch' => minimumResultsForSearch, @@ -742,6 +742,9 @@ module ApplicationHelper html = select_tag(name, option_tags, html_options) js = "$j('##{html_id}').select2({#{js_options.map { |k, v| "#{k}:#{v}" }.join(',')}});" + if options[:open] + js += "$j('##{html_id}').select2('open');" + end "#{html}" end diff --git a/sonar-server/src/main/webapp/WEB-INF/app/views/issue/_create_form.html.erb b/sonar-server/src/main/webapp/WEB-INF/app/views/issue/_create_form.html.erb new file mode 100644 index 00000000000..3daf08f9cbb --- /dev/null +++ b/sonar-server/src/main/webapp/WEB-INF/app/views/issue/_create_form.html.erb @@ -0,0 +1,39 @@ +<% + manual_rules = Rule.manual_rules + is_admin = has_role?(:admin) + form_id = "create-issue-#{params[:component]}-#{params[:line]}" + if manual_rules.empty? && !is_admin +%> +
+ No rules. Please contact the administrator. +  <%= link_to_function message('cancel'), 'closeMIF(this)' -%> +
+ +<% else %> +
+ + + +
+
+ <% unless manual_rules.empty? %> + <%= dropdown_tag 'rule', + options_for_select([[]].concat(manual_rules.map{|rule| [rule.name, rule.key] })), + {:show_search_box => true, :placeholder => 'Select a Rule', :open => true}, + {:html_id => "#{form_id}-rules"} -%> + <% end %> + <% if is_admin %> + Add Rule + <% end %> +
+ +
+ + +  <%= link_to_function message('cancel'), 'closeMIF(this)' -%> +
+ +
+
+ +<% end %> \ No newline at end of file diff --git a/sonar-server/src/main/webapp/WEB-INF/app/views/shared/_source_violation_form.html.erb b/sonar-server/src/main/webapp/WEB-INF/app/views/shared/_source_violation_form.html.erb index fa297e8abca..caec3157b91 100644 --- a/sonar-server/src/main/webapp/WEB-INF/app/views/shared/_source_violation_form.html.erb +++ b/sonar-server/src/main/webapp/WEB-INF/app/views/shared/_source_violation_form.html.erb @@ -1,3 +1,3 @@ - + diff --git a/sonar-server/src/main/webapp/javascripts/issue.js b/sonar-server/src/main/webapp/javascripts/issue.js index b5e80bb34d3..bbccd800575 100644 --- a/sonar-server/src/main/webapp/javascripts/issue.js +++ b/sonar-server/src/main/webapp/javascripts/issue.js @@ -156,4 +156,35 @@ function refreshIssue(elt) { replaced.find('.open-modal').modal(); }); return false; -} \ No newline at end of file +} + +function openMIF(elt, componentId, line) { + // TODO check if form is already displayed (by using form id) + $j.get(baseUrl + "/issue/create_form?component=" + componentId + "&line=" + line, function (html) { + $j(elt).closest('tr').find('td.line').append($j(html)); + }); + return false; +} + +function closeMIF(elt) { + $j(elt).closest('.code-issue-create-form').remove(); + return false; +} + +function submitMIF(elt) { + var formElt = $j(elt).closest('form'); + formElt.find('.loading').removeClass('hidden'); + formElt.find(':submit').prop('disabled', true); + $j.ajax({ + type: "POST", + url: baseUrl + '/issue/create', + data: formElt.serialize()} + ).success(function (data) { + formElt.html(data); + } + ).fail(function (jqXHR, textStatus) { + alert(textStatus); + }); + return false; +} + diff --git a/sonar-server/src/main/webapp/stylesheets/style.css b/sonar-server/src/main/webapp/stylesheets/style.css index dc90bfbb5e7..73b2dafc0ce 100644 --- a/sonar-server/src/main/webapp/stylesheets/style.css +++ b/sonar-server/src/main/webapp/stylesheets/style.css @@ -897,13 +897,13 @@ span.rulename a:hover { } .code-issues { background-color: #FFF; - padding: 10px; } .code-issue { background-color: #FFF; margin: 0; font-size: 12px; + padding: 5px 10px; } .code-issue-name { -- 2.39.5