]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-3755 various improvements on plan and assign actions
authorSimon Brandhof <simon.brandhof@gmail.com>
Wed, 22 May 2013 10:19:04 +0000 (12:19 +0200)
committerSimon Brandhof <simon.brandhof@gmail.com>
Wed, 22 May 2013 10:19:13 +0000 (12:19 +0200)
* display deadline besides the action plans
* unplan button
* unassign button
* Ruby API to easily format java or ruby dates

plugins/sonar-core-plugin/src/main/resources/org/sonar/l10n/core.properties
plugins/sonar-core-plugin/src/main/resources/org/sonar/plugins/core/widgets/issues/action_plans.html.erb
sonar-plugin-api/src/main/java/org/sonar/api/issue/IssueQuery.java
sonar-server/src/main/webapp/WEB-INF/app/controllers/issue_controller.rb
sonar-server/src/main/webapp/WEB-INF/app/helpers/application_helper.rb
sonar-server/src/main/webapp/WEB-INF/app/models/api.rb
sonar-server/src/main/webapp/WEB-INF/app/views/issue/_assign_form.html.erb
sonar-server/src/main/webapp/WEB-INF/app/views/issue/_issue.html.erb
sonar-server/src/main/webapp/WEB-INF/app/views/issue/_plan_form.html.erb
sonar-server/src/main/webapp/WEB-INF/app/views/issues_action_plans/index.html.erb

index 460c742272079123514916df8324b7025822921f..5658dd3d0bb8bc9e18813d375a456b653f387716 100644 (file)
@@ -531,6 +531,7 @@ reviews.filtered_by.to=To date
 
 issue.assign.formlink=Assign
 issue.assign.submit=Assign
+issue.unassign.submit=Unassign
 issue.assign.to_me=to me
 issue.comment.formlink=Comment
 issue.comment.submit=Comment
@@ -545,6 +546,7 @@ issue.set_severity=Set Severity
 issue.set_severity.submit=Set Severity
 issue.do_plan=Plan
 issue.plan.submit=Plan
+issue.unplan.submit=Unplan
 issue.plan_must_be_created_first=An action plan should be first created to plan the remediation effort of this issue.
 issue.status.REOPENED=Reopened
 issue.status.RESOLVED=Resolved
index 4d896a83f76a4819b0f36d799f68bc60d8101936..f6736a6cddca97d8f6cbccd0d46abc3f4bc5b79b 100644 (file)
     <tbody>
       <%
          open_action_plans.each do |plan|
-           deadline = Api::Utils.java_to_ruby_datetime(plan.deadLine()) if plan.deadLine()
       %>
       <tr class="<%= show_resolved_issues ? '' : cycle("even", "odd", :name => "action_plan_" + widget.id.to_s) -%>">
         <td class="nowrap <%= line_class -%>"><%= h(plan.name) -%></td>
-        <td class="nowrap small <%= line_class -%> <%= 'over-due' if plan.overDue() -%>" style="text-align: right; padding-left:10px"><%= deadline ? deadline.strftime("%d %b %Y") : ' '  -%></td>
+        <td class="nowrap small <%= line_class -%> <%= 'over-due' if plan.overDue() -%>" style="text-align: right; padding-left:10px"><%= format_date(plan.deadLine())  -%></td>
         
         <% if show_resolved_issues %>
           <% if plan.totalIssues()==0 %>
index 74edf09d6ecb9ff2e42d3701bf9093e79bd26636..b27dd441564467d955cc32c19dd2c94a53dbe365 100644 (file)
@@ -281,7 +281,7 @@ public class IssueQuery {
      * If true, it will return all issues linked to an action plan
      * If false, it will return all issues not linked to an action plan
      */
-    public Builder planned(Boolean planned) {
+    public Builder planned(@Nullable Boolean planned) {
       this.planned = planned;
       return this;
     }
index 83a806f7a88786717d9225cdc1b7e027144d4a75..fb28aded77455f95966fc5ba64d593053bd921ed 100644 (file)
@@ -39,6 +39,10 @@ class IssueController < ApplicationController
   def action_form
     verify_ajax_request
     require_parameters :id, :issue
+
+    @issue_result = Api.issues.find(params[:issue])
+    @issue = @issue_result.issues().get(0)
+
     action_type = params[:id]
     render :partial => "issue/#{action_type}_form"
   end
index 013da3c1bb88e45b538e487ad4413cb4dd070600..1ff52dcb29d6c3c749f1d45be3bd4eec2c31fc2c 100644 (file)
@@ -26,6 +26,40 @@ module ApplicationHelper
     super(location, options)
   end
 
+  # Since 3.6
+  # java.util.Date is supported
+  #
+  # == Options
+  # * :format - See Ruby on Rails localization options
+  #
+  def format_datetime(object, options={})
+    return nil unless object
+    if object.is_a?(Java::JavaUtil::Date)
+      dt = Api::Utils.java_to_ruby_datetime(object)
+    else
+      dt = object
+    end
+    l(dt, options)
+  end
+
+  # Since 3.6
+  # java.util.Date is supported
+  #
+  # == Options
+  # * :format - See Ruby on Rails localization options
+  #
+  def format_date(object, options={})
+    return nil unless object
+    if object.is_a?(Java::JavaUtil::Date)
+      date = Api::Utils.java_to_ruby_datetime(object).to_date
+    elsif object.respond_to?(:to_date)
+      date = object.to_date
+    else
+      date = object
+    end
+    l(date, options)
+  end
+
   def sonar_version
     Java::OrgSonarServerPlatform::Platform.getServer().getVersion()
   end
@@ -724,6 +758,7 @@ module ApplicationHelper
 
   #
   # Creates a dropdown selection box.
+  #
   # ==== Options
   # * <tt>:width</tt> - The width suffixed with unit, for example '300px' or '100%'. Default is '250px'
   # * <tt>:placeholder</tt> - the label to display when nothing is selected. Default is ''.
@@ -732,6 +767,9 @@ module ApplicationHelper
   # * <tt>:open</tt> - true to open the select-box. Default is false. Since 3.6.
   # * <tt>:select2_options</tt> - hash of select2 options
   #
+  # ==== Example
+  # dropdown_tag('user', [['Morgan', 'morgan'], ['Simon', 'simon']], {:show_search_box => false}, {:id => 'users_123'})
+  #
   def dropdown_tag(name, option_tags, options={}, html_options={})
     width=options[:width]||'250px'
     html_id=html_options[:id]||name
@@ -739,8 +777,8 @@ module ApplicationHelper
     minimumResultsForSearch=show_search_box ? 0 : option_tags.size + 1
 
     js_options={
-        'minimumResultsForSearch' => minimumResultsForSearch,
-        'allowClear' => options[:allow_clear]||false,
+      'minimumResultsForSearch' => minimumResultsForSearch,
+      'allowClear' => options[:allow_clear]||false,
     }
     js_options['placeholder']= options.has_key?(:placeholder) ? "'#{options[:placeholder]}'" : "''"
     js_options['width']= "'#{width}'" if width
index 13870a3a4f60f523897d0093695b6ac31a83b922..b3ca183f1ac492830bc6cde0647540923d0b96f7 100644 (file)
 # as an API and can evolve through time.
 class Api
 
-  # since 3.6
+  # See the javadoc of org.sonar.api.issue.RubyIssueService.
+  # Since 3.6
   def self.issues
     Internal.issues_api
   end
 
-  # since 3.6
+  # See the javadoc of org.sonar.api.user.RubyUserService
+  # Since 3.6
   def self.users
     Internal.users_api
   end
index 2d8be33f28f765ec79f17e449f8faa93d2e6a160..1399397f159661881528c8b9c3773df9fc9e3d21 100644 (file)
@@ -1,12 +1,20 @@
+<% user_select_box_id = "assignee-#{params[:issue]}" %>
 <form action="">
   <input type="hidden" name="issue" value="<%= params[:issue] -%>"/>
   <input type="hidden" name="id" value="assign"/>
   <table class="width100">
     <tr>
       <td style="vertical-align:top">
-        <%= user_select_tag('assignee', :html_id => "assignee-#{params[:issue]}", :open => true) -%>
+        <%= user_select_tag('assignee', :html_id => user_select_box_id, :open => true) -%>
         <input type="button" value="<%= message('issue.assign.submit') -%>" onclick="submitIssueForm(this)">
-        &nbsp;<%= link_to_function message('cancel'), 'closeIssueForm(this)' -%>&nbsp;
+        &nbsp;
+        <% if @issue.assignee %>
+          <%= image_tag 'sep12.png' -%>
+          &nbsp;
+          <input type="button" value="<%= message('issue.unassign.submit') -%>" onclick="$j('#<%= user_select_box_id -%>').val('');submitIssueForm(this)">
+          &nbsp;
+        <% end %>
+        <%= link_to_function message('cancel'), 'closeIssueForm(this)' -%>&nbsp;
         <span class="loading hidden"></span>
       </td>
     </tr>
index 7a12817dcee6860cd13ee59627ea9192963898b5..c5520fed88b9aecc97c72351d61f912f415e8ce3 100644 (file)
@@ -13,7 +13,7 @@
     <%
        created_at = Api::Utils.java_to_ruby_datetime(issue.creationDate())
        updated_at = Api::Utils.java_to_ruby_datetime(issue.updateDate())
-       dates_title = "Created at #{l created_at} and updated at #{l updated_at}"
+       dates_title = "Created at #{format_datetime(created_at)} and updated at #{format_datetime(updated_at)}"
     %>
     <span title="<%= h dates_title -%>"><%= distance_of_time_in_words_to_now(created_at) -%></span>
     &nbsp;
index 0749fc032e51012687499edabbd22eb11b493cf6..8848f3fe52bdcae04990a8b8c64debefe7ea3922 100644 (file)
@@ -1,27 +1,41 @@
 <%
-  plans = Internal.issues.findOpenActionPlans(params[:issue])
+   plans_select_box_id = "plans-#{params[:issue]}"
+   plans = Internal.issues.findOpenActionPlans(params[:issue]).sort_by { |plan| plan.deadLine }
 
-  if plans.empty?
+
+   if plans.empty?
 %>
   <span class="error"><%= message('issue.plan_must_be_created_first') -%></span>
   &nbsp;<%= link_to_function message('cancel'), 'closeIssueForm(this)' -%>
+<%
+   else
+     first_plan = plans[0]
+     plan_options = options_for_select([[]] + plans.map { |plan|
+       if plan.deadLine
+         label = "#{h plan.name} (#{format_date(plan.deadLine)})"
+       else
+         label = h plan.name
+       end
+       [label, plan.key]
+     }, first_plan.key)
 
-<% else %>
-<form method="POST">
-  <input type="hidden" name="issue" value="<%= params[:issue] -%>"/>
-  <input type="hidden" name="id" value="plan"/>
+%>
+  <form method="POST">
+    <input type="hidden" name="issue" value="<%= params[:issue] -%>"/>
+    <input type="hidden" name="id" value="plan"/>
 
-  <select name="plan">
-    <option value=""></option>
-    <% plans.each do |plan| %>
-      <option value="<%= plan.key() -%>"><%= h(plan.name()) -%></option>
-    <% end %>
-  </select>
+    <%= dropdown_tag('plan', plan_options, {:show_search_box => false}, {:id => plans_select_box_id}) -%>
 
-  <input type="button" value="<%= message('issue.plan.submit') -%>" onclick="submitIssueForm(this)">
-  &nbsp;<%= link_to_function message('cancel'), 'closeIssueForm(this)' -%>&nbsp;
-  <span class="loading hidden"></span>
+    <input type="button" value="<%= message('issue.plan.submit') -%>" onclick="submitIssueForm(this)">
+    &nbsp;
+    <% if @issue.actionPlanKey %>
+      <%= image_tag 'sep12.png' -%>
+      &nbsp;
+      <input type="button" value="<%= message('issue.unplan.submit') -%>" onclick="$j('#<%= plans_select_box_id -%>').val('');$j('#<%= plans_select_box_id -%>').prop('disabled', false);submitIssueForm(this)">
+    <% end %>
+    <%= link_to_function message('cancel'), 'closeIssueForm(this)' -%>&nbsp;
+    <span class="loading hidden"></span>
 
-</form>
+  </form>
 
 <% end %>
index ffcb7cefc049c6b9d1c7bbbe8ee6595443aebcb4..b42b18f933ff5be1bf4601b176789b99d8e28fe7 100644 (file)
@@ -27,7 +27,7 @@
           <tr>
             <td class="thin nowrap center"><img src="<%= ApplicationController.root_context -%>/images/status/<%= plan.status() -%>.png" title="<%= message('issues_action_plans.status' + plan.status()) -%>"/></td>
             <td class="thin nowrap"><%= h(plan.name()) -%></td>
-            <td class="thin nowrap <%= 'over-due' if plan.overDue() -%>" align="right" x="<%= deadline ? deadline.tv_sec : '' -%>"><%= deadline ? deadline.strftime("%d %b %Y") : ' '  -%></td>
+            <td class="thin nowrap <%= 'over-due' if plan.overDue() -%>" align="right" x="<%= deadline ? deadline.tv_sec : '' -%>"><%= format_date(plan.deadLine())  -%></td>
             <% if plan.totalIssues()==0 %>
               <td class="noprogress thin nowrap">
                 <%= message('issues_action_plans.no_issues_linked_to_action_plan') -%>
@@ -85,8 +85,8 @@
             <tr>
               <td class="thin nowrap center"><img src="<%= ApplicationController.root_context -%>/images/status/<%= plan.status() -%>.png" title="<%= message(plan.status()) -%>"/></td>
               <td class="thin nowrap"><%= h(plan.name) -%></td>
-              <td class="thin nowrap <%= 'over-due' if plan.overDue() -%>" align="right" x="<%= deadline ? deadline.tv_sec : '' -%>"><%= deadline ? deadline.strftime("%d %b %Y") : ' ' -%></td>
-              <td class="thin nowrap" align="right" x="<%= updated_at.tv_sec -%>"><%= updated_at.strftime("%d %b %Y") -%></td>
+              <td class="thin nowrap <%= 'over-due' if plan.overDue() -%>" align="right" x="<%= deadline ? deadline.tv_sec : '' -%>"><%= format_date(plan.deadLine()) -%></td>
+              <td class="thin nowrap" align="right" x="<%= updated_at.tv_sec -%>"><%= format_date(plan.updatedAt()) -%></td>
               <% if plan.totalIssues()==0 %>
                 <td class="noprogress thin nowrap">
                   <%= message('issues_action_plans.no_issues_linked_to_action_plan') -%>