diff options
author | Fabrice Bellingard <bellingard@gmail.com> | 2011-05-24 15:22:06 +0200 |
---|---|---|
committer | Fabrice Bellingard <bellingard@gmail.com> | 2011-05-24 19:03:19 +0200 |
commit | 4b6fbec3e9fc12e5be02878c23b313c460a1266d (patch) | |
tree | 6d2dced867691e856f4021e110ca3fa823008893 /sonar-server | |
parent | 3e32f3cd621a9c751d8355dda697e9fb224b3957 (diff) | |
download | sonarqube-4b6fbec3e9fc12e5be02878c23b313c460a1266d.tar.gz sonarqube-4b6fbec3e9fc12e5be02878c23b313c460a1266d.zip |
SONAR-2443 Improve the user select-box when searching for review
- For field "author" and "assignee"
- Done as a reusable component
Diffstat (limited to 'sonar-server')
7 files changed, 113 insertions, 20 deletions
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<<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 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 @@ + <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 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) { <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 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 %> +<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> 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; +} |