From a31b75609f1158062497205fe63425ef51f190c5 Mon Sep 17 00:00:00 2001 From: Julien Lancelot Date: Tue, 30 Apr 2013 14:17:15 +0200 Subject: [PATCH] SONAR-3755 Display action in issues code viewer --- .../app/controllers/issue_controller.rb | 38 +++++++++++++++++++ .../app/controllers/resource_controller.rb | 2 +- .../issue/code_viewer/_transition_form.erb | 27 +++++++++++++ .../app/views/resource/_issue.html.erb | 26 ++++++++----- .../src/main/webapp/javascripts/resource.js | 35 +++++++++++++++++ 5 files changed, 118 insertions(+), 10 deletions(-) create mode 100644 sonar-server/src/main/webapp/WEB-INF/app/views/issue/code_viewer/_transition_form.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 eac2c3ba6c4..b87e3d41ce2 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 @@ -57,10 +57,48 @@ class IssueController < ApplicationController @transitions = Internal.issues.listTransitions(@issue.key) render :partial => 'issue/view' else + # TODO render :status => 400 end end + # + # + # ACTIONS FROM ISSUES TAB OF RESOURCE VIEWER + # + # + + def issue_transition_form + require_parameters :id, :transition + + init_issue(params[:id]) + @transition = params[:transition] + bad_request('Missing transition') if @transition.blank? + + render :partial => 'issue/code_viewer/transition_form' + end + + # POST + def issue_transition + verify_post_request + require_parameters :id, :transition + issue = Internal.issues.doTransition(params[:id], params[:transition]) + if issue + init_issue(params[:id]) + @transitions = Internal.issues.listTransitions(@issue.key) + render :partial => 'resource/issue', :locals => {:issue => @issue} + else + # TODO + render :status => 400 + end + end + + # GET + def display_issue + init_issue(params[:id]) + render :partial => 'resource/issue', :locals => {:issue => @issue} + end + protected def init_issue(issue_key) diff --git a/sonar-server/src/main/webapp/WEB-INF/app/controllers/resource_controller.rb b/sonar-server/src/main/webapp/WEB-INF/app/controllers/resource_controller.rb index afa2f1fcfe4..799222640e3 100644 --- a/sonar-server/src/main/webapp/WEB-INF/app/controllers/resource_controller.rb +++ b/sonar-server/src/main/webapp/WEB-INF/app/controllers/resource_controller.rb @@ -413,7 +413,7 @@ class ResourceController < ApplicationController @filtered = !@expanded rule_param = params[:rule] - options = {'components' => @resource.key, 'resolutions' => 'OPEN'} + options = {'components' => @resource.key, 'resolutions' => ['OPEN', 'FIXED']} if rule_param.blank? && params[:metric] metric = Metric.by_id(params[:metric]) diff --git a/sonar-server/src/main/webapp/WEB-INF/app/views/issue/code_viewer/_transition_form.erb b/sonar-server/src/main/webapp/WEB-INF/app/views/issue/code_viewer/_transition_form.erb new file mode 100644 index 00000000000..1420131db61 --- /dev/null +++ b/sonar-server/src/main/webapp/WEB-INF/app/views/issue/code_viewer/_transition_form.erb @@ -0,0 +1,27 @@ +
+ + + + + + + + + +
+ + + <%= render :partial => 'markdown/tips' -%> +
+ +
+ <%= submit_to_remote "submit_btn"+params[:id], + message("issues.transition.#{params[:transition]}.button"), + :url => {:controller => 'issue', :action => 'issue_transition'}, + :html => {:id => "submit_btn"+params[:id]}, + :update => 'issue-key'+params[:id] -%> +   + <%= link_to_function message('cancel'), "cancelIssueAction('#{params[:id]}')" -%> +
+
diff --git a/sonar-server/src/main/webapp/WEB-INF/app/views/resource/_issue.html.erb b/sonar-server/src/main/webapp/WEB-INF/app/views/resource/_issue.html.erb index 22d717c3c33..38f22725de3 100644 --- a/sonar-server/src/main/webapp/WEB-INF/app/views/resource/_issue.html.erb +++ b/sonar-server/src/main/webapp/WEB-INF/app/views/resource/_issue.html.erb @@ -1,14 +1,9 @@ -
+
- <% - # TODO - #if violation.review - if false - %> - <% end %>   @@ -63,12 +58,25 @@
-
+
<% issue_description = issue.description ? Api::Utils.split_newlines(h(issue.description)).join('
') : '' %> <%= issue_description || ' ' -%>
-
+ <% if current_user %> +
+ <% if defined?(error_message) && error_message %> + + <% end %> + <% transitions = Internal.issues.listTransitions(issue.key) %> + <% transitions.each do |transition| %> + <%= link_to_function message("issues.transition.#{transition.key}.button"), "displayIssueTransitionForm('#{issue.key}', '#{transition.key}')", + :name => message("issues.transition.#{transition.key}.button"), :class => 'link-action spacer-right' -%> + <% end %> +
+ <% end %> + +
\ No newline at end of file diff --git a/sonar-server/src/main/webapp/javascripts/resource.js b/sonar-server/src/main/webapp/javascripts/resource.js index d6da6359dce..7c102fc7583 100644 --- a/sonar-server/src/main/webapp/javascripts/resource.js +++ b/sonar-server/src/main/webapp/javascripts/resource.js @@ -183,6 +183,41 @@ function hVF(elt, line) { return false; } +/* + Functions used in issues code viewer + */ + +// show the form for transition +function displayIssueTransitionForm(issueKey, transitionKey) { + // TODO + //hideMoreViolationActions(violation_id); + new Ajax.Updater('issue-form' + issueKey, + baseUrl + '/issue/issue_transition_form?id=' + issueKey + '&transition='+ transitionKey, + { + asynchronous:true, + evalScripts:true, + onComplete:function (request) { + $('issue-actions' + issueKey).remove(); + $('issue-form' + issueKey).show(); + // TODO +// $('commentText' + issueKey).focus(); + } + }); + return false; +} + +// cancel action : hide form and refresh issue +function cancelIssueAction(issueKey) { + new Ajax.Updater( + 'issue-key' + issueKey, + baseUrl + '/issue/display_issue/' + issueKey, + { + asynchronous:true, + evalScripts:true + }); + return false; +} + /* Functions used in tests viewer */ -- 2.39.5