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
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.
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
measure_filter.error.UNKNOWN=Unexpected error. Please contact the administrator.
measure_filter.error.TOO_MANY_RESULTS=Too many results. Please refine your search.
+
#------------------------------------------------------------------------------
#
# ISSUES
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;
}
boolean isOnDate() {
- return Field.DATE.equals(field);
+ return Field.DATE.equals(field) || Field.PROJECT_CREATION_DATE.equals(field);
}
boolean isAsc() {
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");
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");
<!-- 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]"
"#{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'
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
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
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|
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
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|
: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| %>