From c147c80eebda2b1cd89cf9d792fd1f094d81be9b Mon Sep 17 00:00:00 2001 From: Julien Lancelot Date: Tue, 30 Apr 2013 21:28:17 +0200 Subject: [PATCH] SONAR-3755 Add assign button in issues code viewer --- .../resources/org/sonar/l10n/core.properties | 4 ++ .../app/controllers/issue_controller.rb | 61 +++++++++++++------ .../views/issue/code_viewer/_assign_form.erb | 41 +++++++++++++ .../issue/code_viewer/_transition_form.erb | 2 +- .../app/views/resource/_issue.html.erb | 10 ++- .../src/main/webapp/javascripts/resource.js | 23 ++++++- 6 files changed, 117 insertions(+), 24 deletions(-) create mode 100644 sonar-server/src/main/webapp/WEB-INF/app/views/issue/code_viewer/_assign_form.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 87c98f85903..cac34dc7d41 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 @@ -528,6 +528,7 @@ reviews.filtered_by.to=To date issues.issue_number=Issue #{0} issues.hide_this_message=Hide this message +issues.user_does_not_exist=\ : user does not exist. \\nPlease select a valid user or leave the field blank. issues.status.REOPENED=Reopened issues.status.RESOLVED=Resolved issues.status.OPEN=Open @@ -539,6 +540,9 @@ issues.transition.resolve.button=Resolved issues.transition.falsepositive.button=False-positive issues.transition.reopen.button=Reopen issues.transition.close.button=Close +issues.action.comment.button=Comment +issues.action.assign.button=Assign +issues.action.assign_to_me.button=Assign to me #------------------------------------------------------------------------------ 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 2848d152981..2dd4ec67cf1 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 @@ -55,13 +55,12 @@ class IssueController < ApplicationController render :partial => 'issue/transition_form' end - # POST def transition verify_post_request require_parameters :issue, :transition - issue = Internal.issues.doTransition(params[:issue], params[:transition]) - if issue - init_issue(params[:issue]) + + @issue = Internal.issues.doTransition(params[:issue], params[:transition]) + if @issue init_resource @transitions = Internal.issues.listTransitions(@issue.key) render :partial => 'issue/view' @@ -73,10 +72,15 @@ class IssueController < ApplicationController # # - # ACTIONS FROM ISSUES TAB OF RESOURCE VIEWER + # ACTIONS FROM ISSUES TAB OF CODE VIEWER # # + def display_issue + init_issue(params[:issue]) + render :partial => 'resource/issue', :locals => {:issue => @issue} + end + def issue_transition_form require_parameters :issue, :transition @@ -87,27 +91,38 @@ class IssueController < ApplicationController render :partial => 'issue/code_viewer/transition_form' end - # POST def issue_transition verify_post_request require_parameters :issue, :transition - issue = Internal.issues.doTransition(params[:issue], params[:transition]) - if issue - init_issue(params[:issue]) - @transitions = Internal.issues.listTransitions(@issue.key) - render :partial => 'resource/issue', :locals => {:issue => @issue} - else - # TODO - render :status => 400 - end + + @issue = Internal.issues.doTransition(params[:issue], params[:transition]) + render_issue_code_viewer end - # GET - def display_issue + def issue_assign_form + require_parameters :issue init_issue(params[:issue]) - render :partial => 'resource/issue', :locals => {:issue => @issue} + + render :partial => 'issue/code_viewer/assign_form' end + def issue_assign + verify_post_request + require_parameters :issue + + assignee = nil + if params[:me]=='true' + assignee = current_user.login + + elsif params[:issue_assignee_login].present? + assignee = params[:issue_assignee_login] + end + + @issue = Internal.issues.assign(params[:issue], assignee) + render_issue_code_viewer + end + + protected def init_issue(issue_key) @@ -121,6 +136,16 @@ class IssueController < ApplicationController @resource = @component.root_project end + def render_issue_code_viewer + if @issue + @transitions = Internal.issues.listTransitions(@issue.key) + render :partial => 'resource/issue', :locals => {:issue => @issue} + else + # TODO + render :status => 400 + end + end + def find_issues(map) Api.issues.find(map) end diff --git a/sonar-server/src/main/webapp/WEB-INF/app/views/issue/code_viewer/_assign_form.erb b/sonar-server/src/main/webapp/WEB-INF/app/views/issue/code_viewer/_assign_form.erb new file mode 100644 index 00000000000..04433a34418 --- /dev/null +++ b/sonar-server/src/main/webapp/WEB-INF/app/views/issue/code_viewer/_assign_form.erb @@ -0,0 +1,41 @@ +<% + assignee_check_script = "if ($('autocompleteText-issue_assignee_login').value != '' && $('issue_assignee_login').value == '') { alert($('autocompleteText-issue_assignee_login').value + '" + message('issues.user_does_not_exist') + "'); return false;}" +%> + +
+ + + + + + + + + +
+ + + <%= render :partial => 'markdown/tips' -%> +
+ + <%= user_autocomplete_field 'issue_assignee_login', '' -%> + +    + <%= submit_to_remote "submit_btn", message('issues.action.assign.button'), + :url => {:action => 'issue_assign'}, + :update => "issue-key" + params[:issue], + :before => assignee_check_script -%> +   + <%= image_tag 'sep12.png' -%> +   + <%= submit_to_remote "submit_me_btn", message('issues.action.assign_to_me.button'), + :url => {:action => 'issue_assign', :issue => params[:issue], :me => true}, + :update => "issue-key" + params[:issue], + :html => {:disabled => (@issue.assignee == current_user.login)} -%> +   + <%= link_to_function message('cancel'), "cancelIssueAction('#{params[:issue]}')" -%> + +
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 index 122e654e56b..7f4fade047d 100644 --- 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 @@ -6,7 +6,7 @@
- + 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 b043eba250a..95c08294eee 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 @@ -71,11 +71,17 @@ <% end %> - <% transitions = Internal.issues.listTransitions(issue.key) %> - <% transitions.each do |transition| %> + + <% Internal.issues.listTransitions(issue.key).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 %> + + <% unless issue.status == 'RESOLVED' %> + <%= link_to_function message('issues.action.assign.button'), "displayIssueAssignForm('#{issue.key}')", + :name => message('issues.action.assign.button'), :class => 'link-action spacer-right' -%> + <% end %> + <% end %> diff --git a/sonar-server/src/main/webapp/javascripts/resource.js b/sonar-server/src/main/webapp/javascripts/resource.js index 335d309b395..9091c9e9705 100644 --- a/sonar-server/src/main/webapp/javascripts/resource.js +++ b/sonar-server/src/main/webapp/javascripts/resource.js @@ -190,7 +190,7 @@ function hVF(elt, line) { // show the form for transition function displayIssueTransitionForm(issueKey, transitionKey) { // TODO - //hideMoreViolationActions(violation_id); + //hideMoreIssueActions(issueKey); new Ajax.Updater('issue-form' + issueKey, baseUrl + '/issue/issue_transition_form?issue=' + issueKey + '&transition='+ transitionKey, { @@ -199,8 +199,25 @@ function displayIssueTransitionForm(issueKey, transitionKey) { onComplete:function (request) { $('issue-actions' + issueKey).remove(); $('issue-form' + issueKey).show(); - // TODO -// $('commentText' + issueKey).focus(); + $('issue-comment' + issueKey).focus(); + } + }); + return false; +} + +// show the form to assign issue +function displayIssueAssignForm(issueKey) { + // TODO + //hideMoreIssueActions(issueKey); + new Ajax.Updater('issue-form' + issueKey, + baseUrl + '/issue/issue_assign_form/?issue=' +issueKey, + { + asynchronous:true, + evalScripts:true, + onComplete:function (request) { + $('issue-actions' + issueKey).remove(); + $('issue-form' + issueKey).show(); + $('issue_assignee_login').focus(); } }); return false; -- 2.39.5