aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSimon Brandhof <simon.brandhof@gmail.com>2013-05-16 19:17:18 +0200
committerSimon Brandhof <simon.brandhof@gmail.com>2013-05-16 19:17:18 +0200
commitaf15ec0936f37962e17f2c17e1c7d814a1c90b2e (patch)
tree742db8b6cc68efc82fd25af8735a0c185c0c74a1
parent7780e113a3893223328a1ad8028f4ab979c27ce4 (diff)
downloadsonarqube-af15ec0936f37962e17f2c17e1c7d814a1c90b2e.tar.gz
sonarqube-af15ec0936f37962e17f2c17e1c7d814a1c90b2e.zip
SONAR-4304 add form for manual issues
-rw-r--r--sonar-server/src/main/webapp/WEB-INF/app/controllers/issue_controller.rb20
-rw-r--r--sonar-server/src/main/webapp/WEB-INF/app/helpers/application_helper.rb7
-rw-r--r--sonar-server/src/main/webapp/WEB-INF/app/views/issue/_create_form.html.erb39
-rw-r--r--sonar-server/src/main/webapp/WEB-INF/app/views/shared/_source_violation_form.html.erb2
-rw-r--r--sonar-server/src/main/webapp/javascripts/issue.js33
-rw-r--r--sonar-server/src/main/webapp/stylesheets/style.css2
6 files changed, 98 insertions, 5 deletions
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
# * <tt>:placeholder</tt> - the label to display when nothing is selected. Default is ''.
# * <tt>:allow_clear</tt> - true if value can be de-selected. Default is false.
# * <tt>:show_search_box</tt> - true to display the search box. Default is false.
- # * <tt>:html_options</tt> - hash for html options (id, class, onchange, ...)
+ # * <tt>:open</tt> - true to open the select-box. Default is false. Since 3.6.
# * <tt>:select2_options</tt> - 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}<script>#{js}</script>"
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
+%>
+ <div class="warning">
+ No rules. Please contact the administrator.
+ &nbsp;<%= link_to_function message('cancel'), 'closeMIF(this)' -%>
+ </div>
+
+<% else %>
+ <form action="" class="code-issue-create-form" id="<%= form_id -%>">
+ <input type="hidden" name="line" value="<%= params[:line] -%>"/>
+ <input type="hidden" name="component" value="<%= params[:component] -%>"/>
+
+ <div class="code-issue">
+ <div class="code-issue-name">
+ <% 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 %>
+ <a href="#">Add Rule</a>
+ <% end %>
+ </div>
+
+ <div class="code-issue-msg">
+ <textarea rows="4" name="message" class="width100 marginbottom5"></textarea>
+
+ <input type="submit" value="Create" onclick="return submitMIF(this);"> &nbsp;<%= link_to_function message('cancel'), 'closeMIF(this)' -%>
+ </div>
+ <div class="code-issue-form hidden"></div>
+ </div>
+ </form>
+
+<% 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 @@
<td class="plus">
- <a onclick="return sVF(this, <%= resource_id -%>,<%= index + 1 -%>,<%= gray_colspan -%>,<%= white_colspan -%>)"></a>
+ <a onclick="return openMIF(this, <%= resource_id -%>,<%= index + 1 -%>)"></a>
</td>
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 {