From: Simon Brandhof Date: Wed, 19 Dec 2012 09:59:07 +0000 (+0100) Subject: Fix sorting by time + fix sorting in list widget X-Git-Tag: 3.4~16 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=14211c7c028056ce00756aaeee88e1256c16dc6e;p=sonarqube.git Fix sorting by time + fix sorting in list widget --- diff --git a/plugins/sonar-core-plugin/src/main/resources/org/sonar/l10n/core.properties b/plugins/sonar-core-plugin/src/main/resources/org/sonar/l10n/core.properties index 787986ec9fd..e0ec07ada5c 100644 --- a/plugins/sonar-core-plugin/src/main/resources/org/sonar/l10n/core.properties +++ b/plugins/sonar-core-plugin/src/main/resources/org/sonar/l10n/core.properties @@ -394,7 +394,7 @@ measure_filter.shared_with_all_users=Shared with all users measure_filter.private=Private measure_filter.manage.shared_filters=Shared Filters measure_filter.manage.my_filters=My Filters -measure_filter.criteria.what=What? +measure_filter.criteria.what=What? Projects, files... measure_filter.criteria.age=Age measure_filter.criteria.date=Date measure_filter.criteria.only_favourites=Favourites only diff --git a/sonar-core/src/main/java/org/sonar/core/measure/MeasureFilterRow.java b/sonar-core/src/main/java/org/sonar/core/measure/MeasureFilterRow.java index a168e340111..3ad737195db 100644 --- a/sonar-core/src/main/java/org/sonar/core/measure/MeasureFilterRow.java +++ b/sonar-core/src/main/java/org/sonar/core/measure/MeasureFilterRow.java @@ -21,14 +21,14 @@ package org.sonar.core.measure; import org.apache.commons.lang.StringUtils; -import java.sql.Date; +import java.sql.Timestamp; public class MeasureFilterRow { private final long snapshotId; private final long resourceId; private final long resourceRootId; private String sortText = null; - private Date sortDate = null; + private Timestamp sortDate = null; private Double sortDouble = null; MeasureFilterRow(long snapshotId, long resourceId, long resourceRootId) { @@ -57,11 +57,11 @@ public class MeasureFilterRow { this.sortText = StringUtils.defaultString(s); } - Date getSortDate() { + Timestamp getSortDate() { return sortDate; } - void setSortDate(Date sortDate) { + void setSortDate(Timestamp sortDate) { this.sortDate = sortDate; } diff --git a/sonar-core/src/main/java/org/sonar/core/measure/MeasureFilterSql.java b/sonar-core/src/main/java/org/sonar/core/measure/MeasureFilterSql.java index 78de713e2b6..d8f2d8a4149 100644 --- a/sonar-core/src/main/java/org/sonar/core/measure/MeasureFilterSql.java +++ b/sonar-core/src/main/java/org/sonar/core/measure/MeasureFilterSql.java @@ -22,7 +22,6 @@ package org.sonar.core.measure; import com.google.common.base.Function; import com.google.common.collect.Lists; import com.google.common.collect.Ordering; -import com.google.common.primitives.Doubles; import org.apache.commons.lang.StringEscapeUtils; import org.apache.commons.lang.StringUtils; import org.sonar.core.persistence.Database; @@ -36,6 +35,7 @@ import java.sql.Date; import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.SQLException; +import java.sql.Timestamp; import java.util.Comparator; import java.util.List; @@ -272,67 +272,34 @@ class MeasureFilterSql { } Ordering sortFieldOrdering(boolean ascending) { - if (ascending) { - return Ordering.from(new Comparator() { - public int compare(@Nullable Double left, @Nullable Double right) { - if (left == null) { - return 1; - } - if (right == null) { - return -1; - } - - return Doubles.compare(left, right); - } - }); - } - return Ordering.from(new Comparator() { - public int compare(@Nullable Double left, @Nullable Double right) { - if (left == null) { - return 1; - } - if (right == null) { - return -1; - } - - return -Doubles.compare(left, right); - } - }); + return newObjectOrdering(ascending); } } static class DateSortRowProcessor extends RowProcessor { MeasureFilterRow fetch(ResultSet rs) throws SQLException { MeasureFilterRow row = new MeasureFilterRow(rs.getLong(1), rs.getLong(2), rs.getLong(3)); - row.setSortDate(rs.getDate(4)); + row.setSortDate(rs.getTimestamp(4)); return row; } Function sortFieldFunction() { - return new Function() { - public Date apply(MeasureFilterRow row) { + return new Function() { + public Timestamp apply(MeasureFilterRow row) { return row.getSortDate(); } }; } Ordering sortFieldOrdering(boolean ascending) { - if (ascending) { - return Ordering.from(new Comparator() { - public int compare(@Nullable Date left, @Nullable Date right) { - if (left == null) { - return 1; - } - if (right == null) { - return -1; - } - - return left.compareTo(right); - } - }); - } - return Ordering.from(new Comparator() { - public int compare(@Nullable Date left, @Nullable Date right) { + return newObjectOrdering(ascending); + } + } + + private static Ordering newObjectOrdering(boolean ascending) { + if (ascending) { + return Ordering.from(new Comparator() { + public int compare(@Nullable Comparable left, @Nullable Comparable right) { if (left == null) { return 1; } @@ -340,9 +307,21 @@ class MeasureFilterSql { return -1; } - return -left.compareTo(right); + return left.compareTo(right); } }); } + return Ordering.from(new Comparator() { + public int compare(@Nullable Comparable left, @Nullable Comparable right) { + if (left == null) { + return 1; + } + if (right == null) { + return -1; + } + + return -left.compareTo(right); + } + }); } } diff --git a/sonar-server/src/main/webapp/WEB-INF/app/models/measure_filter_display_list.rb b/sonar-server/src/main/webapp/WEB-INF/app/models/measure_filter_display_list.rb index 2a109537790..4d139b0e998 100644 --- a/sonar-server/src/main/webapp/WEB-INF/app/models/measure_filter_display_list.rb +++ b/sonar-server/src/main/webapp/WEB-INF/app/models/measure_filter_display_list.rb @@ -20,7 +20,7 @@ require 'set' class MeasureFilterDisplayList < MeasureFilterDisplay KEY = :list - MAX_PAGE_SIZE = 200 + MAX_PAGE_SIZE = 250 class Column attr_reader :key, :metric, :period @@ -87,7 +87,7 @@ class MeasureFilterDisplayList < MeasureFilterDisplay filter.set_criteria_default_value(:cols, ['metric:alert_status', 'name', 'date', 'metric:ncloc', 'metric:violations', 'links']) filter.set_criteria_default_value(:sort, 'name') filter.set_criteria_default_value(:asc, true) - filter.set_criteria_default_value(:pageSize, 30) + filter.set_criteria_default_value(:pageSize, 100) filter.set_criteria_value(:pageSize, MAX_PAGE_SIZE) if filter.criteria(:pageSize).to_i>MAX_PAGE_SIZE @columns = [] diff --git a/sonar-server/src/main/webapp/WEB-INF/app/views/measures/_copy_form.html.erb b/sonar-server/src/main/webapp/WEB-INF/app/views/measures/_copy_form.html.erb index 019edbafc84..8ccf9a9e876 100644 --- a/sonar-server/src/main/webapp/WEB-INF/app/views/measures/_copy_form.html.erb +++ b/sonar-server/src/main/webapp/WEB-INF/app/views/measures/_copy_form.html.erb @@ -8,10 +8,6 @@ <% @filter.errors.each do |attr, msg| %>

<%= h msg -%>

<% 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 83654fa0081..597df3699a8 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,14 +1,16 @@
<% content_for :script do %> diff --git a/sonar-server/src/main/webapp/WEB-INF/app/views/measures/_display_treemap.html.erb b/sonar-server/src/main/webapp/WEB-INF/app/views/measures/_display_treemap.html.erb index 9715c75e694..9c6915325fd 100644 --- a/sonar-server/src/main/webapp/WEB-INF/app/views/measures/_display_treemap.html.erb +++ b/sonar-server/src/main/webapp/WEB-INF/app/views/measures/_display_treemap.html.erb @@ -1,3 +1,6 @@ + <% treemap_id = (defined? widget) ? widget.id : 1 unless edit_mode @@ -57,17 +60,17 @@ 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 6b3b340579c..54d231c9d23 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 @@ -1,11 +1,9 @@ -
+
<%= render :partial => 'measures/sidebar' -%>
<% if @filter && @filter.display %> - -
@@ -46,6 +44,7 @@
<% if @filter.id && @filter.name.present? %> +

<%= h @filter.name -%> <% if !@filter.shared %> @@ -58,12 +57,14 @@ [<%= message 'shared_by' -%> Sonar] <% end %> - <% if @filter.description.present? %> - - <%= h @filter.description -%> - <% end %> <% if @filter.owner?(current_user) %> -  <%= image_tag 'pencil-small.png', :alt => message('edit') -%> +  <%= image_tag 'pencil-small.png', :alt => message('edit') -%> + <% end %> +

+ <% if @filter.description.present? %> +

<%= h @filter.description -%>

<% end %> + <% end %>
diff --git a/sonar-server/src/main/webapp/stylesheets/layout.css b/sonar-server/src/main/webapp/stylesheets/layout.css index 1d706ab8baf..036f40c8f20 100644 --- a/sonar-server/src/main/webapp/stylesheets/layout.css +++ b/sonar-server/src/main/webapp/stylesheets/layout.css @@ -175,7 +175,7 @@ body, a { } #body { -/* position: relative;*/ + /* position: relative;*/ } #footer { @@ -193,7 +193,7 @@ body, a { #sidebar { width: 150px; - float:left; + float: left; margin: 0 0 0 10px; top: 0; left: 0; @@ -238,11 +238,11 @@ ul.sidebar li.spacer { margin: 0; padding: 0; } + ul.sidebar select, ul.sidebar input { font-size: 93%; } - #logo { text-align: center; padding: 10px 0 0 0; @@ -266,18 +266,19 @@ ul.sidebar select, ul.sidebar input { max-width: 200px; width: 200px; margin: 0; - display: block; + display: table-cell; vertical-align: top; border-top: none; border-left: none; - float: left; } .page-split-right { - display: block; + position: relative; + display: table-cell; margin: 0; vertical-align: top; - padding: 0 0 0 200px; + padding: 0; + width: 100%; } .gray-sidebar {