]> source.dussan.org Git - sonarqube.git/commitdiff
Fix sorting by time + fix sorting in list widget
authorSimon Brandhof <simon.brandhof@gmail.com>
Wed, 19 Dec 2012 09:59:07 +0000 (10:59 +0100)
committerSimon Brandhof <simon.brandhof@gmail.com>
Wed, 19 Dec 2012 09:59:07 +0000 (10:59 +0100)
plugins/sonar-core-plugin/src/main/resources/org/sonar/l10n/core.properties
sonar-core/src/main/java/org/sonar/core/measure/MeasureFilterRow.java
sonar-core/src/main/java/org/sonar/core/measure/MeasureFilterSql.java
sonar-server/src/main/webapp/WEB-INF/app/models/measure_filter_display_list.rb
sonar-server/src/main/webapp/WEB-INF/app/views/measures/_copy_form.html.erb
sonar-server/src/main/webapp/WEB-INF/app/views/measures/_display_list.html.erb
sonar-server/src/main/webapp/WEB-INF/app/views/measures/_display_treemap.html.erb
sonar-server/src/main/webapp/WEB-INF/app/views/measures/search.html.erb
sonar-server/src/main/webapp/stylesheets/layout.css

index 787986ec9fd70a47c5c147a4fc17c1a87b94db7f..e0ec07ada5cb770951f2c2a4b3409d5f352e7653 100644 (file)
@@ -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
index a168e3401118021319397bccaa6b88afb958157f..3ad737195db9c38cec80830898c13d0b9bdc130b 100644 (file)
@@ -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;
   }
 
index 78de713e2b680828af110559fce6d967840a5b1f..d8f2d8a4149a5e41800d248086b7400a8df13c33 100644 (file)
@@ -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<Double>() {
-          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<Double>() {
-        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<MeasureFilterRow, Date>() {
-        public Date apply(MeasureFilterRow row) {
+      return new Function<MeasureFilterRow, Timestamp>() {
+        public Timestamp apply(MeasureFilterRow row) {
           return row.getSortDate();
         }
       };
     }
 
     Ordering sortFieldOrdering(boolean ascending) {
-      if (ascending) {
-        return Ordering.from(new Comparator<Date>() {
-          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<Date>() {
-        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<Comparable>() {
+        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<Comparable>() {
+      public int compare(@Nullable Comparable left, @Nullable Comparable right) {
+        if (left == null) {
+          return 1;
+        }
+        if (right == null) {
+          return -1;
+        }
+
+        return -left.compareTo(right);
+      }
+    });
   }
 }
index 2a109537790497454eef5e9d096a1e32ce4107de..4d139b0e9985273c7c6c3de087f2945d215da1b8 100644 (file)
@@ -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 = []
index 019edbafc84e538c126c291e9c2b76ccb87dcf02..8ccf9a9e87623081d6a1cf162f0040df0b1a4225 100644 (file)
@@ -8,10 +8,6 @@
       <% @filter.errors.each do |attr, msg| %>
         <p class="error"><%= h msg -%></p>
       <% end %>
-      <div class="form-field">
-        <label>Copy</label>
-        <input type="text" size="50" maxlength="100" value="<%= h @filter.name -%>" disabled="disabled"/>
-      </div>
       <div class="form-field">
         <label for="name"><%= h message('name') -%> <em class="mandatory">*</em></label>
         <input id="name" name="name" type="text" size="50" maxlength="100" value=""/>
index 83654fa0081a4dc538d3f11f03226727c85d6a8b..597df3699a8b9bc7d0d386ebfe8b1a47cd01b340 100644 (file)
@@ -1,14 +1,16 @@
 <div id="measure_filter_list<%= widget_id -%>">
 <% content_for :script do %>
   <script>
+    var filterCriteria<%= widget_id -%> = <%= filter.criteria.to_json -%>;
+
     function refreshList<%= widget_id -%>(sort, asc, page) {
       $j('#measure_filter_foot<%= widget_id -%>_pages').hide();
       $j('#measure_filter_foot<%= widget_id -%>_loading').show();
 
-      filterCriteria['sort']=sort;
-      filterCriteria['asc']=asc;
-      filterCriteria['page']=page;
-      var url=baseUrl + '/measures/search/?' + $j.param(filterCriteria);
+      filterCriteria<%= widget_id -%>['sort']=sort;
+      filterCriteria<%= widget_id -%>['asc']=asc;
+      filterCriteria<%= widget_id -%>['page']=page;
+      var url=baseUrl + '/measures/search/<%= filter.id -%>?widget_id=<%= widget_id -%>&' + $j.param(filterCriteria<%= widget_id -%>);
 
       <% if widget_id %>
       $j('#measure_filter_list<%= widget_id -%>').load(url);
@@ -37,7 +39,7 @@
         }
       }
       function rightCol(id) {
-        var cols = filterCriteria['cols']||[];
+        var cols = filterCriteria<%= widget_id -%>['cols']||[];
         var cell = $j('#measures-table tr td[index=' + id + ']');
         var columnIndex = cell.parent().children().index(cell);
 
@@ -46,7 +48,7 @@
         }
       }
       function moveCol(from, to) {
-        var cols = filterCriteria['cols']||[];
+        var cols = filterCriteria<%= widget_id -%>['cols']||[];
         var temp = cols[from-colOffset];
         cols[from-colOffset] = cols[to-colOffset];
         cols[to-colOffset] = temp;
@@ -64,7 +66,7 @@
         });
       }
       function deleteCol(id) {
-        var cols = filterCriteria['cols']||[];
+        var cols = filterCriteria<%= widget_id -%>['cols']||[];
         var cell = $j('#measures-table tr td[index=' + id + ']');
         var columnIndex = cell.parent().children().index(cell);
         cols.splice(columnIndex-colOffset, 1);
 
         });
         $j("#add-metric").on("click", function (e) {
-          var cols = filterCriteria['cols']||[];
+          var cols = filterCriteria<%= widget_id -%>['cols']||[];
           var columnKey = $j("#select-metric option:selected").val();
           var period = $j("#select-period option:selected").val();
           if (period.length > 0) {
           }
           cols.push(columnKey);
           filterCriteria['edit']='true';
-          window.location = baseUrl + '/measures/search/<%= filter.id -%>?' + $j.param(filterCriteria);
+          window.location = baseUrl + '/measures/search/<%= filter.id -%>?' + $j.param(filterCriteria<%= widget_id -%>);
         });
         $j("#exit-edit").on("click", function (e) {
           delete filterCriteria['edit'];
-          window.location = baseUrl + '/measures/search/<%= filter.id -%>?' + $j.param(filterCriteria);
+          window.location = baseUrl + '/measures/search/<%= filter.id -%>?' + $j.param(filterCriteria<%= widget_id -%>);
         });
       });
     </script>
index 9715c75e69446411a423cddbe22cb5366bca232c..9c6915325fdc607cbea6b9e79c1ec037a3a84138 100644 (file)
@@ -1,3 +1,6 @@
+<script>
+  var filterCriteria<%= widget_id -%> = <%= filter.criteria.to_json -%>;
+</script>
 <%
    treemap_id = (defined? widget) ? widget.id : 1
    unless edit_mode
     <script>
       $j(document).ready(function () {
         $j("#update-treemap").on("click", function (e) {
-          filterCriteria['tmSize']=$j('#select-tm-size').val();
+          filterCriteria<%= widget_id -%>['tmSize']=$j('#select-tm-size').val();
           var color = $j('#select-tm-color').val();
           if (color != null && color != '') {
-            filterCriteria['tmColor']=color;
+            filterCriteria<%= widget_id -%>['tmColor']=color;
           }
-          filterCriteria['edit']=true;
-          window.location = baseUrl + '/measures/search/<%= filter.id -%>?' + $j.param(filterCriteria);
+          filterCriteria<%= widget_id -%>['edit']=true;
+          window.location = baseUrl + '/measures/search/<%= filter.id -%>?' + $j.param(filterCriteria<%= widget_id -%>);
         });
         $j("#exit-edit").on("click", function (e) {
-          delete filterCriteria['edit'];
-          window.location = baseUrl + '/measures/search/<%= filter.id -%>?' + $j.param(filterCriteria);
+          delete filterCriteria<%= widget_id -%>['edit'];
+          window.location = baseUrl + '/measures/search/<%= filter.id -%>?' + $j.param(filterCriteria<%= widget_id -%>);
         });
       });
     </script>
index 6b3b340579ce606cedf291efae1f8d6c135c3083..54d231c9d23ece421d6163618b8ad58722cbaf28 100644 (file)
@@ -1,11 +1,9 @@
-<div>
+<div xmlns="http://www.w3.org/1999/html">
   <div class="page-split-left">
     <%= render :partial => 'measures/sidebar' -%>
   </div>
 
   <% if @filter && @filter.display %>
-    <script>var filterCriteria = <%= @filter.criteria.to_json -%>;</script>
-
     <div class="page-split-right">
       <div id="content">
         <div class="line-block marginbottom10">
@@ -46,6 +44,7 @@
           </ul>
           <div class="page_title" id="filter-title">
             <% if @filter.id && @filter.name.present? %>
+              <p>
               <span class="h3"><%= h @filter.name -%></span>
               <span class="note">
                 <% if !@filter.shared %>
                   [<%= message 'shared_by' -%> Sonar]
                 <% end %>
               </span>
-              <% if @filter.description.present? %>
-                - <span class="note"><%= h @filter.description -%></span>
-              <% end %>
               <% if @filter.owner?(current_user) %>
-                &nbsp;<a href="<%= url_for :action => 'edit_form', :id => @filter.id -%>" class="open-modal" id="edit-filter"><%= image_tag 'pencil-small.png', :alt => message('edit') -%></a>
+                              &nbsp;<a href="<%= url_for :action => 'edit_form', :id => @filter.id -%>" class="open-modal" id="edit-filter"><%= image_tag 'pencil-small.png', :alt => message('edit') -%></a>
+                            <% end %>
+              </p>
+              <% if @filter.description.present? %>
+                <p class="note"><%= h @filter.description -%></p>
               <% end %>
+
             <% end %>
           </div>
         </div>
index 1d706ab8baff9c3afa7cce3f6c3eff28379b00b7..036f40c8f200ca1fd3e68f742b79cd90fd3e59bb 100644 (file)
@@ -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 {