From 281956944bdabadcd453b4e2d422a6bfde03bea3 Mon Sep 17 00:00:00 2001 From: Stas Vilchik Date: Mon, 19 Jan 2015 13:37:12 +0100 Subject: [PATCH] SONAR-5820/SONAR-6019 add severities, status and characteristic facet --- .../src/main/js/coding-rules/controller.js | 2 +- .../facets/characteristic-facet.js | 22 +++++++++++++------ .../js/coding-rules/facets/severity-facet.js | 12 ---------- .../js/coding-rules/facets/status-facet.js | 17 +++++++++----- .../resources/org/sonar/l10n/core.properties | 1 + 5 files changed, 29 insertions(+), 25 deletions(-) diff --git a/server/sonar-web/src/main/js/coding-rules/controller.js b/server/sonar-web/src/main/js/coding-rules/controller.js index 1819c98c5a3..168fece4780 100644 --- a/server/sonar-web/src/main/js/coding-rules/controller.js +++ b/server/sonar-web/src/main/js/coding-rules/controller.js @@ -9,7 +9,7 @@ define([ return Controller.extend({ allFacets: ['q', 'languages', 'repositories', 'tags', 'qprofile', 'debt_characteristics', 'severities', 'statuses', 'available_since', 'inheritance', 'active_severities', 'is_template'], - facetsFromServer: ['languages', 'repositories', 'tags'], + facetsFromServer: ['languages', 'repositories', 'tags', 'severities', 'statuses', 'debt_characteristics'], pageSize: 200, ruleFields: ['name', 'lang', 'langName', 'sysTags', 'tags', 'status'], diff --git a/server/sonar-web/src/main/js/coding-rules/facets/characteristic-facet.js b/server/sonar-web/src/main/js/coding-rules/facets/characteristic-facet.js index f0ba53566bc..256db1fa3d8 100644 --- a/server/sonar-web/src/main/js/coding-rules/facets/characteristic-facet.js +++ b/server/sonar-web/src/main/js/coding-rules/facets/characteristic-facet.js @@ -7,13 +7,21 @@ define([ return BaseFacet.extend({ getValues: function () { - var values = _.map(this.options.app.characteristics, function (value, key) { - return { - label: value, - val: key - }; + var values = this.model.getValues(), + characteristics = this.options.app.characteristics; + return values.map(function (value) { + var label = characteristics[value.val]; + if (value.val === 'NONE') { + label = t('coding_rules.noncharacterized'); + } + return _.extend(value, { label: label }); + }); + }, + + sortValues: function (values) { + return _.sortBy(values, function (v) { + return v.val === 'NONE' ? -999999 : -v.count; }); - return _.sortBy(values, 'label'); }, toggleFacet: function (e) { @@ -29,7 +37,7 @@ define([ serializeData: function () { return _.extend(BaseFacet.prototype.serializeData.apply(this, arguments), { - values: this.getValues() + values: this.sortValues(this.getValues()) }); } }); diff --git a/server/sonar-web/src/main/js/coding-rules/facets/severity-facet.js b/server/sonar-web/src/main/js/coding-rules/facets/severity-facet.js index 360d5677fa9..cf466543361 100644 --- a/server/sonar-web/src/main/js/coding-rules/facets/severity-facet.js +++ b/server/sonar-web/src/main/js/coding-rules/facets/severity-facet.js @@ -12,18 +12,6 @@ define([ return _.sortBy(values, function (v) { return order.indexOf(v.val); }); - }, - - getValues: function () { - return this.severities.map(function (s) { - return { val: s }; - }); - }, - - serializeData: function () { - return _.extend(BaseFacet.prototype.serializeData.apply(this, arguments), { - values: this.sortValues(this.getValues()) - }); } }); diff --git a/server/sonar-web/src/main/js/coding-rules/facets/status-facet.js b/server/sonar-web/src/main/js/coding-rules/facets/status-facet.js index 3429f1a5147..967e2f90946 100644 --- a/server/sonar-web/src/main/js/coding-rules/facets/status-facet.js +++ b/server/sonar-web/src/main/js/coding-rules/facets/status-facet.js @@ -3,13 +3,20 @@ define([ ], function (BaseFacet) { return BaseFacet.extend({ + statuses: ['READY', 'DEPRECATED', 'BETA'], getValues: function () { - return ['BETA', 'DEPRECATED', 'READY'].map(function (s) { - return { - label: t('rules.status', s.toLowerCase()), - val: s - }; + var values = this.model.getValues(); + var x = values.map(function (value) { + return _.extend(value, { label: t('rules.status', value.val.toLowerCase()) }); + }); + return x; + }, + + sortValues: function (values) { + var order = this.statuses; + return _.sortBy(values, function (v) { + return order.indexOf(v.val); }); }, diff --git a/sonar-core/src/main/resources/org/sonar/l10n/core.properties b/sonar-core/src/main/resources/org/sonar/l10n/core.properties index 6d654dfcde5..9b39bc3135a 100644 --- a/sonar-core/src/main/resources/org/sonar/l10n/core.properties +++ b/sonar-core/src/main/resources/org/sonar/l10n/core.properties @@ -1831,6 +1831,7 @@ coding_rules.rule_template.title=This rule can be used as a template to create c coding_rules._rules=rules coding_rules.select_tag=Select Tag coding_rules.show_template=Show Template +coding_rules.noncharacterized=Noncharacterized coding_rules.update_custom_rule=Update Custom Rule coding_rules.update_manual_rule=Update Manual Rule -- 2.39.5