diff options
author | Simon Brandhof <simon.brandhof@gmail.com> | 2012-04-01 17:59:35 +0200 |
---|---|---|
committer | Simon Brandhof <simon.brandhof@gmail.com> | 2012-04-01 17:59:35 +0200 |
commit | 95e88b5521a5362c3d493cea20eb3a02fa1a03a8 (patch) | |
tree | 82e07d3d7638ef386ed2b44ce39f1de36661fa35 /sonar-server | |
parent | c0ce45747b734a106b90771c104ce3d7f374ada3 (diff) | |
download | sonarqube-95e88b5521a5362c3d493cea20eb3a02fa1a03a8.tar.gz sonarqube-95e88b5521a5362c3d493cea20eb3a02fa1a03a8.zip |
Improve the ruby class Api::Pagination
Diffstat (limited to 'sonar-server')
5 files changed, 38 insertions, 22 deletions
diff --git a/sonar-server/src/main/webapp/WEB-INF/app/controllers/roles_controller.rb b/sonar-server/src/main/webapp/WEB-INF/app/controllers/roles_controller.rb index c239a383b15..fdb364e30d7 100644 --- a/sonar-server/src/main/webapp/WEB-INF/app/controllers/roles_controller.rb +++ b/sonar-server/src/main/webapp/WEB-INF/app/controllers/roles_controller.rb @@ -39,19 +39,19 @@ class RolesController < ApplicationController conditions_sql = 'projects.enabled=:enabled and projects.qualifier=:qualifier' conditions_values = {:enabled => true, :qualifier => @qualifier} - if params[:q].present? && params[:q].size>=ResourceIndex::MIN_SEARCH_SIZE - conditions_sql += ' and projects.id in (select ri.resource_id from resource_index ri where ri.qualifier=:qualifier and ri.kee like :filter)' - conditions_values[:filter]="#{params[:q].downcase}%" + if params[:q].present? + conditions_sql += ' and projects.id in (select ri.resource_id from resource_index ri where ri.qualifier=:qualifier and ri.kee like :search)' + conditions_values[:search]="#{params[:q].downcase}%" end @pagination = Api::Pagination.new(params.merge(:per_page => 50)) - @pagination.results= Project.count(:conditions => [conditions_sql, conditions_values]) @projects=Project.find(:all, :include => %w(user_roles group_roles index), :conditions => [conditions_sql, conditions_values], :order => 'resource_index.kee', :offset => @pagination.offset, :limit => @pagination.limit) + @pagination.count=Project.count(:conditions => [conditions_sql, conditions_values]) end def edit_users diff --git a/sonar-server/src/main/webapp/WEB-INF/app/models/api/pagination.rb b/sonar-server/src/main/webapp/WEB-INF/app/models/api/pagination.rb index cb74b5299ea..b5a256f8805 100644 --- a/sonar-server/src/main/webapp/WEB-INF/app/models/api/pagination.rb +++ b/sonar-server/src/main/webapp/WEB-INF/app/models/api/pagination.rb @@ -20,22 +20,30 @@ class Api::Pagination DEFAULT_PER_PAGE=25 - attr_accessor :per_page, :page, :results + + # entries per page + attr_accessor :per_page + + # index of selected page. Start with 1. + attr_accessor :page + + # total count of entries, greater or equal than 0 + attr_accessor :count + + # optional reference to the entries of the selected page + attr_accessor :page_entries def initialize(options={}) @per_page=options[:per_page]||DEFAULT_PER_PAGE @page=options[:page].to_i @page=1 if @page<1 - @results = options[:results].to_i + @count = options[:count].to_i end def pages - @pages ||= - begin - p=(@results / @per_page) - p+=1 if @results % @per_page > 0 - p - end + p=(count / per_page) + p+=1 if count % per_page>0 + p end def offset @@ -47,11 +55,6 @@ class Api::Pagination per_page end - # inclusive index - #def to_index - # [results-1, (page * per_page)-1].min - #end - def previous? page>1 end @@ -59,4 +62,8 @@ class Api::Pagination def next? page<pages end + + def empty? + count==0 + end end diff --git a/sonar-server/src/main/webapp/WEB-INF/app/views/roles/projects.html.erb b/sonar-server/src/main/webapp/WEB-INF/app/views/roles/projects.html.erb index 0b6e6e1a3fc..8f9af84f47c 100644 --- a/sonar-server/src/main/webapp/WEB-INF/app/views/roles/projects.html.erb +++ b/sonar-server/src/main/webapp/WEB-INF/app/views/roles/projects.html.erb @@ -70,8 +70,8 @@ <tr> <th> <form action="<%= url_for :action => 'projects', :qualifier => @qualifier -%>" method="GET"> - <input type="text" name="q" value="<%= params[:q] -%>" id="filter_text"/> - <input type="submit" value="Filter" id="filter_submit"/> + <input type="text" name="q" value="<%= params[:q] -%>" id="search_text"/> + <input type="submit" value="Search" id="search_submit"/> </form> </th> <th>Role: Administrators</th> @@ -130,4 +130,7 @@ end %> </tbody> </table> -</div>
\ No newline at end of file +</div> +<script> + $('search_text').focus(); +</script>
\ No newline at end of file diff --git a/sonar-server/src/main/webapp/WEB-INF/app/views/utils/_tfoot_pagination.html.erb b/sonar-server/src/main/webapp/WEB-INF/app/views/utils/_tfoot_pagination.html.erb index 3e27189cc4b..ea752abaa23 100644 --- a/sonar-server/src/main/webapp/WEB-INF/app/views/utils/_tfoot_pagination.html.erb +++ b/sonar-server/src/main/webapp/WEB-INF/app/views/utils/_tfoot_pagination.html.erb @@ -1,8 +1,8 @@ <tfoot> <tr> <td colspan="<%= colspan || 1 -%>"> - <% if pagination.results>0 %> - <%= pagination.results -%> <%= message('results').downcase -%> + <% if pagination.count>0 %> + <%= pagination.count -%> <%= message('results').downcase -%> <% end %> <% if pagination.pages>1 diff --git a/sonar-server/src/main/webapp/stylesheets/style.css b/sonar-server/src/main/webapp/stylesheets/style.css index 4ffc233f0f4..10ad01d82d5 100644 --- a/sonar-server/src/main/webapp/stylesheets/style.css +++ b/sonar-server/src/main/webapp/stylesheets/style.css @@ -2463,6 +2463,12 @@ td.spacer-top { padding: 4px 5px; vertical-align: top; } +.table > tfoot > tr > td { + font-size: 93%; + color: #777; + padding: 4px 5px; +} + .table-bordered > tbody { border-left: 1px solid #DDD; |