]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-2443 Improve the user select-box when searching for review
authorFabrice Bellingard <bellingard@gmail.com>
Tue, 24 May 2011 13:22:06 +0000 (15:22 +0200)
committerFabrice Bellingard <bellingard@gmail.com>
Tue, 24 May 2011 17:03:19 +0000 (19:03 +0200)
- For field "author" and "assignee"
- Done as a reusable component

sonar-server/src/main/webapp/WEB-INF/app/controllers/reviews_controller.rb
sonar-server/src/main/webapp/WEB-INF/app/controllers/users_controller.rb
sonar-server/src/main/webapp/WEB-INF/app/helpers/users_helper.rb
sonar-server/src/main/webapp/WEB-INF/app/views/autocomplete/_text_field.html.erb [new file with mode: 0644]
sonar-server/src/main/webapp/WEB-INF/app/views/reviews/index.html.erb
sonar-server/src/main/webapp/WEB-INF/app/views/users/_autocomplete.html.erb [new file with mode: 0644]
sonar-server/src/main/webapp/stylesheets/style.css

index 58fe6a6190eca447ce75768ff0e2f15f09fee3d7..8ab6f3a2f7478bd07af71c7856b4bf4d632b2634 100644 (file)
@@ -26,7 +26,7 @@ class ReviewsController < ApplicationController
          :only => [:assign, :comment_form, :flag_as_false_positive, 
                    :violation_assign, :violation_flag_as_false_positive,:violation_save_comment, :violation_delete_comment], 
          :redirect_to => {:action => :error_not_post}
-  helper SourceHelper
+  helper SourceHelper, UsersHelper
 
   def index
     init_params()
@@ -270,9 +270,9 @@ class ReviewsController < ApplicationController
 
   def init_params
     @user_names = [["Any", ""]] + options_for_users
-    default_user = (current_user ? [current_user.id.to_s] : [''])
-    @authors = filter_any(params[:authors]) || ['']
-    @assignees = filter_any(params[:assignees]) || default_user
+    default_user = (current_user ? current_user.id : '')
+    @assignee_id = params[:assignee_id] || default_user
+    @author_id = params[:author_id] || ''
     @severities = filter_any(params[:severities]) || ['']
     @statuses = filter_any(params[:statuses]) || [Review::STATUS_OPEN]
     @projects = filter_any(params[:projects]) || ['']
@@ -311,11 +311,11 @@ class ReviewsController < ApplicationController
     unless @severities == ['']
       options['severities']=@severities.join(',')
     end
-    unless @authors == ['']
-      options['authors']=@authors.map{|s| s.to_i}.join(',')
+    if @author_id
+      options['authors']=@author_id.to_s
     end
-    unless @assignees == ['']
-      options['assignees']=@assignees.map{|s| s.to_i}.join(',')
+    if @assignee_id
+      options['assignees']=@assignee_id.to_s
     end
     unless @id  == ''
       if is_number? @id
index 19ccb8ae9852b0575e3456f5c637462bbf7561df..fb82342a0a64a66ff295bee88faae516363b7937 100644 (file)
@@ -21,8 +21,8 @@
 class UsersController < ApplicationController
 
   SECTION=Navigation::SECTION_CONFIGURATION
-  before_filter :admin_required, :except => ['new', 'signup']
-  skip_before_filter :check_authentication, :only => ['new', 'signup']
+  before_filter :admin_required, :except => ['new', 'signup', 'autocomplete']
+  skip_before_filter :check_authentication, :only => ['new', 'signup', 'autocomplete']
 
   def create
     return unless request.post?
@@ -129,4 +129,11 @@ class UsersController < ApplicationController
     user.groups<<default_group if default_group
     user
   end
+  
+  def autocomplete
+    @users = User.find(:all, :conditions => ["UPPER(name) like UPPER(?)", params[:user_name_start]+"%"])
+    @char_count = params[:user_name_start].size
+    render :partial => 'autocomplete'
+  end
+  
 end
index c9c91ccf68df6d01c87cfa1349137f8dc4a611cb..a99f1fd7b3094c4bc8c88c0b6319e7e6afba10d6 100644 (file)
@@ -108,5 +108,33 @@ module UsersHelper
       link_to_login_with_IP content_text, options
     end
   end
+  
+  #
+  # Generates a text input field that knows how to contact the server to retrieve 
+  # and suggest a list of user names & IDs based on the first letters typed by
+  # the user.
+  # The text input displays a string (the name of the user) but the real input 
+  # field that is submitted is a hidden one that contains the user ID that corresponds
+  # to the typed name (if the user exists, of course).
+  #
+  # Example:
+  #   <%= user_autocomplete_field "assignee_id", @assignee_id -%>
+  #   # => generates an input field for the parameter 'assignee_id'
+  #
+  def user_autocomplete_field(param_id, param_value)
+    param_id_name = param_id
+    param_id_value = param_value
+    
+    unless param_id_value.blank?
+      user = User.find(param_id_value)
+      param_displayed_value = user.name if user
+      param_displayed_value += " (me)" if user && current_user && current_user.id == param_id_value.to_i
+    end
+    
+    server_url = url_for :controller => 'users', :action => 'autocomplete'
+    
+    render :partial => 'autocomplete/text_field', :locals => {:param_id_name => param_id_name, :param_id_value => param_id_value, 
+                                                              :param_displayed_value => param_displayed_value, :server_url => server_url }
+  end
 
 end
diff --git a/sonar-server/src/main/webapp/WEB-INF/app/views/autocomplete/_text_field.html.erb b/sonar-server/src/main/webapp/WEB-INF/app/views/autocomplete/_text_field.html.erb
new file mode 100644 (file)
index 0000000..3930072
--- /dev/null
@@ -0,0 +1,17 @@
+  <input type="text" id="autocompleteText-<%= param_id_name -%>" value="<%= param_displayed_value -%>" onkeyup="if (this.value=='') $('<%= param_id_name -%>').value='';"/>
+  <input type="hidden" id="<%= param_id_name -%>" name="<%= param_id_name -%>" value="<%= param_id_value -%>"/>
+  <span id="load-<%= param_id_name -%>" style="display: none">
+    <%= image_tag("loading.gif") -%>
+  </span>
+  <div id="autocomplete-<%= param_id_name -%>" class="autocomplete"></div>
+  <script>
+    new Ajax.Autocompleter("autocompleteText-<%= param_id_name -%>", "autocomplete-<%= param_id_name -%>", "<%= server_url -%>", {
+      paramName: "user_name_start", 
+      minChars: 2, 
+      indicator: 'load-<%= param_id_name -%>',
+      afterUpdateElement : getSelection<%= param_id_name -%>
+    });
+    function getSelection<%= param_id_name -%>(text, li) {
+      $('<%= param_id_name -%>').value = li.id
+    }
+  </script>
\ No newline at end of file
index 5b4b818387cdae4af2cf333af062e2bf0ba946bb..0ea652fc444faa84f963befff262394b9d59c497 100644 (file)
@@ -4,8 +4,10 @@ function reviewIdFieldModified(field) {
     $('statuses').value = ''
     $('severities').value = ''
     $('projects').value = ''
-    $('authors').value = ''
-    $('assignees').value = ''
+    $('author_id').value = ''
+    $('autocompleteText-author_id').value = ''
+    $('assignee_id').value = ''
+    $('autocompleteText-assignee_id').value = ''    
   }
 }
 function launchSearch(columnName, link) {
@@ -48,7 +50,6 @@ function launchSearch(columnName, link) {
             <option value="<%= Severity::INFO -%>" class="sev_INFO" <%= 'selected' if @severities.include?(Severity::INFO) -%>>Info</option>
            </select>
         </td>
-
         <td width="1%" nowrap>
           <span class="note">Project</span><br/>
           <select size="6" name="projects[]" multiple="multiple" id="projects">
@@ -60,14 +61,13 @@ function launchSearch(columnName, link) {
             <% end %>
           </select>
         </td>
-
         <td width="1%" nowrap>
           <span class="note">Created by</span><br/>
-          <%= select_tag "authors", options_for_select(@user_names, @authors), :multiple => true, :size => 6 %>
-        </td>
-        <td width="1%" nowrap>
+          <%= user_autocomplete_field "author_id", @author_id -%>
+          <br/>
           <span class="note">Assigned to</span><br/>
-          <%= select_tag "assignees", options_for_select(@user_names, @assignees), :multiple => true, :size => 6 %>
+          <%= user_autocomplete_field "assignee_id", @assignee_id -%>
+          <br/>
         </td>
         <td width="1%" nowrap>
           <span class="note">Id</span><br/>
diff --git a/sonar-server/src/main/webapp/WEB-INF/app/views/users/_autocomplete.html.erb b/sonar-server/src/main/webapp/WEB-INF/app/views/users/_autocomplete.html.erb
new file mode 100644 (file)
index 0000000..415f6eb
--- /dev/null
@@ -0,0 +1,9 @@
+<% current_user_id = current_user.id if current_user %>
+<ul>
+  <% 
+    @users.each do |user|
+      user_name =  user.name
+  %>
+    <li id="<%= h(user.id) -%>"><strong><%= h(user_name)[0..@char_count-1] -%></strong><%= h(user_name)[@char_count..user_name.size-1] -%> <i><%= "(me)" if current_user_id == user.id -%></i></li>
+  <% end %>
+</ul>
index 40cc82ebe7759bbadf2e80683e9c649bb721afc7..6fa9beb0a19b312441de5ecf1b28e361131dff76 100644 (file)
@@ -830,7 +830,7 @@ span.rulename a:hover {
 
 
 
-
+/* REVIEWS */
 div#review .actions{
   visibility: hidden;
 }
@@ -906,7 +906,39 @@ div.comment-excerpt {
 }
 
 
-
+/* AUTOCOMPLETE FIELDS */
+div.autocomplete {
+  position:absolute;
+  width:250px;
+  background-color:#fff;
+  border:1px solid #ccc;
+  margin:0;
+  padding:0;
+  color: #111;
+  line-height: 1em;
+}
+div.autocomplete ul {
+  list-style-type:none;
+  margin:0;
+  padding:0;
+}
+div.autocomplete ul li.selected { 
+  background-color: #4b9fd5;
+  color: #fff;
+  margin: 0;
+}
+div.autocomplete ul li {
+  list-style-type:none;
+  display:block;
+  margin:0;
+  padding: 5px 10px;
+  cursor:pointer;
+  color: #333;
+  line-height: 1em;
+}
+div.autocomplete strong {
+  font-weight: bold;
+}