aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-server
diff options
context:
space:
mode:
authorSimon Brandhof <simon.brandhof@gmail.com>2012-12-12 07:54:42 +0100
committerSimon Brandhof <simon.brandhof@gmail.com>2012-12-12 07:54:42 +0100
commit2de6b4a37197ab978c104a87b7a8409bf0591dbd (patch)
tree75f4bb8a58c5d188be5eef75e677862750b20080 /sonar-server
parentce39ee5cefd82316c3941652625135659e67f764 (diff)
downloadsonarqube-2de6b4a37197ab978c104a87b7a8409bf0591dbd.tar.gz
sonarqube-2de6b4a37197ab978c104a87b7a8409bf0591dbd.zip
SONAR-3825 widget should support column sorting and pagination
Diffstat (limited to 'sonar-server')
-rw-r--r--sonar-server/src/main/webapp/WEB-INF/app/controllers/measures_controller.rb6
-rw-r--r--sonar-server/src/main/webapp/WEB-INF/app/helpers/application_helper.rb3
-rw-r--r--sonar-server/src/main/webapp/WEB-INF/app/helpers/measures_helper.rb4
-rw-r--r--sonar-server/src/main/webapp/WEB-INF/app/views/measures/_display.html.erb11
-rw-r--r--sonar-server/src/main/webapp/WEB-INF/app/views/measures/_display_list.html.erb123
-rw-r--r--sonar-server/src/main/webapp/WEB-INF/app/views/measures/search.html.erb12
-rw-r--r--sonar-server/src/main/webapp/WEB-INF/app/views/utils/_tfoot_ajax_pagination.html.erb48
-rw-r--r--sonar-server/src/main/webapp/WEB-INF/app/views/utils/_tfoot_pagination.html.erb13
8 files changed, 157 insertions, 63 deletions
diff --git a/sonar-server/src/main/webapp/WEB-INF/app/controllers/measures_controller.rb b/sonar-server/src/main/webapp/WEB-INF/app/controllers/measures_controller.rb
index 3447146fbff..a63af45542a 100644
--- a/sonar-server/src/main/webapp/WEB-INF/app/controllers/measures_controller.rb
+++ b/sonar-server/src/main/webapp/WEB-INF/app/controllers/measures_controller.rb
@@ -31,9 +31,13 @@ class MeasuresController < ApplicationController
else
@filter = MeasureFilter.new
end
- @filter.criteria=(params)
+ @filter.criteria=(params.merge({:controller => nil, :action => nil, :search => nil, :widget_id => nil}))
@filter.enable_default_display
@filter.execute(self, :user => current_user)
+
+ if request.xhr?
+ render :partial => 'measures/display', :locals => {:filter => @filter, :edit_mode => false, :widget_id => params[:widget_id]}
+ end
end
# Load existing filter
diff --git a/sonar-server/src/main/webapp/WEB-INF/app/helpers/application_helper.rb b/sonar-server/src/main/webapp/WEB-INF/app/helpers/application_helper.rb
index 81684742838..99a440fe75c 100644
--- a/sonar-server/src/main/webapp/WEB-INF/app/helpers/application_helper.rb
+++ b/sonar-server/src/main/webapp/WEB-INF/app/helpers/application_helper.rb
@@ -688,4 +688,7 @@ module ApplicationHelper
"<a href='#{url}' modal-width='#{width}' class='open-modal #{clazz}' #{id}>#{h label}</a>"
end
+ def link_to_function_if(condition, name, *args)
+ condition ? link_to_function(name, args) : name
+ end
end
diff --git a/sonar-server/src/main/webapp/WEB-INF/app/helpers/measures_helper.rb b/sonar-server/src/main/webapp/WEB-INF/app/helpers/measures_helper.rb
index 05b3e471d39..64ccbf731d3 100644
--- a/sonar-server/src/main/webapp/WEB-INF/app/helpers/measures_helper.rb
+++ b/sonar-server/src/main/webapp/WEB-INF/app/helpers/measures_helper.rb
@@ -19,9 +19,9 @@
#
module MeasuresHelper
- def list_column_html(filter, column)
+ def list_column_html(filter, column, widget_id)
if column.sort?
- html = link_to_function(h(column.title_label), "reloadParameters({asc:'#{(!filter.sort_asc?).to_s}', sort:'#{column.key}'})", :title => h(column.tooltip))
+ html = link_to_function(h(column.title_label), "sortList#{widget_id}('#{escape_javascript column.key}',#{!filter.sort_asc?})", :title => h(column.tooltip))
else
html=h(column.title_label)
end
diff --git a/sonar-server/src/main/webapp/WEB-INF/app/views/measures/_display.html.erb b/sonar-server/src/main/webapp/WEB-INF/app/views/measures/_display.html.erb
new file mode 100644
index 00000000000..09d7858646a
--- /dev/null
+++ b/sonar-server/src/main/webapp/WEB-INF/app/views/measures/_display.html.erb
@@ -0,0 +1,11 @@
+<% if filter.security_exclusions %>
+ <p class="notes"><%= message('results_not_display_due_to_security') -%></p>
+<% end %>
+
+<% if !filter.errors.empty? %>
+ <% filter.errors.full_messages.each do |message| %>
+ <div class="warning"><%= h message %></div>
+ <% end %>
+<% elsif filter.rows && filter.display %>
+ <%= render :partial => "measures/display_#{filter.display.class::KEY}", :locals => {:filter => filter, :edit_mode => edit_mode, :widget_id => widget_id} -%>
+<% end %>
diff --git a/sonar-server/src/main/webapp/WEB-INF/app/views/measures/_display_list.html.erb b/sonar-server/src/main/webapp/WEB-INF/app/views/measures/_display_list.html.erb
index df8ad570af0..8e9f33549c4 100644
--- a/sonar-server/src/main/webapp/WEB-INF/app/views/measures/_display_list.html.erb
+++ b/sonar-server/src/main/webapp/WEB-INF/app/views/measures/_display_list.html.erb
@@ -1,4 +1,30 @@
+<div id="measure_filter_list<%= widget_id -%>">
+<% content_for :script do %>
+ <script>
+ function refreshUrl<%= widget_id -%>(url) {
+ $j('#measure_filter_foot<%= widget_id -%>_pages').hide();
+ $j('#measure_filter_foot<%= widget_id -%>_loading').show();
+ <% if widget_id %>
+ $j('#measure_filter_list<%= widget_id -%>').load(url);
+ <% else %>
+ window.location = url;
+ <% end %>
+ return false;
+ }
+ function sortList<%= widget_id -%>(sort, asc) {
+ var url = decodeURI('<%= url_for filter.criteria.merge(:controller => 'measures', :action => 'search', :sort => nil, :asc => nil, :search => nil, :widget_id => widget_id, :trailing_slash => true) -%>');
+ url += '&sort=' + sort + '&asc=' + asc;
+ return refreshUrl<%= widget_id -%>(url);
+ }
+ function pageList<%= widget_id -%>(page) {
+ var url = decodeURI('<%= url_for filter.criteria.merge(:controller => 'measures', :action => 'search', :page => nil, :search => nil, :widget_id => widget_id, :trailing_slash => true) -%>');
+ url += '&page=' + page;
+ return refreshUrl<%= widget_id -%>(url);
+ }
+ </script>
<%
+ end
+
display_favourites = logged_in?
colspan = filter.display.columns.size
colspan += 1 if display_favourites
@@ -56,13 +82,48 @@
td1.remove();
});
}
+ $j(document).ready(function () {
+ $j("#select-metric").on("change", function (e) {
+ var selectedKey = $j("#select-metric option:selected").val();
+ if (selectedKey.indexOf('metric:') == 0) {
+ if (selectedKey.indexOf('metric:new_') == 0) {
+ $j('#select-period option :eq(0)').attr('disabled', 'disabled');
+ $j('#select-period ').val('1');
+ } else {
+ $j('#select-period option :eq(0)').removeAttr('disabled');
+ $j('#select-period').val('');
+ }
+ $j('#select-period').show();
+ } else {
+ $j('#select-period').hide();
+ }
+ $j("#add-metric").removeAttr('disabled');
+
+ });
+ $j("#add-metric").on("click", function (e) {
+ var columnKey = $j("#select-metric option:selected").val();
+ var period = $j("#select-period option:selected").val();
+ if (period.length > 0) {
+ columnKey += ':' + period;
+ }
+ cols.push(columnKey);
+ window.location = removeUrlAttr(decodeURI(window.location.href), 'cols\\[\\]') + '&' + $j.map(cols,function (a) {
+ return a ? 'cols[]=' + a : null;
+ }).join('&');
+ });
+ $j("#exit-edit").on("click", function (e) {
+ var url = removeUrlAttr(decodeURI(window.location.href), 'cols\\[\\]');
+ url = removeUrlAttr(url, 'edit');
+ url += '&' + $j.map(cols,function (a) {
+ return a ? 'cols[]=' + a : null;
+ }).join('&');
+ window.location = url;
+ });
+ });
</script>
<%
end
- end
%>
-
-<% if edit_mode %>
<table class="spaced width100 box">
<tr>
<td>
@@ -88,45 +149,9 @@
</td>
</tr>
</table>
- <script>
- $j("#select-metric").on("change", function (e) {
- var selectedKey = $j("#select-metric option:selected").val();
- if (selectedKey.indexOf('metric:') == 0) {
- if (selectedKey.indexOf('metric:new_') == 0) {
- $j('#select-period option :eq(0)').attr('disabled', 'disabled');
- $j('#select-period ').val('1');
- } else {
- $j('#select-period option :eq(0)').removeAttr('disabled');
- $j('#select-period').val('');
- }
- $j('#select-period').show();
- } else {
- $j('#select-period').hide();
- }
- $j("#add-metric").removeAttr('disabled');
-
- });
- $j("#add-metric").on("click", function (e) {
- var columnKey = $j("#select-metric option:selected").val();
- var period = $j("#select-period option:selected").val();
- if (period.length > 0) {
- columnKey += ':' + period;
- }
- cols.push(columnKey);
- window.location = removeUrlAttr(decodeURI(window.location.href), 'cols\\[\\]') + '&' + $j.map(cols,function (a) {
- return a ? 'cols[]=' + a : null;
- }).join('&');
- });
- $j("#exit-edit").on("click", function (e) {
- var url = removeUrlAttr(decodeURI(window.location.href), 'cols\\[\\]');
- url = removeUrlAttr(url, 'edit');
- url += '&' + $j.map(cols,function (a) {
- return a ? 'cols[]=' + a : null;
- }).join('&');
- window.location = url;
- });
- </script>
-<% end %>
+<%
+ end
+%>
<table class="data" id="measures-table">
<thead>
@@ -135,7 +160,7 @@
<th class="thin"></th>
<% end %>
<% filter.display.columns.each do |column| %>
- <%= list_column_html(filter, column) -%>
+ <%= list_column_html(filter, column, widget_id) -%>
<% end %>
</tr>
</thead>
@@ -188,5 +213,13 @@
<% end %>
</tbody>
- <%= render :partial => 'utils/tfoot_pagination', :locals => {:pagination => filter.pagination, :colspan => colspan} %>
-</table> \ No newline at end of file
+ <% pagination_partial = widget_id ? 'utils/tfoot_ajax_pagination' : 'utils/tfoot_pagination' %>
+ <%= render :partial => pagination_partial, :locals => {
+ :pagination => filter.pagination,
+ :colspan => colspan,
+ :id => "measure_filter_foot#{widget_id}",
+ :include_loading => true,
+ :js_function => "pageList#{widget_id}"
+ } -%>
+</table>
+</div> \ No newline at end of file
diff --git a/sonar-server/src/main/webapp/WEB-INF/app/views/measures/search.html.erb b/sonar-server/src/main/webapp/WEB-INF/app/views/measures/search.html.erb
index 7129a6b3748..242bb0e6f4e 100644
--- a/sonar-server/src/main/webapp/WEB-INF/app/views/measures/search.html.erb
+++ b/sonar-server/src/main/webapp/WEB-INF/app/views/measures/search.html.erb
@@ -56,17 +56,7 @@
</div>
</div>
- <% if @filter.security_exclusions %>
- <p class="notes"><%= message('results_not_display_due_to_security') -%></p>
- <% end %>
-
- <% if !@filter.errors.empty? %>
- <% @filter.errors.full_messages.each do |message| %>
- <div class="warning"><%= h message %></div>
- <% end %>
- <% elsif @filter.rows && @filter.display %>
- <%= render :partial => "measures/display_#{@filter.display.class::KEY}", :locals => {:filter => @filter, :edit_mode => edit_mode} -%>
- <% end %>
+ <%= render :partial => 'measures/display', :locals => {:filter => @filter, :edit_mode => edit_mode, :widget_id => nil} -%>
</div>
</div>
<% end %>
diff --git a/sonar-server/src/main/webapp/WEB-INF/app/views/utils/_tfoot_ajax_pagination.html.erb b/sonar-server/src/main/webapp/WEB-INF/app/views/utils/_tfoot_ajax_pagination.html.erb
new file mode 100644
index 00000000000..2ee7bb04433
--- /dev/null
+++ b/sonar-server/src/main/webapp/WEB-INF/app/views/utils/_tfoot_ajax_pagination.html.erb
@@ -0,0 +1,48 @@
+<tfoot <%= "id=#{id}" if id -%>>
+<tr>
+ <td colspan="<%= colspan || 1 -%>">
+ <div <%= "id=#{id}_pages" if id -%>>
+ <% if pagination.count > 0 %>
+ <%= message('x_results', :params => [pagination.count]) -%>
+ <% end %>
+ <%
+ if pagination.pages > 1
+ max_pages = pagination.pages
+ current_page = pagination.page
+ start_page = 1
+ end_page = max_pages
+ if max_pages > 20
+ if current_page < 12
+ start_page = 1
+ end_page = 20
+ elsif current_page > max_pages-10
+ start_page = max_pages-20
+ end_page = max_pages
+ else
+ start_page = current_page-10
+ end_page = current_page+9
+ end
+ end
+ %>
+ |
+ <% if max_pages > 20 && start_page > 1 %>
+ <%= link_to_function_if current_page != 1, message('paging_first'), "#{js_function}(1)" -%>
+ <% end %>
+ <%= link_to_function_if pagination.previous?, message('paging_previous'), "#{js_function}(#{current_page-1})" -%>
+ <% for index in start_page..end_page %>
+ <%= link_to_function_if index != current_page, index.to_s, "#{js_function}(#{index})" -%>
+ <% end %>
+ <%= link_to_function_if pagination.next?, message('paging_next'), "#{js_function}(#{current_page+1})" -%>
+ <% if max_pages > 20 && end_page < max_pages %>
+ <%= link_to_function_if current_page != max_pages, message('paging_last'), "#{js_function}(#{max_pages})" -%>
+ <%
+ end
+ end
+ %>
+ </div>
+ <% if id && local_assigns[:include_loading] %>
+ <img src="<%= ApplicationController.root_context -%>/images/loading-small.gif" style="display: none" id="<%= id -%>_loading">
+ <% end %>
+ </td>
+</tr>
+</tfoot> \ 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 f50dafc2aa1..b35a2976be0 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,6 +1,7 @@
-<tfoot>
+<tfoot <%= "id=#{id}" if id -%>>
<tr>
<td colspan="<%= colspan || 1 -%>">
+ <div <%= "id=#{id}_pages" if id -%>>
<% if pagination.count > 0 %>
<%= message('x_results', :params => [pagination.count]) -%>
<% end %>
@@ -25,7 +26,7 @@
%>
|
<% if max_pages > 20 && start_page > 1 %>
- <%= link_to_if current_page != 1, message('paging_first'), params.merge(:page => 1) %>
+ <%= link_to_if current_page != 1, message('paging_first'), params.merge(:page => 1) %>
<% end %>
<%= link_to_if pagination.previous?, message('paging_previous'), params.merge(:page => current_page-1) %>
<% for index in start_page..end_page %>
@@ -33,11 +34,15 @@
<% end %>
<%= link_to_if pagination.next?, message('paging_next'), params.merge(:page => current_page+1) %>
<% if max_pages > 20 && end_page < max_pages %>
- <%= link_to_if current_page != max_pages, message('paging_last'), params.merge(:page => max_pages) %>
+ <%= link_to_if current_page != max_pages, message('paging_last'), params.merge(:page => max_pages) %>
<% end %>
- <%
+ <%
end
%>
+ </div>
+ <% if id && local_assigns[:include_loading] %>
+ <img src="<%= ApplicationController.root_context -%>/images/loading-small.gif" style="display: none" id="<%= id -%>_loading">
+ <% end %>
</td>
</tr>
</tfoot> \ No newline at end of file