From d969077cf266597edd11d0b36714a03081873816 Mon Sep 17 00:00:00 2001 From: Julien Lancelot Date: Fri, 24 May 2013 09:42:18 +0200 Subject: [PATCH] SONAR-4303 Refactor the issue detail in the issues code viewer --- .../resources/org/sonar/l10n/core.properties | 3 + .../org/sonar/server/issue/IssueService.java | 25 +----- .../WEB-INF/app/views/issue/_issue.html.erb | 83 ++++++++++++------- .../main/webapp/javascripts/application.js | 22 +++-- 4 files changed, 73 insertions(+), 60 deletions(-) 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 cbe300e096c..94704fff45f 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 @@ -557,8 +557,11 @@ issue.resolution.OPEN=Open issue.resolution.FALSE-POSITIVE=False-positive issue.resolution.FIXED=Fixed issue.planned_for_x=Planned for {0} +issue.planned_for=Planned for issue.manual.missing_rule=Missing rule issue.manual.no_rules=No rules. +issue.reported_by=Reported by + #------------------------------------------------------------------------------ # diff --git a/sonar-server/src/main/java/org/sonar/server/issue/IssueService.java b/sonar-server/src/main/java/org/sonar/server/issue/IssueService.java index 14ea05ed66a..042396d81f1 100644 --- a/sonar-server/src/main/java/org/sonar/server/issue/IssueService.java +++ b/sonar-server/src/main/java/org/sonar/server/issue/IssueService.java @@ -36,7 +36,6 @@ import org.sonar.server.platform.UserSession; import javax.annotation.Nullable; import java.util.Collections; -import java.util.Comparator; import java.util.Date; import java.util.List; @@ -67,23 +66,12 @@ public class IssueService implements ServerComponent { } /** - * List of available transitions, ordered by key. + * List of available transitions. *

* Never return null, but return an empty list if the issue does not exist. */ public List listTransitions(String issueKey) { - DefaultIssue issue = loadIssue(issueKey); - if (issue == null) { - return Collections.emptyList(); - } - List transitions = workflow.outTransitions(issue); - Collections.sort(transitions, new Comparator() { - @Override - public int compare(Transition transition, Transition transition2) { - return transition.key().compareTo(transition2.key()); - } - }); - return transitions; + return listTransitions(loadIssue(issueKey)); } /** @@ -93,14 +81,7 @@ public class IssueService implements ServerComponent { if (issue == null) { return Collections.emptyList(); } - List transitions = workflow.outTransitions(issue); - Collections.sort(transitions, new Comparator() { - @Override - public int compare(Transition transition, Transition transition2) { - return transition.key().compareTo(transition2.key()); - } - }); - return transitions; + return workflow.outTransitions(issue); } public Issue doTransition(String issueKey, String transition, UserSession userSession) { diff --git a/sonar-server/src/main/webapp/WEB-INF/app/views/issue/_issue.html.erb b/sonar-server/src/main/webapp/WEB-INF/app/views/issue/_issue.html.erb index ea1f85f8ad7..a5fbf7c85f2 100644 --- a/sonar-server/src/main/webapp/WEB-INF/app/views/issue/_issue.html.erb +++ b/sonar-server/src/main/webapp/WEB-INF/app/views/issue/_issue.html.erb @@ -7,19 +7,7 @@ <%= h rule_name -%>   - <%= image_tag 'sep12.png' -%> -   - - <% - created_at = Api::Utils.java_to_ruby_datetime(issue.creationDate()) - updated_at = Api::Utils.java_to_ruby_datetime(issue.updateDate()) - dates_title = "Created at #{format_datetime(created_at)} and updated at #{format_datetime(updated_at)}" - %> - <%= distance_of_time_in_words_to_now(created_at) -%> -   - <% - if issue.resolution - %> + <% if issue.resolution %> <%= image_tag 'sep12.png' -%>   <%= message("issue.resolution.#{issue.resolution}") -%> @@ -30,23 +18,21 @@ <%= message("issue.status.#{issue.status}") -%>   <% end %> + <%= image_tag 'sep12.png' -%> +   <% - if issue.assignee - %> - <%= image_tag 'sep12.png' -%> -   - <%= message('assigned_to') -%> <%= h(@issue_results.user(issue.assignee).name) -%> -   - <% end %> - <% - if issue.actionPlanKey() + created_at = Api::Utils.java_to_ruby_datetime(issue.creationDate()) + updated_at = Api::Utils.java_to_ruby_datetime(issue.updateDate()) + dates_title = "Created at #{format_datetime(created_at)} and updated at #{format_datetime(updated_at)}" %> + <%= distance_of_time_in_words_to_now(created_at) -%> +   + <% if issue.reporter %> <%= image_tag 'sep12.png' -%>   - <%= message('issue.planned_for_x', :params => h(@issue_results.actionPlan(issue).name())) if @issue_results.actionPlan(issue) -%> + <%= message('issue.reported_by') -%> <%= @issue_results.user(issue.reporter).name -%>   <% end %> - <% unless issue.message.blank? %> @@ -76,24 +62,61 @@ <% end %> <% if current_user %> + <% transitions = Internal.issues.listTransitions(issue) %> +

<%= message('issue.comment.formlink') -%> <% unless issue.resolution %> + <%= image_tag 'sep12.png' -%> +   - <%= message('issue.assign.formlink') -%> + <% if !issue.assignee %> + <%= message('issue.assign.formlink') -%> <% if issue.assignee!=current_user.login %> - [<%= message('issue.assign.to_me') -%>] + [<%= message('issue.assign.to_me') -%>] + <% end %> + <% else %> + <%= message('assigned_to') -%> <%= @issue_results.user(issue.assignee).name -%> <% end %> <% end %> - <% Internal.issues.listTransitions(issue).each do |transition| %> + <% unless issue.resolution %> + <%= image_tag 'sep12.png' -%> +   + + <% if !@issue_results.actionPlan(issue) %> + <%= message('issue.do_plan') -%> + <% else %> + <%= message('issue.planned_for') -%> <%= h(@issue_results.actionPlan(issue).name()) -%> + <% end %> + + <% end %> + + <% + if transitions.size > 0 && transitions.first + transition = transitions.first + %> + <%= image_tag 'sep12.png' -%> +   <%= message("issue.transition.#{transition.key}") -%> <% end %> - <% unless issue.resolution %> - <%= message("issue.set_severity") -%> - <%= message("issue.do_plan") -%> + <% + if transitions.size > 1 || !issue.resolution + transitions.remove(0) + %> + <% end %>
diff --git a/sonar-server/src/main/webapp/javascripts/application.js b/sonar-server/src/main/webapp/javascripts/application.js index cb408cd7c4d..c9598890583 100644 --- a/sonar-server/src/main/webapp/javascripts/application.js +++ b/sonar-server/src/main/webapp/javascripts/application.js @@ -425,9 +425,8 @@ function expandAccordionItem(elt) { var currentlyDisplayedDropdownMenu; var hideCurrentDropdownMenu = function () { - menu = $j('#' + currentlyDisplayedDropdownMenu); - if (menu) { - menu.hide(); + if (currentlyDisplayedDropdownMenu) { + currentlyDisplayedDropdownMenu.hide(); } $j(document).unbind('mouseup', hideCurrentDropdownMenu); } @@ -447,14 +446,21 @@ var clickOnDropdownMenuLink = function (event) { } function showDropdownMenu(menuId) { - if (menuId == currentlyDisplayedDropdownMenu) { + showDropdownMenuOnElement($j('#' + menuId)); +} + +function showDropdownMenuOnElement(elt) { + var dropdownElt = $j(elt); + var dropdownChildren = dropdownElt.children('li'); + + if (dropdownElt == currentlyDisplayedDropdownMenu) { currentlyDisplayedDropdownMenu = ""; } else { - currentlyDisplayedDropdownMenu = menuId; + currentlyDisplayedDropdownMenu = dropdownElt; $j(document).mouseup(hideCurrentDropdownMenu); - $j('#' + currentlyDisplayedDropdownMenu + ' li').unbind('click'); - $j('#' + currentlyDisplayedDropdownMenu + ' li').click(clickOnDropdownMenuLink); - $j('#' + currentlyDisplayedDropdownMenu).show(); + dropdownChildren.unbind('click'); + dropdownChildren.click(clickOnDropdownMenuLink); + dropdownElt.show(); } } -- 2.39.5