aboutsummaryrefslogtreecommitdiffstats
path: root/server/sonar-web/src/main
diff options
context:
space:
mode:
authorStas Vilchik <vilchiks@gmail.com>2015-04-01 15:00:54 +0200
committerStas Vilchik <vilchiks@gmail.com>2015-04-01 15:00:54 +0200
commitc5ac4e37710b8a8fd93a921816d9474a38b89064 (patch)
tree6c63ecfba8751282674d41f0f87144c254dcaebc /server/sonar-web/src/main
parent5bf0a42ca702e6ee7eae4871849e9f08e82e9f0a (diff)
downloadsonarqube-c5ac4e37710b8a8fd93a921816d9474a38b89064.tar.gz
sonarqube-c5ac4e37710b8a8fd93a921816d9474a38b89064.zip
fix quality flaws
Diffstat (limited to 'server/sonar-web/src/main')
-rw-r--r--server/sonar-web/src/main/js/application.js57
1 files changed, 46 insertions, 11 deletions
diff --git a/server/sonar-web/src/main/js/application.js b/server/sonar-web/src/main/js/application.js
index 4a211ed867f..fdf8dca48ba 100644
--- a/server/sonar-web/src/main/js/application.js
+++ b/server/sonar-web/src/main/js/application.js
@@ -436,6 +436,45 @@ function fileFromPath (path) {
(function () {
/**
+ * Check if days should be displayed for a work duration
+ * @param {number} days
+ * @returns {boolean}
+ */
+ function shouldDisplayDays (days) {
+ return days > 0;
+ }
+
+ /**
+ * Check if hours should be displayed for a work duration
+ * @param {number} days
+ * @param {number} hours
+ * @returns {boolean}
+ */
+ function shouldDisplayHours (days, hours) {
+ return hours > 0 && days < 10;
+ }
+
+ /**
+ * Check if minutes should be displayed for a work duration
+ * @param {number} days
+ * @param {number} hours
+ * @param {number} minutes
+ * @returns {boolean}
+ */
+ function shouldDisplayMinutes (days, hours, minutes) {
+ return minutes > 0 && hours < 10 && days === 0;
+ }
+
+ /**
+ * Add a space between units if needed
+ * @param {string} value
+ * @returns {string}
+ */
+ function addSpaceIfNeeded (value) {
+ return value.length > 0 ? value : value + ' ';
+ }
+
+ /**
* Format a work duration based on parameters
* @param {bool} isNegative
* @param {number} days
@@ -443,25 +482,21 @@ function fileFromPath (path) {
* @param {number} minutes
* @returns {string}
*/
- var formatDuration = function (isNegative, days, hours, minutes) {
+ function formatDuration (isNegative, days, hours, minutes) {
var formatted = '';
- if (days > 0) {
+ if (shouldDisplayDays(days)) {
formatted += tp('work_duration.x_days', isNegative ? -1 * days : days);
}
- if (hours > 0 && days < 10) {
- if (formatted.length > 0) {
- formatted += ' ';
- }
+ if (shouldDisplayHours(days, hours)) {
+ formatted = addSpaceIfNeeded(formatted);
formatted += tp('work_duration.x_hours', isNegative && formatted.length === 0 ? -1 * hours : hours);
}
- if (minutes > 0 && hours < 10 && days === 0) {
- if (formatted.length > 0) {
- formatted += ' ';
- }
+ if (shouldDisplayMinutes(days, hours, minutes)) {
+ formatted = addSpaceIfNeeded(formatted);
formatted += tp('work_duration.x_minutes', isNegative && formatted.length === 0 ? -1 * minutes : minutes);
}
return formatted;
- };
+ }
/**
* Format a work duration measure