]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-4301 Add project and creation date filters on issues search page
authorJulien Lancelot <julien.lancelot@gmail.com>
Thu, 16 May 2013 16:47:34 +0000 (18:47 +0200)
committerJulien Lancelot <julien.lancelot@gmail.com>
Thu, 16 May 2013 16:47:34 +0000 (18:47 +0200)
plugins/sonar-core-plugin/src/main/resources/org/sonar/l10n/core.properties
sonar-server/src/main/java/org/sonar/server/util/RubyUtils.java
sonar-server/src/main/webapp/WEB-INF/app/controllers/api/resources_controller.rb
sonar-server/src/main/webapp/WEB-INF/app/controllers/issues_controller.rb
sonar-server/src/main/webapp/WEB-INF/app/helpers/application_helper.rb
sonar-server/src/main/webapp/WEB-INF/app/views/issues/_sidebar.html.erb

index 4b0dda7fe087c9cab3c680e7c12b8c00ec066165..92b4a6af2c2d29e234ff4940a6177c8b56e1f861 100644 (file)
@@ -569,7 +569,9 @@ issue_filter.criteria.project=Project
 issue_filter.criteria.status=Status
 issue_filter.criteria.assignee=Assignee
 issue_filter.criteria.reporter=Reporter
-issue_filter.criteria.creation_date=Creation date
+issue_filter.criteria.created_after=Created since
+issue_filter.criteria.created_before=Created before
+issue_filter.criteria.date_format=year-month-day (2013-01-31)
 
 
 #------------------------------------------------------------------------------
index 69870669f05e205fa7aa63fa2fa453fff4f337d0..45257af5844061a516b2f02b9f8f6826709772a5 100644 (file)
@@ -25,6 +25,7 @@ import com.google.common.primitives.Ints;
 import org.sonar.api.utils.DateUtils;
 
 import javax.annotation.Nullable;
+
 import java.util.Date;
 import java.util.List;
 
@@ -80,7 +81,11 @@ public class RubyUtils {
       return (Date) o;
     }
     if (o instanceof String) {
-      return DateUtils.parseDateTime((String) o);
+      Date date = DateUtils.parseDateTimeQuietly((String) o);
+      if (date != null) {
+        return date;
+      }
+      return DateUtils.parseDate((String) o);
     }
     return null;
   }
index bd091c182904752ec9e41e69556966cd49c39668..dbccdec21b0a988ffb31edb5b27d3abb3ee0f0f0 100644 (file)
@@ -21,10 +21,15 @@ class Api::ResourcesController < Api::ApiController
 
   # since version 3.3
   # Exemple : /api/resources/search?s=sonar
+  #
+  # -- Optional parameters
+  # 'display_key' is used to return the resource key instead of the resource id. Default is false
+  #
   def search
     search_text = params[:s]||''
     page=(params[:p] ? params[:p].to_i : 1)
     page_size=(params[:ps] ? params[:ps].to_i : 10)
+    display_key=params[:display_key]||false
     if params[:q]
       qualifiers=params[:q].split(',')
     elsif params[:qp]
@@ -74,12 +79,13 @@ class Api::ResourcesController < Api::ApiController
         resources_by_qualifier = resources.group_by(&:qualifier)
         json = {
           :more => false,
-          :results => resources_by_qualifier.map { |qualifier, grouped_resources| {:text => message("qualifiers.#{qualifier}"), :children => grouped_resources.map { |r| {:id => r.id, :text => r.name(true)} }} }
+          :results => resources_by_qualifier.map { |qualifier, grouped_resources| {:text => message("qualifiers.#{qualifier}"),
+                                                                                   :children => grouped_resources.map { |r| {:id => display_key ? r.key : r.id, :text => r.name(true)} }} }
         }
       else
         json = {
           :more => (page * page_size)<total,
-          :results => resources.map { |resource| {:id => resource.id, :text => resource.name(true)} }
+          :results => resources.map { |resource| {:id => display_key ? resource.key : resource.id, :text => resource.name(true)} }
         }
       end
     else
index 5cd8168322e017f2d1b81f8ecd37f0e673ef35be..c10e77552b69d2d1291d229cb5579b8d8eb1dd7b 100644 (file)
@@ -31,6 +31,9 @@ class IssuesController < ApplicationController
     @filter = IssueFilter.new
     @filter.criteria=criteria_params
     @filter.execute
+
+    # TODO replace by project from issues result API
+    @project = Project.by_key(@filter.criteria('componentRoots')).root_project if @filter.criteria('componentRoots')
   end
 
 
index 28cec85c0a113d6583132e039de6a581cc10270e..4679d64df7773ff584d84279e5646fb83dc8bfa6 100644 (file)
@@ -611,6 +611,7 @@ module ApplicationHelper
   # * <tt>:placeholder</tt> - the label to display when nothing is selected
   # * <tt>:allow_clear</tt> - true if resource can be de-selected. Default is false.
   # * <tt>:open</tt> - true if the select-box must be open. Default is false.
+  # * <tt>:display_key</tt> - true if the resource key should be used instead of the resource id. Default is false.
   # * <tt>:select2_options</tt> - hash of select2 options
   #
   def resource_select_tag(name, options={})
@@ -624,9 +625,13 @@ module ApplicationHelper
       ws_url+="qp=#{options[:resource_type_property]}"
     end
 
+    if options[:display_key]
+      ws_url+='&display_key=true'
+    end
+
     selected_resource = options[:selected_resource]
     if selected_resource
-      options[:selected_id]=selected_resource.id
+      options[:selected_id]= options[:display_key] ? "'" + selected_resource.key + "'" : selected_resource.id
       options[:selected_text]=selected_resource.name(true)
     end
 
index 61824824979d6d0d85873e70becda0ec17e7b4d1..21c332a60c24def064c2f34397c90b47b43d4b20 100644 (file)
@@ -3,6 +3,18 @@
     <li class="sidebar-title">
       <%= message('issue_filter.new_search') -%>
     </li>
+    <li id="criteria-project" class="marginbottom5">
+      <!-- TODO replace by project from issues result API-->
+      <% selected_project = @project if @filter.criteria('componentRoots') %>
+      <%= message 'issue_filter.criteria.project' -%>:
+      <%= resource_select_tag 'componentRoots', :resource_type_property => 'supportsGlobalDashboards', :width => '100%',
+                              :selected_resource => selected_project,
+                              :display_key => true,
+                              :placeholder => message('issue_filter.criteria.project'),
+                              :html_id => 'select-project',
+                              :allow_clear => true
+      -%>
+    </li>
     <li id="criteria-severity" class="marginbottom5">
       <%= message 'issue_filter.criteria.severities' -%>:
       <%= dropdown_tag 'severities[]', options_for_select(RulesConfigurationController::RULE_PRIORITIES, @filter.criteria('severities')),
     </li>
     <li>
       <%= message 'issue_filter.criteria.assignee' -%>:
-      <% selected_user = @filter.issues_result.user(@filter.criteria('assignees')) if @filter.issues_result %>
-      <%= user_select_tag('assignees', {:selected_user => selected_user, :width => '100%', :placeholder => message('issue_filter.criteria.assignee'),
+      <% selected_assignee = @filter.issues_result.user(@filter.criteria('assignees')) if @filter.issues_result %>
+      <%= user_select_tag('assignees', {:selected_user => selected_assignee, :width => '100%', :placeholder => message('issue_filter.criteria.assignee'),
                         :html_id => 'select-assignee', :open => false, :allow_clear => true}) -%>
     </li>
+    <li>
+      <%= message 'issue_filter.criteria.reporter' -%>:
+      <% selected_reporter = @filter.issues_result.user(@filter.criteria('reporters')) if @filter.issues_result %>
+      <%= user_select_tag('reporters', {:selected_user => selected_reporter, :width => '100%', :placeholder => message('issue_filter.criteria.reporter'),
+                                        :html_id => 'select-reporter', :open => false, :allow_clear => true}) -%>
+    </li>
+    <li class="marginbottom5">
+      <%= message('issue_filter.criteria.created_after') -%>:<br>
+      <input type="text" name="createdAfter" value="<%= @filter.criteria['createdAfter'] -%>" size="10" maxlength="10" class="marginbottom5">
+      <br>
+      <%= message 'issue_filter.criteria.created_before' -%>:<br>
+      <input type="text" name="createdBefore" value="<%= @filter.criteria['createdBefore'] -%>" size="10" maxlength="10"><br>
+      <span class="small gray"><%= message 'issue_filter.criteria.date_format' -%></span>
+    </li>
     <li>
       <input type="submit" name="search" value="<%= message('search_verb') -%>" id="search-button" />
       <a href="<%= ApplicationController.root_context -%>/issues" class="link-action"><%= message 'issue_filter.new_search' -%></a>