]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-5820/SONAR-5973/SONAR-6017 finish facets on languages, repositories, tags
authorStas Vilchik <vilchiks@gmail.com>
Wed, 21 Jan 2015 10:43:23 +0000 (11:43 +0100)
committerStas Vilchik <vilchiks@gmail.com>
Wed, 21 Jan 2015 11:03:30 +0000 (12:03 +0100)
server/sonar-web/src/main/hbs/coding-rules/facets/coding-rules-custom-values-facet.hbs [new file with mode: 0644]
server/sonar-web/src/main/js/coding-rules/facets-view.js
server/sonar-web/src/main/js/coding-rules/facets/custom-values-facet.js [new file with mode: 0644]
server/sonar-web/src/main/js/coding-rules/facets/language-facet.js
server/sonar-web/src/main/js/coding-rules/facets/repository-facet.js
server/sonar-web/src/main/js/coding-rules/facets/tag-facet.js [new file with mode: 0644]

diff --git a/server/sonar-web/src/main/hbs/coding-rules/facets/coding-rules-custom-values-facet.hbs b/server/sonar-web/src/main/hbs/coding-rules/facets/coding-rules-custom-values-facet.hbs
new file mode 100644 (file)
index 0000000..2d691b2
--- /dev/null
@@ -0,0 +1,14 @@
+{{> '_coding-rules-facet-header'}}
+
+<div class="search-navigator-facet-list">
+  {{#each values}}
+    <a class="facet search-navigator-facet js-facet" data-value="{{val}}" title="{{default label val}}">
+      <span class="facet-name">{{default label val}}{{#if extra}} <span class="subtitle">{{extra}}</span>{{/if}}</span>
+      <span class="facet-stat">{{numberShort count}}</span>
+    </a>
+  {{/each}}
+
+  <div class="search-navigator-facet-custom-value">
+    <input type="hidden" class="js-custom-value">
+  </div>
+</div>
index c10b7e0c5a540e9d6b98cead060fcce6cd3eb83a..7be7ccb8155866255a4d5c13396563998ac32c22 100644 (file)
@@ -4,6 +4,7 @@ define([
       'coding-rules/facets/query-facet',
       'coding-rules/facets/language-facet',
       'coding-rules/facets/repository-facet',
+      'coding-rules/facets/tag-facet',
       'coding-rules/facets/quality-profile-facet',
       'coding-rules/facets/characteristic-facet',
       'coding-rules/facets/severity-facet',
@@ -18,6 +19,7 @@ define([
               QueryFacet,
               LanguageFacet,
               RepositoryFacet,
+              TagFacet,
               QualityProfileFacet,
               CharacteristicFacet,
               SeverityFacet,
@@ -31,6 +33,7 @@ define([
         q: QueryFacet,
         languages: LanguageFacet,
         repositories: RepositoryFacet,
+        tags: TagFacet,
         qprofile: QualityProfileFacet,
         debt_characteristics: CharacteristicFacet,
         severities: SeverityFacet,
diff --git a/server/sonar-web/src/main/js/coding-rules/facets/custom-values-facet.js b/server/sonar-web/src/main/js/coding-rules/facets/custom-values-facet.js
new file mode 100644 (file)
index 0000000..60fe7ed
--- /dev/null
@@ -0,0 +1,70 @@
+define([
+    'coding-rules/facets/base-facet',
+    'templates/coding-rules'
+], function (BaseFacet) {
+
+  return BaseFacet.extend({
+    template: Templates['coding-rules-custom-values-facet'],
+
+    events: function () {
+      return _.extend(BaseFacet.prototype.events.apply(this, arguments), {
+        'change .js-custom-value': 'addCustomValue'
+      });
+    },
+
+    getUrl: function () {
+      return baseUrl;
+    },
+
+    onRender: function () {
+      BaseFacet.prototype.onRender.apply(this, arguments);
+      this.prepareSearch();
+    },
+
+    prepareSearch: function () {
+      this.$('.js-custom-value').select2({
+        placeholder: t('search_verb'),
+        minimumInputLength: 2,
+        allowClear: false,
+        formatNoMatches: function () {
+          return t('select2.noMatches');
+        },
+        formatSearching: function () {
+          return t('select2.searching');
+        },
+        formatInputTooShort: function () {
+          return tp('select2.tooShort', 2);
+        },
+        width: '100%',
+        ajax: this.prepareAjaxSearch()
+      });
+    },
+
+    prepareAjaxSearch: function () {
+      return {
+        quietMillis: 300,
+        url: this.getUrl(),
+        data: function (term, page) {
+          return { s: term, p: page };
+        },
+        results: function (data) {
+          return { more: data.more, results: data.results };
+        }
+      };
+    },
+
+    addCustomValue: function () {
+      var property = this.model.get('property'),
+          customValue = this.$('.js-custom-value').select2('val'),
+          value = this.getValue();
+      if (value.length > 0) {
+        value += ',';
+      }
+      value += customValue;
+      var obj = {};
+      obj[property] = value;
+      this.options.app.state.updateFilter(obj);
+    }
+  });
+
+});
index 6a89c42d93acdf1f4ba855322d5fb379bee5d5f4..494ecad0432cb0d5e81ae69959514e9bc158bae2 100644 (file)
@@ -1,11 +1,49 @@
 define([
-  'coding-rules/facets/custom-labels-facet'
-], function (CustomLabelsFacet) {
+  'coding-rules/facets/custom-values-facet'
+], function (CustomValuesFacet) {
 
-  return CustomLabelsFacet.extend({
+  return CustomValuesFacet.extend({
+
+    getUrl: function () {
+      return baseUrl + '/api/languages/list';
+    },
+
+    prepareAjaxSearch: function () {
+      return {
+        quietMillis: 300,
+        url: this.getUrl(),
+        data: function (term) {
+          return { q: term, ps: 10000 };
+        },
+        results: function (data) {
+          return {
+            more: false,
+            results: data.languages.map(function (lang) {
+              return { id: lang.key, text: lang.name };
+            })
+          };
+        }
+      };
+    },
 
     getLabelsSource: function () {
       return this.options.app.languages;
+    },
+
+    getValues: function () {
+      var that = this,
+          labels = that.getLabelsSource();
+      return this.model.getValues().map(function (item) {
+        return _.extend(item, {
+          label: labels[item.val]
+        });
+      });
+    },
+
+    serializeData: function () {
+      return _.extend(CustomValuesFacet.prototype.serializeData.apply(this, arguments), {
+        values: this.getValues()
+      });
     }
 
   });
index 5bf8361f6e100f5add8adf536906d820f9e76719..a2ec4fdb78148ef3bbfb6fb3112e816d7603d6e1 100644 (file)
@@ -1,8 +1,30 @@
 define([
-  'coding-rules/facets/custom-labels-facet'
-], function (CustomLabelsFacet) {
+  'coding-rules/facets/custom-values-facet'
+], function (CustomValuesFacet) {
 
-  return CustomLabelsFacet.extend({
+  return CustomValuesFacet.extend({
+
+    getUrl: function () {
+      return baseUrl + '/api/rules/repositories';
+    },
+
+    prepareAjaxSearch: function () {
+      return {
+        quietMillis: 300,
+        url: this.getUrl(),
+        data: function (term) {
+          return { q: term, ps: 10000 };
+        },
+        results: function (data) {
+          return {
+            more: false,
+            results: data.repositories.map(function (repo) {
+              return { id: repo.key, text: repo.name + ' (' + repo.language + ')' };
+            })
+          };
+        }
+      };
+    },
 
     getLabelsSource: function () {
       var repos = this.options.app.repositories;
@@ -11,14 +33,20 @@ define([
 
     getValues: function () {
       var that = this,
-          values = CustomLabelsFacet.prototype.getValues.apply(this, arguments);
-      return values.map(function (value) {
+          labels = that.getLabelsSource();
+      return this.model.getValues().map(function (value) {
         var repo = _.findWhere(that.options.app.repositories, { key: value.val });
         if (repo != null) {
           var langName = that.options.app.languages[repo.language];
           _.extend(value, { extra: langName });
         }
-        return value;
+        return _.extend(value, { label: labels[value.val] });
+      });
+    },
+
+    serializeData: function () {
+      return _.extend(CustomValuesFacet.prototype.serializeData.apply(this, arguments), {
+        values: this.getValues()
       });
     }
 
diff --git a/server/sonar-web/src/main/js/coding-rules/facets/tag-facet.js b/server/sonar-web/src/main/js/coding-rules/facets/tag-facet.js
new file mode 100644 (file)
index 0000000..250edbb
--- /dev/null
@@ -0,0 +1,31 @@
+define([
+  'coding-rules/facets/custom-values-facet'
+], function (CustomValuesFacet) {
+
+  return CustomValuesFacet.extend({
+
+    getUrl: function () {
+      return baseUrl + '/api/rules/tags';
+    },
+
+    prepareAjaxSearch: function () {
+      return {
+        quietMillis: 300,
+        url: this.getUrl(),
+        data: function (term) {
+          return { q: term, ps: 10000 };
+        },
+        results: function (data) {
+          return {
+            more: false,
+            results: data.tags.map(function (tag) {
+              return { id: tag, text: tag };
+            })
+          };
+        }
+      };
+    }
+
+  });
+
+});