]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-5083 Support of WORK_DUR
authorStas Vilchik <vilchiks@gmail.com>
Tue, 4 Mar 2014 14:11:54 +0000 (15:11 +0100)
committerStas Vilchik <vilchiks@gmail.com>
Tue, 4 Mar 2014 14:11:54 +0000 (15:11 +0100)
sonar-server/src/main/webapp/WEB-INF/app/views/layouts/_head.html.erb
sonar-server/src/main/webapp/WEB-INF/app/views/measures/search.html.erb
sonar-server/src/main/webapp/WEB-INF/app/views/quality_gates/index.html.erb
sonar-server/src/main/webapp/WEB-INF/app/views/quality_gates/templates/_quality_gate_detail_condition_template.hbs.erb
sonar-server/src/main/webapp/javascripts/common/inputs.coffee [new file with mode: 0644]
sonar-server/src/main/webapp/javascripts/common/inputs.js [new file with mode: 0644]
sonar-server/src/main/webapp/javascripts/navigator/filters/metric-filters.js
sonar-server/src/main/webapp/javascripts/quality-gate/views/quality-gate-detail-condition-view.coffee
sonar-server/src/main/webapp/javascripts/quality-gate/views/quality-gate-detail-condition-view.js
sonar-server/wro.xml

index 82205d6970b3578ce027e1def69c13e23076443f..c569bfe5a2d2433a38ea076135c8d15973e45510 100644 (file)
@@ -54,6 +54,7 @@
 
     <%= javascript_include_tag 'top-search' %>
     <%= javascript_include_tag 'sortable' %>
+    <%= javascript_include_tag 'common/inputs' %>
 
     <%= javascript_include_tag 'application' %>
     <%= javascript_include_tag 'dashboard' %>
index 85391726a049adbc56d4873fd175dd763aa938d8..b02bf22edc0303bd032ccd04ce7f43a707cb2b93 100644 (file)
       '3': '<%= Api::Utils.period_label(3) -%>'
     },
     favorites: <%= render :partial => 'measures/favourites2' -%>,
+    workDuration: {
+      days: '<%= message('work_duration.x_days') -%>',
+      hours: '<%= message('work_duration.x_hours') -%>',
+      minutes: '<%= message('work_duration.x_minutes') -%>'
+    },
 
     phrases: {
       'any':            '<%= escape_javascript message('any') -%>',
index f8be9355257a18dc20b64d882644817163b4873f..ff814fc9ccb4888acf5f0dbf171fda8d2964f070 100644 (file)
       { key: '3', text: '<%= Api::Utils.period_label(3) -%>' }
     ],
 
+    workDuration: {
+      days: '<%= message('work_duration.x_days') -%>',
+      hours: '<%= message('work_duration.x_hours') -%>',
+      minutes: '<%= message('work_duration.x_minutes') -%>'
+    },
+
     phrases: {
       areYouSure: '<%= message('are_you_sure') -%>',
       alerts: {
index 139f58b345415f3cd3c0d9860537b349df8839cc..0458e7e3571ab73e428a2aca21bea79a9c762cb8 100644 (file)
@@ -26,7 +26,7 @@
   <td width="15%">
     <i class="icon-alert-warn" title="<%= message('alerts.warn_tooltip') -%>"></i>
     {{#if canEdit}}
-      <input name="warning" type="text" value="{{warning}}">
+      <input name="warning" class="measure-input" data-type="{{metric.type}}" type="text">
     {{else}}
       {{warning}}
     {{/if}}
@@ -34,7 +34,7 @@
   <td width="15%">
     <i class="icon-alert-error" title="<%= message('alerts.error_tooltip') -%>"></i>
     {{#if canEdit}}
-      <input name="error" type="text" value="{{error}}">
+      <input name="error" class="measure-input" data-type="{{metric.type}}" type="text">
     {{else}}
       {{error}}
     {{/if}}
diff --git a/sonar-server/src/main/webapp/javascripts/common/inputs.coffee b/sonar-server/src/main/webapp/javascripts/common/inputs.coffee
new file mode 100644 (file)
index 0000000..9431dcd
--- /dev/null
@@ -0,0 +1,71 @@
+$ = jQuery
+
+$ ->
+
+  transformPattern = (pattern) ->
+    return pattern.replace /\{0\}/g, '(\\d+)'
+
+
+  convertWorkDuration = (value) ->
+    daysPattern = transformPattern window.SS.workDuration.days
+    hoursPattern = transformPattern window.SS.workDuration.hours
+    minutesPattern = transformPattern window.SS.workDuration.minutes
+
+    days = value.match daysPattern
+    hours = value.match hoursPattern
+    minutes = value.match minutesPattern
+
+    days = if days then +days[1] else 0
+    hours = if hours then +hours[1] else 0
+    minutes = if minutes then +minutes[1] else 0
+
+    if value && value.length > 0 && days == 0 && hours == 0 && minutes == 0
+      value
+    else
+      (days * 8 + hours) * 60 + minutes
+
+
+  restoreWorkDuration = (value) ->
+    days = Math.floor(value / (8 * 60))
+    hours = Math.floor((value - days * 8 * 60) / 60)
+    minutes = value % 60
+    result = []
+    result.push window.SS.workDuration.days.replace('{0}', days) if days > 0
+    result.push window.SS.workDuration.hours.replace('{0}', hours) if hours > 0
+    result.push window.SS.workDuration.minutes.replace('{0}', minutes) if minutes > 0
+    result.join ' '
+
+
+  convertValue = (value, input) ->
+    type = input.data 'type'
+
+    # No convertation if input doesn't have data-type
+    return value unless type?
+
+    # Do necessary convertion depeneds on input data-type
+    switch type
+      when 'WORK_DUR' then convertWorkDuration value
+      else value
+
+
+  restoreValue = (value, input) ->
+    type = input.data 'type'
+
+    # No convertation if input doesn't have data-type
+    return value unless type?
+
+    # Do necessary convertion depeneds on input data-type
+    switch type
+      when 'WORK_DUR' then restoreWorkDuration value
+      else value
+
+
+  originalVal = $.fn.val
+  $.fn.val = (value) ->
+    if arguments.length
+      originalVal.call @, (restoreValue value, @)
+    else
+      convertValue originalVal.call(@), @
+
+  $.fn.originalVal = originalVal
+
diff --git a/sonar-server/src/main/webapp/javascripts/common/inputs.js b/sonar-server/src/main/webapp/javascripts/common/inputs.js
new file mode 100644 (file)
index 0000000..53b0c9a
--- /dev/null
@@ -0,0 +1,83 @@
+// Generated by CoffeeScript 1.6.3
+(function() {
+  var $;
+
+  $ = jQuery;
+
+  $(function() {
+    var convertValue, convertWorkDuration, originalVal, restoreValue, restoreWorkDuration, transformPattern;
+    transformPattern = function(pattern) {
+      return pattern.replace(/\{0\}/g, '(\\d+)');
+    };
+    convertWorkDuration = function(value) {
+      var days, daysPattern, hours, hoursPattern, minutes, minutesPattern;
+      daysPattern = transformPattern(window.SS.workDuration.days);
+      hoursPattern = transformPattern(window.SS.workDuration.hours);
+      minutesPattern = transformPattern(window.SS.workDuration.minutes);
+      days = value.match(daysPattern);
+      hours = value.match(hoursPattern);
+      minutes = value.match(minutesPattern);
+      days = days ? +days[1] : 0;
+      hours = hours ? +hours[1] : 0;
+      minutes = minutes ? +minutes[1] : 0;
+      if (value && value.length > 0 && days === 0 && hours === 0 && minutes === 0) {
+        return value;
+      } else {
+        return (days * 8 + hours) * 60 + minutes;
+      }
+    };
+    restoreWorkDuration = function(value) {
+      var days, hours, minutes, result;
+      days = Math.floor(value / (8 * 60));
+      hours = Math.floor((value - days * 8 * 60) / 60);
+      minutes = value % 60;
+      result = [];
+      if (days > 0) {
+        result.push(window.SS.workDuration.days.replace('{0}', days));
+      }
+      if (hours > 0) {
+        result.push(window.SS.workDuration.hours.replace('{0}', hours));
+      }
+      if (minutes > 0) {
+        result.push(window.SS.workDuration.minutes.replace('{0}', minutes));
+      }
+      return result.join(' ');
+    };
+    convertValue = function(value, input) {
+      var type;
+      type = input.data('type');
+      if (type == null) {
+        return value;
+      }
+      switch (type) {
+        case 'WORK_DUR':
+          return convertWorkDuration(value);
+        default:
+          return value;
+      }
+    };
+    restoreValue = function(value, input) {
+      var type;
+      type = input.data('type');
+      if (type == null) {
+        return value;
+      }
+      switch (type) {
+        case 'WORK_DUR':
+          return restoreWorkDuration(value);
+        default:
+          return value;
+      }
+    };
+    originalVal = $.fn.val;
+    $.fn.val = function(value) {
+      if (arguments.length) {
+        return originalVal.call(this, restoreValue(value, this));
+      } else {
+        return convertValue(originalVal.call(this), this);
+      }
+    };
+    return $.fn.originalVal = originalVal;
+  });
+
+}).call(this);
index f86f90299bd2643093d02a05419d6354435f7405..b97c557654f7cede8c58ab43b24b80cdaa728575 100644 (file)
@@ -17,12 +17,24 @@ define(['navigator/filters/base-filters', 'common/handlebars-extensions'], funct
         periodText: this.$('[name=period] option:selected').text(),
         op: this.$('[name=op]').val(),
         opText: this.$('[name=op] option:selected').text(),
-        val: this.$('[name=val]').val()
+        val: this.$('[name=val]').val(),
+        valText: this.$('[name=val]').originalVal()
       };
+      this.updateDataType(value);
       this.model.set('value', value);
     },
 
 
+    updateDataType: function(value) {
+      var metric = _.find(window.SS.metrics, function(m) {
+        return m.metric.name === value.metric;
+      });
+      if (metric) {
+        this.$('[name=val]').data('type', metric.metric.val_type);
+      }
+    },
+
+
     onRender: function() {
       var value = this.model.get('value') || {};
       this.$('[name=metric]').val(value.metric).select2({
@@ -38,6 +50,7 @@ define(['navigator/filters/base-filters', 'common/handlebars-extensions'], funct
         placeholder: '=',
         minimumResultsForSearch: 100
       });
+      this.updateDataType(value);
       this.$('[name=val]').val(value.val);
       this.inputChanged();
     },
@@ -88,7 +101,7 @@ define(['navigator/filters/base-filters', 'common/handlebars-extensions'], funct
     renderValue: function() {
       return this.isDefaultValue() ?
           window.SS.phrases.notSet :
-          this.model.get('value').metricText + ' ' + this.model.get('value').opText + ' ' + this.model.get('value').val;
+          this.model.get('value').metricText + ' ' + this.model.get('value').opText + ' ' + this.model.get('value').valText;
     },
 
 
index f4d5125946ada330836177fd024b977f38784e6e..f60bd4439a1d5ed28d7b375a71db90a3e2de72c5 100644 (file)
@@ -47,6 +47,8 @@ define [
     onRender: ->
       @ui.periodSelect.val @model.get('period') || '0'
       @ui.operatorSelect.val @model.get('op')
+      @ui.warningInput.val @model.get('warning')
+      @ui.errorInput.val @model.get('error')
 
       @ui.periodSelect.select2
         allowClear: false
index 53c44c0fe63601dd2dd2212358361142ffd1d79d..6e29ecc2db13f11f9d7c764e2d5003524052b0c1 100644 (file)
@@ -61,6 +61,8 @@
       QualityGateDetailConditionView.prototype.onRender = function() {
         this.ui.periodSelect.val(this.model.get('period') || '0');
         this.ui.operatorSelect.val(this.model.get('op'));
+        this.ui.warningInput.val(this.model.get('warning'));
+        this.ui.errorInput.val(this.model.get('error'));
         this.ui.periodSelect.select2({
           allowClear: false,
           minimumResultsForSearch: 999,
index 7ab7264464d19102abde422b0eaf273079fe32e0..3bcadf2a340a200507a31a28d46eae0cd89dc9ba 100644 (file)
@@ -33,6 +33,7 @@
     
     <js>/javascripts/top-search.js</js>
     <js>/javascripts/sortable.js</js>
+    <js>/javascripts/common/inputs.js</js>
 
     <js>/javascripts/application.js</js>
     <js>/javascripts/dashboard.js</js>