diff options
author | Simon Brandhof <simon.brandhof@gmail.com> | 2012-12-11 11:19:03 +0100 |
---|---|---|
committer | Simon Brandhof <simon.brandhof@gmail.com> | 2012-12-11 11:19:03 +0100 |
commit | 5d5ccf52dcbd3968a5addbe8551efcfcfa673b47 (patch) | |
tree | cc3ba11c2e8b6cea73d80a254111586d4313180f | |
parent | ae07700eab2ff9d072380aca5b607d4c47300802 (diff) | |
download | sonarqube-5d5ccf52dcbd3968a5addbe8551efcfcfa673b47.tar.gz sonarqube-5d5ccf52dcbd3968a5addbe8551efcfcfa673b47.zip |
SONAR-3825 use abbreviations of period labels
6 files changed, 124 insertions, 35 deletions
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 aa33bb80644..05b417f6346 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 @@ -196,6 +196,7 @@ no_data=No data no_lines_match_your_filter_criteria=No lines match your filter criteria. no_results=No results over_x_days=over {0} days +over_x_days.short={0} days page_size=Page size paging_first=First paging_last=Last @@ -211,12 +212,19 @@ set_as_default=Set as default shared_by=Shared by show_more=Show more since_x=since {0} +since_x.short={0} since_previous_analysis=since previous analysis since_previous_analysis_detailed=since previous analysis ({0}) +since_previous_analysis.short=\u0394 last +since_previous_analysis_detailed.short=\u0394 last ({0}) since_version=since version {0} +since_version.short={0} since_version_detailed=since version {0} ({1}) +since_version_detailed.short={0} ({1}) since_previous_version=since previous version +since_previous_version.short=\u0394 version since_previous_version_detailed=since previous version ({0}) +since_previous_version_detailed.short=\u0394 version ({0}) time_changes=Time changes #------------------------------------------------------------------------------ diff --git a/sonar-core/src/main/java/org/sonar/core/timemachine/Periods.java b/sonar-core/src/main/java/org/sonar/core/timemachine/Periods.java index 5c244bef19d..9fe1e96ecb8 100644 --- a/sonar-core/src/main/java/org/sonar/core/timemachine/Periods.java +++ b/sonar-core/src/main/java/org/sonar/core/timemachine/Periods.java @@ -42,53 +42,66 @@ public class Periods implements BatchExtension { } public String label(Snapshot snapshot, int periodIndex) { - String mode = snapshot.getPeriodMode(periodIndex); - String param = snapshot.getPeriodModeParameter(periodIndex); - Date date = snapshot.getPeriodDate(periodIndex); + return label(snapshot.getPeriodMode(periodIndex), snapshot.getPeriodModeParameter(periodIndex), snapshot.getPeriodDate(periodIndex)); + } - return label(mode, param, date); + public String abbreviation(Snapshot snapshot, int periodIndex) { + return abbreviation(snapshot.getPeriodMode(periodIndex), snapshot.getPeriodModeParameter(periodIndex), snapshot.getPeriodDate(periodIndex)); } public String label(int periodIndex) { String periodProperty = settings.getString(CoreProperties.TIMEMACHINE_PERIOD_PREFIX + periodIndex); PeriodParameters periodParameters = new PeriodParameters(periodProperty); + return label(periodParameters.getMode(), periodParameters.getParam(), periodParameters.getDate()); + } - String mode = periodParameters.getMode(); - String param = periodParameters.getParam(); - Date date = periodParameters.getDate(); - - return label(mode, param, date); + public String abbreviation(int periodIndex) { + String periodProperty = settings.getString(CoreProperties.TIMEMACHINE_PERIOD_PREFIX + periodIndex); + PeriodParameters periodParameters = new PeriodParameters(periodProperty); + return abbreviation(periodParameters.getMode(), periodParameters.getParam(), periodParameters.getDate()); } public String label(String mode, String param, Date date) { - String label = ""; + return label(mode, param, date, false); + } + + public String abbreviation(String mode, String param, Date date) { + return label(mode, param, date, true); + } + + private String label(String mode, String param, Date date, boolean shortLabel) { + String label; if (CoreProperties.TIMEMACHINE_MODE_DAYS.equals(mode)) { - label = message("over_x_days", param); + label = label("over_x_days", shortLabel, param); } else if (CoreProperties.TIMEMACHINE_MODE_VERSION.equals(mode)) { - label = message("since_version", param); + label = label("since_version", shortLabel, param); if (date != null) { - label = message("since_version_detailed", param, convertDate(date)); + label = label("since_version_detailed", shortLabel, param, convertDate(date)); } } else if (CoreProperties.TIMEMACHINE_MODE_PREVIOUS_ANALYSIS.equals(mode)) { - label = message("since_previous_analysis"); + label = label("since_previous_analysis", shortLabel); if (date != null) { - label = message("since_previous_analysis_detailed", convertDate(date)); + label = label("since_previous_analysis_detailed", shortLabel, convertDate(date)); } } else if (CoreProperties.TIMEMACHINE_MODE_PREVIOUS_VERSION.equals(mode)) { - label = message("since_previous_version"); + label = label("since_previous_version", shortLabel); if (param != null) { - label = message("since_previous_version_detailed", param); + label = label("since_previous_version_detailed", shortLabel, param); } } else if (CoreProperties.TIMEMACHINE_MODE_DATE.equals(mode)) { - label = message("since_x", convertDate(date)); + label = label("since_x", shortLabel, convertDate(date)); } else { throw new IllegalArgumentException("This mode is not supported : " + mode); } return label; } - private String message(String key, Object... parameters) { - return i18n.message(getLocale(), key, null, parameters); + private String label(String key, boolean shortLabel, Object... parameters) { + String msgKey = key; + if (shortLabel) { + msgKey += ".short"; + } + return i18n.message(getLocale(), msgKey, null, parameters); } private String convertDate(Date date) { @@ -102,9 +115,9 @@ public class Periods implements BatchExtension { private static class PeriodParameters { - private String mode; - private String param; - private Date date; + private String mode = null; + private String param = null; + private Date date = null; public PeriodParameters(String periodProperty) { if (CoreProperties.TIMEMACHINE_MODE_PREVIOUS_ANALYSIS.equals(periodProperty) || CoreProperties.TIMEMACHINE_MODE_PREVIOUS_VERSION.equals(periodProperty)) { diff --git a/sonar-core/src/test/java/org/sonar/core/timemachine/PeriodsTest.java b/sonar-core/src/test/java/org/sonar/core/timemachine/PeriodsTest.java index 5fd891c4128..0edf7be1a13 100644 --- a/sonar-core/src/test/java/org/sonar/core/timemachine/PeriodsTest.java +++ b/sonar-core/src/test/java/org/sonar/core/timemachine/PeriodsTest.java @@ -60,7 +60,7 @@ public class PeriodsTest { } @Test - public void shouldReturnSnapshotLabelInModeDays() { + public void label_of_duration_in_days() { when(snapshot.getPeriodMode(periodIndex)).thenReturn(CoreProperties.TIMEMACHINE_MODE_DAYS); when(snapshot.getPeriodDate(periodIndex)).thenReturn(new Date()); when(snapshot.getPeriodModeParameter(periodIndex)).thenReturn(param); @@ -70,7 +70,17 @@ public class PeriodsTest { } @Test - public void shouldReturnSnapshotLabelInModeVersion() { + public void abbreviation_of_duration_in_days() { + when(snapshot.getPeriodMode(periodIndex)).thenReturn(CoreProperties.TIMEMACHINE_MODE_DAYS); + when(snapshot.getPeriodDate(periodIndex)).thenReturn(new Date()); + when(snapshot.getPeriodModeParameter(periodIndex)).thenReturn(param); + + periods.abbreviation(snapshot, periodIndex); + verify(i18n).message(Mockito.any(Locale.class), Mockito.eq("over_x_days.short"), Mockito.isNull(String.class), Mockito.eq(param)); + } + + @Test + public void label_of_snapshot_version() { when(snapshot.getPeriodMode(periodIndex)).thenReturn(CoreProperties.TIMEMACHINE_MODE_VERSION); when(snapshot.getPeriodDate(periodIndex)).thenReturn(new Date()); when(snapshot.getPeriodModeParameter(periodIndex)).thenReturn(param); @@ -80,7 +90,17 @@ public class PeriodsTest { } @Test - public void shouldReturnSnapshotLabelInModePreviousAnalysisWithDateNotNull() { + public void abbreviation_of_snapshot_version() { + when(snapshot.getPeriodMode(periodIndex)).thenReturn(CoreProperties.TIMEMACHINE_MODE_VERSION); + when(snapshot.getPeriodDate(periodIndex)).thenReturn(new Date()); + when(snapshot.getPeriodModeParameter(periodIndex)).thenReturn(param); + + periods.abbreviation(snapshot, periodIndex); + verify(i18n).message(Mockito.any(Locale.class), Mockito.eq("since_version_detailed.short"), Mockito.isNull(String.class), Mockito.eq(param), Mockito.anyString()); + } + + @Test + public void label_of_previous_analysis_with_date() { when(snapshot.getPeriodMode(periodIndex)).thenReturn(CoreProperties.TIMEMACHINE_MODE_PREVIOUS_ANALYSIS); when(snapshot.getPeriodDate(periodIndex)).thenReturn(new Date()); @@ -89,7 +109,7 @@ public class PeriodsTest { } @Test - public void shouldReturnSnapshotLabelInModePreviousAnalysisWithNullDate() { + public void label_of_previous_analysis_without_date() { when(snapshot.getPeriodMode(periodIndex)).thenReturn(CoreProperties.TIMEMACHINE_MODE_PREVIOUS_ANALYSIS); when(snapshot.getPeriodDate(periodIndex)).thenReturn(null); when(snapshot.getPeriodModeParameter(periodIndex)).thenReturn(param); @@ -99,6 +119,25 @@ public class PeriodsTest { } @Test + public void abbreviation_of_previous_analysis_with_date() { + when(snapshot.getPeriodMode(periodIndex)).thenReturn(CoreProperties.TIMEMACHINE_MODE_PREVIOUS_ANALYSIS); + when(snapshot.getPeriodDate(periodIndex)).thenReturn(new Date()); + + periods.abbreviation(snapshot, periodIndex); + verify(i18n).message(Mockito.any(Locale.class), Mockito.eq("since_previous_analysis_detailed.short"), Mockito.isNull(String.class), Mockito.anyString()); + } + + @Test + public void abbreviation_of_previous_analysis_without_date() { + when(snapshot.getPeriodMode(periodIndex)).thenReturn(CoreProperties.TIMEMACHINE_MODE_PREVIOUS_ANALYSIS); + when(snapshot.getPeriodDate(periodIndex)).thenReturn(null); + when(snapshot.getPeriodModeParameter(periodIndex)).thenReturn(param); + + periods.abbreviation(snapshot, periodIndex); + verify(i18n).message(Mockito.any(Locale.class), Mockito.eq("since_previous_analysis.short"), Mockito.isNull(String.class)); + } + + @Test public void shouldReturnSnapshotLabelInModePreviousVersionWithParamNotNull() { when(snapshot.getPeriodMode(periodIndex)).thenReturn(CoreProperties.TIMEMACHINE_MODE_PREVIOUS_VERSION); when(snapshot.getPeriodModeParameter(periodIndex)).thenReturn(param); @@ -163,7 +202,7 @@ public class PeriodsTest { } @Test - public void shouldReturnLabelInModePreviousVersion() { + public void label_of_previous_version() { int periodIndex = 1; settings.setProperty(CoreProperties.TIMEMACHINE_PERIOD_PREFIX + periodIndex, CoreProperties.TIMEMACHINE_MODE_PREVIOUS_VERSION); @@ -172,7 +211,16 @@ public class PeriodsTest { } @Test - public void shouldReturnLabelInModeDate() { + public void abbreviation_of_previous_version() { + int periodIndex = 1; + settings.setProperty(CoreProperties.TIMEMACHINE_PERIOD_PREFIX + periodIndex, CoreProperties.TIMEMACHINE_MODE_PREVIOUS_VERSION); + + periods.abbreviation(periodIndex); + verify(i18n).message(Mockito.any(Locale.class), Mockito.eq("since_previous_version.short"), Mockito.isNull(String.class)); + } + + @Test + public void label_of_date() { int periodIndex = 1; settings.setProperty(CoreProperties.TIMEMACHINE_PERIOD_PREFIX + periodIndex, "2012-12-12"); @@ -181,6 +229,16 @@ public class PeriodsTest { verify(i18n).message(Mockito.any(Locale.class), Mockito.eq("since_x"), Mockito.isNull(String.class), Mockito.anyString()); } + @Test + public void abbreviation_of_date() { + int periodIndex = 1; + settings.setProperty(CoreProperties.TIMEMACHINE_PERIOD_PREFIX + periodIndex, "2012-12-12"); + + periods.abbreviation(periodIndex); + + verify(i18n).message(Mockito.any(Locale.class), Mockito.eq("since_x.short"), Mockito.isNull(String.class), Mockito.anyString()); + } + @Test(expected = IllegalArgumentException.class) public void shouldNotSupportUnknownModeForLabel() { int periodIndex = 1; diff --git a/sonar-server/src/main/java/org/sonar/server/ui/JRubyFacade.java b/sonar-server/src/main/java/org/sonar/server/ui/JRubyFacade.java index fbeb700e60e..ef7c50933ca 100644 --- a/sonar-server/src/main/java/org/sonar/server/ui/JRubyFacade.java +++ b/sonar-server/src/main/java/org/sonar/server/ui/JRubyFacade.java @@ -320,7 +320,7 @@ public final class JRubyFacade { public void ruleSeverityChanged(int parentProfileId, int activeRuleId, int oldSeverityId, int newSeverityId, String userName) { getProfilesManager().ruleSeverityChanged(parentProfileId, activeRuleId, RulePriority.values()[oldSeverityId], - RulePriority.values()[newSeverityId], userName); + RulePriority.values()[newSeverityId], userName); } public void ruleDeactivated(int parentProfileId, int deactivatedRuleId, String userName) { @@ -516,10 +516,10 @@ public final class JRubyFacade { // notifier is null when creating the administrator in the migration script 011. if (notifier != null) { notifier.onNewUser(NewUserHandler.Context.builder() - .setLogin(fields.get("login")) - .setName(fields.get("name")) - .setEmail(fields.get("email")) - .build()); + .setLogin(fields.get("login")) + .setName(fields.get("name")) + .setEmail(fields.get("email")) + .build()); } } @@ -534,4 +534,8 @@ public final class JRubyFacade { public String getPeriodLabel(String mode, String param, Date date) { return get(Periods.class).label(mode, param, date); } + + public String getPeriodAbbreviation(int periodIndex) { + return get(Periods.class).abbreviation(periodIndex); + } } 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 20a93929340..7e79a383ce3 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 @@ -26,7 +26,7 @@ module MeasuresHelper html=h(column.title_label) end if column.period - html += "<br><span class='note'>#{Api::Utils.period_label(column.period)}</small>" + html += "<br><span class='note'>#{Api::Utils.period_abbreviation(column.period)}</small>" end if filter.sort_key==column.key html << (filter.sort_asc? ? image_tag("asc12.png") : image_tag("desc12.png")) diff --git a/sonar-server/src/main/webapp/WEB-INF/app/models/api/utils.rb b/sonar-server/src/main/webapp/WEB-INF/app/models/api/utils.rb index 35adebd944c..5a96b151aa3 100644 --- a/sonar-server/src/main/webapp/WEB-INF/app/models/api/utils.rb +++ b/sonar-server/src/main/webapp/WEB-INF/app/models/api/utils.rb @@ -185,4 +185,10 @@ class Api::Utils def self.period_label(index) java_facade.getPeriodLabel(index) end + + # Abbreviated label of global periods + # index is in [1..3] + def self.period_abbreviation(index) + java_facade.getPeriodAbbreviation(index) + end end |