]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-4248 SONAR-4238 Add created column and add the possibility the add links and...
authorJulien Lancelot <julien.lancelot@gmail.com>
Thu, 11 Jul 2013 14:44:21 +0000 (16:44 +0200)
committerJulien Lancelot <julien.lancelot@gmail.com>
Thu, 11 Jul 2013 14:44:21 +0000 (16:44 +0200)
plugins/sonar-core-plugin/src/main/resources/org/sonar/l10n/core.properties
sonar-core/src/main/java/org/sonar/core/measure/MeasureFilterSort.java
sonar-core/src/test/java/org/sonar/core/measure/MeasureFilterExecutorTest.java
sonar-core/src/test/resources/org/sonar/core/measure/MeasureFilterExecutorTest/shared.xml
sonar-server/src/main/webapp/WEB-INF/app/helpers/measures_helper.rb
sonar-server/src/main/webapp/WEB-INF/app/models/measure_filter.rb
sonar-server/src/main/webapp/WEB-INF/app/views/measures/_display_list.html.erb

index e125aa371c58d8646b6b854d30991fdbbc01d152..cf14f39fac15c3c568989dc7412b43d17d9cba6c 100644 (file)
@@ -427,7 +427,7 @@ measure_filter.favourite_filters=Favourite Filters
 measure_filter.more_criteria=+ More Criteria
 measure_filter.languages=Languages
 measure_filter.alert_levels=Alert levels
-measure_filter.col.date=Date
+measure_filter.col.date=Last Analysis
 measure_filter.col.description=Description
 measure_filter.col.key=Key
 measure_filter.col.language=Language
@@ -435,7 +435,8 @@ measure_filter.col.links=Links
 measure_filter.col.name=Name
 measure_filter.col.short_name=Short Name
 measure_filter.col.version=Version
-measure_filter.abbr.date=Date
+measure_filter.col.project_creation_date=Created
+measure_filter.abbr.date=Last Analysis
 measure_filter.abbr.description=Description
 measure_filter.abbr.key=Key
 measure_filter.abbr.language=Lang.
@@ -443,6 +444,7 @@ measure_filter.abbr.links=Links
 measure_filter.abbr.name=Name
 measure_filter.abbr.short_name=Name
 measure_filter.abbr.version=Version
+measure_filter.abbr.project_creation_date=Created
 measure_filter.missing_name=Name is missing
 measure_filter.name_too_long=Name is too long
 measure_filter.sharing=Sharing
@@ -461,6 +463,7 @@ measure_filter.widget.unknown_filter_warning=This widget is configured to displa
 measure_filter.error.UNKNOWN=Unexpected error. Please contact the administrator.
 measure_filter.error.TOO_MANY_RESULTS=Too many results. Please refine your search.
 
+
 #------------------------------------------------------------------------------
 #
 # ISSUES
index 92bce6c6407454097413d09d858f6ab5ba8af774..14af5ee8206366efefb087e95d208c7d4b2b2b49 100644 (file)
@@ -23,7 +23,9 @@ import org.sonar.api.measures.Metric;
 
 class MeasureFilterSort {
   public static enum Field {
-    KEY, NAME, VERSION, LANGUAGE, DATE, METRIC, SHORT_NAME, DESCRIPTION
+    KEY, NAME, VERSION, LANGUAGE, METRIC, SHORT_NAME, DESCRIPTION,
+    DATE,  // Sort by last analysis date
+    PROJECT_CREATION_DATE // Sort by project creation date
   }
 
   private Field field = Field.NAME;
@@ -76,7 +78,7 @@ class MeasureFilterSort {
   }
 
   boolean isOnDate() {
-    return Field.DATE.equals(field);
+    return Field.DATE.equals(field) || Field.PROJECT_CREATION_DATE.equals(field);
   }
 
   boolean isAsc() {
@@ -108,6 +110,9 @@ class MeasureFilterSort {
       case DATE:
         column = "s.created_at";
         break;
+      case PROJECT_CREATION_DATE:
+        column = "p.created_at";
+        break;
       case METRIC:
         if (metric.isNumericType()) {
           column = (period != null ? "pmsort.variation_value_" + period : "pmsort.value");
index 214ceba319c69bc4488c975deab0f0b66cf7c7f6..392ead327cd1ce3a86762afde14d428cb9fb1f73 100644 (file)
@@ -335,6 +335,30 @@ public class MeasureFilterExecutorTest {
     verifyJavaProject(rows.get(1));// 2008
   }
 
+  @Test
+  public void sort_by_ascending_created_at() throws SQLException {
+    db.prepareDbUnit(getClass(), "shared.xml");
+    MeasureFilter filter = new MeasureFilter().setResourceQualifiers(Arrays.asList("TRK")).setSortOn(MeasureFilterSort.Field.PROJECT_CREATION_DATE);
+    List<MeasureFilterRow> rows = executor.execute(filter, new MeasureFilterContext());
+
+    verifyJavaProject(rows.get(0));// 2008
+    assertThat(DateUtils.formatDate(rows.get(0).getSortDate())).isEqualTo("2008-12-19");
+    verifyPhpProject(rows.get(1));// 2012
+    assertThat(DateUtils.formatDate(rows.get(1).getSortDate())).isEqualTo("2012-12-12");
+  }
+
+  @Test
+  public void sort_by_descending_created_at() throws SQLException {
+    db.prepareDbUnit(getClass(), "shared.xml");
+    MeasureFilter filter = new MeasureFilter().setResourceQualifiers(Arrays.asList("TRK")).setSortOn(MeasureFilterSort.Field.PROJECT_CREATION_DATE).setSortAsc(false);
+    List<MeasureFilterRow> rows = executor.execute(filter, new MeasureFilterContext());
+
+    verifyPhpProject(rows.get(0));// 2012
+    assertThat(DateUtils.formatDate(rows.get(0).getSortDate())).isEqualTo("2012-12-12");
+    verifyJavaProject(rows.get(1));// 2008
+    assertThat(DateUtils.formatDate(rows.get(1).getSortDate())).isEqualTo("2008-12-19");
+  }
+
   @Test
   public void condition_on_numeric_measure() throws SQLException {
     db.prepareDbUnit(getClass(), "shared.xml");
index 8b4a6bbc26ee1c0f2cb354d1f04e490b52783a7d..bcfe738a901c42ef704ef7a927215e35374c7b59 100644 (file)
   <!-- java project -->
   <projects kee="java_project" long_name="Java project" scope="PRJ" qualifier="TRK" name="Java project"
             id="1" root_id="[null]"
-            description="[null]" enabled="[true]" language="java" copy_resource_id="[null]" person_id="[null]"/>
+            description="[null]" enabled="[true]" language="java" copy_resource_id="[null]" person_id="[null]"
+            created_at="2008-12-19 00:00:00.00"/>
 
   <projects kee="java_project:org.sonar.foo" scope="DIR" qualifier="PAC" long_name="org.sonar.foo" name="org.sonar.foo"
             id="2" root_id="1"
-            description="[null]" enabled="[true]" language="java" copy_resource_id="[null]" person_id="[null]"/>
+            description="[null]" enabled="[true]" language="java" copy_resource_id="[null]" person_id="[null]"
+            created_at="2008-12-19 00:00:00.00"/>
 
   <projects kee="java_project:org.sonar.foo.Big" scope="FIL" qualifier="CLA" long_name="org.sonar.foo.Big"
             name="Big"
             id="3" root_id="1"
-            description="[null]" enabled="[true]" language="java" copy_resource_id="[null]" person_id="[null]"/>
+            description="[null]" enabled="[true]" language="java" copy_resource_id="[null]" person_id="[null]"
+            created_at="2008-12-19 00:00:00.00"/>
 
   <projects kee="java_project:org.sonar.foo.Tiny" scope="FIL" qualifier="CLA" long_name="org.sonar.foo.Tiny" name="Tiny"
             id="4" root_id="1"
-            description="[null]" enabled="[true]" language="java" copy_resource_id="[null]" person_id="[null]"/>
+            description="[null]" enabled="[true]" language="java" copy_resource_id="[null]" person_id="[null]"
+            created_at="2008-12-19 00:00:00.00"/>
 
   <snapshots id="101" project_id="1" root_project_id="1" root_snapshot_id="[null]" parent_snapshot_id="[null]"
              scope="PRJ" qualifier="TRK" path="" depth="0"
   <!-- php project -->
   <projects kee="php_project" long_name="PHP project" scope="PRJ" qualifier="TRK" name="PHP project"
             id="10" root_id="[null]"
-            description="[null]" enabled="[true]" language="php" copy_resource_id="[null]" person_id="[null]"/>
+            description="[null]" enabled="[true]" language="php" copy_resource_id="[null]" person_id="[null]"
+            created_at="2012-12-12 04:06:00.00"/>
 
 
   <snapshots id="110" project_id="10" root_project_id="10" root_snapshot_id="[null]" parent_snapshot_id="[null]"
index 07b00192e256170ac39e39a529557c7c049c25e3..3607074a0b5dd8f6cad52724c3cca59d4c527e1b 100644 (file)
@@ -55,6 +55,8 @@ module MeasuresHelper
       "#{qualifier_icon(row.snapshot)} #{link_to(h(row.snapshot.resource.name(false)), {:controller => 'dashboard', :id => row.snapshot.resource_id}, :title => h(row.snapshot.resource.key))}"
     elsif column.key=='date'
       human_short_date(row.snapshot.created_at)
+    elsif column.key=='project_creation_date'
+      human_short_date(row.snapshot.resource.created_at)
     elsif column.key=='key'
       "<span class='small'>#{row.snapshot.resource.kee}</span>"
     elsif column.key=='description'
index 1f4bb44e29e8b834ae03ea55523281d360ea2861..e0e8e519dadbe880c852fa513dd7f230e0f5b860 100644 (file)
@@ -185,7 +185,7 @@ class MeasureFilter < ActiveRecord::Base
 
   def base_resource
     if criteria('base')
-      Project.find(:first, :conditions => ['kee=? and copy_resource_id is null and person_id is null', criteria('base')])
+      Project.first(:conditions => ['kee=? and copy_resource_id is null and person_id is null', criteria('base')])
     elsif criteria('baseId')
       Project.find(criteria('baseId'))
     end
@@ -249,7 +249,7 @@ class MeasureFilter < ActiveRecord::Base
 
     if !snapshot_ids.empty?
       rows_by_snapshot_id = {}
-      snapshots = Snapshot.find(:all, :include => ['project'], :conditions => ['id in (?)', snapshot_ids])
+      snapshots = Snapshot.all(:include => ['project'], :conditions => ['id in (?)', snapshot_ids])
       snapshots.each do |snapshot|
         row = Row.new(snapshot)
         rows_by_snapshot_id[snapshot.id] = row
@@ -261,7 +261,7 @@ class MeasureFilter < ActiveRecord::Base
       end
 
       unless metric_ids.empty?
-        measures = ProjectMeasure.find(:all, :conditions =>
+        measures = ProjectMeasure.all(:conditions =>
           ['rule_priority is null and rule_id is null and characteristic_id is null and person_id is null and snapshot_id in (?) and metric_id in (?)', snapshot_ids, metric_ids]
         )
         measures.each do |measure|
@@ -277,7 +277,7 @@ class MeasureFilter < ActiveRecord::Base
           project_ids << snapshot.project_id
           rows_by_project_id[snapshot.project_id] = rows_by_snapshot_id[snapshot.id]
         end
-        links = ProjectLink.find(:all, :conditions => {:project_id => project_ids}, :order => 'link_type')
+        links = ProjectLink.all(:conditions => {:project_id => project_ids}, :order => 'link_type')
         links.each do |link|
           rows_by_project_id[link.project_id].add_link(link)
         end
@@ -288,7 +288,7 @@ class MeasureFilter < ActiveRecord::Base
       if base_snapshot
         @base_row = Row.new(base_snapshot)
         unless metric_ids.empty?
-          base_measures = ProjectMeasure.find(:all, :conditions =>
+          base_measures = ProjectMeasure.all(:conditions =>
             ['rule_priority is null and rule_id is null and characteristic_id is null and person_id is null and snapshot_id=? and metric_id in (?)', base_snapshot.id, metric_ids]
           )
           base_measures.each do |base_measure|
index 597df3699a8b9bc7d0d386ebfe8b1a47cd01b340..7d5c6e76bde86012898816a8788c4266863a7c85 100644 (file)
                               :html_id => 'select-metric',
                               :allow_empty => true,
                               :key_prefix => 'metric:',
-                              :extra_values => [[message('measure_filter.col.name'), 'name'], [message('measure_filter.col.short_name'), 'short_name'], [message('measure_filter.col.description'), 'description'], [message('measure_filter.col.language'), 'language'], [message('measure_filter.col.version'), 'version']] -%>
+                              :extra_values => [
+                                  [message('measure_filter.col.name'), 'name'],
+                                  [message('measure_filter.col.short_name'), 'short_name'],
+                                  [message('measure_filter.col.description'), 'description'],
+                                  [message('measure_filter.col.language'), 'language'],
+                                  [message('measure_filter.col.version'), 'version'],
+                                  [message('measure_filter.col.date'), 'date'],
+                                  [message('measure_filter.col.project_creation_date'), 'project_creation_date'],
+                                  [message('measure_filter.col.links'), 'links']
+                              ]
+        -%>
         <select id="select-period" style="display: none;">
           <option value="">Value</option>
           <% period_labels.each_with_index do |period_label, index| %>