]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-6233 fix characteristic facet on rules page
authorStas Vilchik <vilchiks@gmail.com>
Tue, 3 Mar 2015 16:57:32 +0000 (17:57 +0100)
committerStas Vilchik <vilchiks@gmail.com>
Tue, 3 Mar 2015 16:57:32 +0000 (17:57 +0100)
server/sonar-web/src/main/hbs/coding-rules/facets/coding-rules-characteristic-facet.hbs
server/sonar-web/src/main/js/coding-rules/facets/characteristic-facet.js
server/sonar-web/src/main/js/coding-rules/models/state.js

index 1742660c33aba05871a227880ff22191b40d5448..645205b0c5c65aad7bbe2e6c3202c99c0460d571 100644 (file)
@@ -2,10 +2,18 @@
 
 <div class="search-navigator-facet-list">
   {{#each values}}
-    <a class="facet search-navigator-facet {{#if parent}}search-navigator-facet-indent{{/if}} js-facet"
-       data-value="{{val}}" title="{{default label val}}">
-      <span class="facet-name">{{default label val}}</span>
-      <span class="facet-stat">{{numberShort count}}</span>
-    </a>
+    {{#eq val 'NONE'}}
+      <a class="facet search-navigator-facet js-facet" data-empty-characteristic
+         title="{{t 'coding_rules.noncharacterized'}}">
+        <span class="facet-name">{{t 'coding_rules.noncharacterized'}}</span>
+        <span class="facet-stat">{{numberShort count}}</span>
+      </a>
+    {{else}}
+      <a class="facet search-navigator-facet {{#if parent}}search-navigator-facet-indent{{/if}} js-facet"
+         data-value="{{val}}" title="{{default label val}}">
+        <span class="facet-name">{{default label val}}</span>
+        <span class="facet-stat">{{numberShort count}}</span>
+      </a>
+    {{/eq}}
   {{/each}}
 </div>
index 94a954abc7a60a3102af923710646a9bbcbd08d5..5275d260317c071bad3f7956d9afa967ae33cc00 100644 (file)
@@ -22,9 +22,44 @@ define([
   'templates/coding-rules'
 ], function (BaseFacet) {
 
+  var $ = jQuery;
+
   return BaseFacet.extend({
     template: Templates['coding-rules-characteristic-facet'],
 
+    onRender: function () {
+      BaseFacet.prototype.onRender.apply(this, arguments);
+      var value = this.options.app.state.get('query').has_debt_characteristic;
+      if (value != null && ('' + value === 'false')) {
+        this.$('.js-facet').filter('[data-empty-characteristic]').addClass('active');
+      }
+    },
+
+    toggleFacet: function (e) {
+      var noneCharacteristic = $(e.currentTarget).is('[data-empty-characteristic]'),
+          property = this.model.get('property'),
+          obj = {};
+      $(e.currentTarget).toggleClass('active');
+      if (noneCharacteristic) {
+        var checked = $(e.currentTarget).is('.active');
+        obj.has_debt_characteristic = checked ? 'false' : null;
+        obj[property] = null;
+      } else {
+        obj.has_debt_characteristic = null;
+        obj[property] = this.getValue();
+      }
+      console.log(obj);
+      this.options.app.state.updateFilter(obj);
+    },
+
+    disable: function () {
+      var property = this.model.get('property'),
+          obj = {};
+      obj.has_debt_characteristic = null;
+      obj[property] = null;
+      this.options.app.state.updateFilter(obj);
+    },
+
     getValues: function () {
       var values = this.model.getValues(),
           characteristics = this.options.app.characteristics;
@@ -32,8 +67,6 @@ define([
         var ch = _.findWhere(characteristics, { key: value.val });
         if (ch != null) {
           _.extend(value, ch, { label: ch.name });
-        } else {
-          _.extend(value, { label: t('coding_rules.noncharacterized') });
         }
         return value;
       });
index 050a7ff58b3f9b229c6b0a4b07bbf111c546a563..97720d9d5def6033c8fb351e7c7f096d8ef97d3b 100644 (file)
@@ -30,7 +30,9 @@ define([
       allFacets: ['q', 'rule_key', 'languages', 'tags', 'repositories', 'debt_characteristics', 'severities',
                   'statuses', 'available_since', 'is_template', 'qprofile', 'inheritance', 'active_severities'],
       facetsFromServer: ['languages', 'repositories', 'tags', 'severities', 'statuses', 'debt_characteristics'],
-      transform: {}
+      transform: {
+        'has_debt_characteristic': 'debt_characteristics'
+      }
     }
   });