--- /dev/null
+{{> '_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>
'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',
QueryFacet,
LanguageFacet,
RepositoryFacet,
+ TagFacet,
QualityProfileFacet,
CharacteristicFacet,
SeverityFacet,
q: QueryFacet,
languages: LanguageFacet,
repositories: RepositoryFacet,
+ tags: TagFacet,
qprofile: QualityProfileFacet,
debt_characteristics: CharacteristicFacet,
severities: SeverityFacet,
--- /dev/null
+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);
+ }
+ });
+
+});
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()
+ });
}
});
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;
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()
});
}
--- /dev/null
+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 };
+ })
+ };
+ }
+ };
+ }
+
+ });
+
+});