]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-4812 Remove "Value" option when selecting differential metric
authorJean-Baptiste Lievremont <jean-baptiste.lievremont@sonarsource.com>
Tue, 29 Jul 2014 13:41:09 +0000 (15:41 +0200)
committerJean-Baptiste Lievremont <jean-baptiste.lievremont@sonarsource.com>
Tue, 29 Jul 2014 13:42:08 +0000 (15:42 +0200)
server/sonar-web/src/main/js/navigator/filters/metric-filters.js

index 0bb84819e0bf8d966ffdf710a80c50aa5b2cd591..332d2bb4e248c75469ce8eec61b2a36e37e7be65 100644 (file)
@@ -14,16 +14,37 @@ define([
 
 
     inputChanged: function() {
-      var value = {
-        metric: this.$('[name=metric]').val(),
+      var metric = this.$('[name=metric]').val(),
+          isDifferentialMetric = metric.startsWith('new_'),
+          periodSelect = this.$('[name=period]'),
+          period = periodSelect.val(),
+          optionZero = periodSelect.children('[value="0"]'),
+          value = {
+        metric: metric,
         metricText: this.$('[name=metric] option:selected').text(),
-        period: this.$('[name=period]').val(),
+        period: period,
         periodText: this.$('[name=period] option:selected').text(),
         op: this.$('[name=op]').val(),
         opText: this.$('[name=op] option:selected').text(),
         val: this.$('[name=val]').val(),
         valText: this.$('[name=val]').originalVal()
       };
+
+      if (isDifferentialMetric) {
+        optionZero.remove();
+        if (period === '0') {
+          period = '1';
+        }
+      } else {
+        if (optionZero.length === 0) {
+          periodSelect.prepend(this.periodZeroOption);
+        }
+      }
+      periodSelect.select2('destroy').val(period).select2({
+        width: '100%',
+        minimumResultsForSearch: 100
+      });
+
       this.updateDataType(value);
       this.model.set('value', value);
     },
@@ -46,6 +67,9 @@ define([
 
 
     onRender: function() {
+      var periodZeroLabel = this.$('[name=period]').children('[value="0"]').html();
+      this.periodZeroOption = '<option value="0">' + periodZeroLabel + '</option>'
+
       var value = this.model.get('value') || {};
       this.$('[name=metric]').val(value.metric).select2({
         width: '100%',