From 4b6fbec3e9fc12e5be02878c23b313c460a1266d Mon Sep 17 00:00:00 2001 From: Fabrice Bellingard Date: Tue, 24 May 2011 15:22:06 +0200 Subject: [PATCH] SONAR-2443 Improve the user select-box when searching for review - For field "author" and "assignee" - Done as a reusable component --- .../app/controllers/reviews_controller.rb | 16 ++++----- .../app/controllers/users_controller.rb | 11 ++++-- .../WEB-INF/app/helpers/users_helper.rb | 28 +++++++++++++++ .../views/autocomplete/_text_field.html.erb | 17 +++++++++ .../WEB-INF/app/views/reviews/index.html.erb | 16 ++++----- .../app/views/users/_autocomplete.html.erb | 9 +++++ .../src/main/webapp/stylesheets/style.css | 36 +++++++++++++++++-- 7 files changed, 113 insertions(+), 20 deletions(-) create mode 100644 sonar-server/src/main/webapp/WEB-INF/app/views/autocomplete/_text_field.html.erb create mode 100644 sonar-server/src/main/webapp/WEB-INF/app/views/users/_autocomplete.html.erb diff --git a/sonar-server/src/main/webapp/WEB-INF/app/controllers/reviews_controller.rb b/sonar-server/src/main/webapp/WEB-INF/app/controllers/reviews_controller.rb index 58fe6a6190e..8ab6f3a2f74 100644 --- a/sonar-server/src/main/webapp/WEB-INF/app/controllers/reviews_controller.rb +++ b/sonar-server/src/main/webapp/WEB-INF/app/controllers/reviews_controller.rb @@ -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 diff --git a/sonar-server/src/main/webapp/WEB-INF/app/controllers/users_controller.rb b/sonar-server/src/main/webapp/WEB-INF/app/controllers/users_controller.rb index 19ccb8ae985..fb82342a0a6 100644 --- a/sonar-server/src/main/webapp/WEB-INF/app/controllers/users_controller.rb +++ b/sonar-server/src/main/webapp/WEB-INF/app/controllers/users_controller.rb @@ -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< ["UPPER(name) like UPPER(?)", params[:user_name_start]+"%"]) + @char_count = params[:user_name_start].size + render :partial => 'autocomplete' + end + end diff --git a/sonar-server/src/main/webapp/WEB-INF/app/helpers/users_helper.rb b/sonar-server/src/main/webapp/WEB-INF/app/helpers/users_helper.rb index c9c91ccf68d..a99f1fd7b30 100644 --- a/sonar-server/src/main/webapp/WEB-INF/app/helpers/users_helper.rb +++ b/sonar-server/src/main/webapp/WEB-INF/app/helpers/users_helper.rb @@ -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 index 00000000000..393007219de --- /dev/null +++ b/sonar-server/src/main/webapp/WEB-INF/app/views/autocomplete/_text_field.html.erb @@ -0,0 +1,17 @@ + + + +
+ \ No newline at end of file diff --git a/sonar-server/src/main/webapp/WEB-INF/app/views/reviews/index.html.erb b/sonar-server/src/main/webapp/WEB-INF/app/views/reviews/index.html.erb index 5b4b818387c..0ea652fc444 100644 --- a/sonar-server/src/main/webapp/WEB-INF/app/views/reviews/index.html.erb +++ b/sonar-server/src/main/webapp/WEB-INF/app/views/reviews/index.html.erb @@ -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) { - Project
- Created by
- <%= select_tag "authors", options_for_select(@user_names, @authors), :multiple => true, :size => 6 %> - - + <%= user_autocomplete_field "author_id", @author_id -%> +
Assigned to
- <%= select_tag "assignees", options_for_select(@user_names, @assignees), :multiple => true, :size => 6 %> + <%= user_autocomplete_field "assignee_id", @assignee_id -%> +
Id
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 index 00000000000..415f6eb3ddc --- /dev/null +++ b/sonar-server/src/main/webapp/WEB-INF/app/views/users/_autocomplete.html.erb @@ -0,0 +1,9 @@ +<% current_user_id = current_user.id if current_user %> + diff --git a/sonar-server/src/main/webapp/stylesheets/style.css b/sonar-server/src/main/webapp/stylesheets/style.css index 40cc82ebe77..6fa9beb0a19 100644 --- a/sonar-server/src/main/webapp/stylesheets/style.css +++ b/sonar-server/src/main/webapp/stylesheets/style.css @@ -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; +} -- 2.39.5